@aws/nx-plugin 1.0.0-rc.36 → 1.0.0-rc.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generators.json +7 -0
- package/package.json +1 -1
- package/src/init/generator.d.ts +18 -0
- package/src/init/generator.js +35 -0
- package/src/init/generator.js.map +1 -0
- package/src/init/schema.d.js +6 -0
- package/src/init/schema.d.js.map +1 -0
- package/src/init/schema.d.ts +16 -0
- package/src/init/schema.json +35 -0
- package/src/mcp-server/generator-info.js +27 -13
- package/src/mcp-server/generator-info.js.map +1 -1
- package/src/mcp-server/guide-pipeline.js +16 -1
- package/src/mcp-server/guide-pipeline.js.map +1 -1
- package/src/mcp-server/server.js +2 -0
- package/src/mcp-server/server.js.map +1 -1
- package/src/mcp-server/tools/add-to-existing-project.d.ts +12 -0
- package/src/mcp-server/tools/add-to-existing-project.js +36 -0
- package/src/mcp-server/tools/add-to-existing-project.js.map +1 -0
- package/src/mcp-server/tools/general-guidance.d.ts +1 -1
- package/src/mcp-server/tools/general-guidance.js +1 -0
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +3 -0
- package/src/preset/generator.js +19 -129
- package/src/preset/generator.js.map +1 -1
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +19 -3
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +2 -2
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +17 -1
- package/src/py/agent/files/http/main.py.template +2 -2
- package/src/py/agent/files/http-langchain/main.py.template +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +35 -2
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +38 -6
- package/src/ts/agent/files/http/router.ts.template +2 -2
- package/src/ts/lib/ts-project-utils.js +0 -7
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +35 -2
- package/src/utils/agent-chat/files/http-py/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +24 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +5 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +12 -1
- package/src/utils/base-tsconfig.d.ts +30 -0
- package/src/utils/base-tsconfig.js +32 -0
- package/src/utils/base-tsconfig.js.map +1 -0
- package/src/utils/commands.d.ts +9 -2
- package/src/utils/commands.js +19 -9
- package/src/utils/commands.js.map +1 -1
- package/src/utils/init.d.ts +53 -0
- package/src/utils/init.js +251 -0
- package/src/utils/init.js.map +1 -0
|
@@ -444,7 +444,7 @@ class TrpcWebSocketAdapter implements ChatAdapter {
|
|
|
444
444
|
const stream = new ReadableStream<string>({
|
|
445
445
|
start: (controller) => {
|
|
446
446
|
this.client.invoke.subscribe(
|
|
447
|
-
{
|
|
447
|
+
{ prompt: text },
|
|
448
448
|
{
|
|
449
449
|
onData: (chunk: string) => controller.enqueue(chunk),
|
|
450
450
|
onComplete: () => controller.close(),
|
|
@@ -546,7 +546,7 @@ class TrpcWebSocketAdapter implements ChatAdapter {
|
|
|
546
546
|
const stream = new ReadableStream<string>({
|
|
547
547
|
start: (controller) => {
|
|
548
548
|
this.client.invoke.subscribe(
|
|
549
|
-
{
|
|
549
|
+
{ prompt: text },
|
|
550
550
|
{
|
|
551
551
|
onData: (chunk: string) => controller.enqueue(chunk),
|
|
552
552
|
onComplete: () => controller.close(),
|
|
@@ -585,7 +585,7 @@ CMD [ "node", "--require", "@aws/aws-distro-opentelemetry-node-autoinstrumentati
|
|
|
585
585
|
`;
|
|
586
586
|
|
|
587
587
|
exports[`ts#agent generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > agent-construct.ts 1`] = `
|
|
588
|
-
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
588
|
+
"import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
589
589
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
590
590
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
591
591
|
import { Construct } from 'constructs';
|
|
@@ -686,6 +686,22 @@ export class SnapshotBedrockAgent
|
|
|
686
686
|
return this.agentCoreRuntime.connections;
|
|
687
687
|
}
|
|
688
688
|
|
|
689
|
+
/**
|
|
690
|
+
* The HTTPS invocation URL of the runtime.
|
|
691
|
+
*/
|
|
692
|
+
public get invocationUrl(): string {
|
|
693
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
694
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
695
|
+
const encodedArn = Fn.join(
|
|
696
|
+
'%2F',
|
|
697
|
+
Fn.split(
|
|
698
|
+
'/',
|
|
699
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
700
|
+
),
|
|
701
|
+
);
|
|
702
|
+
return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
|
|
703
|
+
}
|
|
704
|
+
|
|
689
705
|
/**
|
|
690
706
|
* Grants IAM permissions to invoke this agent runtime.
|
|
691
707
|
*
|
|
@@ -835,6 +851,11 @@ output "agent_core_runtime_arn" {
|
|
|
835
851
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
836
852
|
}
|
|
837
853
|
|
|
854
|
+
output "invocation_url" {
|
|
855
|
+
description = "HTTPS invocation URL of the runtime"
|
|
856
|
+
value = module.agent_core_runtime.invocation_url
|
|
857
|
+
}
|
|
858
|
+
|
|
838
859
|
output "appconfig_application_id" {
|
|
839
860
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
840
861
|
value = var.appconfig_application_id
|
|
@@ -1308,6 +1329,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
1308
1329
|
}
|
|
1309
1330
|
|
|
1310
1331
|
# Outputs
|
|
1332
|
+
locals {
|
|
1333
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
1334
|
+
# wait until the runtime serves MCP.
|
|
1335
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1311
1338
|
output "agent_core_runtime_role_arn" {
|
|
1312
1339
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
1313
1340
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -1325,7 +1352,12 @@ output "agent_runtime_name" {
|
|
|
1325
1352
|
|
|
1326
1353
|
output "agent_core_runtime_arn" {
|
|
1327
1354
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
1328
|
-
value =
|
|
1355
|
+
value = local.ready_runtime_arn
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
output "invocation_url" {
|
|
1359
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
1360
|
+
value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
1329
1361
|
}
|
|
1330
1362
|
|
|
1331
1363
|
output "agent_runtime_id" {
|
|
@@ -1661,7 +1693,7 @@ const agent = withSessionId(getAgent);
|
|
|
1661
1693
|
|
|
1662
1694
|
export const appRouter = router({
|
|
1663
1695
|
invoke: publicProcedure
|
|
1664
|
-
.input(z.object({
|
|
1696
|
+
.input(z.object({ prompt: z.string().max(100000) }))
|
|
1665
1697
|
.output(
|
|
1666
1698
|
zAsyncIterable({
|
|
1667
1699
|
yield: z.string(),
|
|
@@ -1671,7 +1703,7 @@ export const appRouter = router({
|
|
|
1671
1703
|
.subscription(async function* (opts) {
|
|
1672
1704
|
// Bind the session ID for this subscription so downstream MCP / A2A clients forward it on outbound calls.
|
|
1673
1705
|
enterSessionContext(opts.ctx.sessionId);
|
|
1674
|
-
for await (const event of agent.stream(opts.input.
|
|
1706
|
+
for await (const event of agent.stream(opts.input.prompt)) {
|
|
1675
1707
|
if (
|
|
1676
1708
|
event.type === 'modelStreamUpdateEvent' &&
|
|
1677
1709
|
event.event.type === 'modelContentBlockDeltaEvent' &&
|
|
@@ -10,7 +10,7 @@ const agent = withSessionId(getAgent);
|
|
|
10
10
|
|
|
11
11
|
export const appRouter = router({
|
|
12
12
|
invoke: publicProcedure
|
|
13
|
-
.input(z.object({
|
|
13
|
+
.input(z.object({ prompt: z.string().max(100000) }))
|
|
14
14
|
.output(
|
|
15
15
|
zAsyncIterable({
|
|
16
16
|
yield: z.string(),
|
|
@@ -20,7 +20,7 @@ export const appRouter = router({
|
|
|
20
20
|
.subscription(async function* (opts) {
|
|
21
21
|
// Bind the session ID for this subscription so downstream MCP / A2A clients forward it on outbound calls.
|
|
22
22
|
enterSessionContext(opts.ctx.sessionId);
|
|
23
|
-
for await (const event of agent.stream(opts.input.
|
|
23
|
+
for await (const event of agent.stream(opts.input.prompt)) {
|
|
24
24
|
if (
|
|
25
25
|
event.type === 'modelStreamUpdateEvent' &&
|
|
26
26
|
event.event.type === 'modelContentBlockDeltaEvent' &&
|
|
@@ -92,13 +92,6 @@ import { configureVitest } from "./vitest.js";
|
|
|
92
92
|
])
|
|
93
93
|
}));
|
|
94
94
|
}
|
|
95
|
-
// Update the root package.json. ESM projects require `type: module`; for
|
|
96
|
-
// CommonJS we write an explicit `type: commonjs` marker (which Node treats
|
|
97
|
-
// identically to an absent `type`).
|
|
98
|
-
updateJson(tree, 'package.json', (packageJson)=>({
|
|
99
|
-
...packageJson,
|
|
100
|
-
type: esm ? 'module' : 'commonjs'
|
|
101
|
-
}));
|
|
102
95
|
// Remove package.json if it exists
|
|
103
96
|
if (tree.exists(join(options.dir, 'package.json'))) {
|
|
104
97
|
tree.delete(join(options.dir, 'package.json'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/ts-project-utils.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, type Tree, updateJson } from '@nx/devkit';\nimport { join, relative } from 'path';\nimport { addLicenseCheckToLintTarget } from '../../license/config';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { toScopeAlias } from '../../utils/npm-scope';\nimport { configureBiomeLint } from './biome';\nimport type { ConfigureProjectOptions } from './types';\nimport { configureVitest } from './vitest';\n\ninterface TsConfigReference {\n path: string;\n}\n\n/**\n * Merges new TypeScript project references into existing ones, deduplicating by\n * path and preserving the order of existing references so re-running a\n * generator neither duplicates nor reorders references.\n */\nexport const mergeTsReferences = (\n existing: TsConfigReference[] | undefined,\n toAdd: TsConfigReference[],\n): TsConfigReference[] => {\n const references = [...(existing ?? [])];\n const existingPaths = new Set(references.map((ref) => ref.path));\n for (const ref of toAdd) {\n if (!existingPaths.has(ref.path)) {\n references.push(ref);\n existingPaths.add(ref.path);\n }\n }\n return references;\n};\n\n/**\n * Updates typescript projects\n */\nexport const configureTsProject = async (\n tree: Tree,\n options: ConfigureProjectOptions,\n) => {\n // When the caller doesn't specify a module format, infer it from the\n // workspace root package.json (defaulting to ESM for a fresh workspace).\n const esm = options.esm ?? isEsmWorkspace(tree);\n\n // Remove a conflicting `module: commonjs` from the project tsconfig.json\n // (CommonJS is configured on tsconfig.lib.json below when needed).\n updateJson(tree, join(options.dir, 'tsconfig.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n module:\n tsConfig.compilerOptions?.module === 'commonjs'\n ? undefined\n : tsConfig.compilerOptions?.module,\n },\n }));\n const outDirToRootRelativePath = relative(\n join(tree.root, options.dir),\n tree.root,\n );\n const distDir = join(outDirToRootRelativePath, 'dist', options.dir, 'tsc');\n // Remove baseUrl and rootDir from the tsconfig.lib.json\n if (tree.exists(join(options.dir, 'tsconfig.lib.json'))) {\n updateJson(tree, join(options.dir, 'tsconfig.lib.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n baseUrl: undefined,\n rootDir: '.',\n outDir: distDir,\n tsBuildInfoFile: join(distDir, 'tsconfig.lib.tsbuildinfo'),\n // @nx/js configures the lib for ESM (module `nodenext`). CommonJS\n // projects use `node16`, which honours the workspace's\n // `type: commonjs`, emits CommonJS and resolves extensionless relative\n // imports. (Plain `commonjs`/`node` is deprecated in TypeScript 6.)\n ...(esm ? {} : { module: 'node16', moduleResolution: 'node16' }),\n },\n }));\n }\n // Update root project tsconfig\n updateJson(tree, 'tsconfig.base.json', (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n // baseUrl is deprecated in TypeScript 6 — use ./ prefix in paths instead\n baseUrl: undefined,\n rootDir: '.',\n paths: {\n // Remove any path aliases for this project with the npm scope prefix (eg remove @foo/bar)\n ...Object.fromEntries(\n Object.entries(tsConfig.compilerOptions?.paths ?? {}).filter(\n ([k]) => k !== options.fullyQualifiedName,\n ),\n ),\n // Add aliases which begin with colon (eg :foo/bar) to avoid sniping attacks\n [toScopeAlias(options.fullyQualifiedName)]: [\n `./${joinPathFragments(options.dir, 'src', 'index.ts')}`,\n ],\n },\n },\n }));\n if (tree.exists('tsconfig.json')) {\n updateJson(tree, 'tsconfig.json', (tsConfig) => ({\n ...tsConfig,\n // Add project references, deduplicating and preserving existing order\n references: mergeTsReferences(tsConfig.references, [\n { path: `./${options.dir}` },\n ]),\n }));\n }\n //
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/ts-project-utils.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, type Tree, updateJson } from '@nx/devkit';\nimport { join, relative } from 'path';\nimport { addLicenseCheckToLintTarget } from '../../license/config';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { toScopeAlias } from '../../utils/npm-scope';\nimport { configureBiomeLint } from './biome';\nimport type { ConfigureProjectOptions } from './types';\nimport { configureVitest } from './vitest';\n\ninterface TsConfigReference {\n path: string;\n}\n\n/**\n * Merges new TypeScript project references into existing ones, deduplicating by\n * path and preserving the order of existing references so re-running a\n * generator neither duplicates nor reorders references.\n */\nexport const mergeTsReferences = (\n existing: TsConfigReference[] | undefined,\n toAdd: TsConfigReference[],\n): TsConfigReference[] => {\n const references = [...(existing ?? [])];\n const existingPaths = new Set(references.map((ref) => ref.path));\n for (const ref of toAdd) {\n if (!existingPaths.has(ref.path)) {\n references.push(ref);\n existingPaths.add(ref.path);\n }\n }\n return references;\n};\n\n/**\n * Updates typescript projects\n */\nexport const configureTsProject = async (\n tree: Tree,\n options: ConfigureProjectOptions,\n) => {\n // When the caller doesn't specify a module format, infer it from the\n // workspace root package.json (defaulting to ESM for a fresh workspace).\n const esm = options.esm ?? isEsmWorkspace(tree);\n\n // Remove a conflicting `module: commonjs` from the project tsconfig.json\n // (CommonJS is configured on tsconfig.lib.json below when needed).\n updateJson(tree, join(options.dir, 'tsconfig.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n module:\n tsConfig.compilerOptions?.module === 'commonjs'\n ? undefined\n : tsConfig.compilerOptions?.module,\n },\n }));\n const outDirToRootRelativePath = relative(\n join(tree.root, options.dir),\n tree.root,\n );\n const distDir = join(outDirToRootRelativePath, 'dist', options.dir, 'tsc');\n // Remove baseUrl and rootDir from the tsconfig.lib.json\n if (tree.exists(join(options.dir, 'tsconfig.lib.json'))) {\n updateJson(tree, join(options.dir, 'tsconfig.lib.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n baseUrl: undefined,\n rootDir: '.',\n outDir: distDir,\n tsBuildInfoFile: join(distDir, 'tsconfig.lib.tsbuildinfo'),\n // @nx/js configures the lib for ESM (module `nodenext`). CommonJS\n // projects use `node16`, which honours the workspace's\n // `type: commonjs`, emits CommonJS and resolves extensionless relative\n // imports. (Plain `commonjs`/`node` is deprecated in TypeScript 6.)\n ...(esm ? {} : { module: 'node16', moduleResolution: 'node16' }),\n },\n }));\n }\n // Update root project tsconfig\n updateJson(tree, 'tsconfig.base.json', (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n // baseUrl is deprecated in TypeScript 6 — use ./ prefix in paths instead\n baseUrl: undefined,\n rootDir: '.',\n paths: {\n // Remove any path aliases for this project with the npm scope prefix (eg remove @foo/bar)\n ...Object.fromEntries(\n Object.entries(tsConfig.compilerOptions?.paths ?? {}).filter(\n ([k]) => k !== options.fullyQualifiedName,\n ),\n ),\n // Add aliases which begin with colon (eg :foo/bar) to avoid sniping attacks\n [toScopeAlias(options.fullyQualifiedName)]: [\n `./${joinPathFragments(options.dir, 'src', 'index.ts')}`,\n ],\n },\n },\n }));\n if (tree.exists('tsconfig.json')) {\n updateJson(tree, 'tsconfig.json', (tsConfig) => ({\n ...tsConfig,\n // Add project references, deduplicating and preserving existing order\n references: mergeTsReferences(tsConfig.references, [\n { path: `./${options.dir}` },\n ]),\n }));\n }\n // Remove package.json if it exists\n if (tree.exists(join(options.dir, 'package.json'))) {\n tree.delete(join(options.dir, 'package.json'));\n }\n\n await configureBiomeLint(tree, options);\n await configureVitest(tree, options);\n\n // If license checking is configured, make this project's lint target depend\n // on the root license-check target. No-op if there's no license-check target\n // (i.e. the license generator hasn't run); the license generator wires up\n // existing projects itself, so this works regardless of generator order.\n addLicenseCheckToLintTarget(tree, options.fullyQualifiedName);\n};\n"],"names":["joinPathFragments","updateJson","join","relative","addLicenseCheckToLintTarget","isEsmWorkspace","toScopeAlias","configureBiomeLint","configureVitest","mergeTsReferences","existing","toAdd","references","existingPaths","Set","map","ref","path","has","push","add","configureTsProject","tree","options","esm","dir","tsConfig","compilerOptions","module","undefined","outDirToRootRelativePath","root","distDir","exists","baseUrl","rootDir","outDir","tsBuildInfoFile","moduleResolution","paths","Object","fromEntries","entries","filter","k","fullyQualifiedName","delete"],"mappings":"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"}
|
|
@@ -14,7 +14,7 @@ export * from './workspace.js';
|
|
|
14
14
|
`;
|
|
15
15
|
|
|
16
16
|
exports[`ts#mcp-server generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > mcp-server-construct.ts 1`] = `
|
|
17
|
-
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
17
|
+
"import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
18
18
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
19
19
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
20
20
|
import { Construct } from 'constructs';
|
|
@@ -102,6 +102,23 @@ export class SnapshotBedrockServer
|
|
|
102
102
|
return this.agentCoreRuntime.connections;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The MCP endpoint URL of the runtime, e.g. for use as a Gateway target
|
|
107
|
+
* endpoint.
|
|
108
|
+
*/
|
|
109
|
+
public get invocationUrl(): string {
|
|
110
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
111
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
112
|
+
const encodedArn = Fn.join(
|
|
113
|
+
'%2F',
|
|
114
|
+
Fn.split(
|
|
115
|
+
'/',
|
|
116
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
|
|
120
|
+
}
|
|
121
|
+
|
|
105
122
|
/**
|
|
106
123
|
* Grants IAM permissions to invoke this agent runtime.
|
|
107
124
|
*
|
|
@@ -589,6 +606,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
589
606
|
}
|
|
590
607
|
|
|
591
608
|
# Outputs
|
|
609
|
+
locals {
|
|
610
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
611
|
+
# wait until the runtime serves MCP.
|
|
612
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
613
|
+
}
|
|
614
|
+
|
|
592
615
|
output "agent_core_runtime_role_arn" {
|
|
593
616
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
594
617
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -606,7 +629,12 @@ output "agent_runtime_name" {
|
|
|
606
629
|
|
|
607
630
|
output "agent_core_runtime_arn" {
|
|
608
631
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
609
|
-
value =
|
|
632
|
+
value = local.ready_runtime_arn
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
output "invocation_url" {
|
|
636
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
637
|
+
value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
610
638
|
}
|
|
611
639
|
|
|
612
640
|
output "agent_runtime_id" {
|
|
@@ -724,6 +752,11 @@ output "agent_core_runtime_arn" {
|
|
|
724
752
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
725
753
|
}
|
|
726
754
|
|
|
755
|
+
output "invocation_url" {
|
|
756
|
+
description = "HTTPS invocation URL of the runtime (the MCP endpoint, e.g. for use as a Gateway target endpoint)"
|
|
757
|
+
value = module.agent_core_runtime.invocation_url
|
|
758
|
+
}
|
|
759
|
+
|
|
727
760
|
output "appconfig_application_id" {
|
|
728
761
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
729
762
|
value = var.appconfig_application_id
|
|
@@ -34,7 +34,7 @@ class <%- agentNameClassName %>Adapter implements ChatAdapter {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
async *sendMessage(text: string): AsyncIterable<string> {
|
|
37
|
-
for await (const chunk of this.client.invoke({
|
|
37
|
+
for await (const chunk of this.client.invoke({ prompt: text })) {
|
|
38
38
|
if (typeof chunk.content === 'string') yield chunk.content;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -37,7 +37,7 @@ class TrpcWebSocketAdapter implements ChatAdapter {
|
|
|
37
37
|
const stream = new ReadableStream<string>({
|
|
38
38
|
start: (controller) => {
|
|
39
39
|
this.client.invoke.subscribe(
|
|
40
|
-
{
|
|
40
|
+
{ prompt: text },
|
|
41
41
|
{
|
|
42
42
|
onData: (chunk: string) => controller.enqueue(chunk),
|
|
43
43
|
onComplete: () => controller.close(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lazy, Names } from 'aws-cdk-lib';
|
|
1
|
+
import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
2
2
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
3
3
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
4
4
|
import { Construct } from 'constructs';
|
|
@@ -136,6 +136,29 @@ export class <%- nameClassName %> extends Construct implements IGrantable, IConn
|
|
|
136
136
|
public get connections(): Connections {
|
|
137
137
|
return this.agentCoreRuntime.connections;
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
<%_ if (serverProtocol === 'mcp') { _%>
|
|
142
|
+
* The MCP endpoint URL of the runtime, e.g. for use as a Gateway target
|
|
143
|
+
* endpoint.
|
|
144
|
+
<%_ } else if (serverProtocol === 'a2a') { _%>
|
|
145
|
+
* The A2A endpoint URL of the runtime (the trailing slash is required).
|
|
146
|
+
<%_ } else { _%>
|
|
147
|
+
* The HTTPS invocation URL of the runtime.
|
|
148
|
+
<%_ } _%>
|
|
149
|
+
*/
|
|
150
|
+
public get invocationUrl(): string {
|
|
151
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
152
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
153
|
+
const encodedArn = Fn.join(
|
|
154
|
+
'%2F',
|
|
155
|
+
Fn.split(
|
|
156
|
+
'/',
|
|
157
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
return `https://bedrock-agentcore.${Stack.of(this).region}.amazonaws.com/runtimes/${encodedArn}/invocations<%- serverProtocol === 'a2a' ? '/' : '?qualifier=DEFAULT' %>`;
|
|
161
|
+
}
|
|
139
162
|
<%_ if (auth === 'iam') { _%>
|
|
140
163
|
|
|
141
164
|
/**
|
|
@@ -133,6 +133,11 @@ output "agent_core_runtime_arn" {
|
|
|
133
133
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
output "invocation_url" {
|
|
137
|
+
description = "HTTPS invocation URL of the runtime<% if (serverProtocol === 'mcp') { %> (the MCP endpoint, e.g. for use as a Gateway target endpoint)<% } else if (serverProtocol === 'a2a') { %> (the A2A endpoint)<% } %>"
|
|
138
|
+
value = module.agent_core_runtime.invocation_url
|
|
139
|
+
}
|
|
140
|
+
|
|
136
141
|
output "appconfig_application_id" {
|
|
137
142
|
description = "AppConfig Application ID for runtime config (passthrough of the shared `appconfig_application_id` input)."
|
|
138
143
|
value = var.appconfig_application_id
|
|
@@ -458,6 +458,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
# Outputs
|
|
461
|
+
locals {
|
|
462
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
463
|
+
# wait until the runtime serves MCP.
|
|
464
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
465
|
+
}
|
|
466
|
+
|
|
461
467
|
output "agent_core_runtime_role_arn" {
|
|
462
468
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
463
469
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -475,7 +481,12 @@ output "agent_runtime_name" {
|
|
|
475
481
|
|
|
476
482
|
output "agent_core_runtime_arn" {
|
|
477
483
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
478
|
-
value =
|
|
484
|
+
value = local.ready_runtime_arn
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
output "invocation_url" {
|
|
488
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
489
|
+
value = "https://bedrock-agentcore.${local.aws_region}.amazonaws.com/runtimes/${urlencode(local.ready_runtime_arn)}/invocations${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
479
490
|
}
|
|
480
491
|
|
|
481
492
|
output "agent_runtime_id" {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The `tsconfig.base.json` compiler options the plugin's TypeScript projects
|
|
7
|
+
* rely on (project references, ESM, emit-less typecheck). Mirrors what
|
|
8
|
+
* `@nx/js` `initGenerator` produces for a fresh TS-solution workspace.
|
|
9
|
+
*
|
|
10
|
+
* Kept dependency-free so the docs site can import it directly and render the
|
|
11
|
+
* options without them drifting from what the generator writes.
|
|
12
|
+
*/
|
|
13
|
+
export declare const BASE_TSCONFIG_COMPILER_OPTIONS: {
|
|
14
|
+
composite: boolean;
|
|
15
|
+
declarationMap: boolean;
|
|
16
|
+
emitDeclarationOnly: boolean;
|
|
17
|
+
importHelpers: boolean;
|
|
18
|
+
isolatedModules: boolean;
|
|
19
|
+
lib: string[];
|
|
20
|
+
module: string;
|
|
21
|
+
moduleResolution: string;
|
|
22
|
+
noEmitOnError: boolean;
|
|
23
|
+
noFallthroughCasesInSwitch: boolean;
|
|
24
|
+
noImplicitOverride: boolean;
|
|
25
|
+
noImplicitReturns: boolean;
|
|
26
|
+
noUnusedLocals: boolean;
|
|
27
|
+
skipLibCheck: boolean;
|
|
28
|
+
strict: boolean;
|
|
29
|
+
target: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ /**
|
|
5
|
+
* The `tsconfig.base.json` compiler options the plugin's TypeScript projects
|
|
6
|
+
* rely on (project references, ESM, emit-less typecheck). Mirrors what
|
|
7
|
+
* `@nx/js` `initGenerator` produces for a fresh TS-solution workspace.
|
|
8
|
+
*
|
|
9
|
+
* Kept dependency-free so the docs site can import it directly and render the
|
|
10
|
+
* options without them drifting from what the generator writes.
|
|
11
|
+
*/ export const BASE_TSCONFIG_COMPILER_OPTIONS = {
|
|
12
|
+
composite: true,
|
|
13
|
+
declarationMap: true,
|
|
14
|
+
emitDeclarationOnly: true,
|
|
15
|
+
importHelpers: true,
|
|
16
|
+
isolatedModules: true,
|
|
17
|
+
lib: [
|
|
18
|
+
'es2022'
|
|
19
|
+
],
|
|
20
|
+
module: 'nodenext',
|
|
21
|
+
moduleResolution: 'nodenext',
|
|
22
|
+
noEmitOnError: true,
|
|
23
|
+
noFallthroughCasesInSwitch: true,
|
|
24
|
+
noImplicitOverride: true,
|
|
25
|
+
noImplicitReturns: true,
|
|
26
|
+
noUnusedLocals: true,
|
|
27
|
+
skipLibCheck: true,
|
|
28
|
+
strict: true,
|
|
29
|
+
target: 'es2022'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=base-tsconfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/base-tsconfig.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * The `tsconfig.base.json` compiler options the plugin's TypeScript projects\n * rely on (project references, ESM, emit-less typecheck). Mirrors what\n * `@nx/js` `initGenerator` produces for a fresh TS-solution workspace.\n *\n * Kept dependency-free so the docs site can import it directly and render the\n * options without them drifting from what the generator writes.\n */\nexport const BASE_TSCONFIG_COMPILER_OPTIONS = {\n composite: true,\n declarationMap: true,\n emitDeclarationOnly: true,\n importHelpers: true,\n isolatedModules: true,\n lib: ['es2022'],\n module: 'nodenext',\n moduleResolution: 'nodenext',\n noEmitOnError: true,\n noFallthroughCasesInSwitch: true,\n noImplicitOverride: true,\n noImplicitReturns: true,\n noUnusedLocals: true,\n skipLibCheck: true,\n strict: true,\n target: 'es2022',\n};\n"],"names":["BASE_TSCONFIG_COMPILER_OPTIONS","composite","declarationMap","emitDeclarationOnly","importHelpers","isolatedModules","lib","module","moduleResolution","noEmitOnError","noFallthroughCasesInSwitch","noImplicitOverride","noImplicitReturns","noUnusedLocals","skipLibCheck","strict","target"],"mappings":"AAAA;;;CAGC,GAED;;;;;;;CAOC,GACD,OAAO,MAAMA,iCAAiC;IAC5CC,WAAW;IACXC,gBAAgB;IAChBC,qBAAqB;IACrBC,eAAe;IACfC,iBAAiB;IACjBC,KAAK;QAAC;KAAS;IACfC,QAAQ;IACRC,kBAAkB;IAClBC,eAAe;IACfC,4BAA4B;IAC5BC,oBAAoB;IACpBC,mBAAmB;IACnBC,gBAAgB;IAChBC,cAAc;IACdC,QAAQ;IACRC,QAAQ;AACV,EAAE"}
|
package/src/utils/commands.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* The nx version the plugin is built against. Commands that download nx
|
|
3
|
+
* (e.g. `nx init`) pin to this version so the workspace's nx matches the
|
|
4
|
+
* plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.
|
|
4
5
|
*/
|
|
6
|
+
export declare const NX_VERSION: "23.0.2";
|
|
5
7
|
/**
|
|
6
8
|
* Display-friendly command prefixes for each package manager.
|
|
7
9
|
*
|
|
@@ -32,6 +34,11 @@ export declare const buildPackageManagerShortCommand: (pm: string, command: stri
|
|
|
32
34
|
* Build an install command for a given package manager
|
|
33
35
|
*/
|
|
34
36
|
export declare const buildInstallCommand: (pm: string, pkg: string, dev: boolean) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Build the command that adds Nx to a non-Nx project, pinned to the nx
|
|
39
|
+
* version the plugin is built against.
|
|
40
|
+
*/
|
|
41
|
+
export declare const buildNxInitCommand: (pm: string) => string;
|
|
35
42
|
/**
|
|
36
43
|
* Build a command to create a new workspace using @aws/create-nx-workspace.
|
|
37
44
|
*
|
package/src/utils/commands.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @see docs/src/components/package-manager-short-command.astro
|
|
12
|
-
*/ export const PACKAGE_MANAGER_COMMANDS = {
|
|
4
|
+
*/ import { TS_VERSIONS } from "./versions.js";
|
|
5
|
+
/**
|
|
6
|
+
* The nx version the plugin is built against. Commands that download nx
|
|
7
|
+
* (e.g. `nx init`) pin to this version so the workspace's nx matches the
|
|
8
|
+
* plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.
|
|
9
|
+
*/ export const NX_VERSION = TS_VERSIONS['@nx/devkit'];
|
|
10
|
+
export const PACKAGE_MANAGER_COMMANDS = {
|
|
13
11
|
npm: {
|
|
14
12
|
exec: 'npx',
|
|
15
13
|
run: 'npm run',
|
|
@@ -59,6 +57,18 @@
|
|
|
59
57
|
return `${pm} install ${dev ? '-D ' : ''}${pkg}`;
|
|
60
58
|
}
|
|
61
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Build the command that adds Nx to a non-Nx project, pinned to the nx
|
|
62
|
+
* version the plugin is built against.
|
|
63
|
+
*/ export const buildNxInitCommand = (pm)=>{
|
|
64
|
+
const dlxPrefix = {
|
|
65
|
+
npm: 'npx',
|
|
66
|
+
pnpm: 'pnpm dlx',
|
|
67
|
+
yarn: 'yarn dlx',
|
|
68
|
+
bun: 'bunx'
|
|
69
|
+
}[pm] ?? 'npx';
|
|
70
|
+
return `${dlxPrefix} nx@${NX_VERSION} init`;
|
|
71
|
+
};
|
|
62
72
|
/**
|
|
63
73
|
* Build a command to create a new workspace using @aws/create-nx-workspace.
|
|
64
74
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command for a given package manager\n */\nexport const buildInstallCommand = (pm: string, pkg: string, dev: boolean) => {\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun install ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n module?: 'esm' | 'cjs',\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ...(module ? [`--module=${module}`] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","buildCreateNxWorkspaceCommand","workspace","iac","tag","module","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { TS_VERSIONS } from './versions';\n\n/**\n * The nx version the plugin is built against. Commands that download nx\n * (e.g. `nx init`) pin to this version so the workspace's nx matches the\n * plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.\n */\nexport const NX_VERSION = TS_VERSIONS['@nx/devkit'];\n\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command for a given package manager\n */\nexport const buildInstallCommand = (pm: string, pkg: string, dev: boolean) => {\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun install ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build the command that adds Nx to a non-Nx project, pinned to the nx\n * version the plugin is built against.\n */\nexport const buildNxInitCommand = (pm: string) => {\n const dlxPrefix =\n { npm: 'npx', pnpm: 'pnpm dlx', yarn: 'yarn dlx', bun: 'bunx' }[pm] ??\n 'npx';\n return `${dlxPrefix} nx@${NX_VERSION} init`;\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n module?: 'esm' | 'cjs',\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ...(module ? [`--module=${module}`] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["TS_VERSIONS","NX_VERSION","PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","buildNxInitCommand","dlxPrefix","buildCreateNxWorkspaceCommand","workspace","iac","tag","module","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD,SAASA,WAAW,QAAQ,gBAAa;AAEzC;;;;CAIC,GACD,OAAO,MAAMC,aAAaD,WAAW,CAAC,aAAa,CAAC;AAoBpD,OAAO,MAAME,2BAGT;IACFC,KAAK;QAAEC,MAAM;QAAOC,KAAK;QAAWC,QAAQ;IAAa;IACzDC,MAAM;QAAEH,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDE,MAAM;QAAEJ,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDG,KAAK;QAAEL,MAAM;QAAQC,KAAK;QAAOC,QAAQ;IAAa;AACxD,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMI,iCAAiC,CAACC,IAAYC;IACzD,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEP,QAAQO;IACrD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAME,kCAAkC,CAC7CH,IACAC;IAEA,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEN,OAAOM;IACpD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMG,sBAAsB,CAACJ,IAAYK,KAAaC;IAC3D,OAAQN;QACN,KAAK;YACH,OAAO,CAAC,SAAS,EAAEM,MAAM,OAAO,IAAI,EAAE,EAAED,KAAK;QAC/C,KAAK;YACH,OAAO,CAAC,SAAS,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QAC7C,KAAK;YACH,OAAO,CAAC,+BAA+B,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QACnE,KAAK;YACH,OAAO,CAAC,YAAY,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QAChD;YACE,OAAO,GAAGL,GAAG,SAAS,EAAEM,MAAM,QAAQ,KAAKD,KAAK;IACpD;AACF,EAAE;AAEF;;;CAGC,GACD,OAAO,MAAME,qBAAqB,CAACP;IACjC,MAAMQ,YACJ;QAAEhB,KAAK;QAAOI,MAAM;QAAYC,MAAM;QAAYC,KAAK;IAAO,CAAC,CAACE,GAAG,IACnE;IACF,OAAO,GAAGQ,UAAU,IAAI,EAAElB,WAAW,KAAK,CAAC;AAC7C,EAAE;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAMmB,gCAAgC,CAC3CT,IACAU,WACAC,KACAC,KACAC;IAEA,MAAMC,eAAevB,wBAAwB,CAACS,GAAG,EAAEL,UAAU,GAAGK,GAAG,OAAO,CAAC;IAC3E,MAAMe,UAAUH,MAAM,CAAC,kBAAkB,EAAEA,KAAK,GAAG;IACnD,MAAMI,QAAQ;QACZF;QACAC;QACA,wEAAwE;WACpEf,OAAO,QAAQ;YAAC;SAAK,GAAG,EAAE;QAC9BU;WACIC,MAAM;YAAC,CAAC,MAAM,EAAEA,KAAK;SAAC,GAAG,EAAE;WAC3BE,SAAS;YAAC,CAAC,SAAS,EAAEA,QAAQ;SAAC,GAAG,EAAE;KACzC;IACD,OAAOG,MAAMC,IAAI,CAAC;AACpB,EAAE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { OverwriteStrategy, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type Containers } from './containers';
|
|
7
|
+
import type { Iac } from './iac';
|
|
8
|
+
export declare const PNPM_BUILT_DEPENDENCIES: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Options controlling how the workspace is initialised. These mirror the
|
|
11
|
+
* preset schema so a workspace created via the preset and one initialised via
|
|
12
|
+
* the `init` generator end up in the same shape.
|
|
13
|
+
*/
|
|
14
|
+
export interface ApplyWorkspaceInitOptions {
|
|
15
|
+
/** The IaC provider to record in the plugin config. */
|
|
16
|
+
readonly iac: Iac;
|
|
17
|
+
/**
|
|
18
|
+
* The container engine to record. `undefined`/`'infer'` picks docker when
|
|
19
|
+
* installed, else finch.
|
|
20
|
+
*/
|
|
21
|
+
readonly containers?: Containers | 'infer';
|
|
22
|
+
/** Whether to configure MCP servers for coding agents. Defaults to true. */
|
|
23
|
+
readonly mcp?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* How to treat the generated workspace README. The preset owns the README of
|
|
26
|
+
* a greenfield workspace (`Overwrite`); the `init` generator must not clobber
|
|
27
|
+
* an existing workspace's README (`KeepExisting`, the default).
|
|
28
|
+
*/
|
|
29
|
+
readonly readmeOverwriteStrategy?: OverwriteStrategy;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to overwrite root package.json scripts that already exist. The
|
|
32
|
+
* preset owns a greenfield workspace's scripts (`true`); the `init`
|
|
33
|
+
* generator must not clobber an existing workspace's scripts (`false`,
|
|
34
|
+
* the default) — it only adds the convenience scripts that are absent.
|
|
35
|
+
*/
|
|
36
|
+
readonly overwriteScripts?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Transform an Nx workspace into one ready to run `@aws/nx-plugin` generators.
|
|
40
|
+
*
|
|
41
|
+
* This is the deterministic core shared by the workspace preset and the `init`
|
|
42
|
+
* generator. It is safe to re-run: every step is idempotent (config merges,
|
|
43
|
+
* keyed nx.json / package.json entries, create-if-missing files), so running
|
|
44
|
+
* it against an already-initialised workspace is a no-op.
|
|
45
|
+
*
|
|
46
|
+
* It preserves the workspace's module format: the root package.json `type`
|
|
47
|
+
* field is owned by the preset (written from its `--module` option) and left
|
|
48
|
+
* untouched here. It does NOT rewrite an existing `tsconfig.base.json`'s
|
|
49
|
+
* compiler options, migrate a workspace's package manager, or restructure
|
|
50
|
+
* existing projects — those are decisions for the user (see the "add to an
|
|
51
|
+
* existing workspace" guide).
|
|
52
|
+
*/
|
|
53
|
+
export declare const applyWorkspaceInit: (tree: Tree, { iac, containers, mcp, readmeOverwriteStrategy, overwriteScripts, }: ApplyWorkspaceInitOptions) => Promise<void>;
|