@aws/nx-plugin 1.0.0-rc.58 → 1.0.0-rc.59

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 (96) hide show
  1. package/generators.json +17 -1
  2. package/migrations.json +12 -7
  3. package/package.json +1 -1
  4. package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +273 -0
  5. package/src/agentcore-gateway/agent-connection/generator.d.ts +19 -0
  6. package/src/agentcore-gateway/agent-connection/generator.js +90 -0
  7. package/src/agentcore-gateway/agent-connection/generator.js.map +1 -0
  8. package/src/agentcore-gateway/agent-connection/schema.d.js +6 -0
  9. package/src/agentcore-gateway/agent-connection/schema.d.js.map +1 -0
  10. package/src/agentcore-gateway/agent-connection/schema.d.ts +13 -0
  11. package/src/agentcore-gateway/agent-connection/schema.json +31 -0
  12. package/src/agentcore-gateway/attach-upstream.d.ts +16 -0
  13. package/src/agentcore-gateway/attach-upstream.js +32 -11
  14. package/src/agentcore-gateway/attach-upstream.js.map +1 -1
  15. package/src/agentcore-gateway/files/project/http/local-dev.ts.template +77 -0
  16. package/src/agentcore-gateway/generator.d.ts +1 -0
  17. package/src/agentcore-gateway/generator.js +22 -10
  18. package/src/agentcore-gateway/generator.js.map +1 -1
  19. package/src/agentcore-gateway/react-connection/__snapshots__/generator.spec.ts.snap +68 -0
  20. package/src/agentcore-gateway/react-connection/generator.d.ts +19 -0
  21. package/src/agentcore-gateway/react-connection/generator.js +119 -0
  22. package/src/agentcore-gateway/react-connection/generator.js.map +1 -0
  23. package/src/agentcore-gateway/react-connection/schema.d.js +6 -0
  24. package/src/agentcore-gateway/react-connection/schema.d.js.map +1 -0
  25. package/src/agentcore-gateway/react-connection/schema.d.ts +13 -0
  26. package/src/agentcore-gateway/react-connection/schema.json +31 -0
  27. package/src/agentcore-gateway/schema.d.js.map +1 -1
  28. package/src/agentcore-gateway/schema.d.ts +1 -1
  29. package/src/agentcore-gateway/schema.json +2 -2
  30. package/src/connection/agent-local-dev.d.ts +16 -0
  31. package/src/connection/agent-local-dev.js +44 -2
  32. package/src/connection/agent-local-dev.js.map +1 -1
  33. package/src/connection/gateway-runtime-config.d.ts +19 -0
  34. package/src/connection/gateway-runtime-config.js +47 -0
  35. package/src/connection/gateway-runtime-config.js.map +1 -0
  36. package/src/connection/generator.js +5 -0
  37. package/src/connection/generator.js.map +1 -1
  38. package/src/connection/scaffold-catalog.d.ts +107 -0
  39. package/src/connection/scaffold-catalog.js +140 -0
  40. package/src/connection/scaffold-catalog.js.map +1 -1
  41. package/src/connection/supported-connections.d.ts +9 -0
  42. package/src/connection/supported-connections.js +12 -0
  43. package/src/connection/supported-connections.js.map +1 -1
  44. package/src/internal/test-matrix/generator.js +39 -1
  45. package/src/internal/test-matrix/generator.js.map +1 -1
  46. package/src/migrations/latest/gateway-agent-targets/__snapshots__/migration.spec.ts.snap +223 -0
  47. package/src/migrations/latest/gateway-agent-targets/metadata.json +3 -0
  48. package/src/migrations/latest/gateway-agent-targets/migration.d.ts +6 -0
  49. package/src/migrations/latest/gateway-agent-targets/migration.js +217 -0
  50. package/src/migrations/latest/gateway-agent-targets/migration.js.map +1 -0
  51. package/src/migrations/latest/smithy-ssdk-bundle-pins/metadata.json +3 -0
  52. package/src/migrations/v1.0.0-rc.50/modernize-function-props-cast/metadata.json +3 -0
  53. package/src/migrations/v1.0.0-rc.50/restrict-cors-to-custom-domains/metadata.json +3 -0
  54. package/src/migrations/v1.0.0-rc.50/terraform-bootstrap-adopt-existing-bucket/metadata.json +3 -0
  55. package/src/migrations/v1.0.0-rc.52/user-identity-waf-allow-localhost-callback/metadata.json +3 -0
  56. package/src/migrations/v1.0.0-rc.54/order-access-log-delivery-after-bucket-policy/metadata.json +3 -0
  57. package/src/migrations/v1.0.0-rc.55/backfill-generator-metadata/metadata.json +3 -0
  58. package/src/migrations/v1.0.0-rc.56/dynamodb-local-remove-optimize-flag/metadata.json +3 -0
  59. package/src/migrations/v1.0.0-rc.57/ts-agent-session-management-support/metadata.json +3 -0
  60. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +2 -0
  61. package/src/py/agent/react-connection/generator.d.ts +4 -1
  62. package/src/py/agent/react-connection/generator.js +35 -14
  63. package/src/py/agent/react-connection/generator.js.map +1 -1
  64. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +4 -0
  65. package/src/ts/agent/react-connection/generator.d.ts +16 -1
  66. package/src/ts/agent/react-connection/generator.js +21 -8
  67. package/src/ts/agent/react-connection/generator.js.map +1 -1
  68. package/src/ts/nx-migration/generator.js +40 -27
  69. package/src/ts/nx-migration/generator.js.map +1 -1
  70. package/src/ts/react-website/agui/files/common/src/hooks/useAgui__agentNameClassName__.tsx.template +16 -0
  71. package/src/ts/react-website/agui/generator.d.ts +11 -0
  72. package/src/ts/react-website/agui/generator.js +11 -7
  73. package/src/ts/react-website/agui/generator.js.map +1 -1
  74. package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +5 -0
  75. package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -0
  76. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  77. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -0
  78. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +6 -4
  79. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +119 -3
  80. package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +17 -0
  81. package/src/utils/config/utils.d.ts +5 -0
  82. package/src/utils/config/utils.js +7 -1
  83. package/src/utils/config/utils.js.map +1 -1
  84. package/src/utils/connection/open-api/files/components/__apiNameClassName__Provider.tsx.template +13 -2
  85. package/src/utils/connection/open-api/react.d.ts +10 -1
  86. package/src/utils/connection/open-api/react.js +3 -2
  87. package/src/utils/connection/open-api/react.js.map +1 -1
  88. package/src/utils/migration-manifest.d.ts +58 -0
  89. package/src/utils/migration-manifest.js +76 -0
  90. package/src/utils/migration-manifest.js.map +1 -0
  91. package/src/utils/migration-versions.d.ts +2 -0
  92. package/src/utils/migration-versions.js.map +1 -1
  93. package/src/utils/version-upgrade-migration/register.d.ts +4 -2
  94. package/src/utils/version-upgrade-migration/register.js +13 -13
  95. package/src/utils/version-upgrade-migration/register.js.map +1 -1
  96. /package/src/agentcore-gateway/files/project/{local-dev.ts.template → mcp/local-dev.ts.template} +0 -0
@@ -0,0 +1,77 @@
1
+ import express from 'express';
2
+ import { Readable } from 'node:stream';
3
+
4
+ const PORT = parseInt(process.env.PORT || '<%- port %>');
5
+
6
+ interface AttachedAgent {
7
+ name: string;
8
+ url: string;
9
+ /**
10
+ * Whether to strip the `/invocations` path prefix when proxying. The
11
+ * deployed gateway maps an A2A target's `/invocations/...` paths onto the
12
+ * agent container's root; HTTP and AG-UI agents serve `/invocations`
13
+ * themselves.
14
+ */
15
+ stripInvocations: boolean;
16
+ }
17
+
18
+ // Upstream agent endpoints attached to this gateway, maintained by the
19
+ // `agentcore-gateway#agent-connection` generator.
20
+ const ATTACHED_AGENTS: AttachedAgent[] = [<% attachedAgents.forEach((a) => { %>
21
+ { name: '<%- a.name %>', url: 'http://localhost:<%- a.port %>', stripInvocations: <%- a.stripInvocations %> },<% }); %>
22
+ ];
23
+
24
+ /**
25
+ * Local gateway for <%- nameClassName %>: proxies `/<targetName>/<path>` to
26
+ * the attached agent's local server, matching the deployed AgentCore
27
+ * Gateway's path-based routing for agent runtime targets.
28
+ */
29
+ const app = express();
30
+
31
+ app.use(async (req, res) => {
32
+ const [, targetName, ...rest] = req.url.split('/');
33
+ const upstream = ATTACHED_AGENTS.find((a) => a.name === targetName);
34
+ if (!upstream) {
35
+ res.status(404).json({ message: `Unknown gateway target: ${targetName}` });
36
+ return;
37
+ }
38
+ const upstreamPath = upstream.stripInvocations
39
+ ? rest.join('/').replace(/^invocations\/?/, '')
40
+ : rest.join('/');
41
+ try {
42
+ const response = await fetch(`${upstream.url}/${upstreamPath}`, {
43
+ method: req.method,
44
+ headers: Object.fromEntries(
45
+ Object.entries(req.headers).filter(
46
+ ([key, value]) => typeof value === 'string' && key !== 'host',
47
+ ) as [string, string][],
48
+ ),
49
+ body: ['GET', 'HEAD'].includes(req.method)
50
+ ? undefined
51
+ : Readable.toWeb(req),
52
+ // Node's fetch requires half-duplex for streamed request bodies.
53
+ duplex: 'half',
54
+ } as RequestInit);
55
+ res.status(response.status);
56
+ response.headers.forEach((value, key) => {
57
+ // The upstream body arrives decoded, so its encoding headers would be incorrect.
58
+ if (!['content-encoding', 'content-length'].includes(key)) {
59
+ res.setHeader(key, value);
60
+ }
61
+ });
62
+ if (response.body) {
63
+ Readable.fromWeb(response.body as any).pipe(res);
64
+ } else {
65
+ res.end();
66
+ }
67
+ } catch (error) {
68
+ console.error(`Error proxying to ${upstream.name}:`, error);
69
+ if (!res.headersSent) {
70
+ res.status(502).json({ message: 'Bad gateway' });
71
+ }
72
+ }
73
+ });
74
+
75
+ app.listen(PORT, () => {
76
+ console.log(`<%- nameKebabCase %>: local gateway listening on port ${PORT}`);
77
+ });
@@ -8,6 +8,7 @@ import type { IacMetadata } from '../utils/shared-constructs-constants';
8
8
  import type { AgentcoreGatewayGeneratorSchema } from './schema';
9
9
  export declare const DEPENDENCIES: import("../utils/declared-dependencies").DependencyDeclaration<readonly [{
10
10
  readonly name: "@modelcontextprotocol/sdk";
11
+ readonly when: (m: AgentCoreGatewayMetadata) => boolean;
11
12
  }, {
12
13
  readonly name: "express";
13
14
  }, {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
- */ import { addProjectConfiguration, generateFiles, joinPathFragments, OverwriteStrategy, updateProjectConfiguration } from "@nx/devkit";
4
+ */ import { addProjectConfiguration, generateFiles, joinPathFragments, logger, OverwriteStrategy, updateProjectConfiguration } from "@nx/devkit";
5
5
  import { addTsDependencies } from "../utils/add-dependencies.js";
6
6
  import { AGENT_CORE_CONSTRUCTS_DEPENDENCIES, AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES, addAgentCoreGatewayInfra } from "../utils/agent-core-constructs/agent-core-constructs.js";
7
7
  import { declareDependencies, ownedElsewhere } from "../utils/declared-dependencies.js";
@@ -15,12 +15,14 @@ import { addGeneratorMetadata, getGeneratorInfo, projectExists, readProjectConfi
15
15
  import { assignPort } from "../utils/port.js";
16
16
  import { ensureProjectPackageJson } from "../utils/project-package-json.js";
17
17
  import { SHARED_CONSTRUCTS_DEPENDENCIES, sharedConstructsGenerator } from "../utils/shared-constructs.js";
18
- // The gateway's local-dev server and Cedar policy rendering need these whatever
19
- // the protocol or auth, so no entry is conditional.
18
+ // The gateway's local-dev server and Cedar policy rendering need these
19
+ // whatever the auth; only the MCP SDK is protocol-specific (the http local
20
+ // gateway is a plain proxy).
20
21
  export const DEPENDENCIES = declareDependencies()({
21
22
  ts: [
22
23
  {
23
- name: '@modelcontextprotocol/sdk'
24
+ name: '@modelcontextprotocol/sdk',
25
+ when: (m)=>m.protocol === 'mcp'
24
26
  },
25
27
  {
26
28
  name: 'express'
@@ -57,15 +59,23 @@ export const agentcoreGatewayGenerator = async (tree, options)=>{
57
59
  const subDir = options.subDirectory ?? name;
58
60
  const projectRoot = joinPathFragments(parentDir, subDir);
59
61
  const fullyQualifiedName = `${getNpmScopePrefix(tree)}${name}`;
60
- // Protocol is fixed to mcp the enum accepts only this value, but we still
61
- // persist the resolved value in metadata so connection generators can read
62
- // it uniformly (and future additions are non-breaking).
62
+ // Protocol is mcp (aggregate MCP server targets into one MCP endpoint) or
63
+ // http (proxy agent runtime targets via path-based routing). Persisted in
64
+ // metadata so connection generators can validate it.
63
65
  const protocol = options.protocol ?? 'mcp';
64
66
  // Inbound auth is iam (default) or cognito. Persisted in metadata so
65
67
  // connection generators can validate it (agent -> gateway connections
66
68
  // require an IAM gateway).
67
69
  const auth = options.auth ?? 'iam';
68
- const cedarPolicy = options.cedarPolicy ?? true;
70
+ // Cedar policies authorize MCP tool actions, which an http gateway has none
71
+ // of — its runtime targets are plain proxied endpoints — so the policy
72
+ // engine only applies to mcp gateways. cedarPolicy defaults to true in the
73
+ // schema, so an http gateway quietly drops it rather than requiring
74
+ // --cedarPolicy=false.
75
+ if (protocol === 'http' && options.cedarPolicy) {
76
+ logger.warn('Cedar policies authorize MCP tool actions, so cedarPolicy is ignored for http-protocol gateways.');
77
+ }
78
+ const cedarPolicy = protocol === 'mcp' && (options.cedarPolicy ?? true);
69
79
  const infra = options.infra ?? 'agentcore';
70
80
  // local-dev.ts is the local gateway: a continuous MCP aggregator chaining
71
81
  // onto attached MCP servers' dev targets (added by the mcp-connection
@@ -119,11 +129,12 @@ export const agentcoreGatewayGenerator = async (tree, options)=>{
119
129
  project.targets['dev'] ??= localGatewayTarget(port);
120
130
  updateProjectConfiguration(tree, project.name, project);
121
131
  // Scaffold the gateway project: local-dev.ts (+ Cedar policies if requested)
122
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'project'), projectRoot, {
132
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'project', protocol), projectRoot, {
123
133
  nameClassName,
124
134
  nameKebabCase: name,
125
135
  port,
126
- attachedMcpServers: []
136
+ attachedMcpServers: [],
137
+ attachedAgents: []
127
138
  }, {
128
139
  overwriteStrategy: OverwriteStrategy.KeepExisting
129
140
  });
@@ -172,6 +183,7 @@ export const agentcoreGatewayGenerator = async (tree, options)=>{
172
183
  projectDirectory: projectRoot,
173
184
  cedarPolicy,
174
185
  auth,
186
+ protocol,
175
187
  iac
176
188
  }, DEPENDENCIES);
177
189
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-gateway/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../utils/add-dependencies';\nimport {\n AGENT_CORE_CONSTRUCTS_DEPENDENCIES,\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addAgentCoreGatewayInfra,\n} from '../utils/agent-core-constructs/agent-core-constructs';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../utils/declared-dependencies';\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 } from '../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n readProjectConfigurationUnqualified,\n} from '../utils/nx';\nimport { assignPort } from '../utils/port';\nimport { ensureProjectPackageJson } from '../utils/project-package-json';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../utils/shared-constructs';\nimport type { IacMetadata } from '../utils/shared-constructs-constants';\nimport type { AgentcoreGatewayGeneratorSchema } from './schema';\n\n// The gateway's local-dev server and Cedar policy rendering need these whatever\n// the protocol or auth, so no entry is conditional.\nexport const DEPENDENCIES = declareDependencies<AgentCoreGatewayMetadata>()({\n ts: [\n { name: '@modelcontextprotocol/sdk' },\n { name: 'express' },\n { name: '@types/express', dev: true },\n // ejs renders the Cedar policy in the shared gateway construct.\n { name: 'ejs', dev: true },\n { name: '@types/ejs', dev: true },\n // local-dev.ts runs via tsx, which is shared tooling.\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(AGENT_CORE_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const AGENTCORE_GATEWAY_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const agentcoreGatewayGenerator = async (\n tree: Tree,\n options: AgentcoreGatewayGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const name = kebabCase(options.name);\n const nameClassName = toClassName(name);\n const parentDir = options.directory ?? 'packages';\n const subDir = options.subDirectory ?? name;\n const projectRoot = joinPathFragments(parentDir, subDir);\n const fullyQualifiedName = `${getNpmScopePrefix(tree)}${name}`;\n\n // Protocol is fixed to mcp — the enum accepts only this value, but we still\n // persist the resolved value in metadata so connection generators can read\n // it uniformly (and future additions are non-breaking).\n const protocol = options.protocol ?? 'mcp';\n // Inbound auth is iam (default) or cognito. Persisted in metadata so\n // connection generators can validate it (agent -> gateway connections\n // require an IAM gateway).\n const auth = options.auth ?? 'iam';\n const cedarPolicy = options.cedarPolicy ?? true;\n const infra = options.infra ?? 'agentcore';\n\n // local-dev.ts is the local gateway: a continuous MCP aggregator chaining\n // onto attached MCP servers' dev targets (added by the mcp-connection\n // generator), so a single `nx dev <gateway>` boots the gateway and every\n // attached MCP server together.\n //\n // `serve` exists for parity with other generators; the deployed Gateway is\n // a managed AWS resource, so `serve`-mode agents talk to it via runtime\n // config and the local gateway sits idle.\n const localGatewayTarget = (port: number) => ({\n executor: 'nx:run-commands' as const,\n continuous: true,\n options: {\n command: 'tsx local-dev.ts',\n cwd: '{projectRoot}',\n env: { PORT: `${port}` },\n },\n dependsOn: [] as Array<string | { projects: string[]; target: string }>,\n });\n let project: ProjectConfiguration;\n if (projectExists(tree, fullyQualifiedName)) {\n project = readProjectConfigurationUnqualified(tree, fullyQualifiedName);\n } else {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: projectRoot,\n projectType: 'library',\n sourceRoot: projectRoot,\n tags: [],\n targets: {},\n metadata: {\n generator: AGENTCORE_GATEWAY_GENERATOR_INFO.id,\n } as any,\n });\n project = readProjectConfigurationUnqualified(tree, fullyQualifiedName);\n }\n // Ensure the project has its own package.json so its runtime dependencies\n // (added below) are declared in it rather than the workspace root.\n ensureProjectPackageJson(tree, {\n dir: projectRoot,\n fullyQualifiedName,\n });\n const port = assignPort(tree, project, 8100);\n // A gateway is its own standalone project, so it uses plain `serve` / `dev`\n // targets. Re-run: keep existing targets (their dependsOn may have been\n // populated by the mcp-connection generator), just ensure both exist.\n project.targets ??= {};\n project.targets['serve'] ??= localGatewayTarget(port);\n project.targets['dev'] ??= localGatewayTarget(port);\n updateProjectConfiguration(tree, project.name, project);\n\n // Scaffold the gateway project: local-dev.ts (+ Cedar policies if requested)\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'project'),\n projectRoot,\n { nameClassName, nameKebabCase: name, port, attachedMcpServers: [] },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n if (cedarPolicy) {\n // The default permit-all policy differs by auth type: AgentCore represents\n // IAM callers as `AgentCore::IamEntity` and Cognito/JWT callers as\n // `AgentCore::OAuthUser`, so the two policies match different principals.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cedar'),\n projectRoot,\n { nameClassName, auth },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: AgentCoreGatewayMetadata = {\n name,\n rc: nameClassName,\n protocol,\n auth,\n port,\n ...(iac ? { iac } : {}),\n };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n AGENTCORE_GATEWAY_GENERATOR_INFO,\n metadata,\n );\n\n addTsDependencies(tree, DEPENDENCIES, { metadata, projectRoot });\n\n // Wire up infra (CDK or Terraform); re-running with infra=agentcore adds\n // the infrastructure to a previously infra-less gateway.\n\n if (infra === 'agentcore') {\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n await addAgentCoreGatewayInfra(\n tree,\n {\n gatewayNameClassName: nameClassName,\n gatewayNameKebabCase: name,\n projectName: fullyQualifiedName,\n projectDirectory: projectRoot,\n cedarPolicy,\n auth,\n iac,\n },\n DEPENDENCIES,\n );\n }\n\n await addGeneratorMetricsIfApplicable(tree, [\n AGENTCORE_GATEWAY_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\n/**\n * Gateway details stored in the gateway project's metadata.\n */\nexport interface AgentCoreGatewayMetadata extends IacMetadata {\n name: string;\n rc: string;\n protocol: string;\n auth: string;\n port: number;\n}\n\n/**\n * Read a gateway project's metadata, validating it was generated by the\n * agentcore-gateway generator.\n */\nexport const readAgentCoreGatewayMetadata = (\n project: ProjectConfiguration,\n): AgentCoreGatewayMetadata => {\n const metadata = project.metadata as any;\n if (metadata?.generator !== AGENTCORE_GATEWAY_GENERATOR_INFO.id) {\n throw new Error(\n `Project '${project.name}' was not generated by the '${AGENTCORE_GATEWAY_GENERATOR_INFO.id}' generator.`,\n );\n }\n return metadata as AgentCoreGatewayMetadata;\n};\n\nexport default agentcoreGatewayGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","AGENT_CORE_CONSTRUCTS_DEPENDENCIES","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addAgentCoreGatewayInfra","declareDependencies","ownedElsewhere","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","readProjectConfigurationUnqualified","assignPort","ensureProjectPackageJson","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","name","dev","root","py","AGENTCORE_GATEWAY_GENERATOR_INFO","filename","agentcoreGatewayGenerator","tree","options","nameClassName","parentDir","directory","subDir","subDirectory","projectRoot","fullyQualifiedName","protocol","auth","cedarPolicy","infra","localGatewayTarget","port","executor","continuous","command","cwd","env","PORT","dependsOn","project","projectType","sourceRoot","tags","targets","metadata","generator","id","dir","dirname","nameKebabCase","attachedMcpServers","overwriteStrategy","KeepExisting","iac","undefined","rc","gatewayNameClassName","gatewayNameKebabCase","projectName","projectDirectory","preferInstallDependencies","languages","readAgentCoreGatewayMetadata","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,+BAA4B;AAC9D,SACEC,kCAAkC,EAClCC,qCAAqC,EACrCC,wBAAwB,QACnB,0DAAuD;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,oCAAiC;AACxC,SAASC,oBAAoB,QAAQ,qBAAkB;AACvD,SAASC,UAAU,QAAQ,kBAAe;AAC1C,SAASC,mBAAmB,QAAQ,sBAAmB;AACvD,SAASC,+BAA+B,QAAQ,sBAAmB;AACnE,SAASC,SAAS,EAAEC,WAAW,QAAQ,oBAAiB;AACxD,SAASC,iBAAiB,QAAQ,wBAAqB;AACvD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,EACbC,mCAAmC,QAC9B,iBAAc;AACrB,SAASC,UAAU,QAAQ,mBAAgB;AAC3C,SAASC,wBAAwB,QAAQ,mCAAgC;AACzE,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,gCAA6B;AAIpC,gFAAgF;AAChF,oDAAoD;AACpD,OAAO,MAAMC,eAAejB,sBAAgD;IAC1EkB,IAAI;QACF;YAAEC,MAAM;QAA4B;QACpC;YAAEA,MAAM;QAAU;QAClB;YAAEA,MAAM;YAAkBC,KAAK;QAAK;QACpC,gEAAgE;Q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;IACxB;IAEArD,qBACEiB,MACAQ,oBACAX,kCACA8B;IAGFzD,kBAAkB8B,MAAMT,cAAc;QAAEoC;QAAUpB;IAAY;IAE9D,yEAAyE;IACzE,yDAAyD;IAEzD,IAAIK,UAAU,aAAa;QACzB,MAAMtB,0BAA0BU,MAAM;YAAEoC;QAAI,GAAG7C;QAE/C,MAAMlB,yBACJ2B,MACA;YACEuC,sBAAsBrC;YACtBsC,sBAAsB/C;YACtBgD,aAAajC;YACbkC,kBAAkBnC;YAClBI;YACAD;YACA0B;QACF,GACA7C;IAEJ;IAEA,MAAMZ,gCAAgCqB,MAAM;QAC1CH;KACD;IAED,MAAMrB,qBAAqBwB;IAC3B,OAAO,IACLtB,oBAAoBsB,MAAMC,QAAQ0C,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAaF;;;CAGC,GACD,OAAO,MAAMC,+BAA+B,CAC1CvB;IAEA,MAAMK,WAAWL,QAAQK,QAAQ;IACjC,IAAIA,UAAUC,cAAc/B,iCAAiCgC,EAAE,EAAE;QAC/D,MAAM,IAAIiB,MACR,CAAC,SAAS,EAAExB,QAAQ7B,IAAI,CAAC,4BAA4B,EAAEI,iCAAiCgC,EAAE,CAAC,YAAY,CAAC;IAE5G;IACA,OAAOF;AACT,EAAE;AAEF,eAAe5B,0BAA0B"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-gateway/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n logger,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../utils/add-dependencies';\nimport {\n AGENT_CORE_CONSTRUCTS_DEPENDENCIES,\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addAgentCoreGatewayInfra,\n} from '../utils/agent-core-constructs/agent-core-constructs';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../utils/declared-dependencies';\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 } from '../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n readProjectConfigurationUnqualified,\n} from '../utils/nx';\nimport { assignPort } from '../utils/port';\nimport { ensureProjectPackageJson } from '../utils/project-package-json';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../utils/shared-constructs';\nimport type { IacMetadata } from '../utils/shared-constructs-constants';\nimport type { AgentcoreGatewayGeneratorSchema } from './schema';\n\n// The gateway's local-dev server and Cedar policy rendering need these\n// whatever the auth; only the MCP SDK is protocol-specific (the http local\n// gateway is a plain proxy).\nexport const DEPENDENCIES = declareDependencies<AgentCoreGatewayMetadata>()({\n ts: [\n { name: '@modelcontextprotocol/sdk', when: (m) => m.protocol === 'mcp' },\n { name: 'express' },\n { name: '@types/express', dev: true },\n // ejs renders the Cedar policy in the shared gateway construct.\n { name: 'ejs', dev: true },\n { name: '@types/ejs', dev: true },\n // local-dev.ts runs via tsx, which is shared tooling.\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(AGENT_CORE_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const AGENTCORE_GATEWAY_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const agentcoreGatewayGenerator = async (\n tree: Tree,\n options: AgentcoreGatewayGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const name = kebabCase(options.name);\n const nameClassName = toClassName(name);\n const parentDir = options.directory ?? 'packages';\n const subDir = options.subDirectory ?? name;\n const projectRoot = joinPathFragments(parentDir, subDir);\n const fullyQualifiedName = `${getNpmScopePrefix(tree)}${name}`;\n\n // Protocol is mcp (aggregate MCP server targets into one MCP endpoint) or\n // http (proxy agent runtime targets via path-based routing). Persisted in\n // metadata so connection generators can validate it.\n const protocol = options.protocol ?? 'mcp';\n // Inbound auth is iam (default) or cognito. Persisted in metadata so\n // connection generators can validate it (agent -> gateway connections\n // require an IAM gateway).\n const auth = options.auth ?? 'iam';\n // Cedar policies authorize MCP tool actions, which an http gateway has none\n // of — its runtime targets are plain proxied endpoints — so the policy\n // engine only applies to mcp gateways. cedarPolicy defaults to true in the\n // schema, so an http gateway quietly drops it rather than requiring\n // --cedarPolicy=false.\n if (protocol === 'http' && options.cedarPolicy) {\n logger.warn(\n 'Cedar policies authorize MCP tool actions, so cedarPolicy is ignored for http-protocol gateways.',\n );\n }\n const cedarPolicy = protocol === 'mcp' && (options.cedarPolicy ?? true);\n const infra = options.infra ?? 'agentcore';\n\n // local-dev.ts is the local gateway: a continuous MCP aggregator chaining\n // onto attached MCP servers' dev targets (added by the mcp-connection\n // generator), so a single `nx dev <gateway>` boots the gateway and every\n // attached MCP server together.\n //\n // `serve` exists for parity with other generators; the deployed Gateway is\n // a managed AWS resource, so `serve`-mode agents talk to it via runtime\n // config and the local gateway sits idle.\n const localGatewayTarget = (port: number) => ({\n executor: 'nx:run-commands' as const,\n continuous: true,\n options: {\n command: 'tsx local-dev.ts',\n cwd: '{projectRoot}',\n env: { PORT: `${port}` },\n },\n dependsOn: [] as Array<string | { projects: string[]; target: string }>,\n });\n let project: ProjectConfiguration;\n if (projectExists(tree, fullyQualifiedName)) {\n project = readProjectConfigurationUnqualified(tree, fullyQualifiedName);\n } else {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: projectRoot,\n projectType: 'library',\n sourceRoot: projectRoot,\n tags: [],\n targets: {},\n metadata: {\n generator: AGENTCORE_GATEWAY_GENERATOR_INFO.id,\n } as any,\n });\n project = readProjectConfigurationUnqualified(tree, fullyQualifiedName);\n }\n // Ensure the project has its own package.json so its runtime dependencies\n // (added below) are declared in it rather than the workspace root.\n ensureProjectPackageJson(tree, {\n dir: projectRoot,\n fullyQualifiedName,\n });\n const port = assignPort(tree, project, 8100);\n // A gateway is its own standalone project, so it uses plain `serve` / `dev`\n // targets. Re-run: keep existing targets (their dependsOn may have been\n // populated by the mcp-connection generator), just ensure both exist.\n project.targets ??= {};\n project.targets['serve'] ??= localGatewayTarget(port);\n project.targets['dev'] ??= localGatewayTarget(port);\n updateProjectConfiguration(tree, project.name, project);\n\n // Scaffold the gateway project: local-dev.ts (+ Cedar policies if requested)\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'project', protocol),\n projectRoot,\n {\n nameClassName,\n nameKebabCase: name,\n port,\n attachedMcpServers: [],\n attachedAgents: [],\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n if (cedarPolicy) {\n // The default permit-all policy differs by auth type: AgentCore represents\n // IAM callers as `AgentCore::IamEntity` and Cognito/JWT callers as\n // `AgentCore::OAuthUser`, so the two policies match different principals.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cedar'),\n projectRoot,\n { nameClassName, auth },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: AgentCoreGatewayMetadata = {\n name,\n rc: nameClassName,\n protocol,\n auth,\n port,\n ...(iac ? { iac } : {}),\n };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n AGENTCORE_GATEWAY_GENERATOR_INFO,\n metadata,\n );\n\n addTsDependencies(tree, DEPENDENCIES, { metadata, projectRoot });\n\n // Wire up infra (CDK or Terraform); re-running with infra=agentcore adds\n // the infrastructure to a previously infra-less gateway.\n\n if (infra === 'agentcore') {\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n await addAgentCoreGatewayInfra(\n tree,\n {\n gatewayNameClassName: nameClassName,\n gatewayNameKebabCase: name,\n projectName: fullyQualifiedName,\n projectDirectory: projectRoot,\n cedarPolicy,\n auth,\n protocol,\n iac,\n },\n DEPENDENCIES,\n );\n }\n\n await addGeneratorMetricsIfApplicable(tree, [\n AGENTCORE_GATEWAY_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\n/**\n * Gateway details stored in the gateway project's metadata.\n */\nexport interface AgentCoreGatewayMetadata extends IacMetadata {\n name: string;\n rc: string;\n protocol: string;\n auth: string;\n port: number;\n}\n\n/**\n * Read a gateway project's metadata, validating it was generated by the\n * agentcore-gateway generator.\n */\nexport const readAgentCoreGatewayMetadata = (\n project: ProjectConfiguration,\n): AgentCoreGatewayMetadata => {\n const metadata = project.metadata as any;\n if (metadata?.generator !== AGENTCORE_GATEWAY_GENERATOR_INFO.id) {\n throw new Error(\n `Project '${project.name}' was not generated by the '${AGENTCORE_GATEWAY_GENERATOR_INFO.id}' generator.`,\n );\n }\n return metadata as AgentCoreGatewayMetadata;\n};\n\nexport default agentcoreGatewayGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","logger","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","AGENT_CORE_CONSTRUCTS_DEPENDENCIES","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addAgentCoreGatewayInfra","declareDependencies","ownedElsewhere","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","readProjectConfigurationUnqualified","assignPort","ensureProjectPackageJson","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","name","when","m","protocol","dev","root","py","AGENTCORE_GATEWAY_GENERATOR_INFO","filename","agentcoreGatewayGenerator","tree","options","nameClassName","parentDir","directory","subDir","subDirectory","projectRoot","fullyQualifiedName","auth","cedarPolicy","warn","infra","localGatewayTarget","port","executor","continuous","command","cwd","env","PORT","dependsOn","project","projectType","sourceRoot","tags","targets","metadata","generator","id","dir","dirname","nameKebabCase","attachedMcpServers","attachedAgents","overwriteStrategy","KeepExisting","iac","undefined","rc","gatewayNameClassName","gatewayNameKebabCase","projectName","projectDirectory","preferInstallDependencies","languages","readAgentCoreGatewayMetadata","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,MAAM,EACNC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,+BAA4B;AAC9D,SACEC,kCAAkC,EAClCC,qCAAqC,EACrCC,wBAAwB,QACnB,0DAAuD;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,oCAAiC;AACxC,SAASC,oBAAoB,QAAQ,qBAAkB;AACvD,SAASC,UAAU,QAAQ,kBAAe;AAC1C,SAASC,mBAAmB,QAAQ,sBAAmB;AACvD,SAASC,+BAA+B,QAAQ,sBAAmB;AACnE,SAASC,SAAS,EAAEC,WAAW,QAAQ,oBAAiB;AACxD,SAASC,iBAAiB,QAAQ,wBAAqB;AACvD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,EACbC,mCAAmC,QAC9B,iBAAc;AACrB,SAASC,UAAU,QAAQ,mBAAgB;AAC3C,SAASC,wBAAwB,QAAQ,mCAAgC;AACzE,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,gCAA6B;AAIpC,uEAAuE;AACvE,2EAA2E;A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AY,CAAC;IAE5G;IACA,OAAOF;AACT,EAAE;AAEF,eAAe5B,0BAA0B"}
@@ -0,0 +1,68 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`agentcore-gateway#react-connection generator > generates a gateway-routed AG-UI hook for each fronted agent > useAguiMyAgent.tsx 1`] = `
4
+ "import { HttpAgent } from '@ag-ui/client';
5
+ import type { AbstractAgent, RunAgentInput } from '@ag-ui/client';
6
+ import { useMemo } from 'react';
7
+ import { useRuntimeConfig } from './useRuntimeConfig';
8
+ import { useSigV4, type SigV4Client } from './useSigV4';
9
+
10
+ // The agent sits behind an AgentCore Gateway, which proxies
11
+ // \`/<targetName>/invocations\` to the agent runtime.
12
+ function buildGatewayUrl(gatewayUrl: string): string {
13
+ return \`\${new URL(gatewayUrl).origin}/my-agent/invocations\`;
14
+ }
15
+
16
+ // AgentCore session ids must be at least 33 characters.
17
+ function agentCoreSessionId(input: RunAgentInput): string {
18
+ return (input.threadId ?? '').padEnd(33, '0');
19
+ }
20
+
21
+ class SigV4HttpAgent extends HttpAgent {
22
+ sigV4Client: SigV4Client;
23
+
24
+ constructor(
25
+ config: ConstructorParameters<typeof HttpAgent>[0],
26
+ sigV4Client: SigV4Client,
27
+ ) {
28
+ super({
29
+ ...config,
30
+ fetch: sigV4Client.fetch as (
31
+ url: string,
32
+ init: RequestInit,
33
+ ) => Promise<Response>,
34
+ });
35
+ this.sigV4Client = sigV4Client;
36
+ }
37
+
38
+ protected override requestInit(input: RunAgentInput): RequestInit {
39
+ const init = super.requestInit(input);
40
+ init.headers = {
41
+ ...(init.headers as Record<string, string>),
42
+ 'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': agentCoreSessionId(input),
43
+ };
44
+ return init;
45
+ }
46
+
47
+ override clone(): SigV4HttpAgent {
48
+ const cloned = super.clone() as SigV4HttpAgent;
49
+ cloned.sigV4Client = this.sigV4Client;
50
+ return cloned;
51
+ }
52
+ }
53
+
54
+ export const useAguiMyAgent = (): Record<string, AbstractAgent> => {
55
+ const runtimeConfig = useRuntimeConfig();
56
+ const gatewayUrl = runtimeConfig.gateways.MyGateway;
57
+ const sigv4 = useSigV4();
58
+
59
+ const url = useMemo(() => buildGatewayUrl(gatewayUrl), [gatewayUrl]);
60
+
61
+ return useMemo((): Record<string, AbstractAgent> => {
62
+ const agent = new SigV4HttpAgent({ url }, sigv4);
63
+
64
+ return { 'my-agent': agent };
65
+ }, [url, sigv4]);
66
+ };
67
+ "
68
+ `;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { type Tree } from '@nx/devkit';
6
+ import { type NxGeneratorInfo } from '../../utils/nx';
7
+ import type { AgentcoreGatewayReactConnectionGeneratorSchema } from './schema';
8
+ export declare const AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
9
+ /**
10
+ * Connect a React website to an AgentCore Gateway fronting agents.
11
+ *
12
+ * For each agent attached to the gateway (via the
13
+ * `agentcore-gateway#agent-connection` generator), generates the same website
14
+ * client as connecting to the agent directly, but routed through the
15
+ * gateway's `/<targetName>` path — so the browser only needs to reach the
16
+ * gateway, and the agent runtimes can sit in a VPC behind it.
17
+ */
18
+ export declare const agentcoreGatewayReactConnectionGenerator: (tree: Tree, options: AgentcoreGatewayReactConnectionGeneratorSchema) => Promise<() => Promise<void>>;
19
+ export default agentcoreGatewayReactConnectionGenerator;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */ import { getProjects, logger } from "@nx/devkit";
5
+ import { addGatewayTargetToLocalDev } from "../../connection/agent-local-dev.js";
6
+ import { addGatewayUrlToConnectionNamespace } from "../../connection/gateway-runtime-config.js";
7
+ import { PY_AGENT_GENERATOR_INFO } from "../../py/agent/generator.js";
8
+ import { pyAgentReactConnectionGenerator } from "../../py/agent/react-connection/generator.js";
9
+ import { TS_AGENT_GENERATOR_INFO } from "../../ts/agent/generator.js";
10
+ import { tsAgentReactConnectionGenerator } from "../../ts/agent/react-connection/generator.js";
11
+ import { formatFilesInSubtree } from "../../utils/format.js";
12
+ import { installDependencies } from "../../utils/install.js";
13
+ import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
14
+ import { kebabCase } from "../../utils/names.js";
15
+ import { addComponentGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
16
+ import { AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO } from "../agent-connection/generator.js";
17
+ import { readAgentCoreGatewayMetadata } from "../generator.js";
18
+ export const AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
19
+ /**
20
+ * Connect a React website to an AgentCore Gateway fronting agents.
21
+ *
22
+ * For each agent attached to the gateway (via the
23
+ * `agentcore-gateway#agent-connection` generator), generates the same website
24
+ * client as connecting to the agent directly, but routed through the
25
+ * gateway's `/<targetName>` path — so the browser only needs to reach the
26
+ * gateway, and the agent runtimes can sit in a VPC behind it.
27
+ */ export const agentcoreGatewayReactConnectionGenerator = async (tree, options)=>{
28
+ const frontendProject = readProjectConfigurationUnqualified(tree, options.sourceProject);
29
+ const gatewayProject = readProjectConfigurationUnqualified(tree, options.targetProject);
30
+ const gateway = readAgentCoreGatewayMetadata(gatewayProject);
31
+ if (gateway.protocol !== 'http') {
32
+ throw new Error(`Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Websites can only connect to http-protocol gateways, which proxy requests to their agent targets.`);
33
+ }
34
+ // A2A targets speak agent-to-agent JSON-RPC, not a browser protocol, so
35
+ // the website only connects to the gateway's AG-UI / HTTP agents. A gateway
36
+ // with none attached yet still gets its URL published and dev wiring —
37
+ // re-running this connection after attaching agents generates their
38
+ // website clients.
39
+ const agents = frontedAgents(tree, gatewayProject.name).filter((agent)=>(agent.component.protocol ?? '').toLowerCase() !== 'a2a');
40
+ if (agents.length === 0) {
41
+ logger.warn(`Gateway '${gateway.name}' has no AG-UI or HTTP agents attached, so no website clients were generated. Connect agents to the gateway, then re-run this connection to generate their clients.`);
42
+ }
43
+ // One website client per fronted agent, routed through the gateway.
44
+ for (const agent of agents){
45
+ const generator = agent.language === 'ts' ? tsAgentReactConnectionGenerator : pyAgentReactConnectionGenerator;
46
+ await generator(tree, {
47
+ sourceProject: frontendProject.name,
48
+ targetProject: agent.projectName,
49
+ targetComponent: agent.component,
50
+ preferInstallDependencies: options.preferInstallDependencies,
51
+ gatewayRoute: {
52
+ gatewayClassName: gateway.rc,
53
+ targetName: agent.targetName,
54
+ gatewayAuth: gateway.auth
55
+ }
56
+ });
57
+ }
58
+ // Publish the gateway URL to the website via the 'connection' namespace.
59
+ await addGatewayUrlToConnectionNamespace(tree, {
60
+ gatewayNameKebabCase: kebabCase(gateway.rc),
61
+ gatewayNameClassName: gateway.rc
62
+ });
63
+ // Wire the website's dev target to the local gateway, which proxies to the
64
+ // attached agents (transitively starting them via its own dev dependencies).
65
+ await addGatewayTargetToLocalDev(tree, frontendProject.name, gatewayProject.name, {
66
+ gatewayClassName: gateway.rc,
67
+ port: gateway.port
68
+ });
69
+ // Recorded so the version sync can identify this connection.
70
+ addComponentGeneratorMetadata(tree, frontendProject.name, AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO, gatewayProject.root, gateway.rc);
71
+ await addGeneratorMetricsIfApplicable(tree, [
72
+ AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO
73
+ ]);
74
+ await formatFilesInSubtree(tree);
75
+ return ()=>installDependencies(tree, options.preferInstallDependencies, {
76
+ languages: [
77
+ 'typescript'
78
+ ]
79
+ });
80
+ };
81
+ /**
82
+ * The agents attached to the gateway, resolved from the connection entries
83
+ * the `agentcore-gateway#agent-connection` generator recorded: each names the
84
+ * agent project by root (`path`) and its gateway target name (`name`), which
85
+ * matches the agent component's class name in kebab-case.
86
+ */ const frontedAgents = (tree, gatewayProjectName)=>{
87
+ const gatewayProject = readProjectConfigurationUnqualified(tree, gatewayProjectName);
88
+ const connections = (gatewayProject.metadata?.components ?? []).filter((c)=>c.generator === AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO.id);
89
+ const projectsByRoot = new Map([
90
+ ...getProjects(tree).values()
91
+ ].map((p)=>[
92
+ p.root,
93
+ p
94
+ ]));
95
+ return connections.flatMap((connection)=>{
96
+ const agentProject = connection.path ? projectsByRoot.get(connection.path) : undefined;
97
+ if (!agentProject) {
98
+ return [];
99
+ }
100
+ const component = (agentProject.metadata?.components ?? []).find((c)=>[
101
+ TS_AGENT_GENERATOR_INFO.id,
102
+ PY_AGENT_GENERATOR_INFO.id
103
+ ].includes(c.generator) && kebabCase(c.rc ?? '') === connection.name);
104
+ if (!component) {
105
+ return [];
106
+ }
107
+ return [
108
+ {
109
+ projectName: agentProject.name,
110
+ component,
111
+ targetName: connection.name,
112
+ language: component.generator === TS_AGENT_GENERATOR_INFO.id ? 'ts' : 'py'
113
+ }
114
+ ];
115
+ });
116
+ };
117
+ export default agentcoreGatewayReactConnectionGenerator;
118
+
119
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/agentcore-gateway/react-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { getProjects, logger, type Tree } from '@nx/devkit';\nimport { addGatewayTargetToLocalDev } from '../../connection/agent-local-dev';\nimport { addGatewayUrlToConnectionNamespace } from '../../connection/gateway-runtime-config';\nimport { PY_AGENT_GENERATOR_INFO } from '../../py/agent/generator';\nimport { pyAgentReactConnectionGenerator } from '../../py/agent/react-connection/generator';\nimport { TS_AGENT_GENERATOR_INFO } from '../../ts/agent/generator';\nimport { tsAgentReactConnectionGenerator } from '../../ts/agent/react-connection/generator';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase } from '../../utils/names';\nimport {\n addComponentGeneratorMetadata,\n type ComponentMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO } from '../agent-connection/generator';\nimport { readAgentCoreGatewayMetadata } from '../generator';\nimport type { AgentcoreGatewayReactConnectionGeneratorSchema } from './schema';\n\nexport const AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\n/** An agent fronted by the gateway, resolved from its connection metadata. */\ninterface FrontedAgent {\n readonly projectName: string;\n readonly component: ComponentMetadata;\n readonly targetName: string;\n readonly language: 'ts' | 'py';\n}\n\n/**\n * Connect a React website to an AgentCore Gateway fronting agents.\n *\n * For each agent attached to the gateway (via the\n * `agentcore-gateway#agent-connection` generator), generates the same website\n * client as connecting to the agent directly, but routed through the\n * gateway's `/<targetName>` path — so the browser only needs to reach the\n * gateway, and the agent runtimes can sit in a VPC behind it.\n */\nexport const agentcoreGatewayReactConnectionGenerator = async (\n tree: Tree,\n options: AgentcoreGatewayReactConnectionGeneratorSchema,\n) => {\n const frontendProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const gatewayProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n const gateway = readAgentCoreGatewayMetadata(gatewayProject);\n\n if (gateway.protocol !== 'http') {\n throw new Error(\n `Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Websites can only connect to http-protocol gateways, which proxy requests to their agent targets.`,\n );\n }\n\n // A2A targets speak agent-to-agent JSON-RPC, not a browser protocol, so\n // the website only connects to the gateway's AG-UI / HTTP agents. A gateway\n // with none attached yet still gets its URL published and dev wiring —\n // re-running this connection after attaching agents generates their\n // website clients.\n const agents = frontedAgents(tree, gatewayProject.name).filter(\n (agent) =>\n ((agent.component.protocol as string) ?? '').toLowerCase() !== 'a2a',\n );\n if (agents.length === 0) {\n logger.warn(\n `Gateway '${gateway.name}' has no AG-UI or HTTP agents attached, so no website clients were generated. Connect agents to the gateway, then re-run this connection to generate their clients.`,\n );\n }\n\n // One website client per fronted agent, routed through the gateway.\n for (const agent of agents) {\n const generator =\n agent.language === 'ts'\n ? tsAgentReactConnectionGenerator\n : pyAgentReactConnectionGenerator;\n await generator(tree, {\n sourceProject: frontendProject.name,\n targetProject: agent.projectName,\n targetComponent: agent.component,\n preferInstallDependencies: options.preferInstallDependencies,\n gatewayRoute: {\n gatewayClassName: gateway.rc,\n targetName: agent.targetName,\n gatewayAuth: gateway.auth,\n },\n });\n }\n\n // Publish the gateway URL to the website via the 'connection' namespace.\n await addGatewayUrlToConnectionNamespace(tree, {\n gatewayNameKebabCase: kebabCase(gateway.rc),\n gatewayNameClassName: gateway.rc,\n });\n\n // Wire the website's dev target to the local gateway, which proxies to the\n // attached agents (transitively starting them via its own dev dependencies).\n await addGatewayTargetToLocalDev(\n tree,\n frontendProject.name,\n gatewayProject.name,\n {\n gatewayClassName: gateway.rc,\n port: gateway.port,\n },\n );\n\n // Recorded so the version sync can identify this connection.\n addComponentGeneratorMetadata(\n tree,\n frontendProject.name,\n AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO,\n gatewayProject.root,\n gateway.rc,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\n/**\n * The agents attached to the gateway, resolved from the connection entries\n * the `agentcore-gateway#agent-connection` generator recorded: each names the\n * agent project by root (`path`) and its gateway target name (`name`), which\n * matches the agent component's class name in kebab-case.\n */\nconst frontedAgents = (\n tree: Tree,\n gatewayProjectName: string,\n): FrontedAgent[] => {\n const gatewayProject = readProjectConfigurationUnqualified(\n tree,\n gatewayProjectName,\n );\n const connections = (\n ((gatewayProject.metadata as any)?.components ?? []) as ComponentMetadata[]\n ).filter(\n (c) => c.generator === AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO.id,\n );\n\n const projectsByRoot = new Map(\n [...getProjects(tree).values()].map((p) => [p.root, p]),\n );\n\n return connections.flatMap((connection) => {\n const agentProject = connection.path\n ? projectsByRoot.get(connection.path)\n : undefined;\n if (!agentProject) {\n return [];\n }\n const component = (\n ((agentProject.metadata as any)?.components ?? []) as ComponentMetadata[]\n ).find(\n (c) =>\n [TS_AGENT_GENERATOR_INFO.id, PY_AGENT_GENERATOR_INFO.id].includes(\n c.generator,\n ) && kebabCase((c.rc as string) ?? '') === connection.name,\n );\n if (!component) {\n return [];\n }\n return [\n {\n projectName: agentProject.name,\n component,\n targetName: connection.name,\n language: (component.generator === TS_AGENT_GENERATOR_INFO.id\n ? 'ts'\n : 'py') as 'ts' | 'py',\n },\n ];\n });\n};\n\nexport default agentcoreGatewayReactConnectionGenerator;\n"],"names":["getProjects","logger","addGatewayTargetToLocalDev","addGatewayUrlToConnectionNamespace","PY_AGENT_GENERATOR_INFO","pyAgentReactConnectionGenerator","TS_AGENT_GENERATOR_INFO","tsAgentReactConnectionGenerator","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO","readAgentCoreGatewayMetadata","AGENTCORE_GATEWAY_REACT_CONNECTION_GENERATOR_INFO","filename","agentcoreGatewayReactConnectionGenerator","tree","options","frontendProject","sourceProject","gatewayProject","targetProject","gateway","protocol","Error","name","agents","frontedAgents","filter","agent","component","toLowerCase","length","warn","generator","language","projectName","targetComponent","preferInstallDependencies","gatewayRoute","gatewayClassName","rc","targetName","gatewayAuth","auth","gatewayNameKebabCase","gatewayNameClassName","port","root","languages","gatewayProjectName","connections","metadata","components","c","id","projectsByRoot","Map","values","map","p","flatMap","connection","agentProject","path","get","undefined","find","includes"],"mappings":"AAAA;;;CAGC,GACD,SAASA,WAAW,EAAEC,MAAM,QAAmB,aAAa;AAC5D,SAASC,0BAA0B,QAAQ,sCAAmC;AAC9E,SAASC,kCAAkC,QAAQ,6CAA0C;AAC7F,SAASC,uBAAuB,QAAQ,8BAA2B;AACnE,SAASC,+BAA+B,QAAQ,+CAA4C;AAC5F,SAASC,uBAAuB,QAAQ,8BAA2B;AACnE,SAASC,+BAA+B,QAAQ,+CAA4C;AAC5F,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,QAAQ,uBAAoB;AAC9C,SACEC,6BAA6B,EAE7BC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,iDAAiD,QAAQ,mCAAgC;AAClG,SAASC,4BAA4B,QAAQ,kBAAe;AAG5D,OAAO,MAAMC,oDACXJ,iBAAiB,YAAYK,QAAQ,EAAE;AAUzC;;;;;;;;CAQC,GACD,OAAO,MAAMC,2CAA2C,OACtDC,MACAC;IAEA,MAAMC,kBAAkBR,oCACtBM,MACAC,QAAQE,aAAa;IAEvB,MAAMC,iBAAiBV,oCACrBM,MACAC,QAAQI,aAAa;IAEvB,MAAMC,UAAUV,6BAA6BQ;IAE7C,IAAIE,QAAQC,QAAQ,KAAK,QAAQ;QAC/B,MAAM,IAAIC,MACR,CAAC,SAAS,EAAEF,QAAQG,IAAI,CAAC,gBAAgB,EAAEH,QAAQC,QAAQ,CAAC,oGAAoG,CAAC;IAErK;IAEA,wEAAwE;IACxE,4EAA4E;IAC5E,uEAAuE;IACvE,oEAAoE;IACpE,mBAAmB;IACnB,MAAMG,SAASC,cAAcX,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,GACD,MAAMtB,gBAAgB,CACpBX,MACAkC;IAEA,MAAM9B,iBAAiBV,oCACrBM,MACAkC;IAEF,MAAMC,cAAc,AACjB,CAAA,AAAC/B,eAAegC,QAAQ,EAAUC,cAAc,EAAE,AAAD,EAClDzB,MAAM,CACN,CAAC0B,IAAMA,EAAEpB,SAAS,KAAKvB,kDAAkD4C,EAAE;IAG7E,MAAMC,iBAAiB,IAAIC,IACzB;WAAI7D,YAAYoB,MAAM0C,MAAM;KAAG,CAACC,GAAG,CAAC,CAACC,IAAM;YAACA,EAAEZ,IAAI;YAAEY;SAAE;IAGxD,OAAOT,YAAYU,OAAO,CAAC,CAACC;QAC1B,MAAMC,eAAeD,WAAWE,IAAI,GAChCR,eAAeS,GAAG,CAACH,WAAWE,IAAI,IAClCE;QACJ,IAAI,CAACH,cAAc;YACjB,OAAO,EAAE;QACX;QACA,MAAMjC,YAAY,AACf,CAAA,AAACiC,aAAaX,QAAQ,EAAUC,cAAc,EAAE,AAAD,EAChDc,IAAI,CACJ,CAACb,IACC;gBAACpD,wBAAwBqD,EAAE;gBAAEvD,wBAAwBuD,EAAE;aAAC,CAACa,QAAQ,CAC/Dd,EAAEpB,SAAS,KACR3B,UAAU,AAAC+C,EAAEb,EAAE,IAAe,QAAQqB,WAAWrC,IAAI;QAE9D,IAAI,CAACK,WAAW;YACd,OAAO,EAAE;QACX;QACA,OAAO;YACL;gBACEM,aAAa2B,aAAatC,IAAI;gBAC9BK;gBACAY,YAAYoB,WAAWrC,IAAI;gBAC3BU,UAAWL,UAAUI,SAAS,KAAKhC,wBAAwBqD,EAAE,GACzD,OACA;YACN;SACD;IACH;AACF;AAEA,eAAexC,yCAAyC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */ export { };
5
+
6
+ //# sourceMappingURL=schema.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/agentcore-gateway/react-connection/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { ComponentMetadata } from '../../utils/nx';\n\nexport interface AgentcoreGatewayReactConnectionGeneratorSchema {\n sourceProject: string;\n targetProject: string;\n sourceComponent?: ComponentMetadata;\n targetComponent?: ComponentMetadata;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAMC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import type { ComponentMetadata } from '../../utils/nx';
6
+
7
+ export interface AgentcoreGatewayReactConnectionGeneratorSchema {
8
+ sourceProject: string;
9
+ targetProject: string;
10
+ sourceComponent?: ComponentMetadata;
11
+ targetComponent?: ComponentMetadata;
12
+ preferInstallDependencies?: boolean;
13
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "agentcore-gateway#react-connection",
4
+ "title": "agentcore-gateway#react-connection",
5
+ "description": "Connect a React website to an AgentCore Gateway fronting agents",
6
+ "type": "object",
7
+ "properties": {
8
+ "sourceProject": {
9
+ "type": "string",
10
+ "description": "The React website project"
11
+ },
12
+ "targetProject": {
13
+ "type": "string",
14
+ "description": "The gateway project"
15
+ },
16
+ "sourceComponent": {
17
+ "type": "string",
18
+ "description": "The website component in the source project"
19
+ },
20
+ "targetComponent": {
21
+ "type": "string",
22
+ "description": "The gateway component in the target project"
23
+ },
24
+ "preferInstallDependencies": {
25
+ "type": "boolean",
26
+ "description": "Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end.",
27
+ "default": true
28
+ }
29
+ },
30
+ "required": ["sourceProject", "targetProject"]
31
+ }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-gateway/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { IacOption } from '../utils/iac';\n\nexport interface AgentcoreGatewayGeneratorSchema {\n name: string;\n directory?: string;\n subDirectory?: string;\n protocol?: 'mcp';\n auth?: 'iam' | 'cognito';\n cedarPolicy?: boolean;\n infra?: 'agentcore' | 'none';\n iac: IacOption;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAUC"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-gateway/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { IacOption } from '../utils/iac';\n\nexport interface AgentcoreGatewayGeneratorSchema {\n name: string;\n directory?: string;\n subDirectory?: string;\n protocol?: 'mcp' | 'http';\n auth?: 'iam' | 'cognito';\n cedarPolicy?: boolean;\n infra?: 'agentcore' | 'none';\n iac: IacOption;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAUC"}
@@ -8,7 +8,7 @@ export interface AgentcoreGatewayGeneratorSchema {
8
8
  name: string;
9
9
  directory?: string;
10
10
  subDirectory?: string;
11
- protocol?: 'mcp';
11
+ protocol?: 'mcp' | 'http';
12
12
  auth?: 'iam' | 'cognito';
13
13
  cedarPolicy?: boolean;
14
14
  infra?: 'agentcore' | 'none';
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "protocol": {
29
29
  "type": "string",
30
- "description": "The inbound protocol exposed by your gateway. Only mcp is supported today; additional protocols may be added in future.",
31
- "enum": ["mcp"],
30
+ "description": "The inbound protocol exposed by your gateway. An mcp gateway aggregates MCP server targets into a single MCP endpoint. An http gateway proxies requests to agent runtime targets via path-based routing, so callers (e.g. a website) can reach agents through the gateway.",
31
+ "enum": ["mcp", "http"],
32
32
  "default": "mcp",
33
33
  "x-priority": "important"
34
34
  },
@@ -31,3 +31,19 @@ export interface AgentLocalDevOptions {
31
31
  * Agent react-connection generators.
32
32
  */
33
33
  export declare const addAgentTargetToLocalDev: (tree: Tree, sourceProjectName: string, targetProjectName: string, options: AgentLocalDevOptions) => Promise<void>;
34
+ export interface GatewayLocalDevOptions {
35
+ gatewayClassName: string;
36
+ /** Local port the gateway project's dev target listens on. */
37
+ port: number;
38
+ /**
39
+ * Additional targets to add as dev dependencies.
40
+ */
41
+ additionalDependencyTargets?: string[];
42
+ }
43
+ /**
44
+ * Adds an AgentCore Gateway project's dev target as a dependency of the
45
+ * source project's dev target (transitively starting the gateway's attached
46
+ * agents), and updates the RuntimeConfig provider to point the gateway's
47
+ * runtime config entry at the local gateway.
48
+ */
49
+ export declare const addGatewayTargetToLocalDev: (tree: Tree, sourceProjectName: string, gatewayProjectName: string, options: GatewayLocalDevOptions) => Promise<void>;