@aws/nx-plugin 1.0.0-rc.36 → 1.0.0-rc.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/generators.json +7 -0
  2. package/package.json +1 -1
  3. package/src/init/generator.d.ts +18 -0
  4. package/src/init/generator.js +35 -0
  5. package/src/init/generator.js.map +1 -0
  6. package/src/init/schema.d.js +6 -0
  7. package/src/init/schema.d.js.map +1 -0
  8. package/src/init/schema.d.ts +16 -0
  9. package/src/init/schema.json +35 -0
  10. package/src/mcp-server/generator-info.js +27 -13
  11. package/src/mcp-server/generator-info.js.map +1 -1
  12. package/src/mcp-server/guide-pipeline.js +16 -1
  13. package/src/mcp-server/guide-pipeline.js.map +1 -1
  14. package/src/mcp-server/server.js +2 -0
  15. package/src/mcp-server/server.js.map +1 -1
  16. package/src/mcp-server/tools/add-to-existing-project.d.ts +12 -0
  17. package/src/mcp-server/tools/add-to-existing-project.js +36 -0
  18. package/src/mcp-server/tools/add-to-existing-project.js.map +1 -0
  19. package/src/mcp-server/tools/general-guidance.d.ts +1 -1
  20. package/src/mcp-server/tools/general-guidance.js +1 -0
  21. package/src/mcp-server/tools/general-guidance.js.map +1 -1
  22. package/src/preset/__snapshots__/generator.spec.ts.snap +3 -0
  23. package/src/preset/generator.js +19 -129
  24. package/src/preset/generator.js.map +1 -1
  25. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +19 -3
  26. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +2 -2
  27. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +17 -1
  28. package/src/py/agent/files/http/main.py.template +2 -2
  29. package/src/py/agent/files/http-langchain/main.py.template +2 -2
  30. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +35 -2
  31. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +38 -6
  32. package/src/ts/agent/files/http/router.ts.template +2 -2
  33. package/src/ts/lib/ts-project-utils.js +0 -7
  34. package/src/ts/lib/ts-project-utils.js.map +1 -1
  35. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +35 -2
  36. package/src/utils/agent-chat/files/http-py/chat.ts.template +1 -1
  37. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  38. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +24 -1
  39. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +5 -0
  40. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +12 -1
  41. package/src/utils/base-tsconfig.d.ts +30 -0
  42. package/src/utils/base-tsconfig.js +32 -0
  43. package/src/utils/base-tsconfig.js.map +1 -0
  44. package/src/utils/commands.d.ts +9 -2
  45. package/src/utils/commands.js +19 -9
  46. package/src/utils/commands.js.map +1 -1
  47. package/src/utils/init.d.ts +53 -0
  48. package/src/utils/init.js +251 -0
  49. package/src/utils/init.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/mcp-server/tools/add-to-existing-project.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { NxGeneratorInfo } from '../../utils/generators';\nimport { fetchGuidePages } from '../generator-info';\nimport { PackageManagerSchema } from '../schema';\n\n/**\n * The guide page (under `get_started/`) that backs this tool, so the tool and\n * the published docs never drift.\n */\nconst EXISTING_PROJECT_GUIDE = 'existing-project';\n\n/**\n * Add a tool which guides an agent through adding @aws/nx-plugin to an\n * existing Nx or non-Nx workspace. Returns the `existing-project` docs page,\n * which includes the full adoption steps and troubleshooting reference.\n */\nexport const addToExistingProjectTool = (\n server: McpServer,\n generators: NxGeneratorInfo[],\n) => {\n server.registerTool(\n 'add-to-existing-project',\n {\n title: 'Add to Existing Project',\n description:\n 'Tool for adding the Nx Plugin for AWS to an existing Nx workspace or non-Nx monorepo. Use this when a user wants to adopt @aws/nx-plugin in a project that was not created with the plugin preset, or hits configuration errors when running generators in such a workspace.',\n inputSchema: {\n packageManager: PackageManagerSchema.optional(),\n },\n },\n async ({ packageManager }) => {\n const guide = await fetchGuidePages(\n [EXISTING_PROJECT_GUIDE],\n generators,\n packageManager,\n );\n return {\n content: [\n {\n type: 'text' as const,\n text: guide,\n },\n ],\n };\n },\n );\n};\n"],"names":["fetchGuidePages","PackageManagerSchema","EXISTING_PROJECT_GUIDE","addToExistingProjectTool","server","generators","registerTool","title","description","inputSchema","packageManager","optional","guide","content","type","text"],"mappings":"AAAA;;;CAGC,GAGD,SAASA,eAAe,QAAQ,uBAAoB;AACpD,SAASC,oBAAoB,QAAQ,eAAY;AAEjD;;;CAGC,GACD,MAAMC,yBAAyB;AAE/B;;;;CAIC,GACD,OAAO,MAAMC,2BAA2B,CACtCC,QACAC;IAEAD,OAAOE,YAAY,CACjB,2BACA;QACEC,OAAO;QACPC,aACE;QACFC,aAAa;YACXC,gBAAgBT,qBAAqBU,QAAQ;QAC/C;IACF,GACA,OAAO,EAAED,cAAc,EAAE;QACvB,MAAME,QAAQ,MAAMZ,gBAClB;YAACE;SAAuB,EACxBG,YACAK;QAEF,OAAO;YACLG,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAMH;gBACR;aACD;QACH;IACF;AAEJ,EAAE"}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
6
  import type { NxGeneratorInfo } from '../../utils/generators';
7
- export declare const TOOL_SELECTION_GUIDE = "## Tool Selection Guide\n\n- Use the `general-guidance` tool for guidance and best practices for working with Nx and the Nx Plugin for AWS.\n- Use the `create-workspace-command` tool to discover how to create a workspace to start a new project.\n- Use the `list-generators` tool to discover the available generators and how to run them.\n- Use the `generator-guide` tool to retrieve detailed information about a specific generator.";
7
+ export declare const TOOL_SELECTION_GUIDE = "## Tool Selection Guide\n\n- Use the `general-guidance` tool for guidance and best practices for working with Nx and the Nx Plugin for AWS.\n- Use the `create-workspace-command` tool to discover how to create a workspace to start a new project.\n- Use the `add-to-existing-project` tool when adding the plugin to an existing Nx workspace or non-Nx monorepo, or when troubleshooting configuration errors in such a workspace.\n- Use the `list-generators` tool to discover the available generators and how to run them.\n- Use the `generator-guide` tool to retrieve detailed information about a specific generator.";
8
8
  /**
9
9
  * Add a tool which provides general guidance for using Nx and the Nx Plugin for AWS
10
10
  */
@@ -8,6 +8,7 @@ export const TOOL_SELECTION_GUIDE = `## Tool Selection Guide
8
8
 
9
9
  - Use the \`general-guidance\` tool for guidance and best practices for working with Nx and the Nx Plugin for AWS.
10
10
  - Use the \`create-workspace-command\` tool to discover how to create a workspace to start a new project.
11
+ - Use the \`add-to-existing-project\` tool when adding the plugin to an existing Nx workspace or non-Nx monorepo, or when troubleshooting configuration errors in such a workspace.
11
12
  - Use the \`list-generators\` tool to discover the available generators and how to run them.
12
13
  - Use the \`generator-guide\` tool to retrieve detailed information about a specific generator.`;
13
14
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/mcp-server/tools/general-guidance.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { NxGeneratorInfo } from '../../utils/generators';\nimport { IAC_PROVIDERS } from '../../utils/iac-providers';\nimport { buildNxCommand, fetchGuidePages } from '../generator-info';\nimport { PACKAGE_MANAGERS } from '../schema';\n\nexport const TOOL_SELECTION_GUIDE = `## Tool Selection Guide\n\n- Use the \\`general-guidance\\` tool for guidance and best practices for working with Nx and the Nx Plugin for AWS.\n- Use the \\`create-workspace-command\\` tool to discover how to create a workspace to start a new project.\n- Use the \\`list-generators\\` tool to discover the available generators and how to run them.\n- Use the \\`generator-guide\\` tool to retrieve detailed information about a specific generator.`;\n\n/**\n * Add a tool which provides general guidance for using Nx and the Nx Plugin for AWS\n */\nexport const addGeneralGuidanceTool = (\n server: McpServer,\n generators: NxGeneratorInfo[],\n) => {\n server.registerTool(\n 'general-guidance',\n {\n title: 'General Guidance',\n description:\n 'Tool for guidance and best practices for working with Nx and the Nx Plugin for AWS',\n },\n async () => ({\n content: [\n {\n type: 'text' as const,\n text: `# Nx Plugin for AWS Guidance\n\n${TOOL_SELECTION_GUIDE}\n\n## Getting Started\n\n- Choose a package manager first. You can choose between ${PACKAGE_MANAGERS.join(', ')}. It's recommended to use \"pnpm\" if the user has no preference\n- Choose an infrastructure as code (IaC) provider next. You can choose between ${IAC_PROVIDERS.join(', ')}. It's recommended to use CDK if the user has no preference\n- Next, you must create an Nx workspace. Use the \\`create-workspace-command\\` tool for more details, and provide it with your chosen package manager\n- After this, you can start scaffolding the main components of your application using generators. Use the \\`list-generators\\` tool to discover available generators, and the \\`generator-guide\\` tool for more detailed information about a specific generator\n\n## Nx Primer\n\n- Prefix nx commands with the appropriate prefix for your package manager, for example:\n${PACKAGE_MANAGERS.map((pm) => buildNxCommand('<options>', pm)).join(' - \\n')}\n- Each project in your workspace has a file named \\`project.json\\` which contains important project information such as its name, and defines the \"targets\" which can be run for that project, for example building or testing the project\n- Use the command \\`nx reset\\` to reset the Nx daemon when unexpected issues arise\n- After adding dependencies between TypeScript projects, use \\`nx sync\\` to ensure project references are set up correctly\n\n## General Instructions\n\n- Workspaces contain a single \\`package.json\\` file at the root which defines the dependencies for all projects. Therefore when installing dependencies, you must add these to the root workspace using the appropriate command for your package manager:\n - pnpm add -w -D <package>\n - yarn add -D <package>\n - npm install --legacy-peer-deps -D <package>\n - bun install -D <package>\n - (Omit -D for production dependencies)\n- When specifying project names as arguments to generators, prefer the _fully qualified_ project name, for example \\`@workspace-name/project-name\\`. Check the \\`project.json\\` file for the specific package to find its fully qualified name\n- When no generator exists for a specific framework required, use the base \\`ts#project\\` and \\`py#project\\` generators and build on top.\n- Leave the \\`--infra\\` option at its default value unless the user has explicitly instructed otherwise. Generators choose a sensible default type of infrastructure to deploy the project with, so only override \\`--infra\\` when the user has specified a particular requirement.\n\n## Useful Commands\n\n- Fix lint issues with \\`nx run-many --target lint --configuration=fix --all --output-style=stream\\`\n- Build all projects with \\`nx run-many --target build --all --output-style=stream\\`\n- Prefer importing the CDK constructs vended by generators in \\`packages/common/constructs\\` over writing your own\n\n## Best Practices\n\n- After running a generator, use the \\`nx show projects\\` command to check which projects have been added (if any)\n- Carefully examine the files that have been generated and always refer back to the generator guide when working in a generated project\n- Generate all projects into the \\`packages/\\` directory\n- After making changes to your projects, fix linting issues, then run a full build\n- When it's time to start testing a project, suggest to the user that infrastructure is deployed to AWS. For websites, if a runtime-config.json is needed, use the load:runtime-config target after a deployment to point a local website at a sandbox stack.\n\n## Batching Generators\n\nWhen scaffolding several projects in one go, chain generators to avoid a slow dependency install after every generator:\n\n- **Chain generators** with \\`&&\\` in a single command. Pass \\`--prefer-install-dependencies=false\\` on each generator except the last so dependencies install once at the end, for example:\n\n${PACKAGE_MANAGERS.map(\n (pm) => ` \\`\\`\\`bash\n ${buildNxCommand('g @aws/nx-plugin:ts#trpc-api --no-interactive --name=my-app-api --auth=IAM --prefer-install-dependencies=false', pm)} && \\\\\n ${buildNxCommand('g @aws/nx-plugin:ts#react-website --no-interactive --name=my-app-website --prefer-install-dependencies=false', pm)} && \\\\\n ${buildNxCommand('g @aws/nx-plugin:connection --no-interactive --sourceProject=@my-app/my-app-website --targetProject=@my-app/my-app-api --prefer-install-dependencies=false', pm)} && \\\\\n ${buildNxCommand('g @aws/nx-plugin:ts#infra --no-interactive --name=infra', pm)} && \\\\\n ${buildNxCommand('sync', pm)}\n \\`\\`\\``,\n).join('\\n')}\n\n- **\\`--prefer-install-dependencies=false\\`** asks a generator to defer its dependency install so the batch installs once at the end (the final generator above omits the flag and installs everything).\n- **\\`nx sync\\`** is required before building — generators modify TypeScript project references.\n\n## Detailed Guides\n\nPlease refer to the below documentation for important details regarding workspaces and working with TypeScript or Python projects.\n\n${await fetchGuidePages(['workspace', 'typescript-project', 'python-project'], generators)}\n\n `,\n },\n ],\n }),\n );\n};\n"],"names":["IAC_PROVIDERS","buildNxCommand","fetchGuidePages","PACKAGE_MANAGERS","TOOL_SELECTION_GUIDE","addGeneralGuidanceTool","server","generators","registerTool","title","description","content","type","text","join","map","pm"],"mappings":"AAAA;;;CAGC,GAGD,SAASA,aAAa,QAAQ,+BAA4B;AAC1D,SAASC,cAAc,EAAEC,eAAe,QAAQ,uBAAoB;AACpE,SAASC,gBAAgB,QAAQ,eAAY;AAE7C,OAAO,MAAMC,uBAAuB,CAAC;;;;;+FAK0D,CAAC,CAAC;AAEjG;;CAEC,GACD,OAAO,MAAMC,yBAAyB,CACpCC,QACAC;IAEAD,OAAOE,YAAY,CACjB,oBACA;QACEC,OAAO;QACPC,aACE;IACJ,GACA,UAAa,CAAA;YACXC,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC;;AAEjB,EAAET,qBAAqB;;;;yDAIkC,EAAED,iBAAiBW,IAAI,CAAC,MAAM;+EACR,EAAEd,cAAcc,IAAI,CAAC,MAAM;;;;;;;AAO1G,EAAEX,iBAAiBY,GAAG,CAAC,CAACC,KAAOf,eAAe,aAAae,KAAKF,IAAI,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqC9E,EAAEX,iBAAiBY,GAAG,CACpB,CAACC,KAAO,CAAC;EACT,EAAEf,eAAe,kHAAkHe,IAAI;IACrI,EAAEf,eAAe,gHAAgHe,IAAI;IACrI,EAAEf,eAAe,8JAA8Je,IAAI;IACnL,EAAEf,eAAe,2DAA2De,IAAI;IAChF,EAAEf,eAAe,QAAQe,IAAI;QACzB,CAAC,EACPF,IAAI,CAAC,MAAM;;;;;;;;;AASb,EAAE,MAAMZ,gBAAgB;wBAAC;wBAAa;wBAAsB;qBAAiB,EAAEK,YAAY;;IAEvF,CAAC;gBACG;aACD;QACH,CAAA;AAEJ,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/mcp-server/tools/general-guidance.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { NxGeneratorInfo } from '../../utils/generators';\nimport { IAC_PROVIDERS } from '../../utils/iac-providers';\nimport { buildNxCommand, fetchGuidePages } from '../generator-info';\nimport { PACKAGE_MANAGERS } from '../schema';\n\nexport const TOOL_SELECTION_GUIDE = `## Tool Selection Guide\n\n- Use the \\`general-guidance\\` tool for guidance and best practices for working with Nx and the Nx Plugin for AWS.\n- Use the \\`create-workspace-command\\` tool to discover how to create a workspace to start a new project.\n- Use the \\`add-to-existing-project\\` tool when adding the plugin to an existing Nx workspace or non-Nx monorepo, or when troubleshooting configuration errors in such a workspace.\n- Use the \\`list-generators\\` tool to discover the available generators and how to run them.\n- Use the \\`generator-guide\\` tool to retrieve detailed information about a specific generator.`;\n\n/**\n * Add a tool which provides general guidance for using Nx and the Nx Plugin for AWS\n */\nexport const addGeneralGuidanceTool = (\n server: McpServer,\n generators: NxGeneratorInfo[],\n) => {\n server.registerTool(\n 'general-guidance',\n {\n title: 'General Guidance',\n description:\n 'Tool for guidance and best practices for working with Nx and the Nx Plugin for AWS',\n },\n async () => ({\n content: [\n {\n type: 'text' as const,\n text: `# Nx Plugin for AWS Guidance\n\n${TOOL_SELECTION_GUIDE}\n\n## Getting Started\n\n- Choose a package manager first. You can choose between ${PACKAGE_MANAGERS.join(', ')}. It's recommended to use \"pnpm\" if the user has no preference\n- Choose an infrastructure as code (IaC) provider next. You can choose between ${IAC_PROVIDERS.join(', ')}. It's recommended to use CDK if the user has no preference\n- Next, you must create an Nx workspace. Use the \\`create-workspace-command\\` tool for more details, and provide it with your chosen package manager\n- After this, you can start scaffolding the main components of your application using generators. Use the \\`list-generators\\` tool to discover available generators, and the \\`generator-guide\\` tool for more detailed information about a specific generator\n\n## Nx Primer\n\n- Prefix nx commands with the appropriate prefix for your package manager, for example:\n${PACKAGE_MANAGERS.map((pm) => buildNxCommand('<options>', pm)).join(' - \\n')}\n- Each project in your workspace has a file named \\`project.json\\` which contains important project information such as its name, and defines the \"targets\" which can be run for that project, for example building or testing the project\n- Use the command \\`nx reset\\` to reset the Nx daemon when unexpected issues arise\n- After adding dependencies between TypeScript projects, use \\`nx sync\\` to ensure project references are set up correctly\n\n## General Instructions\n\n- Workspaces contain a single \\`package.json\\` file at the root which defines the dependencies for all projects. Therefore when installing dependencies, you must add these to the root workspace using the appropriate command for your package manager:\n - pnpm add -w -D <package>\n - yarn add -D <package>\n - npm install --legacy-peer-deps -D <package>\n - bun install -D <package>\n - (Omit -D for production dependencies)\n- When specifying project names as arguments to generators, prefer the _fully qualified_ project name, for example \\`@workspace-name/project-name\\`. Check the \\`project.json\\` file for the specific package to find its fully qualified name\n- When no generator exists for a specific framework required, use the base \\`ts#project\\` and \\`py#project\\` generators and build on top.\n- Leave the \\`--infra\\` option at its default value unless the user has explicitly instructed otherwise. Generators choose a sensible default type of infrastructure to deploy the project with, so only override \\`--infra\\` when the user has specified a particular requirement.\n\n## Useful Commands\n\n- Fix lint issues with \\`nx run-many --target lint --configuration=fix --all --output-style=stream\\`\n- Build all projects with \\`nx run-many --target build --all --output-style=stream\\`\n- Prefer importing the CDK constructs vended by generators in \\`packages/common/constructs\\` over writing your own\n\n## Best Practices\n\n- After running a generator, use the \\`nx show projects\\` command to check which projects have been added (if any)\n- Carefully examine the files that have been generated and always refer back to the generator guide when working in a generated project\n- Generate all projects into the \\`packages/\\` directory\n- After making changes to your projects, fix linting issues, then run a full build\n- When it's time to start testing a project, suggest to the user that infrastructure is deployed to AWS. For websites, if a runtime-config.json is needed, use the load:runtime-config target after a deployment to point a local website at a sandbox stack.\n\n## Batching Generators\n\nWhen scaffolding several projects in one go, chain generators to avoid a slow dependency install after every generator:\n\n- **Chain generators** with \\`&&\\` in a single command. Pass \\`--prefer-install-dependencies=false\\` on each generator except the last so dependencies install once at the end, for example:\n\n${PACKAGE_MANAGERS.map(\n (pm) => ` \\`\\`\\`bash\n ${buildNxCommand('g @aws/nx-plugin:ts#trpc-api --no-interactive --name=my-app-api --auth=IAM --prefer-install-dependencies=false', pm)} && \\\\\n ${buildNxCommand('g @aws/nx-plugin:ts#react-website --no-interactive --name=my-app-website --prefer-install-dependencies=false', pm)} && \\\\\n ${buildNxCommand('g @aws/nx-plugin:connection --no-interactive --sourceProject=@my-app/my-app-website --targetProject=@my-app/my-app-api --prefer-install-dependencies=false', pm)} && \\\\\n ${buildNxCommand('g @aws/nx-plugin:ts#infra --no-interactive --name=infra', pm)} && \\\\\n ${buildNxCommand('sync', pm)}\n \\`\\`\\``,\n).join('\\n')}\n\n- **\\`--prefer-install-dependencies=false\\`** asks a generator to defer its dependency install so the batch installs once at the end (the final generator above omits the flag and installs everything).\n- **\\`nx sync\\`** is required before building — generators modify TypeScript project references.\n\n## Detailed Guides\n\nPlease refer to the below documentation for important details regarding workspaces and working with TypeScript or Python projects.\n\n${await fetchGuidePages(['workspace', 'typescript-project', 'python-project'], generators)}\n\n `,\n },\n ],\n }),\n );\n};\n"],"names":["IAC_PROVIDERS","buildNxCommand","fetchGuidePages","PACKAGE_MANAGERS","TOOL_SELECTION_GUIDE","addGeneralGuidanceTool","server","generators","registerTool","title","description","content","type","text","join","map","pm"],"mappings":"AAAA;;;CAGC,GAGD,SAASA,aAAa,QAAQ,+BAA4B;AAC1D,SAASC,cAAc,EAAEC,eAAe,QAAQ,uBAAoB;AACpE,SAASC,gBAAgB,QAAQ,eAAY;AAE7C,OAAO,MAAMC,uBAAuB,CAAC;;;;;;+FAM0D,CAAC,CAAC;AAEjG;;CAEC,GACD,OAAO,MAAMC,yBAAyB,CACpCC,QACAC;IAEAD,OAAOE,YAAY,CACjB,oBACA;QACEC,OAAO;QACPC,aACE;IACJ,GACA,UAAa,CAAA;YACXC,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC;;AAEjB,EAAET,qBAAqB;;;;yDAIkC,EAAED,iBAAiBW,IAAI,CAAC,MAAM;+EACR,EAAEd,cAAcc,IAAI,CAAC,MAAM;;;;;;;AAO1G,EAAEX,iBAAiBY,GAAG,CAAC,CAACC,KAAOf,eAAe,aAAae,KAAKF,IAAI,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqC9E,EAAEX,iBAAiBY,GAAG,CACpB,CAACC,KAAO,CAAC;EACT,EAAEf,eAAe,kHAAkHe,IAAI;IACrI,EAAEf,eAAe,gHAAgHe,IAAI;IACrI,EAAEf,eAAe,8JAA8Je,IAAI;IACnL,EAAEf,eAAe,2DAA2De,IAAI;IAChF,EAAEf,eAAe,QAAQe,IAAI;QACzB,CAAC,EACPF,IAAI,CAAC,MAAM;;;;;;;;;AASb,EAAE,MAAMZ,gBAAgB;wBAAC;wBAAa;wBAAsB;qBAAiB,EAAEK,YAAY;;IAEvF,CAAC;gBACG;aACD;QACH,CAAA;AAEJ,EAAE"}
@@ -90,6 +90,8 @@ Nx Console is an editor extension that enriches your developer experience. It le
90
90
  The following list of generators are what is currently available in the \`@aws/nx-plugin\`:
91
91
 
92
92
 
93
+ - **init**: Configure an existing Nx workspace to use the @aws/nx-plugin
94
+
93
95
  - **agentcore-gateway**: Generate an AgentCore Gateway project
94
96
 
95
97
  - **connection**: Integrates a source project with a target project
@@ -340,6 +342,7 @@ exports[`preset generator > should run successfully > package.json 1`] = `
340
342
  "@nx/js": "23.0.2",
341
343
  "@nx/workspace": "23.0.2",
342
344
  "@swc/helpers": "~0.5.18",
345
+ "nx": "23.0.2",
343
346
  "typescript": "6.0.3"
344
347
  },
345
348
  "type": "module",
@@ -1,61 +1,17 @@
1
1
  /**
2
2
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
- */ import { addDependenciesToPackageJson, detectPackageManager, generateFiles, joinPathFragments, OverwriteStrategy, readNxJson, updateJson, updateNxJson } from "@nx/devkit";
5
- import { initGenerator } from "@nx/js";
4
+ */ import { addDependenciesToPackageJson, joinPathFragments, OverwriteStrategy, updateJson } from "@nx/devkit";
6
5
  import { execSync } from "child_process";
7
6
  import enquirer from "enquirer";
8
7
  import { readFileSync } from "fs";
9
- import yaml from "js-yaml";
10
- import { readModulePackageJson } from "nx/src/utils/package-json";
11
- import GeneratorsJson from "../../generators.json" with {
12
- type: 'json'
13
- };
14
- import { SYNC_GENERATOR_NAME as TS_SYNC_GENERATOR_NAME } from "../ts/sync/generator.js";
15
8
  import { ensureAwsNxPluginConfig, updateAwsNxPluginConfig } from "../utils/config/utils.js";
16
- import { inferContainers } from "../utils/containers.js";
17
- import { DEFAULT_BIOME_CONFIG, formatFilesInSubtree } from "../utils/format.js";
9
+ import { formatFilesInSubtree } from "../utils/format.js";
10
+ import { applyWorkspaceInit } from "../utils/init.js";
18
11
  import { installDependencies } from "../utils/install.js";
19
- import { configureMcpServers } from "../utils/mcp.js";
20
- import { getNpmScope } from "../utils/npm-scope.js";
21
12
  import { getGeneratorInfo } from "../utils/nx.js";
22
- import { getPackageManagerDisplayCommands } from "../utils/pkg-manager.js";
23
13
  import { withVersions } from "../utils/versions.js";
24
- const WORKSPACES = [
25
- 'packages/*'
26
- ];
27
- const NX_TYPESCRIPT_SYNC_GENERATOR = '@nx/js:typescript-sync';
28
- // Built dependencies whose install scripts the generated workspace trusts.
29
- // `onlyBuiltDependencies` is the pnpm 10 key (silently ignored by pnpm 11);
30
- // pnpm 11 reads `allowBuilds` instead. Any dep NOT in this allowlist will
31
- // have its install scripts skipped with a warning — matching pnpm 10's
32
- // default behaviour. The user can opt-in later via `pnpm approve-builds`.
33
- const PNPM_BUILT_DEPENDENCIES = [
34
- '@swc/core',
35
- 'esbuild',
36
- 'nx',
37
- 'sharp'
38
- ];
39
14
  export const PRESET_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
40
- const setUpWorkspaces = (tree)=>{
41
- if (detectPackageManager() === 'pnpm') {
42
- tree.write('pnpm-workspace.yaml', yaml.dump({
43
- packages: WORKSPACES,
44
- allowBuilds: Object.fromEntries(PNPM_BUILT_DEPENDENCIES.map((dep)=>[
45
- dep,
46
- true
47
- ])),
48
- onlyBuiltDependencies: PNPM_BUILT_DEPENDENCIES
49
- }, {
50
- quotingType: "'"
51
- }));
52
- } else {
53
- updateJson(tree, 'package.json', (json)=>{
54
- json.workspaces = WORKSPACES;
55
- return json;
56
- });
57
- }
58
- };
59
15
  /**
60
16
  * Determines if the current user is an Amazon employee based on their git configuration.
61
17
  *
@@ -120,8 +76,6 @@ const setUpGitSecrets = (tree)=>{
120
76
  ]));
121
77
  };
122
78
  export const presetGenerator = async (tree, { iac, gitSecrets, mcp, containers, module, preferInstallDependencies })=>{
123
- const resolvedContainers = !containers || containers === 'infer' ? inferContainers() : containers;
124
- const esm = (module ?? 'esm') === 'esm';
125
79
  if (isAmazonian() && !process.env.VITEST && !process.env.CI && process.env.NX_DRY_RUN !== 'true' && process.env.NX_INTERACTIVE !== 'false') {
126
80
  const { engagementId } = await enquirer.prompt([
127
81
  {
@@ -140,93 +94,29 @@ export const presetGenerator = async (tree, { iac, gitSecrets, mcp, containers,
140
94
  });
141
95
  }
142
96
  }
143
- // Write IaC provider and container engine to plugin config
144
- await ensureAwsNxPluginConfig(tree);
145
- await updateAwsNxPluginConfig(tree, {
146
- iac: {
147
- provider: iac
148
- },
149
- containers: {
150
- engine: resolvedContainers
151
- }
152
- });
153
- await initGenerator(tree, {
154
- formatter: 'none',
155
- addTsPlugin: true
156
- });
157
- tree.delete('apps/.gitkeep');
158
- tree.delete('libs/.gitkeep');
159
- tree.write('packages/.gitkeep', '');
160
- setUpWorkspaces(tree);
161
- const nxJson = readNxJson(tree);
162
- updateNxJson(tree, {
163
- ...nxJson,
164
- analytics: false,
165
- targetDefaults: {
166
- ...nxJson.targetDefaults,
167
- compile: {
168
- ...nxJson.targetDefaults?.compile,
169
- syncGenerators: [
170
- ...(nxJson.targetDefaults?.compile?.syncGenerators ?? []).filter((g)=>![
171
- TS_SYNC_GENERATOR_NAME,
172
- NX_TYPESCRIPT_SYNC_GENERATOR
173
- ].includes(g)),
174
- NX_TYPESCRIPT_SYNC_GENERATOR,
175
- TS_SYNC_GENERATOR_NAME
176
- ]
177
- }
178
- }
179
- });
97
+ // The preset owns the greenfield workspace's module format: write the root
98
+ // `type` explicitly from the chosen `--module` so later generators can
99
+ // infer it. The `init` generator never touches an existing workspace's
100
+ // `type` field.
180
101
  updateJson(tree, 'package.json', (packageJson)=>({
181
102
  ...packageJson,
182
- // Written explicitly so later generators can infer the workspace's module
183
- // format from the root `type`.
184
- type: esm ? 'module' : 'commonjs',
185
- scripts: {
186
- ...packageJson.scripts,
187
- dev: 'nx run-many --target dev',
188
- build: 'nx run-many --target build',
189
- lint: 'nx run-many --target lint --configuration=fix',
190
- test: 'nx run-many --target test --all',
191
- 'build:skip-lint': 'nx run-many --target build --configuration=skip-lint',
192
- 'build:all': 'nx run-many --target build --all',
193
- 'affected:all': 'nx affected --target build'
194
- }
103
+ type: (module ?? 'esm') === 'esm' ? 'module' : 'commonjs'
195
104
  }));
196
- addDependenciesToPackageJson(tree, {}, {
197
- '@nx/workspace': readModulePackageJson('@nx/js').packageJson.version,
198
- ...withVersions([
199
- 'typescript',
200
- '@biomejs/biome'
201
- ])
202
- });
203
- // Write biome.json for formatting and linting
204
- if (!tree.exists('biome.json')) {
205
- tree.write('biome.json', JSON.stringify(DEFAULT_BIOME_CONFIG, null, 2));
206
- }
207
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), '.', {
208
- projectName: getNpmScope(tree),
209
- generators: Object.entries(GeneratorsJson.generators).filter(([_, v])=>!v['hidden']).map(([k, v])=>({
210
- name: k,
211
- description: v.description
212
- })),
213
- ...(()=>{
214
- const cmds = getPackageManagerDisplayCommands();
215
- return {
216
- pkgMgrCmd: cmds.exec,
217
- buildCmd: `${cmds.run} build`,
218
- lintCmd: `${cmds.run} lint`
219
- };
220
- })()
221
- }, {
222
- overwriteStrategy: OverwriteStrategy.Overwrite
105
+ // Apply the deterministic workspace configuration shared with the `init`
106
+ // generator. The preset owns the README of a greenfield workspace.
107
+ await applyWorkspaceInit(tree, {
108
+ iac,
109
+ containers,
110
+ mcp,
111
+ readmeOverwriteStrategy: OverwriteStrategy.Overwrite,
112
+ overwriteScripts: true
223
113
  });
114
+ tree.delete('apps/.gitkeep');
115
+ tree.delete('libs/.gitkeep');
116
+ tree.write('packages/.gitkeep', '');
224
117
  if (gitSecrets !== false) {
225
118
  setUpGitSecrets(tree);
226
119
  }
227
- if (mcp !== false) {
228
- configureMcpServers(tree);
229
- }
230
120
  await formatFilesInSubtree(tree);
231
121
  return ()=>installDependencies(tree, preferInstallDependencies, {
232
122
  languages: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/preset/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 detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readNxJson,\n type Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\nimport { initGenerator } from '@nx/js';\nimport { execSync } from 'child_process';\nimport enquirer from 'enquirer';\nimport { readFileSync } from 'fs';\nimport yaml from 'js-yaml';\nimport { readModulePackageJson } from 'nx/src/utils/package-json';\nimport GeneratorsJson from '../../generators.json' with { type: 'json' };\nimport { SYNC_GENERATOR_NAME as TS_SYNC_GENERATOR_NAME } from '../ts/sync/generator';\nimport {\n ensureAwsNxPluginConfig,\n updateAwsNxPluginConfig,\n} from '../utils/config/utils';\nimport { inferContainers } from '../utils/containers';\nimport { DEFAULT_BIOME_CONFIG, formatFilesInSubtree } from '../utils/format';\nimport { installDependencies } from '../utils/install';\nimport { configureMcpServers } from '../utils/mcp';\nimport { addGeneratorMetricsIfApplicable } from '../utils/metrics';\nimport { getNpmScope } from '../utils/npm-scope';\nimport { getGeneratorInfo, type NxGeneratorInfo } from '../utils/nx';\nimport { getPackageManagerDisplayCommands } from '../utils/pkg-manager';\nimport { withVersions } from '../utils/versions';\nimport type { PresetGeneratorSchema } from './schema';\n\nconst WORKSPACES = ['packages/*'];\nconst NX_TYPESCRIPT_SYNC_GENERATOR = '@nx/js:typescript-sync';\n\n// Built dependencies whose install scripts the generated workspace trusts.\n// `onlyBuiltDependencies` is the pnpm 10 key (silently ignored by pnpm 11);\n// pnpm 11 reads `allowBuilds` instead. Any dep NOT in this allowlist will\n// have its install scripts skipped with a warning — matching pnpm 10's\n// default behaviour. The user can opt-in later via `pnpm approve-builds`.\nconst PNPM_BUILT_DEPENDENCIES = ['@swc/core', 'esbuild', 'nx', 'sharp'];\n\nexport const PRESET_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst setUpWorkspaces = (tree: Tree) => {\n if (detectPackageManager() === 'pnpm') {\n tree.write(\n 'pnpm-workspace.yaml',\n yaml.dump(\n {\n packages: WORKSPACES,\n allowBuilds: Object.fromEntries(\n PNPM_BUILT_DEPENDENCIES.map((dep) => [dep, true]),\n ),\n onlyBuiltDependencies: PNPM_BUILT_DEPENDENCIES,\n },\n { quotingType: \"'\" },\n ),\n );\n } else {\n updateJson(tree, 'package.json', (json) => {\n json.workspaces = WORKSPACES;\n return json;\n });\n }\n};\n\n/**\n * Determines if the current user is an Amazon employee based on their git configuration.\n *\n * This function checks the git user email configuration to identify Amazon employees\n * by looking for email addresses with Amazon domains (e.g., @amazon.com, @amazon.co.uk).\n *\n * @returns {boolean} True if the user's git email has an Amazon domain, false otherwise\n *\n * @example\n * // Returns true for Amazon employee emails\n * // git config user.email = \"john.doe@amazon.com\"\n * isAmazonian(); // true\n *\n * @example\n * // Returns false for non-Amazon emails\n * // git config user.email = \"user@example.com\"\n * isAmazonian(); // false\n *\n * @example\n * // Returns false when git config is not available or throws an error\n * isAmazonian(); // false\n */\nexport function isAmazonian(): boolean {\n try {\n // Execute git command to retrieve the user's configured email address\n const gitEmail = execSync('git config user.email', {\n encoding: 'utf8',\n }).trim();\n\n // Return false if no email is configured\n if (!gitEmail) {\n return false;\n }\n\n // Split email address to extract domain part\n const emailParts = gitEmail.split('@');\n if (emailParts.length < 2) {\n return false;\n }\n\n // Extract domain and normalize to lowercase for comparison\n const domain = emailParts[1].toLowerCase();\n\n // Check if domain starts with 'amazon.' (covers amazon.com, amazon.co.uk, etc.)\n return domain.startsWith('amazon.');\n } catch (error) {\n // Return false if git command fails or any other error occurs\n // This handles cases where git is not installed or configured\n return false;\n }\n}\n\nconst setUpGitSecrets = (tree: Tree) => {\n const gitSecretsDir = joinPathFragments(\n import.meta.dirname,\n 'git-secrets-files',\n 'git-secrets-dir',\n );\n const huskyDir = joinPathFragments(\n import.meta.dirname,\n 'git-secrets-files',\n 'husky-dir',\n );\n\n tree.write(\n '.git-secrets/git-secrets',\n readFileSync(joinPathFragments(gitSecretsDir, 'git-secrets'), 'utf-8'),\n );\n tree.write(\n '.husky/pre-commit',\n readFileSync(joinPathFragments(huskyDir, 'pre-commit'), 'utf-8'),\n );\n tree.write('.gitallowed', '\\\\.git-secrets/git-secrets:\\n');\n\n updateJson(tree, 'package.json', (json) => ({\n ...json,\n scripts: {\n ...json.scripts,\n prepare: 'husky',\n },\n }));\n\n addDependenciesToPackageJson(tree, {}, withVersions(['husky']));\n};\n\nexport const presetGenerator = async (\n tree: Tree,\n {\n iac,\n gitSecrets,\n mcp,\n containers,\n module,\n preferInstallDependencies,\n }: PresetGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const resolvedContainers =\n !containers || containers === 'infer' ? inferContainers() : containers;\n const esm = (module ?? 'esm') === 'esm';\n if (\n isAmazonian() &&\n !process.env.VITEST &&\n !process.env.CI &&\n process.env.NX_DRY_RUN !== 'true' &&\n process.env.NX_INTERACTIVE !== 'false'\n ) {\n const { engagementId } = await enquirer.prompt<{ engagementId?: string }>([\n {\n name: 'engagementId',\n message: 'Please enter your engagementId (if known)',\n type: 'input',\n initial: 'None',\n },\n ]);\n\n if (engagementId != 'None') {\n await ensureAwsNxPluginConfig(tree);\n await updateAwsNxPluginConfig(tree, { tags: [engagementId] });\n }\n }\n\n // Write IaC provider and container engine to plugin config\n await ensureAwsNxPluginConfig(tree);\n await updateAwsNxPluginConfig(tree, {\n iac: { provider: iac },\n containers: { engine: resolvedContainers },\n });\n\n await initGenerator(tree, {\n formatter: 'none',\n addTsPlugin: true,\n });\n\n tree.delete('apps/.gitkeep');\n tree.delete('libs/.gitkeep');\n tree.write('packages/.gitkeep', '');\n\n setUpWorkspaces(tree);\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n analytics: false,\n targetDefaults: {\n ...nxJson.targetDefaults,\n compile: {\n ...nxJson.targetDefaults?.compile,\n syncGenerators: [\n ...(nxJson.targetDefaults?.compile?.syncGenerators ?? []).filter(\n (g) =>\n ![TS_SYNC_GENERATOR_NAME, NX_TYPESCRIPT_SYNC_GENERATOR].includes(\n g,\n ),\n ),\n NX_TYPESCRIPT_SYNC_GENERATOR,\n TS_SYNC_GENERATOR_NAME,\n ],\n },\n },\n });\n\n updateJson(tree, 'package.json', (packageJson) => ({\n ...packageJson,\n // Written explicitly so later generators can infer the workspace's module\n // format from the root `type`.\n type: esm ? 'module' : 'commonjs',\n scripts: {\n ...packageJson.scripts,\n dev: 'nx run-many --target dev',\n build: 'nx run-many --target build',\n lint: 'nx run-many --target lint --configuration=fix',\n test: 'nx run-many --target test --all',\n 'build:skip-lint': 'nx run-many --target build --configuration=skip-lint',\n 'build:all': 'nx run-many --target build --all',\n 'affected:all': 'nx affected --target build',\n },\n }));\n\n addDependenciesToPackageJson(\n tree,\n {},\n {\n '@nx/workspace': readModulePackageJson('@nx/js').packageJson.version,\n ...withVersions(['typescript', '@biomejs/biome']),\n },\n );\n\n // Write biome.json for formatting and linting\n if (!tree.exists('biome.json')) {\n tree.write('biome.json', JSON.stringify(DEFAULT_BIOME_CONFIG, null, 2));\n }\n\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files'),\n '.',\n {\n projectName: getNpmScope(tree),\n generators: Object.entries(GeneratorsJson.generators)\n .filter(([_, v]) => !v['hidden'])\n .map(([k, v]) => ({ name: k, description: v.description })),\n ...(() => {\n const cmds = getPackageManagerDisplayCommands();\n return {\n pkgMgrCmd: cmds.exec,\n buildCmd: `${cmds.run} build`,\n lintCmd: `${cmds.run} lint`,\n };\n })(),\n },\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n if (gitSecrets !== false) {\n setUpGitSecrets(tree);\n }\n\n if (mcp !== false) {\n configureMcpServers(tree);\n }\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default presetGenerator;\n"],"names":["addDependenciesToPackageJson","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readNxJson","updateJson","updateNxJson","initGenerator","execSync","enquirer","readFileSync","yaml","readModulePackageJson","GeneratorsJson","type","SYNC_GENERATOR_NAME","TS_SYNC_GENERATOR_NAME","ensureAwsNxPluginConfig","updateAwsNxPluginConfig","inferContainers","DEFAULT_BIOME_CONFIG","formatFilesInSubtree","installDependencies","configureMcpServers","getNpmScope","getGeneratorInfo","getPackageManagerDisplayCommands","withVersions","WORKSPACES","NX_TYPESCRIPT_SYNC_GENERATOR","PNPM_BUILT_DEPENDENCIES","PRESET_GENERATOR_INFO","filename","setUpWorkspaces","tree","write","dump","packages","allowBuilds","Object","fromEntries","map","dep","onlyBuiltDependencies","quotingType","json","workspaces","isAmazonian","gitEmail","encoding","trim","emailParts","split","length","domain","toLowerCase","startsWith","error","setUpGitSecrets","gitSecretsDir","dirname","huskyDir","scripts","prepare","presetGenerator","iac","gitSecrets","mcp","containers","module","preferInstallDependencies","resolvedContainers","esm","process","env","VITEST","CI","NX_DRY_RUN","NX_INTERACTIVE","engagementId","prompt","name","message","initial","tags","provider","engine","formatter","addTsPlugin","delete","nxJson","analytics","targetDefaults","compile","syncGenerators","filter","g","includes","packageJson","dev","build","lint","test","version","exists","JSON","stringify","projectName","generators","entries","_","v","k","description","cmds","pkgMgrCmd","exec","buildCmd","run","lintCmd","overwriteStrategy","Overwrite","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,UAAU,EAEVC,UAAU,EACVC,YAAY,QACP,aAAa;AACpB,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,cAAc,WAAW;AAChC,SAASC,YAAY,QAAQ,KAAK;AAClC,OAAOC,UAAU,UAAU;AAC3B,SAASC,qBAAqB,QAAQ,4BAA4B;AAClE,OAAOC,oBAAoB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACzE,SAASC,uBAAuBC,sBAAsB,QAAQ,0BAAuB;AACrF,SACEC,uBAAuB,EACvBC,uBAAuB,QAClB,2BAAwB;AAC/B,SAASC,eAAe,QAAQ,yBAAsB;AACtD,SAASC,oBAAoB,EAAEC,oBAAoB,QAAQ,qBAAkB;AAC7E,SAASC,mBAAmB,QAAQ,sBAAmB;AACvD,SAASC,mBAAmB,QAAQ,kBAAe;AAEnD,SAASC,WAAW,QAAQ,wBAAqB;AACjD,SAASC,gBAAgB,QAA8B,iBAAc;AACrE,SAASC,gCAAgC,QAAQ,0BAAuB;AACxE,SAASC,YAAY,QAAQ,uBAAoB;AAGjD,MAAMC,aAAa;IAAC;CAAa;AACjC,MAAMC,+BAA+B;AAErC,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,0EAA0E;AAC1E,MAAMC,0BAA0B;IAAC;IAAa;IAAW;IAAM;CA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AGC,aAAaF,EAAEE,WAAW;YAAC,CAAA;QAC1D,GAAG,AAAC,CAAA;YACF,MAAMC,OAAOxF;YACb,OAAO;gBACLyF,WAAWD,KAAKE,IAAI;gBACpBC,UAAU,GAAGH,KAAKI,GAAG,CAAC,MAAM,CAAC;gBAC7BC,SAAS,GAAGL,KAAKI,GAAG,CAAC,KAAK,CAAC;YAC7B;QACF,CAAA,GAAI;IACN,GACA;QACEE,mBAAmBrH,kBAAkBsH,SAAS;IAChD;IAGF,IAAIvD,eAAe,OAAO;QACxBR,gBAAgBxB;IAClB;IAEA,IAAIiC,QAAQ,OAAO;QACjB5C,oBAAoBW;IACtB;IAEA,MAAMb,qBAAqBa;IAC3B,OAAO,IACLZ,oBAAoBY,MAAMoC,2BAA2B;YACnDoD,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe1D,gBAAgB"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/preset/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 joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { execSync } from 'child_process';\nimport enquirer from 'enquirer';\nimport { readFileSync } from 'fs';\nimport {\n ensureAwsNxPluginConfig,\n updateAwsNxPluginConfig,\n} from '../utils/config/utils';\nimport { formatFilesInSubtree } from '../utils/format';\nimport { applyWorkspaceInit } from '../utils/init';\nimport { installDependencies } from '../utils/install';\nimport { getGeneratorInfo, type NxGeneratorInfo } from '../utils/nx';\nimport { withVersions } from '../utils/versions';\nimport type { PresetGeneratorSchema } from './schema';\n\nexport const PRESET_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Determines if the current user is an Amazon employee based on their git configuration.\n *\n * This function checks the git user email configuration to identify Amazon employees\n * by looking for email addresses with Amazon domains (e.g., @amazon.com, @amazon.co.uk).\n *\n * @returns {boolean} True if the user's git email has an Amazon domain, false otherwise\n *\n * @example\n * // Returns true for Amazon employee emails\n * // git config user.email = \"john.doe@amazon.com\"\n * isAmazonian(); // true\n *\n * @example\n * // Returns false for non-Amazon emails\n * // git config user.email = \"user@example.com\"\n * isAmazonian(); // false\n *\n * @example\n * // Returns false when git config is not available or throws an error\n * isAmazonian(); // false\n */\nexport function isAmazonian(): boolean {\n try {\n // Execute git command to retrieve the user's configured email address\n const gitEmail = execSync('git config user.email', {\n encoding: 'utf8',\n }).trim();\n\n // Return false if no email is configured\n if (!gitEmail) {\n return false;\n }\n\n // Split email address to extract domain part\n const emailParts = gitEmail.split('@');\n if (emailParts.length < 2) {\n return false;\n }\n\n // Extract domain and normalize to lowercase for comparison\n const domain = emailParts[1].toLowerCase();\n\n // Check if domain starts with 'amazon.' (covers amazon.com, amazon.co.uk, etc.)\n return domain.startsWith('amazon.');\n } catch (error) {\n // Return false if git command fails or any other error occurs\n // This handles cases where git is not installed or configured\n return false;\n }\n}\n\nconst setUpGitSecrets = (tree: Tree) => {\n const gitSecretsDir = joinPathFragments(\n import.meta.dirname,\n 'git-secrets-files',\n 'git-secrets-dir',\n );\n const huskyDir = joinPathFragments(\n import.meta.dirname,\n 'git-secrets-files',\n 'husky-dir',\n );\n\n tree.write(\n '.git-secrets/git-secrets',\n readFileSync(joinPathFragments(gitSecretsDir, 'git-secrets'), 'utf-8'),\n );\n tree.write(\n '.husky/pre-commit',\n readFileSync(joinPathFragments(huskyDir, 'pre-commit'), 'utf-8'),\n );\n tree.write('.gitallowed', '\\\\.git-secrets/git-secrets:\\n');\n\n updateJson(tree, 'package.json', (json) => ({\n ...json,\n scripts: {\n ...json.scripts,\n prepare: 'husky',\n },\n }));\n\n addDependenciesToPackageJson(tree, {}, withVersions(['husky']));\n};\n\nexport const presetGenerator = async (\n tree: Tree,\n {\n iac,\n gitSecrets,\n mcp,\n containers,\n module,\n preferInstallDependencies,\n }: PresetGeneratorSchema,\n): Promise<GeneratorCallback> => {\n if (\n isAmazonian() &&\n !process.env.VITEST &&\n !process.env.CI &&\n process.env.NX_DRY_RUN !== 'true' &&\n process.env.NX_INTERACTIVE !== 'false'\n ) {\n const { engagementId } = await enquirer.prompt<{ engagementId?: string }>([\n {\n name: 'engagementId',\n message: 'Please enter your engagementId (if known)',\n type: 'input',\n initial: 'None',\n },\n ]);\n\n if (engagementId != 'None') {\n await ensureAwsNxPluginConfig(tree);\n await updateAwsNxPluginConfig(tree, { tags: [engagementId] });\n }\n }\n\n // The preset owns the greenfield workspace's module format: write the root\n // `type` explicitly from the chosen `--module` so later generators can\n // infer it. The `init` generator never touches an existing workspace's\n // `type` field.\n updateJson(tree, 'package.json', (packageJson) => ({\n ...packageJson,\n type: (module ?? 'esm') === 'esm' ? 'module' : 'commonjs',\n }));\n\n // Apply the deterministic workspace configuration shared with the `init`\n // generator. The preset owns the README of a greenfield workspace.\n await applyWorkspaceInit(tree, {\n iac,\n containers,\n mcp,\n readmeOverwriteStrategy: OverwriteStrategy.Overwrite,\n overwriteScripts: true,\n });\n\n tree.delete('apps/.gitkeep');\n tree.delete('libs/.gitkeep');\n tree.write('packages/.gitkeep', '');\n\n if (gitSecrets !== false) {\n setUpGitSecrets(tree);\n }\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default presetGenerator;\n"],"names":["addDependenciesToPackageJson","joinPathFragments","OverwriteStrategy","updateJson","execSync","enquirer","readFileSync","ensureAwsNxPluginConfig","updateAwsNxPluginConfig","formatFilesInSubtree","applyWorkspaceInit","installDependencies","getGeneratorInfo","withVersions","PRESET_GENERATOR_INFO","filename","isAmazonian","gitEmail","encoding","trim","emailParts","split","length","domain","toLowerCase","startsWith","error","setUpGitSecrets","tree","gitSecretsDir","dirname","huskyDir","write","json","scripts","prepare","presetGenerator","iac","gitSecrets","mcp","containers","module","preferInstallDependencies","process","env","VITEST","CI","NX_DRY_RUN","NX_INTERACTIVE","engagementId","prompt","name","message","type","initial","tags","packageJson","readmeOverwriteStrategy","Overwrite","overwriteScripts","delete","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,iBAAiB,EACjBC,iBAAiB,EAEjBC,UAAU,QACL,aAAa;AACpB,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,cAAc,WAAW;AAChC,SAASC,YAAY,QAAQ,KAAK;AAClC,SACEC,uBAAuB,EACvBC,uBAAuB,QAClB,2BAAwB;AAC/B,SAASC,oBAAoB,QAAQ,qBAAkB;AACvD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,mBAAmB,QAAQ,sBAAmB;AACvD,SAASC,gBAAgB,QAA8B,iBAAc;AACrE,SAASC,YAAY,QAAQ,uBAAoB;AAGjD,OAAO,MAAMC,wBAAyCF,iBACpD,YAAYG,QAAQ,EACpB;AAEF;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,SAASC;IACd,IAAI;QACF,sEAAsE;QACtE,MAAMC,WAAWb,SAAS,yBAAyB;YACjDc,UAAU;QACZ,GAAGC,IAAI;QAEP,yCAAyC;QACzC,IAAI,CAACF,UAAU;YACb,OAAO;QACT;QAEA,6CAA6C;QAC7C,MAAMG,aAAaH,SAASI,KAAK,CAAC;QAClC,IAAID,WAAWE,MAAM,GAAG,GAAG;YACzB,OAAO;QACT;QAEA,2DAA2D;QAC3D,MAAMC,SAASH,UAAU,CAAC,EAAE,CAACI,WAAW;QAExC,gFAAgF;QAChF,OAAOD,OAAOE,UAAU,CAAC;IAC3B,EAAE,OAAOC,OAAO;QACd,8DAA8D;QAC9D,8DAA8D;QAC9D,OAAO;IACT;AACF;AAEA,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgB5B,kBACpB,YAAY6B,OAAO,EACnB,qBACA;IAEF,MAAMC,WAAW9B,kBACf,YAAY6B,OAAO,EACnB,qBACA;IAGFF,KAA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SAAS;QACpDC,kBAAkB;IACpB;IAEA/B,KAAKgC,MAAM,CAAC;IACZhC,KAAKgC,MAAM,CAAC;IACZhC,KAAKI,KAAK,CAAC,qBAAqB;IAEhC,IAAIM,eAAe,OAAO;QACxBX,gBAAgBC;IAClB;IAEA,MAAMnB,qBAAqBmB;IAC3B,OAAO,IACLjB,oBAAoBiB,MAAMc,2BAA2B;YACnDmB,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAezB,gBAAgB"}
@@ -20,7 +20,7 @@ CMD ["python", "bin/opentelemetry-instrument", "python", "-m", "proj_test_projec
20
20
  `;
21
21
 
22
22
  exports[`py#agent generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > agent-construct.ts 1`] = `
23
- "import { Lazy, Names } from 'aws-cdk-lib';
23
+ "import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
24
24
  import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
25
25
  import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
26
26
  import { Construct } from 'constructs';
@@ -121,6 +121,22 @@ export class SnapshotBedrockAgent
121
121
  return this.agentCoreRuntime.connections;
122
122
  }
123
123
 
124
+ /**
125
+ * The HTTPS invocation URL of the runtime.
126
+ */
127
+ public get invocationUrl(): string {
128
+ // The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
129
+ // The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
130
+ const encodedArn = Fn.join(
131
+ '%2F',
132
+ Fn.split(
133
+ '/',
134
+ Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
135
+ ),
136
+ );
137
+ return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
138
+ }
139
+
124
140
  /**
125
141
  * Grants IAM permissions to invoke this agent runtime.
126
142
  *
@@ -215,7 +231,7 @@ _agent = _agent_ctx.__enter__()
215
231
 
216
232
 
217
233
  class InvokeInput(BaseModel):
218
- message: str = Field(max_length=100000)
234
+ prompt: str = Field(max_length=100000)
219
235
 
220
236
 
221
237
  class StreamChunk(BaseModel):
@@ -224,7 +240,7 @@ class StreamChunk(BaseModel):
224
240
 
225
241
  async def handle_invoke(input: InvokeInput):
226
242
  """Streaming handler for agent invocation"""
227
- stream = _agent.stream_async(input.message)
243
+ stream = _agent.stream_async(input.prompt)
228
244
  async for event in stream:
229
245
  text = (
230
246
  event.get("event", {})
@@ -454,7 +454,7 @@ class TestProjectAgentAdapter implements ChatAdapter {
454
454
  }
455
455
 
456
456
  async *sendMessage(text: string): AsyncIterable<string> {
457
- for await (const chunk of this.client.invoke({ message: text })) {
457
+ for await (const chunk of this.client.invoke({ prompt: text })) {
458
458
  if (typeof chunk.content === 'string') yield chunk.content;
459
459
  }
460
460
  }
@@ -559,7 +559,7 @@ class TestProjectAgentAdapter implements ChatAdapter {
559
559
  }
560
560
 
561
561
  async *sendMessage(text: string): AsyncIterable<string> {
562
- for await (const chunk of this.client.invoke({ message: text })) {
562
+ for await (const chunk of this.client.invoke({ prompt: text })) {
563
563
  if (typeof chunk.content === 'string') yield chunk.content;
564
564
  }
565
565
  }
@@ -110,6 +110,11 @@ output "agent_core_runtime_arn" {
110
110
  value = module.agent_core_runtime.agent_core_runtime_arn
111
111
  }
112
112
 
113
+ output "invocation_url" {
114
+ description = "HTTPS invocation URL of the runtime"
115
+ value = module.agent_core_runtime.invocation_url
116
+ }
117
+
113
118
  output "appconfig_application_id" {
114
119
  description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
115
120
  value = var.appconfig_application_id
@@ -583,6 +588,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
583
588
  }
584
589
 
585
590
  # Outputs
591
+ locals {
592
+ # For MCP runtimes the ARN flows through the readiness probe, so consumers
593
+ # wait until the runtime serves MCP.
594
+ ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
595
+ }
596
+
586
597
  output "agent_core_runtime_role_arn" {
587
598
  description = "ARN of the Agent Core Runtime IAM role"
588
599
  value = aws_iam_role.agent_core_runtime_role.arn
@@ -600,7 +611,12 @@ output "agent_runtime_name" {
600
611
 
601
612
  output "agent_core_runtime_arn" {
602
613
  description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
603
- value = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
614
+ value = local.ready_runtime_arn
615
+ }
616
+
617
+ output "invocation_url" {
618
+ description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
619
+ value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
604
620
  }
605
621
 
606
622
  output "agent_runtime_id" {
@@ -21,7 +21,7 @@ _agent = _agent_ctx.__enter__()
21
21
 
22
22
 
23
23
  class InvokeInput(BaseModel):
24
- message: str = Field(max_length=100000)
24
+ prompt: str = Field(max_length=100000)
25
25
 
26
26
 
27
27
  class StreamChunk(BaseModel):
@@ -30,7 +30,7 @@ class StreamChunk(BaseModel):
30
30
 
31
31
  async def handle_invoke(input: InvokeInput):
32
32
  """Streaming handler for agent invocation"""
33
- stream = _agent.stream_async(input.message)
33
+ stream = _agent.stream_async(input.prompt)
34
34
  async for event in stream:
35
35
  text = event.get("event", {}).get("contentBlockDelta", {}).get("delta", {}).get("text")
36
36
  if text is not None:
@@ -16,7 +16,7 @@ _graph = get_agent()
16
16
 
17
17
 
18
18
  class InvokeInput(BaseModel):
19
- message: str = Field(max_length=100000)
19
+ prompt: str = Field(max_length=100000)
20
20
 
21
21
 
22
22
  class StreamChunk(BaseModel):
@@ -41,7 +41,7 @@ async def handle_invoke(input: InvokeInput, session_id: str):
41
41
  # Re-bind the session: the streaming body runs outside the middleware scope.
42
42
  with session_id_context(session_id):
43
43
  stream = _graph.astream(
44
- {"messages": [{"role": "user", "content": input.message}]},
44
+ {"messages": [{"role": "user", "content": input.prompt}]},
45
45
  config,
46
46
  stream_mode="messages",
47
47
  )
@@ -14,7 +14,7 @@ export * from './workspace.js';
14
14
  `;
15
15
 
16
16
  exports[`py#mcp-server generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > mcp-server-construct.ts 1`] = `
17
- "import { Lazy, Names } from 'aws-cdk-lib';
17
+ "import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
18
18
  import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
19
19
  import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
20
20
  import { Construct } from 'constructs';
@@ -102,6 +102,23 @@ export class SnapshotBedrockServer
102
102
  return this.agentCoreRuntime.connections;
103
103
  }
104
104
 
105
+ /**
106
+ * The MCP endpoint URL of the runtime, e.g. for use as a Gateway target
107
+ * endpoint.
108
+ */
109
+ public get invocationUrl(): string {
110
+ // The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
111
+ // The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
112
+ const encodedArn = Fn.join(
113
+ '%2F',
114
+ Fn.split(
115
+ '/',
116
+ Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
117
+ ),
118
+ );
119
+ return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
120
+ }
121
+
105
122
  /**
106
123
  * Grants IAM permissions to invoke this agent runtime.
107
124
  *
@@ -589,6 +606,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
589
606
  }
590
607
 
591
608
  # Outputs
609
+ locals {
610
+ # For MCP runtimes the ARN flows through the readiness probe, so consumers
611
+ # wait until the runtime serves MCP.
612
+ ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
613
+ }
614
+
592
615
  output "agent_core_runtime_role_arn" {
593
616
  description = "ARN of the Agent Core Runtime IAM role"
594
617
  value = aws_iam_role.agent_core_runtime_role.arn
@@ -606,7 +629,12 @@ output "agent_runtime_name" {
606
629
 
607
630
  output "agent_core_runtime_arn" {
608
631
  description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
609
- value = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
632
+ value = local.ready_runtime_arn
633
+ }
634
+
635
+ output "invocation_url" {
636
+ description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
637
+ value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
610
638
  }
611
639
 
612
640
  output "agent_runtime_id" {
@@ -724,6 +752,11 @@ output "agent_core_runtime_arn" {
724
752
  value = module.agent_core_runtime.agent_core_runtime_arn
725
753
  }
726
754
 
755
+ output "invocation_url" {
756
+ description = "HTTPS invocation URL of the runtime (the MCP endpoint, e.g. for use as a Gateway target endpoint)"
757
+ value = module.agent_core_runtime.invocation_url
758
+ }
759
+
727
760
  output "appconfig_application_id" {
728
761
  description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
729
762
  value = var.appconfig_application_id