@aws/nx-plugin 1.0.0-rc.31 → 1.0.0-rc.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/LICENSE-THIRD-PARTY +72 -70
  2. package/package.json +5 -5
  3. package/src/infra/app/__snapshots__/generator.spec.ts.snap +15 -15
  4. package/src/infra/app/files/app/src/main.ts.template +1 -1
  5. package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
  6. package/src/infra/app/generator.js +3 -1
  7. package/src/infra/app/generator.js.map +1 -1
  8. package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +64 -3
  9. package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +280 -0
  10. package/src/open-api/ts-client/files/client.gen.ts.template +37 -2
  11. package/src/open-api/ts-client/generator.js +5 -1
  12. package/src/open-api/ts-client/generator.js.map +1 -1
  13. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
  14. package/src/open-api/ts-hooks/generator.js +5 -1
  15. package/src/open-api/ts-hooks/generator.js.map +1 -1
  16. package/src/open-api/utils/normalise.js +13 -6
  17. package/src/open-api/utils/normalise.js.map +1 -1
  18. package/src/open-api/utils/parser.js +12 -1
  19. package/src/open-api/utils/parser.js.map +1 -1
  20. package/src/open-api/utils/types.d.ts +4 -1
  21. package/src/open-api/utils/types.js.map +1 -1
  22. package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
  23. package/src/preset/generator.d.ts +1 -1
  24. package/src/preset/generator.js +5 -2
  25. package/src/preset/generator.js.map +1 -1
  26. package/src/preset/schema.d.js.map +1 -1
  27. package/src/preset/schema.d.ts +2 -0
  28. package/src/preset/schema.json +6 -0
  29. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
  30. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
  31. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
  32. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  33. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +426 -18
  34. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  35. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
  36. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +283 -11
  37. package/src/smithy/ts/api/files/handler.ts.template +2 -2
  38. package/src/smithy/ts/api/files/local-server.ts.template +2 -2
  39. package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
  40. package/src/smithy/ts/api/files/service.ts.template +3 -3
  41. package/src/smithy/ts/api/generator.js +3 -1
  42. package/src/smithy/ts/api/generator.js.map +1 -1
  43. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +426 -18
  44. package/src/trpc/backend/files/src/client/index.ts.template +1 -1
  45. package/src/trpc/backend/files/src/handler.ts.template +1 -1
  46. package/src/trpc/backend/files/src/index.ts.template +5 -5
  47. package/src/trpc/backend/files/src/init.ts.template +1 -1
  48. package/src/trpc/backend/files/src/local-server.ts.template +1 -1
  49. package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
  50. package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
  51. package/src/trpc/backend/files/src/router.ts.template +2 -2
  52. package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
  53. package/src/trpc/backend/generator.js +3 -1
  54. package/src/trpc/backend/generator.js.map +1 -1
  55. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
  56. package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
  57. package/src/ts/agent/a2a-connection/generator.js +3 -1
  58. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  59. package/src/ts/agent/files/a2a/index.ts.template +1 -1
  60. package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
  61. package/src/ts/agent/files/http/client.ts.template +2 -2
  62. package/src/ts/agent/files/http/index.ts.template +2 -2
  63. package/src/ts/agent/files/http/router.ts.template +3 -3
  64. package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
  65. package/src/ts/agent/gateway-connection/generator.js +3 -1
  66. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  67. package/src/ts/agent/generator.js +5 -2
  68. package/src/ts/agent/generator.js.map +1 -1
  69. package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
  70. package/src/ts/agent/mcp-connection/generator.js +3 -1
  71. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  72. package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
  73. package/src/ts/astro-docs/generator.js +2 -0
  74. package/src/ts/astro-docs/generator.js.map +1 -1
  75. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  76. package/src/ts/dynamodb/files/src/client.ts.template +5 -2
  77. package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
  78. package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
  79. package/src/ts/dynamodb/files/src/index.ts.template +2 -2
  80. package/src/ts/dynamodb/generator.js +3 -1
  81. package/src/ts/dynamodb/generator.js.map +1 -1
  82. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  83. package/src/ts/lib/generator.js +7 -1
  84. package/src/ts/lib/generator.js.map +1 -1
  85. package/src/ts/lib/ts-project-utils.js +19 -4
  86. package/src/ts/lib/ts-project-utils.js.map +1 -1
  87. package/src/ts/lib/types.d.ts +6 -0
  88. package/src/ts/lib/types.js.map +1 -1
  89. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -31
  90. package/src/ts/mcp-server/generator.js +11 -22
  91. package/src/ts/mcp-server/generator.js.map +1 -1
  92. package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
  93. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
  94. package/src/ts/nx-generator/generator.js +5 -2
  95. package/src/ts/nx-generator/generator.js.map +1 -1
  96. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
  97. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
  98. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
  99. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
  100. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
  101. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
  102. package/src/ts/nx-plugin/generator.js +3 -1
  103. package/src/ts/nx-plugin/generator.js.map +1 -1
  104. package/src/ts/nx-plugin/utils.js +7 -4
  105. package/src/ts/nx-plugin/utils.js.map +1 -1
  106. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
  107. package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
  108. package/src/ts/rdb/files/src/index.ts.template +1 -1
  109. package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
  110. package/src/ts/rdb/files/src/prisma.ts.template +7 -4
  111. package/src/ts/rdb/generator.js +3 -1
  112. package/src/ts/rdb/generator.js.map +1 -1
  113. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
  114. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
  115. package/src/utils/agent-chat/agent-chat.js +3 -1
  116. package/src/utils/agent-chat/agent-chat.js.map +1 -1
  117. package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
  118. package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
  119. package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
  120. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  121. package/src/utils/agent-connection/agent-connection.js +4 -1
  122. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  123. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
  124. package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
  125. package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
  126. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
  127. package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
  128. package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
  129. package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
  130. package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
  131. package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
  132. package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
  133. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  134. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
  135. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
  136. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
  137. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
  138. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
  139. package/src/utils/api-constructs/api-constructs.js +8 -2
  140. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  141. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
  142. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
  143. package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
  144. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
  145. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
  146. package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
  147. package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
  148. package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
  149. package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
  150. package/src/utils/ast.js +16 -0
  151. package/src/utils/ast.js.map +1 -1
  152. package/src/utils/commands.d.ts +1 -1
  153. package/src/utils/commands.js +4 -1
  154. package/src/utils/commands.js.map +1 -1
  155. package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
  156. package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
  157. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
  158. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
  159. package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
  160. package/src/utils/files/common/constructs/src/index.ts.template +2 -2
  161. package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
  162. package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
  163. package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
  164. package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
  165. package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
  166. package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
  167. package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
  168. package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
  169. package/src/utils/function-constructs/function-constructs.js +3 -1
  170. package/src/utils/function-constructs/function-constructs.js.map +1 -1
  171. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
  172. package/src/utils/identity-constructs/identity-constructs.js +5 -1
  173. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  174. package/src/utils/module-format.d.ts +28 -0
  175. package/src/utils/module-format.js +28 -0
  176. package/src/utils/module-format.js.map +1 -0
  177. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
  178. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
  179. package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
  180. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  181. package/src/utils/shared-constructs.js +3 -1
  182. package/src/utils/shared-constructs.js.map +1 -1
  183. package/src/utils/shared-infra-config.js +3 -1
  184. package/src/utils/shared-infra-config.js.map +1 -1
  185. package/src/utils/shared-infra-scripts.js +3 -1
  186. package/src/utils/shared-infra-scripts.js.map +1 -1
  187. package/src/utils/shared-shadcn.js +3 -1
  188. package/src/utils/shared-shadcn.js.map +1 -1
  189. package/src/utils/test.d.ts +2 -0
  190. package/src/utils/test.js +7 -1
  191. package/src/utils/test.js.map +1 -1
  192. package/src/utils/versions.d.ts +61 -61
  193. package/src/utils/versions.js +59 -59
  194. package/src/utils/versions.js.map +1 -1
  195. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
  196. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
  197. package/src/utils/website-constructs/website-constructs.js +9 -2
  198. package/src/utils/website-constructs/website-constructs.js.map +1 -1
@@ -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,oBAAoB,EACpBC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,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AAW;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","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,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,eAAe;IAC9C,MAAMC,uBAAuBL,QAAQM,eAAe;IAEpD,IAAI,CAACH,kBAAkB,CAACE,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A2BmB,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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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
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/gateway-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { readAgentCoreGatewayMetadata } from '../../../agentcore-gateway/generator';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentGatewayConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentGatewayConnectionGenerator = async (\n tree: Tree,\n options: TsAgentGatewayConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const agentComponent = options.sourceComponent;\n if (!agentComponent) {\n throw new Error(\n 'sourceComponent must be provided for ts#agent -> agentcore-gateway connections',\n );\n }\n const gateway = readAgentCoreGatewayMetadata(targetProject);\n\n if (gateway.protocol !== 'mcp') {\n throw new Error(\n `Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Only MCP-protocol gateways are supported.`,\n );\n }\n if (gateway.auth !== 'iam') {\n throw new Error(\n `Gateway '${gateway.name}' uses auth='${gateway.auth}'. Only IAM-authenticated gateways are supported in v1.`,\n );\n }\n if (agentComponent.auth && agentComponent.auth !== 'iam') {\n throw new Error(\n `Agent '${agentComponent.name}' uses auth='${agentComponent.auth}'. Only IAM-authenticated agents can connect to IAM gateways.`,\n );\n }\n\n const gatewayClassName = gateway.rc;\n const gatewayKebabCase = kebabCase(gatewayClassName);\n // A gateway is its own standalone project, so it exposes plain serve / dev.\n const gatewayServeTargetName = 'serve';\n const gatewayDevTargetName = 'dev';\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the gateway\n // core client template.\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'gateway');\n\n // 2. Generate the per-connection <Gateway>Client into app/. Local mode\n // points at the gateway project's local gateway port.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n gatewayKebabCase,\n gatewayClassName,\n gatewayPort: gateway.port,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Re-export from the agent-connection index\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${gatewayKebabCase}-client-strands.js`,\n );\n\n // 3. AST-transform agent.ts to add the gateway client (an McpClient in\n // both deployed and local modes) to the agent's tools.\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${gatewayClassName}ClientStrands`;\n const clientVarName =\n gatewayClassName.charAt(0).toLowerCase() + gatewayClassName.slice(1);\n\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Wire dev chain — agent's dev depends on gateway's\n // aggregator target, which transitively starts each attached MCP server.\n const agentName = agentComponent.name ?? 'agent';\n const serveTargetName = `${agentName}-serve`;\n const devTargetName = `${agentName}-dev`;\n let projectConfigChanged = false;\n if (sourceProject.targets?.[serveTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, serveTargetName, {\n projects: [targetProject.name],\n target: gatewayServeTargetName,\n });\n projectConfigChanged = true;\n }\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: gatewayDevTargetName,\n });\n projectConfigChanged = true;\n }\n if (projectConfigChanged) {\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGatewayConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","readAgentCoreGatewayMetadata","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO","filename","tsAgentGatewayConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","Error","gateway","protocol","name","auth","gatewayClassName","rc","gatewayKebabCase","gatewayServeTargetName","gatewayDevTargetName","npmScope","dirname","gatewayPort","port","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","toLowerCase","slice","agentName","serveTargetName","devTargetName","projectConfigChanged","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,4BAA4B,QAAQ,0CAAuC;AACpF,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAqB;AAC1E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,6CACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,oCAAoC,OAC/CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAM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CH;KACD;IAED,MAAMT,qBAAqBY;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQsC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAezC,kCAAkC"}
1
+ {"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/gateway-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { readAgentCoreGatewayMetadata } from '../../../agentcore-gateway/generator';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentGatewayConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentGatewayConnectionGenerator = async (\n tree: Tree,\n options: TsAgentGatewayConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const agentComponent = options.sourceComponent;\n if (!agentComponent) {\n throw new Error(\n 'sourceComponent must be provided for ts#agent -> agentcore-gateway connections',\n );\n }\n const gateway = readAgentCoreGatewayMetadata(targetProject);\n\n if (gateway.protocol !== 'mcp') {\n throw new Error(\n `Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Only MCP-protocol gateways are supported.`,\n );\n }\n if (gateway.auth !== 'iam') {\n throw new Error(\n `Gateway '${gateway.name}' uses auth='${gateway.auth}'. Only IAM-authenticated gateways are supported in v1.`,\n );\n }\n if (agentComponent.auth && agentComponent.auth !== 'iam') {\n throw new Error(\n `Agent '${agentComponent.name}' uses auth='${agentComponent.auth}'. Only IAM-authenticated agents can connect to IAM gateways.`,\n );\n }\n\n const gatewayClassName = gateway.rc;\n const gatewayKebabCase = kebabCase(gatewayClassName);\n // A gateway is its own standalone project, so it exposes plain serve / dev.\n const gatewayServeTargetName = 'serve';\n const gatewayDevTargetName = 'dev';\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the gateway\n // core client template.\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'gateway');\n\n // 2. Generate the per-connection <Gateway>Client into app/. Local mode\n // points at the gateway project's local gateway port.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n gatewayKebabCase,\n gatewayClassName,\n gatewayPort: gateway.port,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Re-export from the agent-connection index\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${gatewayKebabCase}-client-strands.js`,\n );\n\n // 3. AST-transform agent.ts to add the gateway client (an McpClient in\n // both deployed and local modes) to the agent's tools.\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${gatewayClassName}ClientStrands`;\n const clientVarName =\n gatewayClassName.charAt(0).toLowerCase() + gatewayClassName.slice(1);\n\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Wire dev chain — agent's dev depends on gateway's\n // aggregator target, which transitively starts each attached MCP server.\n const agentName = agentComponent.name ?? 'agent';\n const serveTargetName = `${agentName}-serve`;\n const devTargetName = `${agentName}-dev`;\n let projectConfigChanged = false;\n if (sourceProject.targets?.[serveTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, serveTargetName, {\n projects: [targetProject.name],\n target: gatewayServeTargetName,\n });\n projectConfigChanged = true;\n }\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: gatewayDevTargetName,\n });\n projectConfigChanged = true;\n }\n if (projectConfigChanged) {\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGatewayConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","readAgentCoreGatewayMetadata","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO","filename","tsAgentGatewayConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","Error","gateway","protocol","name","auth","gatewayClassName","rc","gatewayKebabCase","gatewayServeTargetName","gatewayDevTargetName","npmScope","dirname","gatewayPort","port","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","toLowerCase","slice","agentName","serveTargetName","devTargetName","projectConfigChanged","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,4BAA4B,QAAQ,0CAAuC;AACpF,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAqB;AAC1E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,OAAO,QAAQ,kCAA+B;AACvD,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,6CACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,oCAAo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AClB3B,6BACEyB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMP,gCAAgCW,MAAM;QAC1CH;KACD;IAED,MAAMV,qBAAqBa;IAC3B,OAAO,IACLZ,oBAAoBY,MAAMC,QAAQsC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAezC,kCAAkC"}
@@ -12,6 +12,7 @@ import { FsCommands } from "../../utils/fs.js";
12
12
  import { resolveIac } from "../../utils/iac.js";
13
13
  import { installDependencies } from "../../utils/install.js";
14
14
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
15
+ import { esmVars } from "../../utils/module-format.js";
15
16
  import { kebabCase, toClassName } from "../../utils/names.js";
16
17
  import { getNpmScope } from "../../utils/npm-scope.js";
17
18
  import { addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
@@ -51,7 +52,8 @@ export const tsAgentGenerator = async (tree, options)=>{
51
52
  name,
52
53
  agentNameClassName,
53
54
  distDir,
54
- agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`
55
+ agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`,
56
+ ...esmVars(tree)
55
57
  };
56
58
  // Generate common files shared by both protocols
57
59
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'common'), targetSourceDir, templateContext, {
@@ -74,7 +76,8 @@ export const tsAgentGenerator = async (tree, options)=>{
74
76
  distDir,
75
77
  name,
76
78
  protocol,
77
- adotVersion: TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation']
79
+ adotVersion: TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],
80
+ ...esmVars(tree)
78
81
  }, {
79
82
  overwriteStrategy: OverwriteStrategy.KeepExisting
80
83
  });