@aws/nx-plugin 1.0.0-rc.32 → 1.0.0-rc.34

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 (277) hide show
  1. package/LICENSE-THIRD-PARTY +75 -86
  2. package/generators.json +27 -0
  3. package/package.json +10 -10
  4. package/src/connection/generator.js +12 -1
  5. package/src/connection/generator.js.map +1 -1
  6. package/src/connection/supported-connections.d.ts +10 -1
  7. package/src/connection/supported-connections.js +13 -0
  8. package/src/connection/supported-connections.js.map +1 -1
  9. package/src/infra/app/__snapshots__/generator.spec.ts.snap +21 -21
  10. package/src/infra/app/files/app/src/main.ts.template +1 -1
  11. package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
  12. package/src/infra/app/generator.js +3 -1
  13. package/src/infra/app/generator.js.map +1 -1
  14. package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +12 -12
  15. package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +74 -10
  16. package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +22 -4
  17. package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +53 -8
  18. package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +32 -4
  19. package/src/open-api/ts-client/__snapshots__/generator.fast-api-gaps.spec.ts.snap +736 -0
  20. package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +86 -11
  21. package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +21 -3
  22. package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +2 -2
  23. package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +6 -6
  24. package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +2 -2
  25. package/src/open-api/ts-client/__snapshots__/generator.spec-compliance.spec.ts.snap +1883 -0
  26. package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +4 -4
  27. package/src/open-api/ts-client/files/client.gen.ts.template +196 -13
  28. package/src/open-api/ts-client/files/types.gen.ts.template +2 -0
  29. package/src/open-api/ts-client/generator.js +27 -2
  30. package/src/open-api/ts-client/generator.js.map +1 -1
  31. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
  32. package/src/open-api/ts-hooks/generator.js +5 -1
  33. package/src/open-api/ts-hooks/generator.js.map +1 -1
  34. package/src/open-api/utils/codegen-data/languages.js +6 -0
  35. package/src/open-api/utils/codegen-data/languages.js.map +1 -1
  36. package/src/open-api/utils/codegen-data/types.d.ts +16 -1
  37. package/src/open-api/utils/codegen-data/types.js.map +1 -1
  38. package/src/open-api/utils/codegen-data.js +71 -0
  39. package/src/open-api/utils/codegen-data.js.map +1 -1
  40. package/src/open-api/utils/normalise.js +53 -8
  41. package/src/open-api/utils/normalise.js.map +1 -1
  42. package/src/open-api/utils/parser.js +48 -15
  43. package/src/open-api/utils/parser.js.map +1 -1
  44. package/src/preset/__snapshots__/generator.spec.ts.snap +5 -3
  45. package/src/preset/generator.d.ts +1 -1
  46. package/src/preset/generator.js +5 -2
  47. package/src/preset/generator.js.map +1 -1
  48. package/src/preset/schema.d.js.map +1 -1
  49. package/src/preset/schema.d.ts +2 -0
  50. package/src/preset/schema.json +6 -0
  51. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
  52. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
  53. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
  54. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  55. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
  56. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  57. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
  58. package/src/py/rdb/__snapshots__/generator.spec.ts.snap +2038 -0
  59. package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +104 -0
  60. package/src/py/rdb/agent-connection/generator.d.ts +10 -0
  61. package/src/py/rdb/agent-connection/generator.js +46 -0
  62. package/src/py/rdb/agent-connection/generator.js.map +1 -0
  63. package/src/py/rdb/agent-connection/schema.d.js +8 -0
  64. package/src/py/rdb/agent-connection/schema.d.js.map +1 -0
  65. package/src/py/rdb/agent-connection/schema.d.ts +15 -0
  66. package/src/py/rdb/agent-connection/schema.json +27 -0
  67. package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +44 -0
  68. package/src/py/rdb/fast-api-connection/files/__apiModuleName__/dependencies/__rdbNameSnake__.py.template +14 -0
  69. package/src/py/rdb/fast-api-connection/generator.d.ts +10 -0
  70. package/src/py/rdb/fast-api-connection/generator.js +54 -0
  71. package/src/py/rdb/fast-api-connection/generator.js.map +1 -0
  72. package/src/py/rdb/fast-api-connection/schema.d.js +8 -0
  73. package/src/py/rdb/fast-api-connection/schema.d.js.map +1 -0
  74. package/src/py/rdb/fast-api-connection/schema.d.ts +13 -0
  75. package/src/py/rdb/fast-api-connection/schema.json +23 -0
  76. package/src/py/rdb/files/Dockerfile.create-db-user.template +10 -0
  77. package/src/py/rdb/files/Dockerfile.migration.template +10 -0
  78. package/src/py/rdb/files/__name__/__init__.py.template +3 -0
  79. package/src/py/rdb/files/__name__/connection.py.template +55 -0
  80. package/src/py/rdb/files/__name__/create_db_user_handler.py.template +97 -0
  81. package/src/py/rdb/files/__name__/migration_handler.py.template +36 -0
  82. package/src/py/rdb/files/__name__/models/__init__.py.template +3 -0
  83. package/src/py/rdb/files/__name__/models/example.py.template +8 -0
  84. package/src/py/rdb/files/__name__/utils.py.template +104 -0
  85. package/src/py/rdb/files/alembic.ini.template +38 -0
  86. package/src/py/rdb/files/config.json.template +14 -0
  87. package/src/py/rdb/files/migrations/env.py.template +80 -0
  88. package/src/py/rdb/files/migrations/script.py.mako.template +28 -0
  89. package/src/py/rdb/generator.d.ts +6 -0
  90. package/src/py/rdb/generator.js +263 -0
  91. package/src/py/rdb/generator.js.map +1 -0
  92. package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +101 -0
  93. package/src/py/rdb/mcp-server-connection/generator.d.ts +10 -0
  94. package/src/py/rdb/mcp-server-connection/generator.js +46 -0
  95. package/src/py/rdb/mcp-server-connection/generator.js.map +1 -0
  96. package/src/py/rdb/mcp-server-connection/schema.d.js +8 -0
  97. package/src/py/rdb/mcp-server-connection/schema.d.js.map +1 -0
  98. package/src/py/rdb/mcp-server-connection/schema.d.ts +15 -0
  99. package/src/py/rdb/mcp-server-connection/schema.json +27 -0
  100. package/src/py/rdb/schema.d.js +6 -0
  101. package/src/py/rdb/schema.d.js.map +1 -0
  102. package/src/py/rdb/schema.d.ts +16 -0
  103. package/src/py/rdb/schema.json +77 -0
  104. package/src/py/rdb/utils.d.ts +6 -0
  105. package/src/py/rdb/utils.js +16 -0
  106. package/src/py/rdb/utils.js.map +1 -0
  107. package/src/sdk/py.d.ts +2 -0
  108. package/src/sdk/py.js +1 -0
  109. package/src/sdk/py.js.map +1 -1
  110. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
  111. package/src/smithy/ts/api/files/handler.ts.template +2 -2
  112. package/src/smithy/ts/api/files/local-server.ts.template +2 -2
  113. package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
  114. package/src/smithy/ts/api/files/service.ts.template +3 -3
  115. package/src/smithy/ts/api/generator.js +3 -1
  116. package/src/smithy/ts/api/generator.js.map +1 -1
  117. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
  118. package/src/trpc/backend/files/src/client/index.ts.template +1 -1
  119. package/src/trpc/backend/files/src/handler.ts.template +1 -1
  120. package/src/trpc/backend/files/src/index.ts.template +5 -5
  121. package/src/trpc/backend/files/src/init.ts.template +1 -1
  122. package/src/trpc/backend/files/src/local-server.ts.template +1 -1
  123. package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
  124. package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
  125. package/src/trpc/backend/files/src/router.ts.template +2 -2
  126. package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
  127. package/src/trpc/backend/generator.js +3 -1
  128. package/src/trpc/backend/generator.js.map +1 -1
  129. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
  130. package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
  131. package/src/ts/agent/a2a-connection/generator.js +3 -1
  132. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  133. package/src/ts/agent/files/a2a/index.ts.template +1 -1
  134. package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
  135. package/src/ts/agent/files/http/client.ts.template +2 -2
  136. package/src/ts/agent/files/http/index.ts.template +2 -2
  137. package/src/ts/agent/files/http/router.ts.template +3 -3
  138. package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
  139. package/src/ts/agent/gateway-connection/generator.js +3 -1
  140. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  141. package/src/ts/agent/generator.js +5 -2
  142. package/src/ts/agent/generator.js.map +1 -1
  143. package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
  144. package/src/ts/agent/mcp-connection/generator.js +3 -1
  145. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  146. package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
  147. package/src/ts/astro-docs/generator.js +2 -0
  148. package/src/ts/astro-docs/generator.js.map +1 -1
  149. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  150. package/src/ts/dynamodb/files/src/client.ts.template +5 -2
  151. package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
  152. package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
  153. package/src/ts/dynamodb/files/src/index.ts.template +2 -2
  154. package/src/ts/dynamodb/generator.js +3 -1
  155. package/src/ts/dynamodb/generator.js.map +1 -1
  156. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  157. package/src/ts/lib/generator.js +7 -1
  158. package/src/ts/lib/generator.js.map +1 -1
  159. package/src/ts/lib/ts-project-utils.js +19 -4
  160. package/src/ts/lib/ts-project-utils.js.map +1 -1
  161. package/src/ts/lib/types.d.ts +6 -0
  162. package/src/ts/lib/types.js.map +1 -1
  163. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -8
  164. package/src/ts/mcp-server/generator.js +3 -2
  165. package/src/ts/mcp-server/generator.js.map +1 -1
  166. package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
  167. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
  168. package/src/ts/nx-generator/generator.js +5 -2
  169. package/src/ts/nx-generator/generator.js.map +1 -1
  170. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
  171. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
  172. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
  173. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
  174. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
  175. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
  176. package/src/ts/nx-plugin/generator.js +3 -1
  177. package/src/ts/nx-plugin/generator.js.map +1 -1
  178. package/src/ts/nx-plugin/utils.js +7 -4
  179. package/src/ts/nx-plugin/utils.js.map +1 -1
  180. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +149 -177
  181. package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
  182. package/src/ts/rdb/files/src/index.ts.template +1 -1
  183. package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
  184. package/src/ts/rdb/files/src/prisma.ts.template +7 -4
  185. package/src/ts/rdb/generator.js +7 -4
  186. package/src/ts/rdb/generator.js.map +1 -1
  187. package/src/ts/rdb/schema.json +1 -1
  188. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +45 -45
  189. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
  190. package/src/utils/agent-chat/agent-chat.js +3 -1
  191. package/src/utils/agent-chat/agent-chat.js.map +1 -1
  192. package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
  193. package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
  194. package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
  195. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  196. package/src/utils/agent-connection/agent-connection.js +4 -1
  197. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  198. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
  199. package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
  200. package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
  201. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
  202. package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
  203. package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
  204. package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
  205. package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
  206. package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
  207. package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
  208. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  209. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
  210. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
  211. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
  212. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
  213. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
  214. package/src/utils/api-constructs/api-constructs.js +8 -2
  215. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  216. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
  217. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
  218. package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
  219. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
  220. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
  221. package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
  222. package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
  223. package/src/utils/ast.js +16 -0
  224. package/src/utils/ast.js.map +1 -1
  225. package/src/utils/commands.d.ts +1 -1
  226. package/src/utils/commands.js +4 -1
  227. package/src/utils/commands.js.map +1 -1
  228. package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
  229. package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
  230. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
  231. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
  232. package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
  233. package/src/utils/files/common/constructs/src/index.ts.template +2 -2
  234. package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
  235. package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
  236. package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
  237. package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
  238. package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
  239. package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
  240. package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
  241. package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
  242. package/src/utils/function-constructs/function-constructs.js +3 -1
  243. package/src/utils/function-constructs/function-constructs.js.map +1 -1
  244. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
  245. package/src/utils/identity-constructs/identity-constructs.js +5 -1
  246. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  247. package/src/utils/module-format.d.ts +28 -0
  248. package/src/utils/module-format.js +28 -0
  249. package/src/utils/module-format.js.map +1 -0
  250. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +61 -17
  251. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +68 -78
  252. package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +88 -8
  253. package/src/utils/rdb-constructs/files/terraform/core/rdb/aurora/aurora.tf.template +5 -32
  254. package/src/utils/rdb-constructs/rdb-constructs.d.ts +11 -1
  255. package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
  256. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  257. package/src/utils/shared-constructs.js +12 -22
  258. package/src/utils/shared-constructs.js.map +1 -1
  259. package/src/utils/shared-infra-config.js +3 -1
  260. package/src/utils/shared-infra-config.js.map +1 -1
  261. package/src/utils/shared-infra-scripts.js +3 -1
  262. package/src/utils/shared-infra-scripts.js.map +1 -1
  263. package/src/utils/shared-rdb-scripts.js +5 -1
  264. package/src/utils/shared-rdb-scripts.js.map +1 -1
  265. package/src/utils/shared-shadcn.js +3 -1
  266. package/src/utils/shared-shadcn.js.map +1 -1
  267. package/src/utils/test.d.ts +2 -0
  268. package/src/utils/test.js +7 -1
  269. package/src/utils/test.js.map +1 -1
  270. package/src/utils/versions.d.ts +73 -69
  271. package/src/utils/versions.js +71 -67
  272. package/src/utils/versions.js.map +1 -1
  273. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
  274. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
  275. package/src/utils/website-constructs/website-constructs.js +9 -2
  276. package/src/utils/website-constructs/website-constructs.js.map +1 -1
  277. package/src/utils/files/terraform/scripts/reset-runtime-config.ts.template +0 -25
@@ -3142,7 +3142,7 @@ terraform {
3142
3142
  required_providers {
3143
3143
  aws = {
3144
3144
  source = "hashicorp/aws"
3145
- version = "6.52.0"
3145
+ version = "6.54.0"
3146
3146
  }
3147
3147
  }
3148
3148
  }
@@ -3389,7 +3389,7 @@ output "api_log_group_arn" {
3389
3389
  required_providers {
3390
3390
  aws = {
3391
3391
  source = "hashicorp/aws"
3392
- version = "6.52.0"
3392
+ version = "6.54.0"
3393
3393
  }
3394
3394
  }
3395
3395
  }
@@ -3856,7 +3856,7 @@ terraform {
3856
3856
  required_providers {
3857
3857
  aws = {
3858
3858
  source = "hashicorp/aws"
3859
- version = "6.52.0"
3859
+ version = "6.54.0"
3860
3860
  }
3861
3861
  }
3862
3862
  }
@@ -4103,7 +4103,7 @@ output "api_log_group_arn" {
4103
4103
  required_providers {
4104
4104
  aws = {
4105
4105
  source = "hashicorp/aws"
4106
- version = "6.52.0"
4106
+ version = "6.54.0"
4107
4107
  }
4108
4108
  }
4109
4109
  }
@@ -4642,7 +4642,7 @@ terraform {
4642
4642
  required_providers {
4643
4643
  aws = {
4644
4644
  source = "hashicorp/aws"
4645
- version = "6.52.0"
4645
+ version = "6.54.0"
4646
4646
  }
4647
4647
  }
4648
4648
  }
@@ -4889,7 +4889,7 @@ output "api_log_group_arn" {
4889
4889
  required_providers {
4890
4890
  aws = {
4891
4891
  source = "hashicorp/aws"
4892
- version = "6.52.0"
4892
+ version = "6.54.0"
4893
4893
  }
4894
4894
  }
4895
4895
  }
@@ -5333,7 +5333,7 @@ terraform {
5333
5333
  required_providers {
5334
5334
  aws = {
5335
5335
  source = "hashicorp/aws"
5336
- version = "6.52.0"
5336
+ version = "6.54.0"
5337
5337
  }
5338
5338
  random = {
5339
5339
  source = "hashicorp/random"
@@ -5589,7 +5589,7 @@ output "waf_web_acl_arn" {
5589
5589
  required_providers {
5590
5590
  aws = {
5591
5591
  source = "hashicorp/aws"
5592
- version = "6.52.0"
5592
+ version = "6.54.0"
5593
5593
  }
5594
5594
  }
5595
5595
  }
@@ -6281,7 +6281,7 @@ terraform {
6281
6281
  required_providers {
6282
6282
  aws = {
6283
6283
  source = "hashicorp/aws"
6284
- version = "6.52.0"
6284
+ version = "6.54.0"
6285
6285
  }
6286
6286
  random = {
6287
6287
  source = "hashicorp/random"
@@ -6537,7 +6537,7 @@ output "waf_web_acl_arn" {
6537
6537
  required_providers {
6538
6538
  aws = {
6539
6539
  source = "hashicorp/aws"
6540
- version = "6.52.0"
6540
+ version = "6.54.0"
6541
6541
  }
6542
6542
  }
6543
6543
  }
@@ -7218,7 +7218,7 @@ terraform {
7218
7218
  required_providers {
7219
7219
  aws = {
7220
7220
  source = "hashicorp/aws"
7221
- version = "6.52.0"
7221
+ version = "6.54.0"
7222
7222
  }
7223
7223
  random = {
7224
7224
  source = "hashicorp/random"
@@ -7474,7 +7474,7 @@ output "waf_web_acl_arn" {
7474
7474
  required_providers {
7475
7475
  aws = {
7476
7476
  source = "hashicorp/aws"
7477
- version = "6.52.0"
7477
+ version = "6.54.0"
7478
7478
  }
7479
7479
  }
7480
7480
  }
@@ -7,7 +7,7 @@ import {
7
7
  import { AwsClient } from 'aws4fetch';
8
8
  import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
9
9
  <%_ } _%>
10
- import { AppRouter } from "../router.js";
10
+ import { AppRouter } from "../router<% if (esm) { %>.js<% } %>";
11
11
 
12
12
  <%_ if (auth === 'iam') { %>
13
13
  const credentialProvider = fromNodeProviderChain();
@@ -7,7 +7,7 @@ import {
7
7
  <%_ } _%>
8
8
  } from '@trpc/server/adapters/aws-lambda';
9
9
  import type { <%- apiGatewayEventType %> } from 'aws-lambda';
10
- import { appRouter } from './router.js';
10
+ import { appRouter } from './router<% if (esm) { %>.js<% } %>';
11
11
 
12
12
  <%_ if (infra === 'rest-lambda') { _%>
13
13
  export const handler = awslambda.streamifyResponse(
@@ -1,5 +1,5 @@
1
- export type { AppRouter } from './router.js';
2
- export { appRouter } from './router.js';
3
- export type { Context } from './init.js';
4
- export * from './client/index.js';
5
- export * from './schema/index.js';
1
+ export type { AppRouter } from './router<% if (esm) { %>.js<% } %>';
2
+ export { appRouter } from './router<% if (esm) { %>.js<% } %>';
3
+ export type { Context } from './init<% if (esm) { %>.js<% } %>';
4
+ export * from './client/index<% if (esm) { %>.js<% } %>';
5
+ export * from './schema/index<% if (esm) { %>.js<% } %>';
@@ -5,7 +5,7 @@ import {
5
5
  createMetricsPlugin,
6
6
  createTracerPlugin,
7
7
  IMiddlewareContext,
8
- } from './middleware/index.js';
8
+ } from './middleware/index<% if (esm) { %>.js<% } %>';
9
9
 
10
10
  process.env.POWERTOOLS_SERVICE_NAME = '<%= apiNameClassName %>';
11
11
  process.env.POWERTOOLS_METRICS_NAMESPACE = '<%= apiNameClassName %>';
@@ -1,5 +1,5 @@
1
1
  import { createHTTPServer } from '@trpc/server/adapters/standalone';
2
- import { appRouter } from './router.js';
2
+ import { appRouter } from './router<% if (esm) { %>.js<% } %>';
3
3
  import cors from 'cors';
4
4
 
5
5
  const PORT = <%- port %>;
@@ -1,13 +1,13 @@
1
1
  import { CreateAWSLambdaContextOptions } from '@trpc/server/adapters/aws-lambda';
2
2
  import type { <%- apiGatewayEventType %> } from 'aws-lambda';
3
- import { ILoggerContext } from './logger.js';
4
- import { IMetricsContext } from './metrics.js';
5
- import { ITracerContext } from './tracer.js';
3
+ import { ILoggerContext } from './logger<% if (esm) { %>.js<% } %>';
4
+ import { IMetricsContext } from './metrics<% if (esm) { %>.js<% } %>';
5
+ import { ITracerContext } from './tracer<% if (esm) { %>.js<% } %>';
6
6
 
7
- export * from './logger.js';
8
- export * from './metrics.js';
9
- export * from './tracer.js';
10
- export * from './error.js';
7
+ export * from './logger<% if (esm) { %>.js<% } %>';
8
+ export * from './metrics<% if (esm) { %>.js<% } %>';
9
+ export * from './tracer<% if (esm) { %>.js<% } %>';
10
+ export * from './error<% if (esm) { %>.js<% } %>';
11
11
 
12
12
  export type IMiddlewareContext = CreateAWSLambdaContextOptions<<%- apiGatewayEventType %>>
13
13
  & ILoggerContext
@@ -1,5 +1,5 @@
1
- import { publicProcedure } from '../init.js';
2
- import { EchoInputSchema, EchoOutputSchema } from '../schema/index.js';
1
+ import { publicProcedure } from '../init<% if (esm) { %>.js<% } %>';
2
+ import { EchoInputSchema, EchoOutputSchema } from '../schema/index<% if (esm) { %>.js<% } %>';
3
3
 
4
4
 
5
5
  export const echo = publicProcedure
@@ -1,5 +1,5 @@
1
- import { echo } from './procedures/echo.js';
2
- import { t } from './init.js';
1
+ import { echo } from './procedures/echo<% if (esm) { %>.js<% } %>';
2
+ import { t } from './init<% if (esm) { %>.js<% } %>';
3
3
 
4
4
  export const router = t.router;
5
5
 
@@ -1 +1 @@
1
- export * from './echo.js';
1
+ export * from './echo<% if (esm) { %>.js<% } %>';
@@ -9,6 +9,7 @@ import { formatFilesInSubtree } from "../../utils/format.js";
9
9
  import { resolveIac } from "../../utils/iac.js";
10
10
  import { installDependencies } from "../../utils/install.js";
11
11
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
12
+ import { esmVars } from "../../utils/module-format.js";
12
13
  import { kebabCase, toClassName } from "../../utils/names.js";
13
14
  import { getNpmScopePrefix, toScopeAlias } from "../../utils/npm-scope.js";
14
15
  import { addDependencyToTargetIfNotPresent, addGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
@@ -62,7 +63,8 @@ export async function tsTrpcApiGenerator(tree, options) {
62
63
  pkgMgrCmd: getPackageManagerDisplayCommands().exec,
63
64
  apiGatewayEventType: getApiGatewayEventType(options),
64
65
  port,
65
- ...options
66
+ ...options,
67
+ ...esmVars(tree)
66
68
  };
67
69
  if (options.infra !== 'none') {
68
70
  const iac = await resolveIac(tree, options.iac);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/trpc/backend/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 generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator';\nimport { addApiGatewayInfra } from '../../utils/api-constructs/api-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScopePrefix, toScopeAlias } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { withVersions } from '../../utils/versions';\nimport type { TsTrpcApiGeneratorSchema } from './schema';\n\nexport const TRPC_BACKEND_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([\n 'rest-lambda::isolated',\n 'rest-lambda::shared',\n 'http-lambda::isolated',\n 'http-lambda::shared',\n 'none::isolated',\n 'none::shared',\n]);\n\nexport async function tsTrpcApiGenerator(\n tree: Tree,\n options: TsTrpcApiGeneratorSchema,\n) {\n if (options.infra !== 'none') {\n validateTrpcInfraAndIntegrationPatternCombination(options);\n }\n\n const apiNamespace = getNpmScopePrefix(tree);\n const apiNameKebabCase = kebabCase(options.name);\n const apiNameClassName = toClassName(options.name);\n\n const backendName = apiNameKebabCase;\n const backendProjectName = `${apiNamespace}${backendName}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: backendName,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n backendProjectName,\n );\n const backendRoot = projectConfig.root;\n\n const port = assignPort(tree, projectConfig, 2022);\n\n const enhancedOptions = {\n backendProjectName,\n backendProjectAlias: toScopeAlias(backendProjectName),\n apiNameKebabCase,\n apiNameClassName,\n backendRoot,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n apiGatewayEventType: getApiGatewayEventType(options),\n port,\n ...options,\n };\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n await addApiGatewayInfra(tree, {\n apiProjectName: backendProjectName,\n apiNameClassName,\n apiNameKebabCase,\n constructType: options.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'trpc',\n projectAlias: enhancedOptions.backendProjectAlias,\n bundleOutputDir: joinPathFragments('dist', backendRoot, 'bundle'),\n integrationPattern: getIntegrationPattern(options),\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendRoot,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n auth: options.auth,\n iac,\n });\n }\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n apiName: options.name,\n apiType: 'trpc',\n auth: options.auth,\n infra: options.infra,\n integrationPattern: getIntegrationPattern(options),\n } as unknown;\n\n projectConfig.targets.serve = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: ['tsx --watch src/local-server.ts'],\n cwd: '{projectRoot}',\n },\n };\n\n projectConfig.targets['dev'] = {\n ...projectConfig.targets['dev'],\n ...projectConfig.targets.serve,\n options: {\n ...projectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n\n if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n });\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n });\n }\n\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendRoot,\n enhancedOptions,\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n tree.delete(joinPathFragments(backendRoot, 'src', 'lib'));\n\n if (options.infra !== 'none' && options.auth === 'custom') {\n const authorizerType = options.infra === 'http-lambda' ? 'http' : 'rest';\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'cdk',\n 'authorizer',\n authorizerType,\n ),\n joinPathFragments(backendRoot, 'src'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)\n if (options.infra !== 'rest-lambda' && options.infra !== 'none') {\n tree.delete(\n joinPathFragments(backendRoot, 'src', 'schema', 'z-async-iterable.ts'),\n );\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'aws-xray-sdk-core',\n 'zod',\n '@aws-lambda-powertools/logger',\n '@aws-lambda-powertools/metrics',\n '@aws-lambda-powertools/parameters',\n '@aws-lambda-powertools/tracer',\n '@aws-sdk/client-appconfigdata',\n '@trpc/server',\n '@trpc/client',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ...(options.auth === 'custom'\n ? (['@middy/core', '@aws-lambda-powertools/parser'] as const)\n : []),\n ]),\n withVersions(['@types/aws-lambda', 'tsx', 'cors', '@types/cors']),\n );\n tree.delete(joinPathFragments(backendRoot, 'package.json'));\n\n addGeneratorMetadata(tree, backendName, TRPC_BACKEND_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [TRPC_BACKEND_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\n\nconst validateTrpcInfraAndIntegrationPatternCombination = (\n options: TsTrpcApiGeneratorSchema,\n) => {\n const integrationPattern = getIntegrationPattern(options);\n const permutation = `${options.infra}::${integrationPattern}`;\n\n if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {\n throw new Error(\n `Invalid tRPC infra/integrationPattern combination: ${options.infra} + ${integrationPattern}.`,\n );\n }\n};\n\nconst getIntegrationPattern = (\n options: TsTrpcApiGeneratorSchema,\n): 'isolated' | 'shared' => {\n return options.integrationPattern ?? 'isolated';\n};\n\nconst getApiGatewayEventType = (options: TsTrpcApiGeneratorSchema): string => {\n if (options.infra === 'rest-lambda') {\n return 'APIGatewayProxyEvent';\n }\n if (options.auth === 'iam') {\n return 'APIGatewayProxyEventV2WithIAMAuthorizer';\n } else if (options.auth === 'cognito') {\n return 'APIGatewayProxyEventV2WithJWTAuthorizer';\n }\n return 'APIGatewayProxyEventV2';\n};\n\nexport default tsTrpcApiGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addApiGatewayInfra","addTypeScriptBundleTarget","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","toScopeAlias","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getPackageManagerDisplayCommands","assignPort","sharedConstructsGenerator","withVersions","TRPC_BACKEND_GENERATOR_INFO","filename","VALID_TRPC_INTEGRATION_PERMUTATIONS","Set","tsTrpcApiGenerator","tree","options","infra","validateTrpcInfraAndIntegrationPatternCombination","apiNamespace","apiNameKebabCase","name","apiNameClassName","backendName","backendProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","backendRoot","root","port","enhancedOptions","backendProjectAlias","pkgMgrCmd","exec","apiGatewayEventType","getApiGatewayEventType","iac","apiProjectName","constructType","backend","type","projectAlias","bundleOutputDir","integrationPattern","getIntegrationPattern","auth","authorizerBundleOutputDir","metadata","apiName","apiType","targets","serve","executor","continuous","commands","cwd","env","LOCAL_DEV","targetFilePath","external","dirname","overwriteStrategy","Overwrite","delete","authorizerType","KeepExisting","languages","permutation","has","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,wBAAwB,4BAAyB;AACxD,SAASC,kBAAkB,QAAQ,+CAA4C;AAC/E,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,2BAAwB;AACxE,SACEC,iCAAiC,EACjCC,oBAAo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BsB;IAC3B,OAAO,IACLpB,oBAAoBoB,MAAMC,QAAQY,yBAAyB,EAAE;YAC3DyC,WAAW;gBAAC;aAAa;QAC3B;AACJ;AAEA,MAAMnD,oDAAoD,CACxDF;IAEA,MAAM8B,qBAAqBC,sBAAsB/B;IACjD,MAAMsD,cAAc,GAAGtD,QAAQC,KAAK,CAAC,EAAE,EAAE6B,oBAAoB;IAE7D,IAAI,CAAClC,oCAAoC2D,GAAG,CAACD,cAAc;QACzD,MAAM,IAAIE,MACR,CAAC,mDAAmD,EAAExD,QAAQC,KAAK,CAAC,GAAG,EAAE6B,mBAAmB,CAAC,CAAC;IAElG;AACF;AAEA,MAAMC,wBAAwB,CAC5B/B;IAEA,OAAOA,QAAQ8B,kBAAkB,IAAI;AACvC;AAEA,MAAMR,yBAAyB,CAACtB;IAC9B,IAAIA,QAAQC,KAAK,KAAK,eAAe;QACnC,OAAO;IACT;IACA,IAAID,QAAQgC,IAAI,KAAK,OAAO;QAC1B,OAAO;IACT,OAAO,IAAIhC,QAAQgC,IAAI,KAAK,WAAW;QACrC,OAAO;IACT;IACA,OAAO;AACT;AAEA,eAAelC,mBAAmB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/trpc/backend/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 generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator';\nimport { addApiGatewayInfra } from '../../utils/api-constructs/api-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScopePrefix, toScopeAlias } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { withVersions } from '../../utils/versions';\nimport type { TsTrpcApiGeneratorSchema } from './schema';\n\nexport const TRPC_BACKEND_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([\n 'rest-lambda::isolated',\n 'rest-lambda::shared',\n 'http-lambda::isolated',\n 'http-lambda::shared',\n 'none::isolated',\n 'none::shared',\n]);\n\nexport async function tsTrpcApiGenerator(\n tree: Tree,\n options: TsTrpcApiGeneratorSchema,\n) {\n if (options.infra !== 'none') {\n validateTrpcInfraAndIntegrationPatternCombination(options);\n }\n\n const apiNamespace = getNpmScopePrefix(tree);\n const apiNameKebabCase = kebabCase(options.name);\n const apiNameClassName = toClassName(options.name);\n\n const backendName = apiNameKebabCase;\n const backendProjectName = `${apiNamespace}${backendName}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: backendName,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n backendProjectName,\n );\n const backendRoot = projectConfig.root;\n\n const port = assignPort(tree, projectConfig, 2022);\n\n const enhancedOptions = {\n backendProjectName,\n backendProjectAlias: toScopeAlias(backendProjectName),\n apiNameKebabCase,\n apiNameClassName,\n backendRoot,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n apiGatewayEventType: getApiGatewayEventType(options),\n port,\n ...options,\n ...esmVars(tree),\n };\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n await addApiGatewayInfra(tree, {\n apiProjectName: backendProjectName,\n apiNameClassName,\n apiNameKebabCase,\n constructType: options.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'trpc',\n projectAlias: enhancedOptions.backendProjectAlias,\n bundleOutputDir: joinPathFragments('dist', backendRoot, 'bundle'),\n integrationPattern: getIntegrationPattern(options),\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendRoot,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n auth: options.auth,\n iac,\n });\n }\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n apiName: options.name,\n apiType: 'trpc',\n auth: options.auth,\n infra: options.infra,\n integrationPattern: getIntegrationPattern(options),\n } as unknown;\n\n projectConfig.targets.serve = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: ['tsx --watch src/local-server.ts'],\n cwd: '{projectRoot}',\n },\n };\n\n projectConfig.targets['dev'] = {\n ...projectConfig.targets['dev'],\n ...projectConfig.targets.serve,\n options: {\n ...projectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n\n if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n });\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n });\n }\n\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendRoot,\n enhancedOptions,\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n tree.delete(joinPathFragments(backendRoot, 'src', 'lib'));\n\n if (options.infra !== 'none' && options.auth === 'custom') {\n const authorizerType = options.infra === 'http-lambda' ? 'http' : 'rest';\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'cdk',\n 'authorizer',\n authorizerType,\n ),\n joinPathFragments(backendRoot, 'src'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)\n if (options.infra !== 'rest-lambda' && options.infra !== 'none') {\n tree.delete(\n joinPathFragments(backendRoot, 'src', 'schema', 'z-async-iterable.ts'),\n );\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'aws-xray-sdk-core',\n 'zod',\n '@aws-lambda-powertools/logger',\n '@aws-lambda-powertools/metrics',\n '@aws-lambda-powertools/parameters',\n '@aws-lambda-powertools/tracer',\n '@aws-sdk/client-appconfigdata',\n '@trpc/server',\n '@trpc/client',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ...(options.auth === 'custom'\n ? (['@middy/core', '@aws-lambda-powertools/parser'] as const)\n : []),\n ]),\n withVersions(['@types/aws-lambda', 'tsx', 'cors', '@types/cors']),\n );\n tree.delete(joinPathFragments(backendRoot, 'package.json'));\n\n addGeneratorMetadata(tree, backendName, TRPC_BACKEND_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [TRPC_BACKEND_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\n\nconst validateTrpcInfraAndIntegrationPatternCombination = (\n options: TsTrpcApiGeneratorSchema,\n) => {\n const integrationPattern = getIntegrationPattern(options);\n const permutation = `${options.infra}::${integrationPattern}`;\n\n if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {\n throw new Error(\n `Invalid tRPC infra/integrationPattern combination: ${options.infra} + ${integrationPattern}.`,\n );\n }\n};\n\nconst getIntegrationPattern = (\n options: TsTrpcApiGeneratorSchema,\n): 'isolated' | 'shared' => {\n return options.integrationPattern ?? 'isolated';\n};\n\nconst getApiGatewayEventType = (options: TsTrpcApiGeneratorSchema): string => {\n if (options.infra === 'rest-lambda') {\n return 'APIGatewayProxyEvent';\n }\n if (options.auth === 'iam') {\n return 'APIGatewayProxyEventV2WithIAMAuthorizer';\n } else if (options.auth === 'cognito') {\n return 'APIGatewayProxyEventV2WithJWTAuthorizer';\n }\n return 'APIGatewayProxyEventV2';\n};\n\nexport default tsTrpcApiGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addApiGatewayInfra","addTypeScriptBundleTarget","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScopePrefix","toScopeAlias","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getPackageManagerDisplayCommands","assignPort","sharedConstructsGenerator","withVersions","TRPC_BACKEND_GENERATOR_INFO","filename","VALID_TRPC_INTEGRATION_PERMUTATIONS","Set","tsTrpcApiGenerator","tree","options","infra","validateTrpcInfraAndIntegrationPatternCombination","apiNamespace","apiNameKebabCase","name","apiNameClassName","backendName","backendProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","backendRoot","root","port","enhancedOptions","backendProjectAlias","pkgMgrCmd","exec","apiGatewayEventType","getApiGatewayEventType","iac","apiProjectName","constructType","backend","type","projectAlias","bundleOutputDir","integrationPattern","getIntegrationPattern","auth","authorizerBundleOutputDir","metadata","apiName","apiType","targets","serve","executor","continuous","commands","cwd","env","LOCAL_DEV","targetFilePath","external","dirname","overwriteStrategy","Overwrite","delete","authorizerType","KeepExisting","languages","permutation","has","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,wBAAwB,4BAAyB;AACxD,SAASC,kBAAkB,QAAQ,+CAA4C;AAC/E,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,2BAAwB;AACxE,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,gCAAgC,QAAQ,6BAA0B;AAC3E,SAASC,UAAU,QAAQ,sBAAmB;AAC9C,SAASC,yBAAyB,QAAQ,mCAAgC;AAC1E,SAASC,YAAY,QAAQ,0BAAuB;AAGpD,OAAO,MAAMC,8BAA+CP,iBAC1D,YAAYQ,QAAQ,EACpB;AAEF,MAAMC,sCAAsC,IAAIC,IAAI;IAClD;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,eAAeC,mBACpBC,IAAU,EACVC,OAAiC;IAEjC,IAAIA,QAAQC,KAAK,KAAK,QAAQ;QAC5BC,kDAAkDF;IACpD;IAEA,MAAMG,eAAepB,kBAAkBgB;IACvC,MAAMK,mBAAmBvB,UAAUmB,QAAQK,IAAI;IAC/C,MAAMC,mBAAmBxB,YAAYkB,QAAQK,IAAI;IAEjD,MAAME,cAAcH;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KAAK,OAAO;QAC1B,OAAO;IACT,OAAO,IAAIhC,QAAQgC,IAAI,KAAK,WAAW;QACrC,OAAO;IACT;IACA,OAAO;AACT;AAEA,eAAelC,mBAAmB"}
@@ -748,6 +748,25 @@ variable "tags" {
748
748
  default = {}
749
749
  }
750
750
 
751
+ # VPC Configuration (optional)
752
+ variable "enable_vpc" {
753
+ description = "Run the agent core runtime inside a VPC. Set alongside vpc_id/subnet_ids."
754
+ type = bool
755
+ default = false
756
+ }
757
+
758
+ variable "vpc_id" {
759
+ description = "VPC ID to run the agent core runtime in. Required when enable_vpc is true."
760
+ type = string
761
+ default = null
762
+ }
763
+
764
+ variable "subnet_ids" {
765
+ description = "Subnet IDs to run the agent core runtime in. Required when enable_vpc is true."
766
+ type = list(string)
767
+ default = null
768
+ }
769
+
751
770
  variable "appconfig_application_id" {
752
771
  description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). The agent reads its runtime configuration from this application."
753
772
  type = string
@@ -763,6 +782,9 @@ module "agent_core_runtime" {
763
782
  agent_runtime_name = "TerraformSnapshotAgent"
764
783
  docker_image_tag = "proj-terraform-snapshot-agent:latest"
765
784
  server_protocol = "HTTP"
785
+ enable_vpc = var.enable_vpc
786
+ vpc_id = var.vpc_id
787
+ subnet_ids = var.subnet_ids
766
788
 
767
789
  env = merge({
768
790
  RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
@@ -817,6 +839,11 @@ output "appconfig_application_id" {
817
839
  description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
818
840
  value = var.appconfig_application_id
819
841
  }
842
+
843
+ output "security_group_id" {
844
+ description = "Security group ID of the agent core runtime, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
845
+ value = module.agent_core_runtime.security_group_id
846
+ }
820
847
  "
821
848
  `;
822
849
 
@@ -827,7 +854,7 @@ exports[`ts#agent generator > should match snapshot for Terraform generated file
827
854
  required_providers {
828
855
  aws = {
829
856
  source = "hashicorp/aws"
830
- version = "6.52.0"
857
+ version = "6.54.0"
831
858
  }
832
859
  null = {
833
860
  source = "hashicorp/null"
@@ -893,6 +920,30 @@ variable "additional_iam_policy_statements" {
893
920
  default = []
894
921
  }
895
922
 
923
+ # VPC Configuration (optional)
924
+ variable "enable_vpc" {
925
+ description = "Run the agent core runtime inside a VPC. Set alongside vpc_id/subnet_ids."
926
+ type = bool
927
+ default = false
928
+ }
929
+
930
+ variable "vpc_id" {
931
+ description = "VPC ID to run the agent core runtime in. Required when enable_vpc is true."
932
+ type = string
933
+ default = null
934
+
935
+ validation {
936
+ condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
937
+ error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
938
+ }
939
+ }
940
+
941
+ variable "subnet_ids" {
942
+ description = "Subnet IDs to run the agent core runtime in. Required when enable_vpc is true."
943
+ type = list(string)
944
+ default = null
945
+ }
946
+
896
947
  variable "tags" {
897
948
  description = "Tags to apply to resources"
898
949
  type = map(string)
@@ -1128,6 +1179,28 @@ resource "null_resource" "docker_publish" {
1128
1179
  depends_on = [aws_ecr_repository_policy.agent_core_ecr_policy]
1129
1180
  }
1130
1181
 
1182
+ # Security group for the agent core runtime, used when running inside a VPC
1183
+ resource "aws_security_group" "agent_core_runtime" {
1184
+ count = var.enable_vpc ? 1 : 0
1185
+
1186
+ #checkov:skip=CKV2_AWS_5:Attached to the runtime via network_configuration; Checkov cannot resolve this reference
1187
+ name_prefix = "\${var.agent_runtime_name}-runtime-"
1188
+ description = "Security group for the \${var.agent_runtime_name} agent core runtime"
1189
+ vpc_id = var.vpc_id
1190
+ tags = var.tags
1191
+ }
1192
+
1193
+ resource "aws_vpc_security_group_egress_rule" "agent_core_runtime_https" {
1194
+ count = var.enable_vpc ? 1 : 0
1195
+
1196
+ security_group_id = aws_security_group.agent_core_runtime[0].id
1197
+ cidr_ipv4 = "0.0.0.0/0"
1198
+ from_port = 443
1199
+ to_port = 443
1200
+ ip_protocol = "tcp"
1201
+ description = "Allow outbound HTTPS to AWS service endpoints"
1202
+ }
1203
+
1131
1204
  # Bedrock AgentCore Agent Runtime
1132
1205
  resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
1133
1206
  agent_runtime_name = "\${var.agent_runtime_name}_\${random_id.unique_suffix.hex}"
@@ -1154,7 +1227,15 @@ resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
1154
1227
  }
1155
1228
 
1156
1229
  network_configuration {
1157
- network_mode = "PUBLIC"
1230
+ network_mode = var.enable_vpc ? "VPC" : "PUBLIC"
1231
+
1232
+ dynamic "network_mode_config" {
1233
+ for_each = var.enable_vpc ? [1] : []
1234
+ content {
1235
+ security_groups = [aws_security_group.agent_core_runtime[0].id]
1236
+ subnets = var.subnet_ids
1237
+ }
1238
+ }
1158
1239
  }
1159
1240
 
1160
1241
  protocol_configuration {
@@ -1181,7 +1262,7 @@ resource "null_resource" "runtime_ready" {
1181
1262
 
1182
1263
  provisioner "local-exec" {
1183
1264
  command = <<-EOT
1184
- uv run --with boto3==1.43.37 python -c "
1265
+ uv run --with boto3==1.43.46 python -c "
1185
1266
  import boto3
1186
1267
  import json
1187
1268
  import os
@@ -1256,6 +1337,11 @@ output "agent_runtime_version" {
1256
1337
  description = "Version of the Bedrock Agent Core runtime"
1257
1338
  value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_version
1258
1339
  }
1340
+
1341
+ output "security_group_id" {
1342
+ description = "Security group ID of the agent core runtime, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
1343
+ value = var.enable_vpc ? aws_security_group.agent_core_runtime[0].id : null
1344
+ }
1259
1345
  "
1260
1346
  `;
1261
1347
 
@@ -1,6 +1,6 @@
1
1
  import { A2AAgent } from '@strands-agents/sdk/a2a';
2
- import { AgentCoreA2aClientStrands } from '../core/agentcore-a2a-client-strands.js';
3
- import { getAgentCoreRuntimeConfig } from '../core/runtime-config.js';
2
+ import { AgentCoreA2aClientStrands } from '../core/agentcore-a2a-client-strands<% if (esm) { %>.js<% } %>';
3
+ import { getAgentCoreRuntimeConfig } from '../core/runtime-config<% if (esm) { %>.js<% } %>';
4
4
 
5
5
  /** Strands client for the <%- targetAgentClassName %> A2A agent. */
6
6
  export class <%- targetAgentClassName %>ClientStrands {
@@ -7,6 +7,7 @@ import { addDestructuredImport, addStarExport, applyGritQL } from "../../../util
7
7
  import { formatFilesInSubtree } from "../../../utils/format.js";
8
8
  import { installDependencies } from "../../../utils/install.js";
9
9
  import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
10
+ import { esmVars } from "../../../utils/module-format.js";
10
11
  import { kebabCase } from "../../../utils/names.js";
11
12
  import { getNpmScope } from "../../../utils/npm-scope.js";
12
13
  import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
@@ -38,7 +39,8 @@ export const tsAgentA2aConnectionGenerator = async (tree, options)=>{
38
39
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'), joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
39
40
  targetAgentKebabCase,
40
41
  targetAgentClassName,
41
- targetAgentPort
42
+ targetAgentPort,
43
+ ...esmVars(tree)
42
44
  }, {
43
45
  overwriteStrategy: OverwriteStrategy.KeepExisting
44
46
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/a2a-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport {\n addDestructuredImport,\n addStarExport,\n applyGritQL,\n} from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentA2aConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_A2A_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentA2aConnectionGenerator = async (\n tree: Tree,\n options: TsAgentA2aConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const agentComponent = options.sourceComponent;\n const targetAgentComponent = options.targetComponent;\n\n if (!agentComponent || !targetAgentComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> a2a connections',\n );\n }\n\n if ((targetAgentComponent.protocol ?? '').toLowerCase() !== 'a2a') {\n throw new Error(\n `Target agent '${targetAgentComponent.name}' uses the ${targetAgentComponent.protocol ?? 'http'} protocol — only A2A agents can be connected as tools.`,\n );\n }\n\n if (\n targetAgentComponent.auth &&\n targetAgentComponent.auth.toLowerCase() !== 'iam'\n ) {\n throw new Error(\n `A2A agent connection currently only supports IAM authentication, but '${targetAgentComponent.name}' uses '${targetAgentComponent.auth}' authentication.`,\n );\n }\n\n const targetAgentComponentName = targetAgentComponent.name ?? 'agent';\n const targetAgentClassName = targetAgentComponent.rc as string;\n const targetAgentKebabCase = kebabCase(targetAgentClassName);\n const targetAgentPort = targetAgentComponent.port ?? 9000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the A2A core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'a2a');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n targetAgentKebabCase,\n targetAgentClassName,\n targetAgentPort,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${targetAgentKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add the remote A2A agent as a tool\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${targetAgentClassName}ClientStrands`;\n const clientVarName =\n targetAgentClassName.charAt(0).toLowerCase() +\n targetAgentClassName.slice(1);\n const toolName = `ask${targetAgentClassName}`;\n const toolVarName = `${clientVarName}Tool`;\n\n // Ensure tool + z imports are available\n await addDestructuredImport(\n tree,\n agentFilePath,\n ['tool'],\n '@strands-agents/sdk',\n );\n await addDestructuredImport(tree, agentFilePath, ['z'], 'zod');\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n // Build the tool creation + Agent wiring.\n const toolCreationBlock = `const ${clientVarName} = await ${clientClassName}.create();\n const ${toolVarName} = tool({\n name: '${toolName}',\n description: 'Delegate a question to the remote ${targetAgentClassName} A2A agent and return its reply.',\n inputSchema: z.object({ prompt: z.string() }),\n callback: async ({ prompt }) => (await ${clientVarName}.invoke(prompt)).toString(),\n });`;\n\n // Transform the arrow function that contains `new Agent`:\n // - Expression body: wrap in block with tool creation and return\n // - Block body: prepend tool creation statement\n await applyGritQL(\n tree,\n agentFilePath,\n `or { \\`async ($p) => new Agent($args)\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n return new Agent($args);\n}\\` where { $program <: not contains \\`${clientClassName}.create\\` }, \\`async ($p) => { $body }\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n $body\n}\\` where { $body <: contains \\`new Agent($_)\\`, $program <: not contains \\`${clientClassName}.create\\` } }`,\n );\n\n // Append the tool to the tools array (after existing items)\n await applyGritQL(\n tree,\n agentFilePath,\n `\\`tools: [$items]\\` => \\`tools: [$items, ${toolVarName}]\\` where { $items <: within \\`new Agent($_)\\`, $items <: not contains \\`${toolVarName}\\` }`,\n );\n }\n\n // 4. Set up dev target — depend on the target agent's dev\n // so running the host's dev also spins up the remote A2A agent.\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const targetDevTargetName = `${targetAgentComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: targetDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@a2a-js/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n 'zod',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_A2A_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentA2aConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","applyGritQL","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_A2A_CONNECTION_GENERATOR_INFO","filename","tsAgentA2aConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","targetAgentComponent","targetComponent","Error","protocol","toLowerCase","name","auth","targetAgentComponentName","targetAgentClassName","rc","targetAgentKebabCase","targetAgentPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","toolName","toolVarName","toolCreationBlock","agentName","devTargetName","targetDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,WAAW,QACN,wBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBR,oCACpBK,MACAC,QAAQE,aAAa;IAGvB,MAAMC,iBAAiBH,QAAQI,e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YAC9DG,UAAU;gBAACpC,cAAcQ,IAAI;aAAC;YAC9B6B,QAAQH;QACV;QACAxD,2BAA2BmB,MAAME,cAAcS,IAAI,EAAET;IACvD;IAEA,sBAAsB;IACtBzB,6BACEuB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMN,gCAAgCU,MAAM;QAC1CH;KACD;IAED,MAAMT,qBAAqBY;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQwC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe3C,8BAA8B"}
1
+ {"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/a2a-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport {\n addDestructuredImport,\n addStarExport,\n applyGritQL,\n} from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentA2aConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_A2A_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentA2aConnectionGenerator = async (\n tree: Tree,\n options: TsAgentA2aConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const agentComponent = options.sourceComponent;\n const targetAgentComponent = options.targetComponent;\n\n if (!agentComponent || !targetAgentComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> a2a connections',\n );\n }\n\n if ((targetAgentComponent.protocol ?? '').toLowerCase() !== 'a2a') {\n throw new Error(\n `Target agent '${targetAgentComponent.name}' uses the ${targetAgentComponent.protocol ?? 'http'} protocol — only A2A agents can be connected as tools.`,\n );\n }\n\n if (\n targetAgentComponent.auth &&\n targetAgentComponent.auth.toLowerCase() !== 'iam'\n ) {\n throw new Error(\n `A2A agent connection currently only supports IAM authentication, but '${targetAgentComponent.name}' uses '${targetAgentComponent.auth}' authentication.`,\n );\n }\n\n const targetAgentComponentName = targetAgentComponent.name ?? 'agent';\n const targetAgentClassName = targetAgentComponent.rc as string;\n const targetAgentKebabCase = kebabCase(targetAgentClassName);\n const targetAgentPort = targetAgentComponent.port ?? 9000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the A2A core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'a2a');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n targetAgentKebabCase,\n targetAgentClassName,\n targetAgentPort,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${targetAgentKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add the remote A2A agent as a tool\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${targetAgentClassName}ClientStrands`;\n const clientVarName =\n targetAgentClassName.charAt(0).toLowerCase() +\n targetAgentClassName.slice(1);\n const toolName = `ask${targetAgentClassName}`;\n const toolVarName = `${clientVarName}Tool`;\n\n // Ensure tool + z imports are available\n await addDestructuredImport(\n tree,\n agentFilePath,\n ['tool'],\n '@strands-agents/sdk',\n );\n await addDestructuredImport(tree, agentFilePath, ['z'], 'zod');\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n // Build the tool creation + Agent wiring.\n const toolCreationBlock = `const ${clientVarName} = await ${clientClassName}.create();\n const ${toolVarName} = tool({\n name: '${toolName}',\n description: 'Delegate a question to the remote ${targetAgentClassName} A2A agent and return its reply.',\n inputSchema: z.object({ prompt: z.string() }),\n callback: async ({ prompt }) => (await ${clientVarName}.invoke(prompt)).toString(),\n });`;\n\n // Transform the arrow function that contains `new Agent`:\n // - Expression body: wrap in block with tool creation and return\n // - Block body: prepend tool creation statement\n await applyGritQL(\n tree,\n agentFilePath,\n `or { \\`async ($p) => new Agent($args)\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n return new Agent($args);\n}\\` where { $program <: not contains \\`${clientClassName}.create\\` }, \\`async ($p) => { $body }\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n $body\n}\\` where { $body <: contains \\`new Agent($_)\\`, $program <: not contains \\`${clientClassName}.create\\` } }`,\n );\n\n // Append the tool to the tools array (after existing items)\n await applyGritQL(\n tree,\n agentFilePath,\n `\\`tools: [$items]\\` => \\`tools: [$items, ${toolVarName}]\\` where { $items <: within \\`new Agent($_)\\`, $items <: not contains \\`${toolVarName}\\` }`,\n );\n }\n\n // 4. Set up dev target — depend on the target agent's dev\n // so running the host's dev also spins up the remote A2A agent.\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const targetDevTargetName = `${targetAgentComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: targetDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@a2a-js/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n 'zod',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_A2A_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentA2aConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","applyGritQL","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_A2A_CONNECTION_GENERATOR_INFO","filename","tsAgentA2aConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","targetAgentComponent","targetComponent","Error","protocol","toLowerCase","name","auth","targetAgentComponentName","targetAgentClassName","rc","targetAgentKebabCase","targetAgentPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","toolName","toolVarName","toolCreationBlock","agentName","devTargetName","targetDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,WAAW,QACN,wBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,OAAO,QAAQ,kCAA+B;AACvD,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBR,oCACpBK,MACAC,QAAQE,aAAa;IAGvB,MAAMC,iBAAiBH,QAAQI,eAAe;IAC9C,MAAMC,uBAAuBL,QAAQM,eAAe;IAEpD,IAAI,CAACH,kBAAkB,CAACE,sBAAsB;QAC5C,MAAM,IAAIE,MACR;IAEJ;IAEA,IAAI,AAACF,CAAAA,qBAAqBG,QAAQ,IAAI,EAAC,EAAGC,WAAW,OAAO,OAAO;QACjE,MAAM,IAAIF,MACR,CAAC,cAAc,EAAEF,qBAAqBK,IAAI,CAAC,WAAW,EAAEL,qBAAqBG,QAAQ,IAAI,OAAO,sDAAsD,CAAC;IAE3J;IAEA,IACEH,qBAAqBM,IAAI,IACzBN,qBAAqBM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AC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe3C,8BAA8B"}
@@ -2,7 +2,7 @@ import { A2AExpressServer } from '@strands-agents/sdk/a2a/express';
2
2
  import express, { type Request, type Response, type NextFunction } from 'express';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { runWithSessionId, withSessionId } from '<%- agentConnectionImport %>';
5
- import { getAgent } from './agent.js';
5
+ import { getAgent } from './agent<% if (esm) { %>.js<% } %>';
6
6
 
7
7
  const PORT = parseInt(process.env.PORT || '9000');
8
8
  const HOST = '0.0.0.0';
@@ -3,7 +3,7 @@ import { createStrandsApp } from '@ag-ui/aws-strands/server';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import type { Request, Response, NextFunction } from 'express';
5
5
  import { runWithSessionId } from '<%- agentConnectionImport %>';
6
- import { getAgent } from './agent.js';
6
+ import { getAgent } from './agent<% if (esm) { %>.js<% } %>';
7
7
 
8
8
  const PORT = parseInt(process.env.PORT || '8080');
9
9
  const HOST = '0.0.0.0';
@@ -1,5 +1,5 @@
1
- import { AppRouter } from './router.js';
2
- import { AgentCoreTrpcClient, WebSocketTrpcClient } from './agent-core-trpc-client.js';
1
+ import { AppRouter } from './router<% if (esm) { %>.js<% } %>';
2
+ import { AgentCoreTrpcClient, WebSocketTrpcClient } from './agent-core-trpc-client<% if (esm) { %>.js<% } %>';
3
3
 
4
4
  /**
5
5
  * Client for connecting to <%- agentNameClassName %> on Bedrock AgentCore Runtime via WebSocket from a NodeJS environment
@@ -4,14 +4,14 @@ import {
4
4
  CreateHTTPContextOptions,
5
5
  createHTTPHandler,
6
6
  } from '@trpc/server/adapters/standalone';
7
- import { appRouter, AppRouter } from './router.js';
7
+ import { appRouter, AppRouter } from './router<% if (esm) { %>.js<% } %>';
8
8
  import { WebSocketServer } from 'ws';
9
9
  import cors from 'cors';
10
10
  import {
11
11
  CreateWSSContextFnOptions,
12
12
  applyWSSHandler,
13
13
  } from '@trpc/server/adapters/ws';
14
- import { Context } from './init.js';
14
+ import { Context } from './init<% if (esm) { %>.js<% } %>';
15
15
 
16
16
  const PORT = parseInt(process.env.PORT || '8080');
17
17
 
@@ -1,8 +1,8 @@
1
- import { publicProcedure, t } from './init.js';
1
+ import { publicProcedure, t } from './init<% if (esm) { %>.js<% } %>';
2
2
  import { z } from 'zod';
3
- import { zAsyncIterable } from './schema/z-async-iterable.js';
3
+ import { zAsyncIterable } from './schema/z-async-iterable<% if (esm) { %>.js<% } %>';
4
4
  import { enterSessionContext, withSessionId } from '<%- agentConnectionImport %>';
5
- import { getAgent } from './agent.js';
5
+ import { getAgent } from './agent<% if (esm) { %>.js<% } %>';
6
6
 
7
7
  export const router = t.router;
8
8
 
@@ -1,6 +1,6 @@
1
1
  import { McpClient } from '@strands-agents/sdk';
2
- import { AgentCoreGatewayMcpClientStrands } from '../core/agentcore-gateway-mcp-client-strands.js';
3
- import { getAgentCoreRuntimeConfig } from '../core/runtime-config.js';
2
+ import { AgentCoreGatewayMcpClientStrands } from '../core/agentcore-gateway-mcp-client-strands<% if (esm) { %>.js<% } %>';
3
+ import { getAgentCoreRuntimeConfig } from '../core/runtime-config<% if (esm) { %>.js<% } %>';
4
4
 
5
5
  /**
6
6
  * Strands client for the <%- gatewayClassName %> AgentCore Gateway.
@@ -8,6 +8,7 @@ import { addDestructuredImport, addStarExport } from "../../../utils/ast.js";
8
8
  import { formatFilesInSubtree } from "../../../utils/format.js";
9
9
  import { installDependencies } from "../../../utils/install.js";
10
10
  import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
11
+ import { esmVars } from "../../../utils/module-format.js";
11
12
  import { kebabCase } from "../../../utils/names.js";
12
13
  import { getNpmScope } from "../../../utils/npm-scope.js";
13
14
  import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
@@ -45,7 +46,8 @@ export const tsAgentGatewayConnectionGenerator = async (tree, options)=>{
45
46
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'), joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
46
47
  gatewayKebabCase,
47
48
  gatewayClassName,
48
- gatewayPort: gateway.port
49
+ gatewayPort: gateway.port,
50
+ ...esmVars(tree)
49
51
  }, {
50
52
  overwriteStrategy: OverwriteStrategy.KeepExisting
51
53
  });