@aws/nx-plugin 1.0.0 → 1.0.1

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 (117) hide show
  1. package/LICENSE-THIRD-PARTY +11686 -23398
  2. package/README.md +18 -0
  3. package/generators.json +7 -0
  4. package/migrations.json +34 -1
  5. package/package.json +6 -6
  6. package/src/agentcore-gateway/schema.json +1 -0
  7. package/src/agentcore-harness/generator.d.ts +1 -1
  8. package/src/connection/scaffold-catalog.d.ts +4 -0
  9. package/src/connection/scaffold-catalog.js +3 -6
  10. package/src/connection/scaffold-catalog.js.map +1 -1
  11. package/src/infra/app/generator.d.ts +1 -1
  12. package/src/init/generator.d.ts +1 -1
  13. package/src/mcp-server/guide-pipeline.d.ts +2 -1
  14. package/src/mcp-server/guide-pipeline.js +6 -0
  15. package/src/mcp-server/guide-pipeline.js.map +1 -1
  16. package/src/mcp-server/mdx-ast.d.ts +7 -0
  17. package/src/mcp-server/mdx-ast.js +15 -0
  18. package/src/mcp-server/mdx-ast.js.map +1 -1
  19. package/src/mcp-server/schema-registry.d.ts +2 -2
  20. package/src/mcp-server/schema-registry.js +2 -2
  21. package/src/mcp-server/schema-registry.js.map +1 -1
  22. package/src/open-api/py-client/__snapshots__/generator.additional-properties.spec.ts.snap +34 -0
  23. package/src/open-api/py-client/__snapshots__/generator.arrays.spec.ts.snap +1750 -0
  24. package/src/open-api/py-client/__snapshots__/generator.complex-types.spec.ts.snap +82 -0
  25. package/src/open-api/py-client/__snapshots__/generator.composite-types.spec.ts.snap +447 -0
  26. package/src/open-api/py-client/__snapshots__/generator.duplicate-types.spec.ts.snap +404 -0
  27. package/src/open-api/py-client/__snapshots__/generator.errors.spec.ts.snap +430 -0
  28. package/src/open-api/py-client/__snapshots__/generator.fast-api.spec.ts.snap +447 -0
  29. package/src/open-api/py-client/__snapshots__/generator.petstore.spec.ts.snap +3488 -0
  30. package/src/open-api/py-client/__snapshots__/generator.primitive-types.spec.ts.snap +1444 -0
  31. package/src/open-api/py-client/__snapshots__/generator.request.spec.ts.snap +390 -0
  32. package/src/open-api/py-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +364 -0
  33. package/src/open-api/py-client/__snapshots__/generator.response.spec.ts.snap +739 -0
  34. package/src/open-api/py-client/__snapshots__/generator.streaming.spec.ts.snap +384 -0
  35. package/src/open-api/py-client/__snapshots__/generator.tags.spec.ts.snap +414 -0
  36. package/src/open-api/py-client/files/client/__clientModuleName__.py.template +1076 -0
  37. package/src/open-api/py-client/files/shared/__init__.py.template +28 -0
  38. package/src/open-api/py-client/files/shared/errors.py.template +37 -0
  39. package/src/open-api/py-client/files/shared/types.py.template +319 -0
  40. package/src/open-api/py-client/generator.d.ts +53 -0
  41. package/src/open-api/py-client/generator.js +119 -0
  42. package/src/open-api/py-client/generator.js.map +1 -0
  43. package/src/open-api/py-client/schema.d.js +6 -0
  44. package/src/open-api/py-client/schema.d.js.map +1 -0
  45. package/src/open-api/py-client/schema.d.ts +12 -0
  46. package/src/open-api/py-client/schema.json +28 -0
  47. package/src/open-api/py-client/vessel-registry-spec.json +2716 -0
  48. package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +274 -0
  49. package/src/open-api/ts-client/petstore-spec.d.ts +6 -0
  50. package/src/open-api/ts-client/petstore-spec.js +1275 -0
  51. package/src/open-api/ts-client/petstore-spec.js.map +1 -0
  52. package/src/open-api/ts-hooks/generator.spec.tsx +1 -1
  53. package/src/open-api/utils/codegen-data/languages.d.ts +68 -2
  54. package/src/open-api/utils/codegen-data/languages.js +433 -21
  55. package/src/open-api/utils/codegen-data/languages.js.map +1 -1
  56. package/src/open-api/utils/codegen-data/types.d.ts +187 -0
  57. package/src/open-api/utils/codegen-data/types.js +10 -1
  58. package/src/open-api/utils/codegen-data/types.js.map +1 -1
  59. package/src/open-api/utils/codegen-data.d.ts +40 -1
  60. package/src/open-api/utils/codegen-data.js +622 -17
  61. package/src/open-api/utils/codegen-data.js.map +1 -1
  62. package/src/open-api/utils/normalise.js +175 -41
  63. package/src/open-api/utils/normalise.js.map +1 -1
  64. package/src/open-api/utils/parser.js +1 -1
  65. package/src/open-api/utils/parser.js.map +1 -1
  66. package/src/preset/__snapshots__/generator.spec.ts.snap +3 -3
  67. package/src/preset/generator.d.ts +1 -1
  68. package/src/py/agent/gateway-connection/generator.js +0 -3
  69. package/src/py/agent/gateway-connection/generator.js.map +1 -1
  70. package/src/py/agent/react-connection/generator.d.ts +1 -1
  71. package/src/py/agent/schema.json +2 -0
  72. package/src/py/fast-api/react/generator.d.ts +1 -1
  73. package/src/py/mcp-server/schema.json +1 -0
  74. package/src/sdk/open-api.d.ts +2 -0
  75. package/src/sdk/open-api.js +1 -0
  76. package/src/sdk/open-api.js.map +1 -1
  77. package/src/smithy/project/generator.d.ts +1 -1
  78. package/src/smithy/react-connection/generator.d.ts +1 -1
  79. package/src/terraform/project/generator.d.ts +1 -1
  80. package/src/trpc/react/generator.d.ts +1 -1
  81. package/src/ts/agent/a2a-connection/generator.d.ts +1 -1
  82. package/src/ts/agent/gateway-connection/generator.d.ts +1 -1
  83. package/src/ts/agent/gateway-connection/generator.js +0 -3
  84. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  85. package/src/ts/agent/mcp-connection/generator.d.ts +1 -1
  86. package/src/ts/agent/react-connection/generator.d.ts +1 -1
  87. package/src/ts/agent/schema.json +1 -0
  88. package/src/ts/api/schema.json +2 -0
  89. package/src/ts/astro-docs/generator.d.ts +1 -1
  90. package/src/ts/dcr-proxy/generator.d.ts +1 -1
  91. package/src/ts/dynamodb/generator.d.ts +1 -1
  92. package/src/ts/lambda-function/generator.d.ts +1 -1
  93. package/src/ts/lib/generator.d.ts +1 -1
  94. package/src/ts/mcp-server/schema.json +1 -0
  95. package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +1 -1
  96. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +1 -1
  97. package/src/ts/nx-generator/generator.d.ts +1 -1
  98. package/src/ts/nx-migration/generator.d.ts +1 -1
  99. package/src/ts/nx-plugin/generator.d.ts +1 -1
  100. package/src/ts/rdb/generator.d.ts +1 -1
  101. package/src/ts/react-website/agui/generator.d.ts +1 -1
  102. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +10 -10
  103. package/src/ts/react-website/app/schema.json +1 -0
  104. package/src/ts/website/app/schema.json +1 -0
  105. package/src/utils/metrics-assertions.d.ts +18 -0
  106. package/src/utils/metrics-assertions.js +42 -0
  107. package/src/utils/metrics-assertions.js.map +1 -0
  108. package/src/utils/test/python-dependencies.d.ts +8 -0
  109. package/src/utils/test/python-dependencies.js +14 -0
  110. package/src/utils/test/python-dependencies.js.map +1 -0
  111. package/src/utils/test/python-worker/worker.py +703 -0
  112. package/src/utils/test/warm-python-cache.d.ts +18 -0
  113. package/src/utils/test/warm-python-cache.js +46 -0
  114. package/src/utils/test/warm-python-cache.js.map +1 -0
  115. package/src/utils/versions.d.ts +10 -9
  116. package/src/utils/versions.js +9 -8
  117. package/src/utils/versions.js.map +1 -1
package/README.md CHANGED
@@ -22,12 +22,23 @@
22
22
  alt="Commit activity"
23
23
  />
24
24
  </a>
25
+ <p>
26
+ <a href="https://awslabs.github.io/nx-plugin-for-aws/"><b>Documentation Site</b></a>
27
+ </p>
25
28
  </div>
26
29
 
27
30
  ---
28
31
 
29
32
  **@aws/nx-plugin** is a collection of code generators that scaffold full-stack AWS applications inside an [Nx](https://nx.dev) monorepo. Every generator produces best-practice application code **and** the infrastructure to deploy it — type-safe, locally runnable, and deployable from the start, getting you closer to production.
30
33
 
34
+ <div align="center">
35
+ <img
36
+ src="https://raw.githubusercontent.com/awslabs/nx-plugin-for-aws/main/docs/src/content/docs/assets/nx-plugin-showcase-desktop-dark.gif"
37
+ alt="Scaffolding, running and deploying a full-stack AWS application with the Nx Plugin for AWS"
38
+ width="900"
39
+ />
40
+ </div>
41
+
31
42
  ## Quick Start
32
43
 
33
44
  ### Build with AI
@@ -79,22 +90,29 @@ pnpm nx g @aws/nx-plugin:ts#infra
79
90
 
80
91
  | Generator | Description |
81
92
  | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
93
+ | `init` | Configure an existing Nx workspace to use the plugin |
82
94
  | `ts#project` | TypeScript library |
83
95
  | `ts#api` | TypeScript API (tRPC or Smithy) with API Gateway + Lambda + [Powertools](https://github.com/aws-powertools/powertools-lambda-typescript) |
84
96
  | `ts#rdb` | Relational databases with Aurora RDS |
97
+ | `ts#dynamodb` | Type-safe DynamoDB single-table design (TypeScript, ElectroDB) |
85
98
  | `ts#website` | React app (Vite) |
86
99
  | `ts#website#auth` | Add Cognito auth to a website |
87
100
  | `ts#infra` | AWS CDK infrastructure project |
88
101
  | `ts#lambda-function` | TypeScript Lambda with type-safe event sources |
89
102
  | `ts#mcp-server` | MCP server (TypeScript) |
103
+ | `ts#dcr-proxy` | OAuth DCR proxy construct for Cognito-authenticated MCP servers |
90
104
  | `ts#agent` | [Strands Agent](https://strandsagents.com/) (TypeScript) |
91
105
  | `ts#nx-generator` | Nx generator scaffold |
106
+ | `ts#docs` | Documentation site (Astro + Starlight) |
92
107
  | `smithy#project` | Smithy model project — a service model, or a shape library shared between Smithy projects |
93
108
  | `py#project` | Python project (uv) |
94
109
  | `py#api` | Python API (FastAPI) with API Gateway + Lambda + [Powertools](https://github.com/aws-powertools/powertools-lambda-python) |
110
+ | `py#rdb` | Relational databases with Aurora RDS (Python) |
111
+ | `py#dynamodb` | Python DynamoDB project |
95
112
  | `py#lambda-function` | Python Lambda with type-safe event sources |
96
113
  | `py#mcp-server` | MCP server (Python) |
97
114
  | `py#agent` | [Strands Agent](https://strandsagents.com/) (Python) |
115
+ | `agentcore-gateway` | [AgentCore Gateway](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway.html) project |
98
116
  | `agentcore-harness` | [AgentCore Harness](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/harness.html) agent loop (experimental) |
99
117
  | `connection` | Connect projects together (e.g. frontend to API) |
100
118
  | `terraform#project` | Terraform project |
package/generators.json CHANGED
@@ -104,6 +104,13 @@
104
104
  "metric": "g15",
105
105
  "hidden": true
106
106
  },
107
+ "open-api#py-client": {
108
+ "factory": "./src/open-api/py-client/generator",
109
+ "schema": "./src/open-api/py-client/schema.json",
110
+ "description": "Generate a Python httpx client from an OpenAPI specification",
111
+ "metric": "g73",
112
+ "hidden": true
113
+ },
107
114
  "open-api#ts-client": {
108
115
  "factory": "./src/open-api/ts-client/generator",
109
116
  "schema": "./src/open-api/ts-client/schema.json",
package/migrations.json CHANGED
@@ -368,7 +368,7 @@
368
368
  "implementation": "./src/migrations/v1.0.0-rc.97/0006-script-project-quality-gates/migration"
369
369
  },
370
370
  "sync-vended-versions": {
371
- "version": "1.0.0",
371
+ "version": "1.0.1",
372
372
  "description": "Sync vended dependency versions and the tracked plugin version to those vended by this release",
373
373
  "implementation": "./src/utils/version-upgrade-migration/migration"
374
374
  }
@@ -472,6 +472,39 @@
472
472
  "alwaysAddToPackageJson": false
473
473
  }
474
474
  }
475
+ },
476
+ "nx-23.2.1-nx-packages": {
477
+ "version": "1.0.1",
478
+ "packages": {
479
+ "nx": {
480
+ "version": "23.2.1",
481
+ "alwaysAddToPackageJson": false
482
+ },
483
+ "@nx/devkit": {
484
+ "version": "23.2.1",
485
+ "alwaysAddToPackageJson": false
486
+ },
487
+ "@nx/js": {
488
+ "version": "23.2.1",
489
+ "alwaysAddToPackageJson": false
490
+ },
491
+ "@nx/react": {
492
+ "version": "23.2.1",
493
+ "alwaysAddToPackageJson": false
494
+ },
495
+ "@nx/vite": {
496
+ "version": "23.2.1",
497
+ "alwaysAddToPackageJson": false
498
+ },
499
+ "@nx/vitest": {
500
+ "version": "23.2.1",
501
+ "alwaysAddToPackageJson": false
502
+ },
503
+ "@nx/workspace": {
504
+ "version": "23.2.1",
505
+ "alwaysAddToPackageJson": false
506
+ }
507
+ }
475
508
  }
476
509
  }
477
510
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -36,7 +36,7 @@
36
36
  "node": ">=20.19.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "nx": "23.2.0"
39
+ "nx": "23.2.1"
40
40
  },
41
41
  "dependencies": {
42
42
  "@apidevtools/swagger-parser": "12.1.0",
@@ -46,10 +46,10 @@
46
46
  "@getgrit/gritql": "0.0.3",
47
47
  "@iarna/toml": "2.2.5",
48
48
  "@modelcontextprotocol/sdk": "1.30.0",
49
- "@nx/devkit": "23.2.0",
50
- "@nx/js": "23.2.0",
51
- "@nx/react": "23.2.0",
52
- "@nx/vite": "23.2.0",
49
+ "@nx/devkit": "23.2.1",
50
+ "@nx/js": "23.2.1",
51
+ "@nx/react": "23.2.1",
52
+ "@nx/vite": "23.2.1",
53
53
  "@nxlv/python": "23.0.0",
54
54
  "@phenomnomnominal/tsquery": "6.2.0",
55
55
  "@types/estree": "1.0.9",
@@ -35,6 +35,7 @@
35
35
  "auth": {
36
36
  "type": "string",
37
37
  "description": "The method used to authenticate inbound requests to your gateway. Only applicable when infra is set (ignored when infra is none).",
38
+ "x-when": { "infra": "agentcore" },
38
39
  "enum": ["iam", "cognito"],
39
40
  "default": "iam",
40
41
  "x-prompt": "How would you like to authenticate inbound requests to your gateway?",
@@ -40,7 +40,7 @@ export declare const DEPENDENCIES: import("../utils/declared-dependencies.js").D
40
40
  readonly name: "@types/node";
41
41
  } & {
42
42
  versionOnly: true;
43
- }], readonly import("../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", AgentCoreHarnessMetadata>[]>;
43
+ }], readonly import("../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "pydantic" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", AgentCoreHarnessMetadata>[]>;
44
44
  export declare const AGENTCORE_HARNESS_GENERATOR_INFO: NxGeneratorInfo;
45
45
  export declare const agentcoreHarnessGenerator: (tree: Tree, options: AgentcoreHarnessGeneratorSchema) => Promise<GeneratorCallback>;
46
46
  /**
@@ -75,6 +75,10 @@ export type GeneratorSchema = {
75
75
  enum?: string[];
76
76
  default?: unknown;
77
77
  'x-priority'?: string;
78
+ /** The option values this option applies under. */
79
+ 'x-when'?: Record<string, string | string[]>;
80
+ /** The same, per value, where one of an option's values applies sometimes. */
81
+ 'x-value-when'?: Record<string, Record<string, string | string[]>>;
78
82
  }>;
79
83
  required?: string[];
80
84
  };
@@ -146,13 +146,10 @@ const AGENT_TO_MCP = [
146
146
  reason: 'An agent reaches an MCP server with IAM authentication.'
147
147
  }
148
148
  ];
149
+ // The agent's own `auth` governs inbound requests to it, so it places no
150
+ // requirement here — the agent signs its outbound call to the gateway with
151
+ // SigV4 from its execution role either way.
149
152
  const AGENT_TO_GATEWAY = [
150
- {
151
- side: 'source',
152
- option: 'auth',
153
- equals: 'iam',
154
- reason: 'Only an IAM-authenticated agent can reach an IAM gateway.'
155
- },
156
153
  {
157
154
  side: 'target',
158
155
  option: 'auth',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/connection/scaffold-catalog.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport GeneratorsJson from '../../generators.json' with { type: 'json' };\nimport {\n type ConnectionKey,\n SUPPORTED_CONNECTIONS,\n type SUPPORTED_PROJECT_TYPES,\n} from './supported-connections.js';\n\n/**\n * How to scaffold each end of a connection, derived from the plugin's own\n * metadata rather than hand-listed.\n *\n * Every connection endpoint type is also a generator id, which is what makes the\n * derivation possible:\n *\n * - **kind** — a generator whose schema `required`s a `project` adds a component\n * to an existing project; anything else creates a project of its own.\n * - **host** — a component lands in a project made by its language's base\n * generator (`ts#project` / `py#project`).\n * - **generator + options** — a type whose own generator is `hidden` is reached\n * through the public wrapper that selects it, found by matching the wrapper's\n * enum values against the type's name (`ts#trpc-api` ← `ts#api\n * --framework=trpc`). A visible generator is run directly.\n *\n * - **label** — the generator schema's own `x-label`.\n *\n * The result is that adding a generator and a connection for it needs no edit\n * here at all. The one thing still declared below is the option constraints,\n * which live as imperative guards inside each connection generator and so cannot\n * be read from metadata.\n */\n\n/**\n * Every type that can sit at either end of a connection: the project-level\n * types resolved by introspection, plus the component generator ids recorded in\n * component metadata.\n */\nexport type ConnectionEndpointType =\n | (typeof SUPPORTED_PROJECT_TYPES)[number]\n | (typeof SUPPORTED_CONNECTIONS)[number]['source']\n | (typeof SUPPORTED_CONNECTIONS)[number]['target'];\n\n/**\n * Whether scaffolding an endpoint creates a project of its own, or adds a\n * component to a project that must already exist.\n */\nexport type ScaffoldKind = 'project' | 'component';\n\n/** How to scaffold one end of a connection from the CLI. */\nexport interface ScaffoldRecipe {\n /** Human-readable name for this endpoint type. */\n readonly label: string;\n /** The generator id in `generators.json` that produces this endpoint. */\n readonly generator: string;\n /**\n * Options that select this endpoint type from its generator, for generators\n * producing more than one type (e.g. `framework`).\n */\n readonly options?: Readonly<Record<string, string>>;\n /** Whether the generator creates a project or adds a component to one. */\n readonly kind: ScaffoldKind;\n /**\n * The generator producing a project able to host this component, for\n * `component` recipes. Components are added to an existing project, so one\n * must be scaffolded first.\n */\n readonly host?: {\n readonly generator: string;\n readonly options?: Readonly<Record<string, string>>;\n /**\n * Whether the host project's name is referenced in snake_case. Python\n * project names are snake_cased when qualified, TypeScript ones are not.\n */\n readonly snakeCaseName?: boolean;\n };\n}\n\ntype GeneratorEntry = { schema: string; hidden?: boolean };\n/** The subset of JSON Schema the catalogue and the docs builder read. */\nexport type GeneratorSchema = {\n /**\n * Short display name for the thing this generator produces, used by the docs\n * graph builder's palette. Set it on any generator that can take part in a\n * connection.\n */\n 'x-label'?: string;\n properties?: Record<\n string,\n {\n type?: string;\n description?: string;\n enum?: string[];\n default?: unknown;\n 'x-priority'?: string;\n }\n >;\n required?: string[];\n};\n\ntype Schema = GeneratorSchema;\n\nconst GENERATORS = GeneratorsJson.generators as Record<string, GeneratorEntry>;\n\n/**\n * Resolves a generator's JSON schema by generator id.\n *\n * Injected rather than fixed because the two callers load files differently: the\n * plugin reads from disk (see `./schema-resolver`), while the docs site bundles\n * the schemas for the browser, where `node:fs` does not exist. Keeping this\n * module free of `node:fs` is what lets the browser import it at all.\n */\nexport type SchemaResolver = (generatorId: string) => Schema;\n\n/** The path `generators.json` records for a generator, relative to the plugin root. */\nexport const schemaPathOf = (generatorId: string): string => {\n const entry = GENERATORS[generatorId];\n if (!entry) {\n throw new Error(\n `Scaffold catalog: '${generatorId}' is not in generators.json`,\n );\n }\n return entry.schema;\n};\n\n/** The language prefix of a generator id: `ts` for `ts#agent`, `` for `license`. */\nconst languageOf = (id: string): string =>\n id.includes('#') ? id.slice(0, id.indexOf('#')) : '';\n\n/** Compare ids ignoring the separators that differ between wrapper and variant. */\nconst alike = (a: string, b: string): boolean =>\n a.replace(/[^a-z0-9]/gi, '').toLowerCase() ===\n b.replace(/[^a-z0-9]/gi, '').toLowerCase();\n\n/**\n * The public generator and option value that select a hidden endpoint type.\n *\n * A wrapper like `ts#api` produces several endpoint types, choosing between them\n * with an enum option: `--framework=trpc` yields `ts#trpc-api`. The pairing is\n * found by looking for a same-language public generator with an enum value that\n * reconstructs the endpoint's own name.\n */\nconst findWrapper = (\n endpointType: string,\n schemaOf: SchemaResolver,\n): { generator: string; options: Record<string, string> } | undefined => {\n const language = languageOf(endpointType);\n const name = endpointType.slice(endpointType.indexOf('#') + 1);\n\n for (const [generatorId, entry] of Object.entries(GENERATORS)) {\n if (entry.hidden) continue;\n if (languageOf(generatorId) !== language) continue;\n const wrapperName = generatorId.slice(generatorId.indexOf('#') + 1);\n\n for (const [option, property] of Object.entries(\n schemaOf(generatorId).properties ?? {},\n )) {\n for (const value of property.enum ?? []) {\n // Either the value names the variant outright (`react` for\n // `react-website`), or it qualifies the wrapper's own name\n // (`trpc` + `api` for `trpc-api`).\n if (alike(value, name) || alike(`${value}${wrapperName}`, name)) {\n return { generator: generatorId, options: { [option]: value } };\n }\n }\n }\n }\n return undefined;\n};\n\n/**\n * Derive the recipe for one endpoint type. Exported so a test can assert the\n * derivation against every type the plugin supports.\n */\nexport const deriveScaffoldRecipe = (\n endpointType: string,\n schemaOf: SchemaResolver,\n): ScaffoldRecipe => {\n const own = GENERATORS[endpointType];\n if (!own) {\n throw new Error(\n `Scaffold catalog: connection endpoint '${endpointType}' is not a generator id`,\n );\n }\n\n // A hidden generator is an implementation detail reached through its public\n // wrapper, which is what a user would actually run.\n const wrapper = own.hidden ? findWrapper(endpointType, schemaOf) : undefined;\n if (own.hidden && !wrapper) {\n throw new Error(\n `Scaffold catalog: '${endpointType}' is hidden and no public generator selects it`,\n );\n }\n\n // A generator requiring a `project` adds a component to one; anything else\n // creates its own project.\n const kind: ScaffoldKind = (schemaOf(endpointType).required ?? []).includes(\n 'project',\n )\n ? 'component'\n : 'project';\n\n const language = languageOf(endpointType);\n const hostGenerator = `${language}#project`;\n if (kind === 'component' && !GENERATORS[hostGenerator]) {\n throw new Error(\n `Scaffold catalog: '${endpointType}' is a component but '${hostGenerator}' does not exist to host it`,\n );\n }\n\n return {\n // `x-label` is the short noun a palette entry needs; `title` and\n // `description` are prose aimed at CLI prompts (\"Create a relational database\n // project\"). A generator without one falls back to its id, so a new endpoint\n // type still appears rather than being dropped.\n label: schemaOf(endpointType)['x-label'] ?? endpointType,\n generator: wrapper?.generator ?? endpointType,\n ...(wrapper ? { options: wrapper.options } : {}),\n kind,\n ...(kind === 'component'\n ? {\n host: {\n generator: hostGenerator,\n // Only options the host's schema actually requires, so a base\n // project generator gaining a required option is handled here.\n options: Object.fromEntries(\n (schemaOf(hostGenerator).required ?? [])\n .filter((option) => option !== 'name')\n .map((option) => {\n const property = schemaOf(hostGenerator).properties?.[option];\n const value = property?.default ?? property?.enum?.[0];\n if (value === undefined) {\n throw new Error(\n `Scaffold catalog: '${hostGenerator}' requires '${option}' but its schema offers no value to use`,\n );\n }\n return [option, String(value)];\n }),\n ),\n // Python project names are snake_cased when Nx qualifies them.\n snakeCaseName: language === 'py',\n },\n }\n : {}),\n };\n};\n\n/** Every endpoint type appearing at either end of a supported connection. */\nexport const CONNECTION_ENDPOINT_TYPES: readonly string[] = [\n ...new Set(\n SUPPORTED_CONNECTIONS.flatMap(({ source, target }) => [source, target]),\n ),\n].sort();\n\n/**\n * How to scaffold each connection endpoint type, derived from the generator\n * metadata. A connection added to `SUPPORTED_CONNECTIONS` appears here with no\n * edit to this file.\n */\nexport const buildScaffoldRecipes = (\n schemaOf: SchemaResolver,\n): Readonly<Record<string, ScaffoldRecipe>> =>\n Object.fromEntries(\n CONNECTION_ENDPOINT_TYPES.map((type) => [\n type,\n deriveScaffoldRecipe(type, schemaOf),\n ]),\n );\n\n/**\n * A requirement one end of a connection places on the other's options, mirroring\n * the guard the corresponding connection generator enforces.\n *\n * Declared rather than derived: each guard is an imperative `throw` inside its\n * connection generator, reachable only by running it. Recording them here lets a\n * caller choosing options up front check them first, and the paired test asserts\n * every entry names a real option with a value its enum allows.\n */\nexport interface ConnectionConstraint {\n /** Which end of the connection the constrained option belongs to. */\n readonly side: 'source' | 'target';\n /** The generator option carrying the constrained value. */\n readonly option: string;\n /** The only value accepted, if the option is pinned to one. */\n readonly equals?: string;\n /** A value rejected, for options accepting all but one. */\n readonly notEquals?: string;\n /** Why the constraint exists, phrased for the user choosing the option. */\n readonly reason: string;\n}\n\n/** Reusable constraint shapes, so the map below states each rule once. */\nconst AGENT_TO_AGENT: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'protocol',\n equals: 'a2a',\n reason: 'Only an A2A agent can be connected to another agent as a tool.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'A2A agent connections authenticate with IAM.',\n },\n];\n\nconst WEBSITE_TO_AGENT: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'protocol',\n notEquals: 'a2a',\n reason:\n 'A2A agents are reached by other agents, not by a website. Use the http or ag-ui protocol.',\n },\n];\n\nconst AGENT_TO_MCP: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'An agent reaches an MCP server with IAM authentication.',\n },\n];\n\nconst AGENT_TO_GATEWAY: readonly ConnectionConstraint[] = [\n {\n side: 'source',\n option: 'auth',\n equals: 'iam',\n reason: 'Only an IAM-authenticated agent can reach an IAM gateway.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'Agent connections require the gateway to authenticate with IAM.',\n },\n {\n side: 'target',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'An agent reaches a gateway as an MCP client, so the gateway must serve the mcp protocol. Note a single gateway cannot both front an agent and be called by one, since fronting requires the http protocol.',\n },\n];\n\nconst GATEWAY_TO_MCP: readonly ConnectionConstraint[] = [\n {\n side: 'source',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'MCP server targets can only be attached to an mcp-protocol gateway.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'A gateway reaches an MCP server target with IAM authentication.',\n },\n];\n\nconst GATEWAY_TO_AGENT: readonly ConnectionConstraint[] = [\n {\n side: 'source',\n option: 'protocol',\n equals: 'http',\n reason:\n 'Agent runtime targets can only be attached to an http-protocol gateway.',\n },\n];\n\n/**\n * The option-level requirements each connection places on its endpoints.\n *\n * Only connections carrying a requirement appear. Keyed by `ConnectionKey`, so a\n * key that no longer names a supported connection is a compile error.\n */\nexport const CONNECTION_CONSTRAINTS = {\n 'ts#react-website -> ts#agent': WEBSITE_TO_AGENT,\n 'ts#react-website -> py#agent': WEBSITE_TO_AGENT,\n 'ts#agent -> ts#agent': AGENT_TO_AGENT,\n 'ts#agent -> py#agent': AGENT_TO_AGENT,\n 'py#agent -> ts#agent': AGENT_TO_AGENT,\n 'py#agent -> py#agent': AGENT_TO_AGENT,\n 'ts#agent -> ts#mcp-server': AGENT_TO_MCP,\n 'ts#agent -> py#mcp-server': AGENT_TO_MCP,\n 'py#agent -> ts#mcp-server': AGENT_TO_MCP,\n 'py#agent -> py#mcp-server': AGENT_TO_MCP,\n 'ts#agent -> agentcore-gateway': AGENT_TO_GATEWAY,\n 'py#agent -> agentcore-gateway': AGENT_TO_GATEWAY,\n 'ts#react-website -> agentcore-gateway': [\n {\n side: 'target',\n option: 'protocol',\n equals: 'http',\n reason:\n 'A website connects to an http-protocol gateway, which proxies requests to its agent targets.',\n },\n ],\n 'agentcore-gateway -> ts#agent': [\n ...GATEWAY_TO_AGENT,\n {\n side: 'target',\n option: 'protocol',\n notEquals: 'http',\n reason:\n 'A TypeScript http agent serves tRPC over WebSocket, which AgentCore Gateway does not support. Use the ag-ui or a2a protocol.',\n },\n ],\n 'agentcore-gateway -> py#agent': GATEWAY_TO_AGENT,\n 'agentcore-gateway -> ts#mcp-server': GATEWAY_TO_MCP,\n 'agentcore-gateway -> py#mcp-server': GATEWAY_TO_MCP,\n 'agentcore-gateway -> agentcore-gateway': [\n {\n side: 'source',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'A gateway is aggregated into another as an MCP target, so both must be mcp-protocol gateways.',\n },\n {\n side: 'target',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'A gateway is aggregated into another as an MCP target, so both must be mcp-protocol gateways.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason:\n 'The source gateway signs its request with IAM, so the target gateway must accept IAM.',\n },\n ],\n} as const satisfies Partial<\n Record<ConnectionKey, readonly ConnectionConstraint[]>\n>;\n\n/**\n * A generator run automatically after an endpoint is scaffolded, adding something\n * that endpoint should always have.\n *\n * A website is only useful with authentication in front of it, and `ts#website`\n * does not add it — `ts#website#auth` is a separate follow-up generator. Declared\n * here so the docs graph builder emits it without hardcoding the pairing.\n */\nexport interface FollowUpGenerator {\n /** The generator id to run after the endpoint's own. */\n readonly generator: string;\n /** Options to pass, beyond the `--project` naming the endpoint. */\n readonly options?: Readonly<Record<string, string>>;\n /** What it adds, for the emitted command's comment. */\n readonly adds: string;\n}\n\n/**\n * Generators run automatically after an endpoint type is scaffolded, keyed by\n * endpoint type.\n */\nexport const ENDPOINT_FOLLOW_UPS: Readonly<\n Record<string, readonly FollowUpGenerator[]>\n> = {\n 'ts#react-website': [\n {\n generator: 'ts#website#auth',\n // `cognitoDomain` is derived from the npm scope and project name when\n // omitted, so the command stays short.\n adds: 'Cognito authentication',\n },\n ],\n};\n\n/**\n * An option value a connection works best against, without requiring it.\n *\n * Distinct from `CONNECTION_CONSTRAINTS`: a constraint is a rule the connection\n * generator enforces, whereas a preference is the setting most users want. A\n * React website can call an `http` agent perfectly well, but AG-UI is the\n * protocol built for driving a frontend, so that is what a new connection picks.\n *\n * A caller applies these only where the user has not chosen the option, so a\n * preference never overrides a deliberate decision.\n */\nexport interface ConnectionPreference {\n readonly side: 'source' | 'target';\n readonly option: string;\n readonly value: string;\n /** Why this is the better default, phrased for the user. */\n readonly reason: string;\n}\n\n/** An agent target only attaches to an http gateway, an MCP server only to an mcp one. */\nconst GATEWAY_PREFERS_HTTP: ConnectionPreference = {\n side: 'source',\n option: 'protocol',\n value: 'http',\n reason:\n 'Agent runtime targets are proxied by an http gateway, so attaching an agent selects that protocol.',\n};\n\nconst GATEWAY_PREFERS_MCP: ConnectionPreference = {\n side: 'source',\n option: 'protocol',\n value: 'mcp',\n reason:\n 'MCP server targets are aggregated by an mcp gateway, so attaching an MCP server selects that protocol.',\n};\n\n/**\n * Preferred option values per connection. Keyed by `ConnectionKey`, so a key that\n * no longer names a supported connection is a compile error.\n */\nexport const CONNECTION_PREFERENCES = {\n 'ts#react-website -> ts#agent': [\n {\n side: 'target',\n option: 'protocol',\n value: 'ag-ui',\n reason:\n 'AG-UI is the protocol built for driving a frontend, so a website connection selects it.',\n },\n ],\n 'ts#react-website -> py#agent': [\n {\n side: 'target',\n option: 'protocol',\n value: 'ag-ui',\n reason:\n 'AG-UI is the protocol built for driving a frontend, so a website connection selects it.',\n },\n ],\n // A gateway's protocol is decided by what it fronts, and the two are mutually\n // exclusive: agent runtime targets need an http gateway, MCP server targets an\n // mcp one. The gateway schema defaults to mcp, so only the agent side needs a\n // preference — but both are stated, so whichever target the user attaches\n // first settles the protocol.\n 'agentcore-gateway -> ts#agent': [GATEWAY_PREFERS_HTTP],\n 'agentcore-gateway -> py#agent': [GATEWAY_PREFERS_HTTP],\n 'agentcore-gateway -> ts#mcp-server': [GATEWAY_PREFERS_MCP],\n 'agentcore-gateway -> py#mcp-server': [GATEWAY_PREFERS_MCP],\n 'ts#react-website -> agentcore-gateway': [\n {\n side: 'target',\n option: 'protocol',\n value: 'http',\n reason:\n 'A website reaches a gateway’s agent targets over path-based http routing, so the gateway serves the http protocol.',\n },\n ],\n} as const satisfies Partial<\n Record<ConnectionKey, readonly ConnectionPreference[]>\n>;\n\n/**\n * Connections that must be generated after another, because the generator reads\n * state the earlier one records.\n *\n * The website→gateway generator publishes a route per agent already attached to\n * the gateway, reading them from the gateway project's connection metadata. Run\n * before the gateway→agent connections, it finds none and wires up nothing.\n *\n * Keyed by `ConnectionKey`, so a key that no longer names a supported connection\n * is a compile error.\n */\nexport const CONNECTION_ORDERING = {\n 'ts#react-website -> agentcore-gateway': {\n after: ['agentcore-gateway -> ts#agent', 'agentcore-gateway -> py#agent'],\n reason:\n 'The website connection publishes a route per agent attached to the gateway, so the gateway’s agents must be attached first.',\n },\n} as const satisfies Partial<\n Record<\n ConnectionKey,\n { readonly after: readonly ConnectionKey[]; readonly reason: string }\n >\n>;\n\n/**\n * Connections whose source and target must be distinct projects, because the\n * connection generator refuses to wire a project to itself.\n */\nexport const SELF_CONNECTION_DISALLOWED = [\n 'agentcore-gateway -> agentcore-gateway',\n] as const satisfies readonly ConnectionKey[];\n"],"names":["GeneratorsJson","type","SUPPORTED_CONNECTIONS","GENERATORS","generators","schemaPathOf","generatorId","entry","Error","schema","languageOf","id","includes","slice","indexOf","alike","a","b","replace","toLowerCase","findWrapper","endpointType","schemaOf","language","name","Object","entries","hidden","wrapperName","option","property","properties","value","enum","generator","options","undefined","deriveScaffoldRecipe","own","wrapper","kind","required","hostGenerator","label","host","fromEntries","filter","map","default","String","snakeCaseName","CONNECTION_ENDPOINT_TYPES","Set","flatMap","source","target","sort","buildScaffoldRecipes","AGENT_TO_AGENT","side","equals","reason","WEBSITE_TO_AGENT","notEquals","AGENT_TO_MCP","AGENT_TO_GATEWAY","GATEWAY_TO_MCP","GATEWAY_TO_AGENT","CONNECTION_CONSTRAINTS","ENDPOINT_FOLLOW_UPS","adds","GATEWAY_PREFERS_HTTP","GATEWAY_PREFERS_MCP","CONNECTION_PREFERENCES","CONNECTION_ORDERING","after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Q,sBAET;IACF,oBAAoB;QAClB;YACEnC,WAAW;YACX,sEAAsE;YACtE,uCAAuC;YACvCoC,MAAM;QACR;KACD;AACH,EAAE;AAqBF,wFAAwF,GACxF,MAAMC,uBAA6C;IACjDZ,MAAM;IACN9B,QAAQ;IACRG,OAAO;IACP6B,QACE;AACJ;AAEA,MAAMW,sBAA4C;IAChDb,MAAM;IACN9B,QAAQ;IACRG,OAAO;IACP6B,QACE;AACJ;AAEA;;;CAGC,GACD,OAAO,MAAMY,yBAAyB;IACpC,gCAAgC;QAC9B;YACEd,MAAM;YACN9B,QAAQ;YACRG,OAAO;YACP6B,QACE;QACJ;KACD;IACD,gCAAgC;QAC9B;YACEF,MAAM;YACN9B,QAAQ;YACRG,OAAO;YACP6B,QACE;QACJ;KACD;IACD,8EAA8E;IAC9E,+EAA+E;IAC/E,8EAA8E;IAC9E,0EAA0E;IAC1E,8BAA8B;IAC9B,iCAAiC;QAACU;KAAqB;IACvD,iCAAiC;QAACA;KAAqB;IACvD,sCAAsC;QAACC;KAAoB;IAC3D,sCAAsC;QAACA;KAAoB;IAC3D,yCAAyC;QACvC;YACEb,MAAM;YACN9B,QAAQ;YACRG,OAAO;YACP6B,QACE;QACJ;KACD;AACH,EAEE;AAEF;;;;;;;;;;CAUC,GACD,OAAO,MAAMa,sBAAsB;IACjC,yCAAyC;QACvCC,OAAO;YAAC;YAAiC;SAAgC;QACzEd,QACE;IACJ;AACF,EAKE;AAEF;;;CAGC,GACD,OAAO,MAAMe,6BAA6B;IACxC;CACD,CAA6C"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/connection/scaffold-catalog.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport GeneratorsJson from '../../generators.json' with { type: 'json' };\nimport {\n type ConnectionKey,\n SUPPORTED_CONNECTIONS,\n type SUPPORTED_PROJECT_TYPES,\n} from './supported-connections.js';\n\n/**\n * How to scaffold each end of a connection, derived from the plugin's own\n * metadata rather than hand-listed.\n *\n * Every connection endpoint type is also a generator id, which is what makes the\n * derivation possible:\n *\n * - **kind** — a generator whose schema `required`s a `project` adds a component\n * to an existing project; anything else creates a project of its own.\n * - **host** — a component lands in a project made by its language's base\n * generator (`ts#project` / `py#project`).\n * - **generator + options** — a type whose own generator is `hidden` is reached\n * through the public wrapper that selects it, found by matching the wrapper's\n * enum values against the type's name (`ts#trpc-api` ← `ts#api\n * --framework=trpc`). A visible generator is run directly.\n *\n * - **label** — the generator schema's own `x-label`.\n *\n * The result is that adding a generator and a connection for it needs no edit\n * here at all. The one thing still declared below is the option constraints,\n * which live as imperative guards inside each connection generator and so cannot\n * be read from metadata.\n */\n\n/**\n * Every type that can sit at either end of a connection: the project-level\n * types resolved by introspection, plus the component generator ids recorded in\n * component metadata.\n */\nexport type ConnectionEndpointType =\n | (typeof SUPPORTED_PROJECT_TYPES)[number]\n | (typeof SUPPORTED_CONNECTIONS)[number]['source']\n | (typeof SUPPORTED_CONNECTIONS)[number]['target'];\n\n/**\n * Whether scaffolding an endpoint creates a project of its own, or adds a\n * component to a project that must already exist.\n */\nexport type ScaffoldKind = 'project' | 'component';\n\n/** How to scaffold one end of a connection from the CLI. */\nexport interface ScaffoldRecipe {\n /** Human-readable name for this endpoint type. */\n readonly label: string;\n /** The generator id in `generators.json` that produces this endpoint. */\n readonly generator: string;\n /**\n * Options that select this endpoint type from its generator, for generators\n * producing more than one type (e.g. `framework`).\n */\n readonly options?: Readonly<Record<string, string>>;\n /** Whether the generator creates a project or adds a component to one. */\n readonly kind: ScaffoldKind;\n /**\n * The generator producing a project able to host this component, for\n * `component` recipes. Components are added to an existing project, so one\n * must be scaffolded first.\n */\n readonly host?: {\n readonly generator: string;\n readonly options?: Readonly<Record<string, string>>;\n /**\n * Whether the host project's name is referenced in snake_case. Python\n * project names are snake_cased when qualified, TypeScript ones are not.\n */\n readonly snakeCaseName?: boolean;\n };\n}\n\ntype GeneratorEntry = { schema: string; hidden?: boolean };\n/** The subset of JSON Schema the catalogue and the docs builder read. */\nexport type GeneratorSchema = {\n /**\n * Short display name for the thing this generator produces, used by the docs\n * graph builder's palette. Set it on any generator that can take part in a\n * connection.\n */\n 'x-label'?: string;\n properties?: Record<\n string,\n {\n type?: string;\n description?: string;\n enum?: string[];\n default?: unknown;\n 'x-priority'?: string;\n /** The option values this option applies under. */\n 'x-when'?: Record<string, string | string[]>;\n /** The same, per value, where one of an option's values applies sometimes. */\n 'x-value-when'?: Record<string, Record<string, string | string[]>>;\n }\n >;\n required?: string[];\n};\n\ntype Schema = GeneratorSchema;\n\nconst GENERATORS = GeneratorsJson.generators as Record<string, GeneratorEntry>;\n\n/**\n * Resolves a generator's JSON schema by generator id.\n *\n * Injected rather than fixed because the two callers load files differently: the\n * plugin reads from disk (see `./schema-resolver`), while the docs site bundles\n * the schemas for the browser, where `node:fs` does not exist. Keeping this\n * module free of `node:fs` is what lets the browser import it at all.\n */\nexport type SchemaResolver = (generatorId: string) => Schema;\n\n/** The path `generators.json` records for a generator, relative to the plugin root. */\nexport const schemaPathOf = (generatorId: string): string => {\n const entry = GENERATORS[generatorId];\n if (!entry) {\n throw new Error(\n `Scaffold catalog: '${generatorId}' is not in generators.json`,\n );\n }\n return entry.schema;\n};\n\n/** The language prefix of a generator id: `ts` for `ts#agent`, `` for `license`. */\nconst languageOf = (id: string): string =>\n id.includes('#') ? id.slice(0, id.indexOf('#')) : '';\n\n/** Compare ids ignoring the separators that differ between wrapper and variant. */\nconst alike = (a: string, b: string): boolean =>\n a.replace(/[^a-z0-9]/gi, '').toLowerCase() ===\n b.replace(/[^a-z0-9]/gi, '').toLowerCase();\n\n/**\n * The public generator and option value that select a hidden endpoint type.\n *\n * A wrapper like `ts#api` produces several endpoint types, choosing between them\n * with an enum option: `--framework=trpc` yields `ts#trpc-api`. The pairing is\n * found by looking for a same-language public generator with an enum value that\n * reconstructs the endpoint's own name.\n */\nconst findWrapper = (\n endpointType: string,\n schemaOf: SchemaResolver,\n): { generator: string; options: Record<string, string> } | undefined => {\n const language = languageOf(endpointType);\n const name = endpointType.slice(endpointType.indexOf('#') + 1);\n\n for (const [generatorId, entry] of Object.entries(GENERATORS)) {\n if (entry.hidden) continue;\n if (languageOf(generatorId) !== language) continue;\n const wrapperName = generatorId.slice(generatorId.indexOf('#') + 1);\n\n for (const [option, property] of Object.entries(\n schemaOf(generatorId).properties ?? {},\n )) {\n for (const value of property.enum ?? []) {\n // Either the value names the variant outright (`react` for\n // `react-website`), or it qualifies the wrapper's own name\n // (`trpc` + `api` for `trpc-api`).\n if (alike(value, name) || alike(`${value}${wrapperName}`, name)) {\n return { generator: generatorId, options: { [option]: value } };\n }\n }\n }\n }\n return undefined;\n};\n\n/**\n * Derive the recipe for one endpoint type. Exported so a test can assert the\n * derivation against every type the plugin supports.\n */\nexport const deriveScaffoldRecipe = (\n endpointType: string,\n schemaOf: SchemaResolver,\n): ScaffoldRecipe => {\n const own = GENERATORS[endpointType];\n if (!own) {\n throw new Error(\n `Scaffold catalog: connection endpoint '${endpointType}' is not a generator id`,\n );\n }\n\n // A hidden generator is an implementation detail reached through its public\n // wrapper, which is what a user would actually run.\n const wrapper = own.hidden ? findWrapper(endpointType, schemaOf) : undefined;\n if (own.hidden && !wrapper) {\n throw new Error(\n `Scaffold catalog: '${endpointType}' is hidden and no public generator selects it`,\n );\n }\n\n // A generator requiring a `project` adds a component to one; anything else\n // creates its own project.\n const kind: ScaffoldKind = (schemaOf(endpointType).required ?? []).includes(\n 'project',\n )\n ? 'component'\n : 'project';\n\n const language = languageOf(endpointType);\n const hostGenerator = `${language}#project`;\n if (kind === 'component' && !GENERATORS[hostGenerator]) {\n throw new Error(\n `Scaffold catalog: '${endpointType}' is a component but '${hostGenerator}' does not exist to host it`,\n );\n }\n\n return {\n // `x-label` is the short noun a palette entry needs; `title` and\n // `description` are prose aimed at CLI prompts (\"Create a relational database\n // project\"). A generator without one falls back to its id, so a new endpoint\n // type still appears rather than being dropped.\n label: schemaOf(endpointType)['x-label'] ?? endpointType,\n generator: wrapper?.generator ?? endpointType,\n ...(wrapper ? { options: wrapper.options } : {}),\n kind,\n ...(kind === 'component'\n ? {\n host: {\n generator: hostGenerator,\n // Only options the host's schema actually requires, so a base\n // project generator gaining a required option is handled here.\n options: Object.fromEntries(\n (schemaOf(hostGenerator).required ?? [])\n .filter((option) => option !== 'name')\n .map((option) => {\n const property = schemaOf(hostGenerator).properties?.[option];\n const value = property?.default ?? property?.enum?.[0];\n if (value === undefined) {\n throw new Error(\n `Scaffold catalog: '${hostGenerator}' requires '${option}' but its schema offers no value to use`,\n );\n }\n return [option, String(value)];\n }),\n ),\n // Python project names are snake_cased when Nx qualifies them.\n snakeCaseName: language === 'py',\n },\n }\n : {}),\n };\n};\n\n/** Every endpoint type appearing at either end of a supported connection. */\nexport const CONNECTION_ENDPOINT_TYPES: readonly string[] = [\n ...new Set(\n SUPPORTED_CONNECTIONS.flatMap(({ source, target }) => [source, target]),\n ),\n].sort();\n\n/**\n * How to scaffold each connection endpoint type, derived from the generator\n * metadata. A connection added to `SUPPORTED_CONNECTIONS` appears here with no\n * edit to this file.\n */\nexport const buildScaffoldRecipes = (\n schemaOf: SchemaResolver,\n): Readonly<Record<string, ScaffoldRecipe>> =>\n Object.fromEntries(\n CONNECTION_ENDPOINT_TYPES.map((type) => [\n type,\n deriveScaffoldRecipe(type, schemaOf),\n ]),\n );\n\n/**\n * A requirement one end of a connection places on the other's options, mirroring\n * the guard the corresponding connection generator enforces.\n *\n * Declared rather than derived: each guard is an imperative `throw` inside its\n * connection generator, reachable only by running it. Recording them here lets a\n * caller choosing options up front check them first, and the paired test asserts\n * every entry names a real option with a value its enum allows.\n */\nexport interface ConnectionConstraint {\n /** Which end of the connection the constrained option belongs to. */\n readonly side: 'source' | 'target';\n /** The generator option carrying the constrained value. */\n readonly option: string;\n /** The only value accepted, if the option is pinned to one. */\n readonly equals?: string;\n /** A value rejected, for options accepting all but one. */\n readonly notEquals?: string;\n /** Why the constraint exists, phrased for the user choosing the option. */\n readonly reason: string;\n}\n\n/** Reusable constraint shapes, so the map below states each rule once. */\nconst AGENT_TO_AGENT: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'protocol',\n equals: 'a2a',\n reason: 'Only an A2A agent can be connected to another agent as a tool.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'A2A agent connections authenticate with IAM.',\n },\n];\n\nconst WEBSITE_TO_AGENT: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'protocol',\n notEquals: 'a2a',\n reason:\n 'A2A agents are reached by other agents, not by a website. Use the http or ag-ui protocol.',\n },\n];\n\nconst AGENT_TO_MCP: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'An agent reaches an MCP server with IAM authentication.',\n },\n];\n\n// The agent's own `auth` governs inbound requests to it, so it places no\n// requirement here — the agent signs its outbound call to the gateway with\n// SigV4 from its execution role either way.\nconst AGENT_TO_GATEWAY: readonly ConnectionConstraint[] = [\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'Agent connections require the gateway to authenticate with IAM.',\n },\n {\n side: 'target',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'An agent reaches a gateway as an MCP client, so the gateway must serve the mcp protocol. Note a single gateway cannot both front an agent and be called by one, since fronting requires the http protocol.',\n },\n];\n\nconst GATEWAY_TO_MCP: readonly ConnectionConstraint[] = [\n {\n side: 'source',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'MCP server targets can only be attached to an mcp-protocol gateway.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason: 'A gateway reaches an MCP server target with IAM authentication.',\n },\n];\n\nconst GATEWAY_TO_AGENT: readonly ConnectionConstraint[] = [\n {\n side: 'source',\n option: 'protocol',\n equals: 'http',\n reason:\n 'Agent runtime targets can only be attached to an http-protocol gateway.',\n },\n];\n\n/**\n * The option-level requirements each connection places on its endpoints.\n *\n * Only connections carrying a requirement appear. Keyed by `ConnectionKey`, so a\n * key that no longer names a supported connection is a compile error.\n */\nexport const CONNECTION_CONSTRAINTS = {\n 'ts#react-website -> ts#agent': WEBSITE_TO_AGENT,\n 'ts#react-website -> py#agent': WEBSITE_TO_AGENT,\n 'ts#agent -> ts#agent': AGENT_TO_AGENT,\n 'ts#agent -> py#agent': AGENT_TO_AGENT,\n 'py#agent -> ts#agent': AGENT_TO_AGENT,\n 'py#agent -> py#agent': AGENT_TO_AGENT,\n 'ts#agent -> ts#mcp-server': AGENT_TO_MCP,\n 'ts#agent -> py#mcp-server': AGENT_TO_MCP,\n 'py#agent -> ts#mcp-server': AGENT_TO_MCP,\n 'py#agent -> py#mcp-server': AGENT_TO_MCP,\n 'ts#agent -> agentcore-gateway': AGENT_TO_GATEWAY,\n 'py#agent -> agentcore-gateway': AGENT_TO_GATEWAY,\n 'ts#react-website -> agentcore-gateway': [\n {\n side: 'target',\n option: 'protocol',\n equals: 'http',\n reason:\n 'A website connects to an http-protocol gateway, which proxies requests to its agent targets.',\n },\n ],\n 'agentcore-gateway -> ts#agent': [\n ...GATEWAY_TO_AGENT,\n {\n side: 'target',\n option: 'protocol',\n notEquals: 'http',\n reason:\n 'A TypeScript http agent serves tRPC over WebSocket, which AgentCore Gateway does not support. Use the ag-ui or a2a protocol.',\n },\n ],\n 'agentcore-gateway -> py#agent': GATEWAY_TO_AGENT,\n 'agentcore-gateway -> ts#mcp-server': GATEWAY_TO_MCP,\n 'agentcore-gateway -> py#mcp-server': GATEWAY_TO_MCP,\n 'agentcore-gateway -> agentcore-gateway': [\n {\n side: 'source',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'A gateway is aggregated into another as an MCP target, so both must be mcp-protocol gateways.',\n },\n {\n side: 'target',\n option: 'protocol',\n equals: 'mcp',\n reason:\n 'A gateway is aggregated into another as an MCP target, so both must be mcp-protocol gateways.',\n },\n {\n side: 'target',\n option: 'auth',\n equals: 'iam',\n reason:\n 'The source gateway signs its request with IAM, so the target gateway must accept IAM.',\n },\n ],\n} as const satisfies Partial<\n Record<ConnectionKey, readonly ConnectionConstraint[]>\n>;\n\n/**\n * A generator run automatically after an endpoint is scaffolded, adding something\n * that endpoint should always have.\n *\n * A website is only useful with authentication in front of it, and `ts#website`\n * does not add it — `ts#website#auth` is a separate follow-up generator. Declared\n * here so the docs graph builder emits it without hardcoding the pairing.\n */\nexport interface FollowUpGenerator {\n /** The generator id to run after the endpoint's own. */\n readonly generator: string;\n /** Options to pass, beyond the `--project` naming the endpoint. */\n readonly options?: Readonly<Record<string, string>>;\n /** What it adds, for the emitted command's comment. */\n readonly adds: string;\n}\n\n/**\n * Generators run automatically after an endpoint type is scaffolded, keyed by\n * endpoint type.\n */\nexport const ENDPOINT_FOLLOW_UPS: Readonly<\n Record<string, readonly FollowUpGenerator[]>\n> = {\n 'ts#react-website': [\n {\n generator: 'ts#website#auth',\n // `cognitoDomain` is derived from the npm scope and project name when\n // omitted, so the command stays short.\n adds: 'Cognito authentication',\n },\n ],\n};\n\n/**\n * An option value a connection works best against, without requiring it.\n *\n * Distinct from `CONNECTION_CONSTRAINTS`: a constraint is a rule the connection\n * generator enforces, whereas a preference is the setting most users want. A\n * React website can call an `http` agent perfectly well, but AG-UI is the\n * protocol built for driving a frontend, so that is what a new connection picks.\n *\n * A caller applies these only where the user has not chosen the option, so a\n * preference never overrides a deliberate decision.\n */\nexport interface ConnectionPreference {\n readonly side: 'source' | 'target';\n readonly option: string;\n readonly value: string;\n /** Why this is the better default, phrased for the user. */\n readonly reason: string;\n}\n\n/** An agent target only attaches to an http gateway, an MCP server only to an mcp one. */\nconst GATEWAY_PREFERS_HTTP: ConnectionPreference = {\n side: 'source',\n option: 'protocol',\n value: 'http',\n reason:\n 'Agent runtime targets are proxied by an http gateway, so attaching an agent selects that protocol.',\n};\n\nconst GATEWAY_PREFERS_MCP: ConnectionPreference = {\n side: 'source',\n option: 'protocol',\n value: 'mcp',\n reason:\n 'MCP server targets are aggregated by an mcp gateway, so attaching an MCP server selects that protocol.',\n};\n\n/**\n * Preferred option values per connection. Keyed by `ConnectionKey`, so a key that\n * no longer names a supported connection is a compile error.\n */\nexport const CONNECTION_PREFERENCES = {\n 'ts#react-website -> ts#agent': [\n {\n side: 'target',\n option: 'protocol',\n value: 'ag-ui',\n reason:\n 'AG-UI is the protocol built for driving a frontend, so a website connection selects it.',\n },\n ],\n 'ts#react-website -> py#agent': [\n {\n side: 'target',\n option: 'protocol',\n value: 'ag-ui',\n reason:\n 'AG-UI is the protocol built for driving a frontend, so a website connection selects it.',\n },\n ],\n // A gateway's protocol is decided by what it fronts, and the two are mutually\n // exclusive: agent runtime targets need an http gateway, MCP server targets an\n // mcp one. The gateway schema defaults to mcp, so only the agent side needs a\n // preference — but both are stated, so whichever target the user attaches\n // first settles the protocol.\n 'agentcore-gateway -> ts#agent': [GATEWAY_PREFERS_HTTP],\n 'agentcore-gateway -> py#agent': [GATEWAY_PREFERS_HTTP],\n 'agentcore-gateway -> ts#mcp-server': [GATEWAY_PREFERS_MCP],\n 'agentcore-gateway -> py#mcp-server': [GATEWAY_PREFERS_MCP],\n 'ts#react-website -> agentcore-gateway': [\n {\n side: 'target',\n option: 'protocol',\n value: 'http',\n reason:\n 'A website reaches a gateway’s agent targets over path-based http routing, so the gateway serves the http protocol.',\n },\n ],\n} as const satisfies Partial<\n Record<ConnectionKey, readonly ConnectionPreference[]>\n>;\n\n/**\n * Connections that must be generated after another, because the generator reads\n * state the earlier one records.\n *\n * The website→gateway generator publishes a route per agent already attached to\n * the gateway, reading them from the gateway project's connection metadata. Run\n * before the gateway→agent connections, it finds none and wires up nothing.\n *\n * Keyed by `ConnectionKey`, so a key that no longer names a supported connection\n * is a compile error.\n */\nexport const CONNECTION_ORDERING = {\n 'ts#react-website -> agentcore-gateway': {\n after: ['agentcore-gateway -> ts#agent', 'agentcore-gateway -> py#agent'],\n reason:\n 'The website connection publishes a route per agent attached to the gateway, so the gateway’s agents must be attached first.',\n },\n} as const satisfies Partial<\n Record<\n ConnectionKey,\n { readonly after: readonly ConnectionKey[]; readonly reason: string }\n >\n>;\n\n/**\n * Connections whose source and target must be distinct projects, because the\n * connection generator refuses to wire a project to itself.\n */\nexport const SELF_CONNECTION_DISALLOWED = [\n 'agentcore-gateway -> agentcore-gateway',\n] as const satisfies readonly ConnectionKey[];\n"],"names":["GeneratorsJson","type","SUPPORTED_CONNECTIONS","GENERATORS","generators","schemaPathOf","generatorId","entry","Error","schema","languageOf","id","includes","slice","indexOf","alike","a","b","replace","toLowerCase","findWrapper","endpointType","schemaOf","language","name","Object","entries","hidden","wrapperName","option","property","properties","value","enum","generator","options","undefined","deriveScaffoldRecipe","own","wrapper","kind","required","hostGenerator","label","host","fromEntries","filter","map","default","String","snakeCaseName","CONNECTION_ENDPOINT_TYPES","Set","flatMap","source","target","sort","buildScaffoldRecipes","AGENT_TO_AGENT","side","equals","reason","WEBSITE_TO_AGENT","notEquals","AGENT_TO_MCP","AGENT_TO_GATEWAY","GATEWAY_TO_MCP","GATEWAY_TO_AGENT","CONNECTION_CONSTRAINTS","ENDPOINT_FOLLOW_UPS","adds","GATEWAY_PREFERS_HTTP","GATEWAY_PREFERS_MCP","CONNECTION_PREFERENCES","CONNECTION_ORDERING","after","SELF_CONNECTION_DISALLOWED"],"mappings":"AAAA;;;CAGC,GACD,OAAOA,oBAAoB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACzE,SAEEC,qBAAqB,QAEhB,6BAA6B;AAmGpC,MAAMC,aAAaH,eAAeI,UAAU;AAY5C,qFAAqF,GACrF,OAAO,MAAMC,eAAe,CAACC;IAC3B,MAAMC,QAAQJ,UAAU,CAACG,YAAY;IACrC,IAAI,CAACC,OAAO;QACV,MAAM,IAAIC,MACR,CAAC,mBAAmB,EAAEF,YAAY,2BAA2B,CAAC;IAElE;IACA,OAAOC,MAAME,MAAM;AACrB,EAAE;AAEF,kFAAkF,GAClF,MAAMC,aAAa,CAACC,KAClBA,GAAGC,QAAQ,CAAC,OAAO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D;IACD,8EAA8E;IAC9E,+EAA+E;IAC/E,8EAA8E;IAC9E,0EAA0E;IAC1E,8BAA8B;IAC9B,iCAAiC;QAACU;KAAqB;IACvD,iCAAiC;QAACA;KAAqB;IACvD,sCAAsC;QAACC;KAAoB;IAC3D,sCAAsC;QAACA;KAAoB;IAC3D,yCAAyC;QACvC;YACEb,MAAM;YACN9B,QAAQ;YACRG,OAAO;YACP6B,QACE;QACJ;KACD;AACH,EAEE;AAEF;;;;;;;;;;CAUC,GACD,OAAO,MAAMa,sBAAsB;IACjC,yCAAyC;QACvCC,OAAO;YAAC;YAAiC;SAAgC;QACzEd,QACE;IACJ;AACF,EAKE;AAEF;;;CAGC,GACD,OAAO,MAAMe,6BAA6B;IACxC;CACD,CAA6C"}
@@ -47,7 +47,7 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies.js"
47
47
  readonly when: (m: import("../../utils/shared-constructs-constants.js").IacMetadata) => boolean;
48
48
  } & {
49
49
  versionOnly: true;
50
- }], readonly import("../../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
50
+ }], readonly import("../../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "pydantic" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
51
51
  export declare const INFRA_APP_GENERATOR_INFO: NxGeneratorInfo;
52
52
  export declare function tsInfraGenerator(tree: Tree, schema: TsInfraGeneratorSchema): Promise<GeneratorCallback>;
53
53
  export default tsInfraGenerator;
@@ -17,7 +17,7 @@ export declare const DEPENDENCIES: import("../utils/declared-dependencies.js").D
17
17
  readonly name: "typescript";
18
18
  }, {
19
19
  readonly name: "@biomejs/biome";
20
- }], readonly import("../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
20
+ }], readonly import("../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "pydantic" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
21
21
  export declare const INIT_GENERATOR_INFO: NxGeneratorInfo;
22
22
  /**
23
23
  * Configure an existing Nx workspace to use the @aws/nx-plugin.
@@ -12,7 +12,8 @@
12
12
  * 3. Component transforms — `<NxCommands>` / `<RunGenerator>` /
13
13
  * `<GeneratorParameters>` / `<CreateNxWorkspaceCommand>` /
14
14
  * `<InstallCommand>` / `<PackageManagerShortCommand>` /
15
- * `<PackageManagerExecCommand>` render down to markdown.
15
+ * `<PackageManagerExecCommand>` render down to markdown, and
16
+ * `<ArchitectureDiagram>` drops out as it has no text form.
16
17
  */
17
18
  import type { Root } from 'mdast';
18
19
  import type { NxGeneratorInfo } from '../utils/generators.js';
@@ -348,6 +348,12 @@ const renderComponent = (node, opts, pm, deps)=>{
348
348
  codeBlock(commands.map((c)=>buildPackageManagerExecCommand(pm, c)).join('\n'))
349
349
  ];
350
350
  }
351
+ // A diagram of the AWS resources a project deploys, drawn from the docs
352
+ // site's own artwork. There is nothing to render as text — the prose beside
353
+ // it describes the same architecture — so it is dropped rather than left as
354
+ // a stray tag.
355
+ case 'ArchitectureDiagram':
356
+ return [];
351
357
  default:
352
358
  return undefined;
353
359
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/mcp-server/guide-pipeline.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport fs from 'fs';\n/**\n * Unified + remark-mdx pipeline for the MCP `generator-guide` tool.\n *\n * Passes (in order, each over the already-transformed tree):\n * 1. Snippet inlining — `<Snippet name>` → recursive post-process.\n * 2. Filter transforms — `<OptionFilter>`, `<Infrastructure>` slot\n * selection, `<Tabs><TabItem _filter>` pruning.\n * 3. Component transforms — `<NxCommands>` / `<RunGenerator>` /\n * `<GeneratorParameters>` / `<CreateNxWorkspaceCommand>` /\n * `<InstallCommand>` / `<PackageManagerShortCommand>` /\n * `<PackageManagerExecCommand>` render down to markdown.\n */\nimport type { Root, RootContent } from 'mdast';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport {\n buildCreateNxWorkspaceCommand,\n buildInstallCommand,\n buildNxInitCommand,\n buildPackageManagerExecCommand,\n buildPackageManagerShortCommand,\n} from '../utils/commands.js';\nimport type { NxGeneratorInfo } from '../utils/generators.js';\nimport {\n buildNxCommand,\n renderGeneratorCommand,\n renderSchema,\n} from './guide-render.js';\nimport {\n hasBareAttr,\n isJsxElement,\n type JsxElement,\n type JsxParent,\n readEstreeAttr,\n readExpressionAttr,\n readStringAttr,\n} from './mdx-ast.js';\nimport {\n describePredicate,\n evaluatePredicate,\n extractStringArrayExpression,\n type Predicate,\n parseWhenExpression,\n} from './option-filter.js';\n\nexport interface PipelineOptions {\n generators: NxGeneratorInfo[];\n packageManager?: string;\n snippetContentProvider?: (name: string) => Promise<string> | string;\n options?: Record<string, string>;\n}\n\n// unified v11 is ESM-only and this package is CJS; dynamic import + rolldown's\n// `codeSplitting: false` bundles everything into the published MCP binary.\ninterface RemarkDeps {\n unified: typeof import('unified').unified;\n remarkParse: typeof import('remark-parse').default;\n remarkMdx: typeof import('remark-mdx').default;\n remarkStringify: typeof import('remark-stringify').default;\n remarkFrontmatter: typeof import('remark-frontmatter').default;\n}\n\nlet depsPromise: Promise<RemarkDeps> | undefined;\nconst loadRemarkDeps = (): Promise<RemarkDeps> => {\n if (!depsPromise) {\n depsPromise = (async () => ({\n unified: (await import('unified')).unified,\n remarkParse: (await import('remark-parse')).default,\n remarkMdx: (await import('remark-mdx')).default,\n remarkStringify: (await import('remark-stringify')).default,\n remarkFrontmatter: (await import('remark-frontmatter')).default,\n }))();\n }\n return depsPromise;\n};\n\nconst parseMdxWithDeps = (source: string, deps: RemarkDeps): Root =>\n deps\n .unified()\n .use(deps.remarkParse)\n .use(deps.remarkFrontmatter)\n .use(deps.remarkMdx)\n .parse(source) as Root;\n\n/** Parse MDX (with frontmatter) into mdast. Exposed so callers like\n * `fetchGuideFrontmatters` don't need to re-load remark themselves. */\nexport const parseMdx = async (source: string): Promise<Root> => {\n const deps = await loadRemarkDeps();\n return parseMdxWithDeps(source, deps);\n};\n\nconst stringifyMdx = (tree: Root, deps: RemarkDeps): string =>\n String(\n deps\n .unified()\n .use(deps.remarkFrontmatter)\n .use(deps.remarkMdx)\n .use(deps.remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n })\n .stringify(tree),\n );\n\n/**\n * Remove nodes that are meaningless once the MDX is rendered to plain markdown\n * for an agent: the YAML frontmatter block and the `import`/`export` (ESM)\n * statements at the top of every docs page. They add noise and tokens without\n * conveying guidance.\n */\nconst stripFrontmatterAndEsm = (tree: Root): void => {\n tree.children = tree.children.filter(\n (node) => node.type !== 'yaml' && node.type !== 'mdxjsEsm',\n );\n};\n\nexport const postProcessGuideWithRemark = async (\n guide: string,\n opts: PipelineOptions,\n): Promise<string> => {\n const deps = await loadRemarkDeps();\n const tree = parseMdxWithDeps(guide, deps);\n\n await inlineSnippets(tree, opts, deps);\n applyFilterTransforms(tree, opts.options);\n applyComponentTransforms(tree, opts, deps);\n stripFrontmatterAndEsm(tree);\n\n return stringifyMdx(tree, deps);\n};\n\nconst inlineSnippets = async (\n tree: Root,\n opts: PipelineOptions,\n deps: RemarkDeps,\n): Promise<void> => {\n const provider = opts.snippetContentProvider;\n if (!provider) return;\n\n interface PendingSnippet {\n parent: JsxParent;\n index: number;\n name: string;\n node: JsxElement;\n }\n\n const pending: PendingSnippet[] = [];\n const walk = (parent: JsxParent): void => {\n const children = parent.children as RootContent[];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (!isJsxElement(child)) continue;\n if (child.name === 'Snippet') {\n const name = readStringAttr(child, 'name');\n if (name) pending.push({ parent, index: i, name, node: child });\n continue;\n }\n walk(child);\n }\n };\n walk(tree);\n if (pending.length === 0) return;\n\n const fetched = await Promise.all(\n pending.map(async (p) => {\n let raw = '';\n try {\n raw = await provider(p.name);\n } catch {\n raw = '';\n }\n if (!raw) return { ...p, replacement: undefined };\n const processed = await postProcessGuideWithRemark(raw.trim(), opts);\n return { ...p, replacement: processed };\n }),\n );\n\n // Splice in descending index order per parent so earlier indices stay valid.\n const byParent = new Map<JsxParent, (typeof fetched)[number][]>();\n for (const f of fetched) {\n const bucket = byParent.get(f.parent) ?? [];\n bucket.push(f);\n byParent.set(f.parent, bucket);\n }\n for (const [parent, items] of byParent) {\n items.sort((a, b) => b.index - a.index);\n for (const { index, name, replacement, node } of items) {\n if (replacement === undefined) continue;\n const snippetTree = parseMdxWithDeps(replacement, deps);\n const wrapper: MdxJsxFlowElement = {\n type: 'mdxJsxFlowElement',\n name: 'Snippet',\n attributes: [{ type: 'mdxJsxAttribute', name: 'name', value: name }],\n children: snippetTree.children as MdxJsxFlowElement['children'],\n };\n if ('position' in node && node.position) {\n (wrapper as { position?: unknown }).position = node.position;\n }\n (parent.children as RootContent[]).splice(\n index,\n 1,\n wrapper as RootContent,\n );\n }\n }\n};\n\nconst applyFilterTransforms = (\n tree: Root,\n options: Record<string, string> | undefined,\n): void => {\n const iac = options?.iac;\n\n const transform = (parent: JsxParent): void => {\n const children = parent.children as RootContent[];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (!isJsxElement(child)) continue;\n\n if (child.name === 'OptionFilter') {\n const when = parseWhenAttr(child);\n if (!when) continue; // malformed — leave alone\n // Recurse first so nested filters collapse before we replace this wrapper.\n transform(child);\n const not = hasBareAttr(child, 'not');\n if (options) {\n const replacement = evaluatePredicate(when, not, options)\n ? (child.children as RootContent[])\n : [];\n children.splice(i, 1, ...replacement);\n i += replacement.length - 1;\n } else {\n children.splice(i, 1, buildNoteQuote(child, when, not));\n }\n continue;\n }\n\n if (child.name === 'Infrastructure') {\n if (iac === 'cdk' || iac === 'terraform') {\n const body = selectInfrastructureSlot(child, iac);\n const pseudo: MdxJsxFlowElement = {\n type: 'mdxJsxFlowElement',\n name: 'tmp',\n attributes: [],\n children: body as MdxJsxFlowElement['children'],\n };\n transform(pseudo);\n children.splice(i, 1, ...(pseudo.children as RootContent[]));\n i--;\n continue;\n }\n // No iac → keep both slots so readers / agents see both variants.\n transform(child);\n continue;\n }\n\n if (child.name === 'Tabs' && child.type === 'mdxJsxFlowElement') {\n transform(child);\n const dropped = applyTabsFilter(child, options);\n if (dropped === 'empty') {\n children.splice(i, 1);\n i--;\n continue;\n }\n if (dropped === 'inline') {\n const survivor = (child.children as RootContent[]).find(\n (c): c is MdxJsxFlowElement =>\n isJsxElement(c) && c.name === 'TabItem',\n )!;\n const body = survivor.children as RootContent[];\n children.splice(i, 1, ...body);\n i += body.length - 1;\n continue;\n }\n continue;\n }\n\n transform(child);\n }\n };\n transform(tree);\n};\n\nconst selectInfrastructureSlot = (\n node: JsxElement,\n iac: 'cdk' | 'terraform',\n): RootContent[] => {\n const slotName = iac.toLowerCase();\n const frag = (node.children as RootContent[]).find(\n (c): c is MdxJsxFlowElement =>\n isJsxElement(c) &&\n c.name === 'Fragment' &&\n readStringAttr(c, 'slot') === slotName,\n );\n return (frag?.children as RootContent[]) ?? [];\n};\n\n/**\n * Prune TabItems whose `_filter` doesn't match `options`. Returns:\n * - `'empty'` if the <Tabs> now has no <TabItem>s — caller drops it.\n * - `'inline'` if exactly one filtered <TabItem> survived — caller\n * inlines the body so agents see just the picked variant.\n * - `'keep'` otherwise.\n */\nconst applyTabsFilter = (\n tabs: MdxJsxFlowElement,\n options: Record<string, string> | undefined,\n): 'empty' | 'inline' | 'keep' => {\n const children = tabs.children as RootContent[];\n const surviving: RootContent[] = [];\n let anyFiltered = false;\n for (const child of children) {\n if (!isJsxElement(child) || child.name !== 'TabItem') {\n surviving.push(child);\n continue;\n }\n const filterEstree = readEstreeAttr(child, '_filter');\n if (!filterEstree) {\n surviving.push(child);\n continue;\n }\n anyFiltered = true;\n let predicate: Predicate;\n try {\n predicate = parseWhenExpression(filterEstree as never);\n } catch {\n stripFilterAttr(child);\n surviving.push(child);\n continue;\n }\n if (!options || evaluatePredicate(predicate, false, options)) {\n stripFilterAttr(child);\n surviving.push(child);\n }\n }\n if (anyFiltered) {\n tabs.children = surviving as MdxJsxFlowElement['children'];\n }\n const tabItems = surviving.filter(\n (c) => isJsxElement(c) && c.name === 'TabItem',\n );\n if (tabItems.length === 0 && surviving.length === 0) return 'empty';\n if (anyFiltered && tabItems.length === 1) return 'inline';\n return 'keep';\n};\n\nconst stripFilterAttr = (el: JsxElement): void => {\n el.attributes = el.attributes.filter(\n (a) => !(a.type === 'mdxJsxAttribute' && a.name === '_filter'),\n );\n};\n\n/**\n * `> [!NOTE] Only when …` blockquote. The alert header goes through as an\n * `html` node so remark-stringify doesn't escape the `[`/`]` brackets —\n * downstream agents match on the literal GitHub alert syntax.\n */\nconst buildNoteQuote = (\n source: JsxElement,\n predicate: Predicate,\n not: boolean,\n): RootContent => {\n const marker = describePredicate(predicate, not);\n const description = readStringAttr(source, 'description');\n const headerLines = description\n ? [`[!NOTE] ${marker}`, description]\n : [`[!NOTE] ${marker}`];\n const headerNodes: RootContent[] = headerLines.map(\n (line) => ({ type: 'html', value: line }) as RootContent,\n );\n return {\n type: 'blockquote',\n children: [...headerNodes, ...(source.children as RootContent[])] as never,\n } as RootContent;\n};\n\nconst parseWhenAttr = (node: JsxElement): Predicate | undefined => {\n const estree = readEstreeAttr(node, 'when');\n if (!estree) return undefined;\n try {\n return parseWhenExpression(estree as never);\n } catch {\n return undefined;\n }\n};\n\nconst applyComponentTransforms = (\n tree: Root,\n opts: PipelineOptions,\n deps: RemarkDeps,\n): void => {\n const pm = opts.packageManager ?? 'pnpm';\n const transform = (parent: JsxParent): void => {\n const children = parent.children as RootContent[];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (!isJsxElement(child)) continue;\n const replacement = renderComponent(child, opts, pm, deps);\n if (replacement !== undefined) {\n children.splice(i, 1, ...replacement);\n i += replacement.length - 1;\n continue;\n }\n transform(child);\n }\n };\n transform(tree);\n};\n\nconst renderComponent = (\n node: JsxElement,\n opts: PipelineOptions,\n pm: string,\n deps: RemarkDeps,\n): RootContent[] | undefined => {\n switch (node.name) {\n case 'NxCommands': {\n const commands = readCommandsAttr(node);\n if (!commands) return undefined;\n return [\n codeBlock(\n commands\n .map((c) => buildNxCommand(c, opts.packageManager))\n .join('\\n'),\n ),\n ];\n }\n case 'RunGenerator': {\n const generatorId = readStringAttr(node, 'generator');\n if (!generatorId) return undefined;\n const schema = findSchema(opts.generators, generatorId);\n if (!schema) return undefined;\n return parseMarkdownFragment(\n renderGeneratorCommand(generatorId, schema, opts.packageManager),\n deps,\n );\n }\n case 'GeneratorParameters': {\n const generatorId = readStringAttr(node, 'generator');\n if (!generatorId) return undefined;\n const schema = findSchema(opts.generators, generatorId);\n if (!schema) return undefined;\n return parseMarkdownFragment(renderSchema(schema), deps);\n }\n case 'CreateNxWorkspaceCommand': {\n const workspace = readStringAttr(node, 'workspace');\n if (!workspace) return undefined;\n const iac = readStringAttr(node, 'iac') as\n | 'cdk'\n | 'terraform'\n | undefined;\n return [codeBlock(buildCreateNxWorkspaceCommand(pm, workspace, iac))];\n }\n case 'NxInitCommand': {\n return [codeBlock(buildNxInitCommand(pm))];\n }\n case 'InstallCommand': {\n // Without `pkg`, installs the workspace's existing dependencies\n const pkg =\n readStringAttr(node, 'pkg') ?? readExpressionAttr(node, 'pkg');\n return [\n codeBlock(buildInstallCommand(pm, pkg, hasBareAttr(node, 'dev'))),\n ];\n }\n case 'PackageManagerShortCommand': {\n const commands = readCommandsAttr(node);\n if (!commands) return undefined;\n return [\n codeBlock(\n commands\n .map((c) => buildPackageManagerShortCommand(pm, c))\n .join('\\n'),\n ),\n ];\n }\n case 'PackageManagerExecCommand': {\n const commands = readCommandsAttr(node);\n if (!commands) return undefined;\n return [\n codeBlock(\n commands.map((c) => buildPackageManagerExecCommand(pm, c)).join('\\n'),\n ),\n ];\n }\n default:\n return undefined;\n }\n};\n\nconst codeBlock = (body: string): RootContent => ({\n type: 'code',\n lang: 'bash',\n value: body,\n});\n\nconst parseMarkdownFragment = (\n markdown: string,\n deps: RemarkDeps,\n): RootContent[] => {\n const fragTree = deps.unified().use(deps.remarkParse).parse(markdown) as Root;\n return fragTree.children as RootContent[];\n};\n\nconst findSchema = (\n generators: NxGeneratorInfo[],\n generatorId: string,\n):\n | { properties?: Record<string, unknown>; required?: string[] }\n | undefined => {\n const info = generators.find((g) => g.id === generatorId);\n if (!info) return undefined;\n try {\n return JSON.parse(fs.readFileSync(info.resolvedSchemaPath, 'utf-8'));\n } catch {\n return undefined;\n }\n};\n\n/** Parse the `commands={[…]}` attribute from the estree that remark-mdx\n * attaches to the JSX attribute value. */\nconst readCommandsAttr = (node: JsxElement): string[] | undefined => {\n const estree = readEstreeAttr(node, 'commands');\n if (!estree) return undefined;\n try {\n return extractStringArrayExpression(estree as never);\n } catch {\n return undefined;\n }\n};\n"],"names":["fs","buildCreateNxWorkspaceCommand","buildInstallCommand","buildNxInitCommand","buildPackageManagerExecCommand","buildPackageManagerShortCommand","buildNxCommand","renderGeneratorCommand","renderSchema","hasBareAttr","isJsxElement","readEstreeAttr","readExpressionAttr","readStringAttr","describePredicate","evaluatePredicate","extractStringArrayExpression","parseWhenExpression","depsPromise","loadRemarkDeps","unified","remarkParse","default","remarkMdx","remarkStringify","remarkFrontmatter","parseMdxWithDeps","source","deps","use","parse","parseMdx","stringifyMdx","tree","String","bullet","fences","listItemIndent","stringify","stripFrontmatterAndEsm","children","filter","node","type","postProcessGuideWithRemark","guide","opts","inlineSnippets","applyFilterTransforms","options","applyComponentTransforms","provider","snippetContentProvider","pending","walk","parent","i","length","child","name","push","index","fetched","Promise","all","map","p","raw","replacement","undefined","processed","trim","byParent","Map","f","bucket","get","set","items","sort","a","b","snippetTree","wrapper","attributes","value","position","splice","iac","transform","when","parseWhenAttr","not","buildNoteQuote","body","selectInfrastructureSlot","pseudo","dropped","applyTabsFilter","survivor","find","c","slotName","toLowerCase","frag","tabs","surviving","anyFiltered","filterEstree","predicate","stripFilterAttr","tabItems","el","marker","description","headerLines","headerNodes","line","estree","pm","packageManager","renderComponent","commands","readCommandsAttr","codeBlock","join","generatorId","schema","findSchema","generators","parseMarkdownFragment","workspace","pkg","lang","markdown","fragTree","info","g","id","JSON","readFileSync","resolvedSchemaPath"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,QAAQ,KAAK;AAepB,SACEC,6BAA6B,EAC7BC,mBAAmB,EACnBC,kBAAkB,EAClBC,8BAA8B,EAC9BC,+BAA+B,QAC1B,uBAAuB;AAE9B,SACEC,cAAc,EACdC,sBAAsB,EACtBC,YAAY,QACP,oBAAoB;AAC3B,SACEC,WAAW,EACXC,YAAY,EAGZC,cAAc,EACdC,kBAAkB,EAClBC,cAAc,QACT,eAAe;AACtB,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,4BAA4B,EAE5BC,mBAAmB,QACd,qBAAqB;AAmB5B,IAAIC;AACJ,MAAMC,iBAAiB;IACrB,IAAI,CAACD,aAAa;QAChBA,cAAc,AAAC,CAAA,UAAa,CAAA;gBAC1BE,SAAS,AAAC,CAAA,MAAM,MAAM,CAAC,UAAS,EAAGA,OAAO;gBAC1CC,aAAa,AAAC,CAAA,MAAM,MAAM,CAAC,eAAc,EAAGC,OAAO;gBACnDC,WAAW,AAAC,CAAA,MAAM,MAAM,CAAC,aAAY,EAAGD,OAAO;gBAC/CE,iBAAiB,AAAC,CAAA,MAAM,MAAM,CAAC,mBAAkB,EAAG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AACgF,UAAU,OAAOrD;gBACtB,OAAO;oBACLuD,UACEF,SAASzD,GAAG,CAAC,CAACoC,IAAMjG,+BAA+BmH,IAAIlB,IAAIwB,IAAI,CAAC;iBAEnE;YACH;QACA;YACE,OAAOxD;IACX;AACF;AAEA,MAAMuD,YAAY,CAAC9B,OAA+B,CAAA;QAChDnD,MAAM;QACN0F,MAAM;QACNhD,OAAOS;IACT,CAAA;AAEA,MAAMoC,wBAAwB,CAC5BI,UACA1G;IAEA,MAAM2G,WAAW3G,KAAKR,OAAO,GAAGS,GAAG,CAACD,KAAKP,WAAW,EAAES,KAAK,CAACwG;IAC5D,OAAOC,SAAS/F,QAAQ;AAC1B;AAEA,MAAMwF,aAAa,CACjBC,YACAH;IAIA,MAAMU,OAAOP,WAAW7B,IAAI,CAAC,CAACqC,IAAMA,EAAEC,EAAE,KAAKZ;IAC7C,IAAI,CAACU,MAAM,OAAOnE;IAClB,IAAI;QACF,OAAOsE,KAAK7G,KAAK,CAAC9B,GAAG4I,YAAY,CAACJ,KAAKK,kBAAkB,EAAE;IAC7D,EAAE,OAAM;QACN,OAAOxE;IACT;AACF;AAEA;yCACyC,GACzC,MAAMsD,mBAAmB,CAACjF;IACxB,MAAM4E,SAAS3G,eAAe+B,MAAM;IACpC,IAAI,CAAC4E,QAAQ,OAAOjD;IACpB,IAAI;QACF,OAAOrD,6BAA6BsG;IACtC,EAAE,OAAM;QACN,OAAOjD;IACT;AACF"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/mcp-server/guide-pipeline.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport fs from 'fs';\n/**\n * Unified + remark-mdx pipeline for the MCP `generator-guide` tool.\n *\n * Passes (in order, each over the already-transformed tree):\n * 1. Snippet inlining — `<Snippet name>` → recursive post-process.\n * 2. Filter transforms — `<OptionFilter>`, `<Infrastructure>` slot\n * selection, `<Tabs><TabItem _filter>` pruning.\n * 3. Component transforms — `<NxCommands>` / `<RunGenerator>` /\n * `<GeneratorParameters>` / `<CreateNxWorkspaceCommand>` /\n * `<InstallCommand>` / `<PackageManagerShortCommand>` /\n * `<PackageManagerExecCommand>` render down to markdown, and\n * `<ArchitectureDiagram>` drops out as it has no text form.\n */\nimport type { Root, RootContent } from 'mdast';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport {\n buildCreateNxWorkspaceCommand,\n buildInstallCommand,\n buildNxInitCommand,\n buildPackageManagerExecCommand,\n buildPackageManagerShortCommand,\n} from '../utils/commands.js';\nimport type { NxGeneratorInfo } from '../utils/generators.js';\nimport {\n buildNxCommand,\n renderGeneratorCommand,\n renderSchema,\n} from './guide-render.js';\nimport {\n hasBareAttr,\n isJsxElement,\n type JsxElement,\n type JsxParent,\n readEstreeAttr,\n readExpressionAttr,\n readStringAttr,\n} from './mdx-ast.js';\nimport {\n describePredicate,\n evaluatePredicate,\n extractStringArrayExpression,\n type Predicate,\n parseWhenExpression,\n} from './option-filter.js';\n\nexport interface PipelineOptions {\n generators: NxGeneratorInfo[];\n packageManager?: string;\n snippetContentProvider?: (name: string) => Promise<string> | string;\n options?: Record<string, string>;\n}\n\n// unified v11 is ESM-only and this package is CJS; dynamic import + rolldown's\n// `codeSplitting: false` bundles everything into the published MCP binary.\ninterface RemarkDeps {\n unified: typeof import('unified').unified;\n remarkParse: typeof import('remark-parse').default;\n remarkMdx: typeof import('remark-mdx').default;\n remarkStringify: typeof import('remark-stringify').default;\n remarkFrontmatter: typeof import('remark-frontmatter').default;\n}\n\nlet depsPromise: Promise<RemarkDeps> | undefined;\nconst loadRemarkDeps = (): Promise<RemarkDeps> => {\n if (!depsPromise) {\n depsPromise = (async () => ({\n unified: (await import('unified')).unified,\n remarkParse: (await import('remark-parse')).default,\n remarkMdx: (await import('remark-mdx')).default,\n remarkStringify: (await import('remark-stringify')).default,\n remarkFrontmatter: (await import('remark-frontmatter')).default,\n }))();\n }\n return depsPromise;\n};\n\nconst parseMdxWithDeps = (source: string, deps: RemarkDeps): Root =>\n deps\n .unified()\n .use(deps.remarkParse)\n .use(deps.remarkFrontmatter)\n .use(deps.remarkMdx)\n .parse(source) as Root;\n\n/** Parse MDX (with frontmatter) into mdast. Exposed so callers like\n * `fetchGuideFrontmatters` don't need to re-load remark themselves. */\nexport const parseMdx = async (source: string): Promise<Root> => {\n const deps = await loadRemarkDeps();\n return parseMdxWithDeps(source, deps);\n};\n\nconst stringifyMdx = (tree: Root, deps: RemarkDeps): string =>\n String(\n deps\n .unified()\n .use(deps.remarkFrontmatter)\n .use(deps.remarkMdx)\n .use(deps.remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n })\n .stringify(tree),\n );\n\n/**\n * Remove nodes that are meaningless once the MDX is rendered to plain markdown\n * for an agent: the YAML frontmatter block and the `import`/`export` (ESM)\n * statements at the top of every docs page. They add noise and tokens without\n * conveying guidance.\n */\nconst stripFrontmatterAndEsm = (tree: Root): void => {\n tree.children = tree.children.filter(\n (node) => node.type !== 'yaml' && node.type !== 'mdxjsEsm',\n );\n};\n\nexport const postProcessGuideWithRemark = async (\n guide: string,\n opts: PipelineOptions,\n): Promise<string> => {\n const deps = await loadRemarkDeps();\n const tree = parseMdxWithDeps(guide, deps);\n\n await inlineSnippets(tree, opts, deps);\n applyFilterTransforms(tree, opts.options);\n applyComponentTransforms(tree, opts, deps);\n stripFrontmatterAndEsm(tree);\n\n return stringifyMdx(tree, deps);\n};\n\nconst inlineSnippets = async (\n tree: Root,\n opts: PipelineOptions,\n deps: RemarkDeps,\n): Promise<void> => {\n const provider = opts.snippetContentProvider;\n if (!provider) return;\n\n interface PendingSnippet {\n parent: JsxParent;\n index: number;\n name: string;\n node: JsxElement;\n }\n\n const pending: PendingSnippet[] = [];\n const walk = (parent: JsxParent): void => {\n const children = parent.children as RootContent[];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (!isJsxElement(child)) continue;\n if (child.name === 'Snippet') {\n const name = readStringAttr(child, 'name');\n if (name) pending.push({ parent, index: i, name, node: child });\n continue;\n }\n walk(child);\n }\n };\n walk(tree);\n if (pending.length === 0) return;\n\n const fetched = await Promise.all(\n pending.map(async (p) => {\n let raw = '';\n try {\n raw = await provider(p.name);\n } catch {\n raw = '';\n }\n if (!raw) return { ...p, replacement: undefined };\n const processed = await postProcessGuideWithRemark(raw.trim(), opts);\n return { ...p, replacement: processed };\n }),\n );\n\n // Splice in descending index order per parent so earlier indices stay valid.\n const byParent = new Map<JsxParent, (typeof fetched)[number][]>();\n for (const f of fetched) {\n const bucket = byParent.get(f.parent) ?? [];\n bucket.push(f);\n byParent.set(f.parent, bucket);\n }\n for (const [parent, items] of byParent) {\n items.sort((a, b) => b.index - a.index);\n for (const { index, name, replacement, node } of items) {\n if (replacement === undefined) continue;\n const snippetTree = parseMdxWithDeps(replacement, deps);\n const wrapper: MdxJsxFlowElement = {\n type: 'mdxJsxFlowElement',\n name: 'Snippet',\n attributes: [{ type: 'mdxJsxAttribute', name: 'name', value: name }],\n children: snippetTree.children as MdxJsxFlowElement['children'],\n };\n if ('position' in node && node.position) {\n (wrapper as { position?: unknown }).position = node.position;\n }\n (parent.children as RootContent[]).splice(\n index,\n 1,\n wrapper as RootContent,\n );\n }\n }\n};\n\nconst applyFilterTransforms = (\n tree: Root,\n options: Record<string, string> | undefined,\n): void => {\n const iac = options?.iac;\n\n const transform = (parent: JsxParent): void => {\n const children = parent.children as RootContent[];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (!isJsxElement(child)) continue;\n\n if (child.name === 'OptionFilter') {\n const when = parseWhenAttr(child);\n if (!when) continue; // malformed — leave alone\n // Recurse first so nested filters collapse before we replace this wrapper.\n transform(child);\n const not = hasBareAttr(child, 'not');\n if (options) {\n const replacement = evaluatePredicate(when, not, options)\n ? (child.children as RootContent[])\n : [];\n children.splice(i, 1, ...replacement);\n i += replacement.length - 1;\n } else {\n children.splice(i, 1, buildNoteQuote(child, when, not));\n }\n continue;\n }\n\n if (child.name === 'Infrastructure') {\n if (iac === 'cdk' || iac === 'terraform') {\n const body = selectInfrastructureSlot(child, iac);\n const pseudo: MdxJsxFlowElement = {\n type: 'mdxJsxFlowElement',\n name: 'tmp',\n attributes: [],\n children: body as MdxJsxFlowElement['children'],\n };\n transform(pseudo);\n children.splice(i, 1, ...(pseudo.children as RootContent[]));\n i--;\n continue;\n }\n // No iac → keep both slots so readers / agents see both variants.\n transform(child);\n continue;\n }\n\n if (child.name === 'Tabs' && child.type === 'mdxJsxFlowElement') {\n transform(child);\n const dropped = applyTabsFilter(child, options);\n if (dropped === 'empty') {\n children.splice(i, 1);\n i--;\n continue;\n }\n if (dropped === 'inline') {\n const survivor = (child.children as RootContent[]).find(\n (c): c is MdxJsxFlowElement =>\n isJsxElement(c) && c.name === 'TabItem',\n )!;\n const body = survivor.children as RootContent[];\n children.splice(i, 1, ...body);\n i += body.length - 1;\n continue;\n }\n continue;\n }\n\n transform(child);\n }\n };\n transform(tree);\n};\n\nconst selectInfrastructureSlot = (\n node: JsxElement,\n iac: 'cdk' | 'terraform',\n): RootContent[] => {\n const slotName = iac.toLowerCase();\n const frag = (node.children as RootContent[]).find(\n (c): c is MdxJsxFlowElement =>\n isJsxElement(c) &&\n c.name === 'Fragment' &&\n readStringAttr(c, 'slot') === slotName,\n );\n return (frag?.children as RootContent[]) ?? [];\n};\n\n/**\n * Prune TabItems whose `_filter` doesn't match `options`. Returns:\n * - `'empty'` if the <Tabs> now has no <TabItem>s — caller drops it.\n * - `'inline'` if exactly one filtered <TabItem> survived — caller\n * inlines the body so agents see just the picked variant.\n * - `'keep'` otherwise.\n */\nconst applyTabsFilter = (\n tabs: MdxJsxFlowElement,\n options: Record<string, string> | undefined,\n): 'empty' | 'inline' | 'keep' => {\n const children = tabs.children as RootContent[];\n const surviving: RootContent[] = [];\n let anyFiltered = false;\n for (const child of children) {\n if (!isJsxElement(child) || child.name !== 'TabItem') {\n surviving.push(child);\n continue;\n }\n const filterEstree = readEstreeAttr(child, '_filter');\n if (!filterEstree) {\n surviving.push(child);\n continue;\n }\n anyFiltered = true;\n let predicate: Predicate;\n try {\n predicate = parseWhenExpression(filterEstree as never);\n } catch {\n stripFilterAttr(child);\n surviving.push(child);\n continue;\n }\n if (!options || evaluatePredicate(predicate, false, options)) {\n stripFilterAttr(child);\n surviving.push(child);\n }\n }\n if (anyFiltered) {\n tabs.children = surviving as MdxJsxFlowElement['children'];\n }\n const tabItems = surviving.filter(\n (c) => isJsxElement(c) && c.name === 'TabItem',\n );\n if (tabItems.length === 0 && surviving.length === 0) return 'empty';\n if (anyFiltered && tabItems.length === 1) return 'inline';\n return 'keep';\n};\n\nconst stripFilterAttr = (el: JsxElement): void => {\n el.attributes = el.attributes.filter(\n (a) => !(a.type === 'mdxJsxAttribute' && a.name === '_filter'),\n );\n};\n\n/**\n * `> [!NOTE] Only when …` blockquote. The alert header goes through as an\n * `html` node so remark-stringify doesn't escape the `[`/`]` brackets —\n * downstream agents match on the literal GitHub alert syntax.\n */\nconst buildNoteQuote = (\n source: JsxElement,\n predicate: Predicate,\n not: boolean,\n): RootContent => {\n const marker = describePredicate(predicate, not);\n const description = readStringAttr(source, 'description');\n const headerLines = description\n ? [`[!NOTE] ${marker}`, description]\n : [`[!NOTE] ${marker}`];\n const headerNodes: RootContent[] = headerLines.map(\n (line) => ({ type: 'html', value: line }) as RootContent,\n );\n return {\n type: 'blockquote',\n children: [...headerNodes, ...(source.children as RootContent[])] as never,\n } as RootContent;\n};\n\nconst parseWhenAttr = (node: JsxElement): Predicate | undefined => {\n const estree = readEstreeAttr(node, 'when');\n if (!estree) return undefined;\n try {\n return parseWhenExpression(estree as never);\n } catch {\n return undefined;\n }\n};\n\nconst applyComponentTransforms = (\n tree: Root,\n opts: PipelineOptions,\n deps: RemarkDeps,\n): void => {\n const pm = opts.packageManager ?? 'pnpm';\n const transform = (parent: JsxParent): void => {\n const children = parent.children as RootContent[];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (!isJsxElement(child)) continue;\n const replacement = renderComponent(child, opts, pm, deps);\n if (replacement !== undefined) {\n children.splice(i, 1, ...replacement);\n i += replacement.length - 1;\n continue;\n }\n transform(child);\n }\n };\n transform(tree);\n};\n\nconst renderComponent = (\n node: JsxElement,\n opts: PipelineOptions,\n pm: string,\n deps: RemarkDeps,\n): RootContent[] | undefined => {\n switch (node.name) {\n case 'NxCommands': {\n const commands = readCommandsAttr(node);\n if (!commands) return undefined;\n return [\n codeBlock(\n commands\n .map((c) => buildNxCommand(c, opts.packageManager))\n .join('\\n'),\n ),\n ];\n }\n case 'RunGenerator': {\n const generatorId = readStringAttr(node, 'generator');\n if (!generatorId) return undefined;\n const schema = findSchema(opts.generators, generatorId);\n if (!schema) return undefined;\n return parseMarkdownFragment(\n renderGeneratorCommand(generatorId, schema, opts.packageManager),\n deps,\n );\n }\n case 'GeneratorParameters': {\n const generatorId = readStringAttr(node, 'generator');\n if (!generatorId) return undefined;\n const schema = findSchema(opts.generators, generatorId);\n if (!schema) return undefined;\n return parseMarkdownFragment(renderSchema(schema), deps);\n }\n case 'CreateNxWorkspaceCommand': {\n const workspace = readStringAttr(node, 'workspace');\n if (!workspace) return undefined;\n const iac = readStringAttr(node, 'iac') as\n | 'cdk'\n | 'terraform'\n | undefined;\n return [codeBlock(buildCreateNxWorkspaceCommand(pm, workspace, iac))];\n }\n case 'NxInitCommand': {\n return [codeBlock(buildNxInitCommand(pm))];\n }\n case 'InstallCommand': {\n // Without `pkg`, installs the workspace's existing dependencies\n const pkg =\n readStringAttr(node, 'pkg') ?? readExpressionAttr(node, 'pkg');\n return [\n codeBlock(buildInstallCommand(pm, pkg, hasBareAttr(node, 'dev'))),\n ];\n }\n case 'PackageManagerShortCommand': {\n const commands = readCommandsAttr(node);\n if (!commands) return undefined;\n return [\n codeBlock(\n commands\n .map((c) => buildPackageManagerShortCommand(pm, c))\n .join('\\n'),\n ),\n ];\n }\n case 'PackageManagerExecCommand': {\n const commands = readCommandsAttr(node);\n if (!commands) return undefined;\n return [\n codeBlock(\n commands.map((c) => buildPackageManagerExecCommand(pm, c)).join('\\n'),\n ),\n ];\n }\n // A diagram of the AWS resources a project deploys, drawn from the docs\n // site's own artwork. There is nothing to render as text — the prose beside\n // it describes the same architecture — so it is dropped rather than left as\n // a stray tag.\n case 'ArchitectureDiagram':\n return [];\n default:\n return undefined;\n }\n};\n\nconst codeBlock = (body: string): RootContent => ({\n type: 'code',\n lang: 'bash',\n value: body,\n});\n\nconst parseMarkdownFragment = (\n markdown: string,\n deps: RemarkDeps,\n): RootContent[] => {\n const fragTree = deps.unified().use(deps.remarkParse).parse(markdown) as Root;\n return fragTree.children as RootContent[];\n};\n\nconst findSchema = (\n generators: NxGeneratorInfo[],\n generatorId: string,\n):\n | { properties?: Record<string, unknown>; required?: string[] }\n | undefined => {\n const info = generators.find((g) => g.id === generatorId);\n if (!info) return undefined;\n try {\n return JSON.parse(fs.readFileSync(info.resolvedSchemaPath, 'utf-8'));\n } catch {\n return undefined;\n }\n};\n\n/** Parse the `commands={[…]}` attribute from the estree that remark-mdx\n * attaches to the JSX attribute value. */\nconst readCommandsAttr = (node: JsxElement): string[] | undefined => {\n const estree = readEstreeAttr(node, 'commands');\n if (!estree) return undefined;\n try {\n return extractStringArrayExpression(estree as never);\n } catch {\n return undefined;\n }\n};\n"],"names":["fs","buildCreateNxWorkspaceCommand","buildInstallCommand","buildNxInitCommand","buildPackageManagerExecCommand","buildPackageManagerShortCommand","buildNxCommand","renderGeneratorCommand","renderSchema","hasBareAttr","isJsxElement","readEstreeAttr","readExpressionAttr","readStringAttr","describePredicate","evaluatePredicate","extractStringArrayExpression","parseWhenExpression","depsPromise","loadRemarkDeps","unified","remarkParse","default","remarkMdx","remarkStringify","remarkFrontmatter","parseMdxWithDeps","source","deps","use","parse","parseMdx","stringifyMdx","tree","String","bullet","fences","listItemIndent","stringify","stripFrontmatterAndEsm","children","filter","node","type","postProcessGuideWithRemark","guide","opts","inlineSnippets","applyFilterTransforms","options","applyComponentTransforms","provider","snippetContentProvider","pending","walk","parent","i","length","child","name","push","index","fetched","Promise","all","map","p","raw","replacement","undefined","processed","trim","byParent","Map","f","bucket","get","set","items","sort","a","b","snippetTree","wrapper","attributes","value","position","splice","iac","transform","when","parseWhenAttr","not","buildNoteQuote","body","selectInfrastructureSlot","pseudo","dropped","applyTabsFilter","survivor","find","c","slotName","toLowerCase","frag","tabs","surviving","anyFiltered","filterEstree","predicate","stripFilterAttr","tabItems","el","marker","description","headerLines","headerNodes","line","estree","pm","packageManager","renderComponent","commands","readCommandsAttr","codeBlock","join","generatorId","schema","findSchema","generators","parseMarkdownFragment","workspace","pkg","lang","markdown","fragTree","info","g","id","JSON","readFileSync","resolvedSchemaPath"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,QAAQ,KAAK;AAgBpB,SACEC,6BAA6B,EAC7BC,mBAAmB,EACnBC,kBAAkB,EAClBC,8BAA8B,EAC9BC,+BAA+B,QAC1B,uBAAuB;AAE9B,SACEC,cAAc,EACdC,sBAAsB,EACtBC,YAAY,QACP,oBAAoB;AAC3B,SACEC,WAAW,EACXC,YAAY,EAGZC,cAAc,EACdC,kBAAkB,EAClBC,cAAc,QACT,eAAe;AACtB,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,4BAA4B,EAE5BC,mBAAmB,QACd,qBAAqB;AAmB5B,IAAIC;AACJ,MAAMC,iBAAiB;IACrB,IAAI,CAACD,aAAa;QAChBA,cAAc,AAAC,CAAA,UAAa,CAAA;gBAC1BE,SAAS,AAAC,CAAA,MAAM,MAAM,CAAC,UAAS,EAAGA,OAAO;gBAC1CC,aAAa,AAAC,CAAA,MAAM,MAAM,CAAC,eAAc,EAAGC,OAAO;gBACnDC,WAAW,AAAC,CAAA,MAAM,MAAM,CAAC,aAAY,EAAGD,OAAO;gBAC/CE,iBAAiB,AAAC,CAAA,MAAM,MAAM,CAAC,mBAAkB,EAAGF,OAAO;gBAC3DG,mBAAmB,AAAC,CAAA,MAAM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ACEF,SAASzD,GAAG,CAAC,CAACoC,IAAMjG,+BAA+BmH,IAAIlB,IAAIwB,IAAI,CAAC;iBAEnE;YACH;QACA,wEAAwE;QACxE,4EAA4E;QAC5E,4EAA4E;QAC5E,eAAe;QACf,KAAK;YACH,OAAO,EAAE;QACX;YACE,OAAOxD;IACX;AACF;AAEA,MAAMuD,YAAY,CAAC9B,OAA+B,CAAA;QAChDnD,MAAM;QACN0F,MAAM;QACNhD,OAAOS;IACT,CAAA;AAEA,MAAMoC,wBAAwB,CAC5BI,UACA1G;IAEA,MAAM2G,WAAW3G,KAAKR,OAAO,GAAGS,GAAG,CAACD,KAAKP,WAAW,EAAES,KAAK,CAACwG;IAC5D,OAAOC,SAAS/F,QAAQ;AAC1B;AAEA,MAAMwF,aAAa,CACjBC,YACAH;IAIA,MAAMU,OAAOP,WAAW7B,IAAI,CAAC,CAACqC,IAAMA,EAAEC,EAAE,KAAKZ;IAC7C,IAAI,CAACU,MAAM,OAAOnE;IAClB,IAAI;QACF,OAAOsE,KAAK7G,KAAK,CAAC9B,GAAG4I,YAAY,CAACJ,KAAKK,kBAAkB,EAAE;IAC7D,EAAE,OAAM;QACN,OAAOxE;IACT;AACF;AAEA;yCACyC,GACzC,MAAMsD,mBAAmB,CAACjF;IACxB,MAAM4E,SAAS3G,eAAe+B,MAAM;IACpC,IAAI,CAAC4E,QAAQ,OAAOjD;IACpB,IAAI;QACF,OAAOrD,6BAA6BsG;IACtC,EAAE,OAAM;QACN,OAAOjD;IACT;AACF"}
@@ -28,3 +28,10 @@ export declare const extractFrontmatter: (tree: Root) => {
28
28
  data: Record<string, unknown>;
29
29
  bodyOffset: number;
30
30
  };
31
+ /**
32
+ * Remove the frontmatter and every ESM `import`/`export` statement from an MDX
33
+ * source, leaving the content behind. The statements are located through the
34
+ * parsed tree, so `import` and `export` lines that appear inside code samples
35
+ * or template literals are kept — they are content, not preamble.
36
+ */
37
+ export declare const stripFrontmatterAndEsm: (raw: string, tree: Root) => string;
@@ -78,5 +78,20 @@ export const hasBareAttr = (node, name)=>node.attributes.some((a)=>a.type === 'm
78
78
  bodyOffset: node.position?.end.offset ?? 0
79
79
  };
80
80
  };
81
+ /**
82
+ * Remove the frontmatter and every ESM `import`/`export` statement from an MDX
83
+ * source, leaving the content behind. The statements are located through the
84
+ * parsed tree, so `import` and `export` lines that appear inside code samples
85
+ * or template literals are kept — they are content, not preamble.
86
+ */ export const stripFrontmatterAndEsm = (raw, tree)=>{
87
+ const cuts = tree.children.filter((c)=>c.type === 'yaml' || c.type === 'mdxjsEsm').map((c)=>c.position).filter((p)=>p?.start.offset !== undefined && p?.end.offset !== undefined);
88
+ let result = '';
89
+ let cursor = 0;
90
+ for (const { start, end } of cuts){
91
+ result += raw.slice(cursor, start.offset);
92
+ cursor = end.offset;
93
+ }
94
+ return (result + raw.slice(cursor)).trim();
95
+ };
81
96
 
82
97
  //# sourceMappingURL=mdx-ast.js.map