@aws/nx-plugin 0.90.1 → 0.92.0

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 (46) hide show
  1. package/generators.json +8 -0
  2. package/package.json +1 -1
  3. package/src/connection/generator.js +6 -3
  4. package/src/connection/generator.js.map +1 -1
  5. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +14 -7
  6. package/src/py/mcp-server/generator.js +3 -0
  7. package/src/py/mcp-server/generator.js.map +1 -1
  8. package/src/py/mcp-server/schema.d.ts +3 -0
  9. package/src/py/mcp-server/schema.json +8 -0
  10. package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +14 -7
  11. package/src/py/strands-agent/generator.js +3 -0
  12. package/src/py/strands-agent/generator.js.map +1 -1
  13. package/src/py/strands-agent/mcp-connection/generator.js +3 -0
  14. package/src/py/strands-agent/mcp-connection/generator.js.map +1 -1
  15. package/src/py/strands-agent/schema.d.ts +3 -0
  16. package/src/py/strands-agent/schema.json +8 -0
  17. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +14 -7
  18. package/src/ts/mcp-server/generator.js +3 -0
  19. package/src/ts/mcp-server/generator.js.map +1 -1
  20. package/src/ts/mcp-server/schema.d.ts +3 -0
  21. package/src/ts/mcp-server/schema.json +8 -0
  22. package/src/ts/react-website/runtime-config/__snapshots__/generator.spec.ts.snap +3 -1
  23. package/src/ts/react-website/runtime-config/files/app/components/RuntimeConfig/index.tsx.template +1 -1
  24. package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +14 -7
  25. package/src/ts/strands-agent/generator.js +3 -1
  26. package/src/ts/strands-agent/generator.js.map +1 -1
  27. package/src/ts/strands-agent/mcp-connection/generator.js +3 -0
  28. package/src/ts/strands-agent/mcp-connection/generator.js.map +1 -1
  29. package/src/ts/strands-agent/react-connection/__snapshots__/generator.spec.ts.snap +376 -0
  30. package/src/ts/strands-agent/react-connection/files/src/components/__agentNameClassName__AgentClientProvider.tsx.template +117 -0
  31. package/src/ts/strands-agent/react-connection/files/src/hooks/use__agentNameClassName__Agent.tsx.template +18 -0
  32. package/src/ts/strands-agent/react-connection/generator.d.ts +10 -0
  33. package/src/ts/strands-agent/react-connection/generator.js +129 -0
  34. package/src/ts/strands-agent/react-connection/generator.js.map +1 -0
  35. package/src/ts/strands-agent/react-connection/schema.d.ts +15 -0
  36. package/src/ts/strands-agent/react-connection/schema.json +26 -0
  37. package/src/ts/strands-agent/react-connection/serve-local.d.ts +17 -0
  38. package/src/ts/strands-agent/react-connection/serve-local.js +45 -0
  39. package/src/ts/strands-agent/react-connection/serve-local.js.map +1 -0
  40. package/src/ts/strands-agent/schema.d.ts +3 -0
  41. package/src/ts/strands-agent/schema.json +8 -0
  42. package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +4 -0
  43. package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -0
  44. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  45. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +59 -2
  46. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +26 -6
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TS_STRANDS_AGENT_REACT_CONNECTION_GENERATOR_INFO = void 0;
4
+ exports.tsStrandsAgentReactConnectionGenerator = tsStrandsAgentReactConnectionGenerator;
5
+ /**
6
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ * SPDX-License-Identifier: Apache-2.0
8
+ */
9
+ const devkit_1 = require("@nx/devkit");
10
+ const generator_1 = require("../../react-website/runtime-config/generator");
11
+ const npm_scope_1 = require("../../../utils/npm-scope");
12
+ const versions_1 = require("../../../utils/versions");
13
+ const ast_1 = require("../../../utils/ast");
14
+ const names_1 = require("../../../utils/names");
15
+ const format_1 = require("../../../utils/format");
16
+ const nx_1 = require("../../../utils/nx");
17
+ const metrics_1 = require("../../../utils/metrics");
18
+ const serve_local_1 = require("./serve-local");
19
+ exports.TS_STRANDS_AGENT_REACT_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
20
+ async function tsStrandsAgentReactConnectionGenerator(tree, options) {
21
+ const frontendProjectConfig = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
22
+ const agentProjectConfig = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
23
+ const targetComponent = options.targetComponent;
24
+ // Extract agent metadata from the target component or project metadata
25
+ const metadata = agentProjectConfig.metadata;
26
+ const agentName = targetComponent?.name ?? 'agent';
27
+ const agentNameClassName = targetComponent?.rc ?? (0, names_1.toClassName)(agentName);
28
+ const agentPort = targetComponent?.port ?? metadata?.ports?.[0] ?? 8081;
29
+ const auth = targetComponent?.auth ?? metadata?.auth ?? 'IAM';
30
+ const agentProjectAlias = (0, npm_scope_1.toScopeAlias)(agentProjectConfig.name);
31
+ const agentPath = targetComponent?.path ?? 'src/agent';
32
+ // Ensure the agent project has a wildcard path entry in tsconfig.base.json
33
+ // so that deep imports (e.g., for the router type) resolve correctly
34
+ ensureWildcardPathEntry(tree, agentProjectConfig.name, agentProjectConfig.root);
35
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), frontendProjectConfig.root, {
36
+ agentName,
37
+ agentNameClassName,
38
+ auth,
39
+ agentProjectAlias,
40
+ agentPath,
41
+ }, {
42
+ overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
43
+ });
44
+ // Generate the tanstack query provider if it does not exist already
45
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../../../utils/files/website/components/tanstack-query'), (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'components'), {}, {
46
+ overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
47
+ });
48
+ if (auth === 'IAM') {
49
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../../../utils/files/website/hooks/sigv4'), (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'hooks'), {}, {
50
+ overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting,
51
+ });
52
+ }
53
+ await (0, generator_1.runtimeConfigGenerator)(tree, {
54
+ project: frontendProjectConfig.name,
55
+ });
56
+ // update main.tsx
57
+ const mainTsxPath = (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'main.tsx');
58
+ await (0, ast_1.addSingleImport)(tree, mainTsxPath, 'QueryClientProvider', './components/QueryClientProvider');
59
+ const clientProviderName = `${agentNameClassName}AgentClientProvider`;
60
+ await (0, ast_1.addSingleImport)(tree, mainTsxPath, clientProviderName, `./components/${clientProviderName}`);
61
+ // Wrap <App /> in QueryClientProvider if not already present
62
+ if (!(await (0, ast_1.matchGritQL)(tree, mainTsxPath, '`<QueryClientProvider>$_</QueryClientProvider>`'))) {
63
+ await (0, ast_1.applyGritQL)(tree, mainTsxPath, '`<App />` => `<QueryClientProvider><App /></QueryClientProvider>`');
64
+ }
65
+ // Wrap <App /> in the agent client provider if not already present
66
+ if (!(await (0, ast_1.matchGritQL)(tree, mainTsxPath, `\`<${clientProviderName}>$_</${clientProviderName}>\``))) {
67
+ await (0, ast_1.applyGritQL)(tree, mainTsxPath, `\`<App />\` => \`<${clientProviderName}><App /></${clientProviderName}>\``);
68
+ }
69
+ await (0, serve_local_1.addStrandsAgentTargetToServeLocal)(tree, frontendProjectConfig.name, agentProjectConfig.name, {
70
+ agentName,
71
+ agentNameClassName,
72
+ port: agentPort,
73
+ targetComponent,
74
+ });
75
+ (0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
76
+ '@trpc/client',
77
+ '@tanstack/react-query',
78
+ '@tanstack/react-query-devtools',
79
+ '@trpc/tanstack-react-query',
80
+ ...(auth === 'IAM'
81
+ ? [
82
+ 'oidc-client-ts',
83
+ 'aws4fetch',
84
+ '@aws-sdk/credential-providers',
85
+ 'react-oidc-context',
86
+ ]
87
+ : []),
88
+ ...(auth === 'Cognito' ? ['react-oidc-context'] : []),
89
+ ]), (0, versions_1.withVersions)(['@smithy/types']));
90
+ await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
91
+ exports.TS_STRANDS_AGENT_REACT_CONNECTION_GENERATOR_INFO,
92
+ ]);
93
+ await (0, format_1.formatFilesInSubtree)(tree);
94
+ return () => {
95
+ (0, devkit_1.installPackagesTask)(tree);
96
+ };
97
+ }
98
+ exports.default = tsStrandsAgentReactConnectionGenerator;
99
+ /**
100
+ * Ensures a wildcard path entry exists in tsconfig.base.json for the given project,
101
+ * allowing deep imports (e.g., `:scope/project/src/agent/router.js`).
102
+ * Both the scope alias and npm package name forms are added.
103
+ */
104
+ function ensureWildcardPathEntry(tree, projectName, projectRoot) {
105
+ const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json'].find((p) => tree.exists(p));
106
+ if (!tsconfigPath)
107
+ return;
108
+ const wildcardValue = [`./${projectRoot}/*`];
109
+ const scopeAlias = (0, npm_scope_1.toScopeAlias)(projectName);
110
+ (0, devkit_1.updateJson)(tree, tsconfigPath, (json) => {
111
+ const paths = json.compilerOptions?.paths ?? {};
112
+ // Add wildcard for the scope alias (used by generated templates)
113
+ const scopeWildcardKey = `${scopeAlias}/*`;
114
+ if (!paths[scopeWildcardKey]) {
115
+ paths[scopeWildcardKey] = wildcardValue;
116
+ }
117
+ // Also add wildcard for the npm package name
118
+ const npmWildcardKey = `${projectName}/*`;
119
+ if (!paths[npmWildcardKey]) {
120
+ paths[npmWildcardKey] = wildcardValue;
121
+ }
122
+ json.compilerOptions = {
123
+ ...json.compilerOptions,
124
+ paths,
125
+ };
126
+ return json;
127
+ });
128
+ }
129
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/str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'../../../utils/nx';
6
+
7
+ /**
8
+ * TypeScript types for options defined in schema.json
9
+ */
10
+ export interface TsStrandsAgentReactConnectionGeneratorSchema {
11
+ sourceProject: string;
12
+ targetProject: string;
13
+ sourceComponent?: ComponentMetadata;
14
+ targetComponent?: ComponentMetadata;
15
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "ts#strands-agent#react-connection",
4
+ "title": "ts#strands-agent#react-connection",
5
+ "description": "Connect a React website to a TypeScript Strands Agent",
6
+ "type": "object",
7
+ "properties": {
8
+ "sourceProject": {
9
+ "type": "string",
10
+ "description": "The React website project"
11
+ },
12
+ "targetProject": {
13
+ "type": "string",
14
+ "description": "The project containing the Strands Agent"
15
+ },
16
+ "sourceComponent": {
17
+ "type": "string",
18
+ "description": "The source component name"
19
+ },
20
+ "targetComponent": {
21
+ "type": "string",
22
+ "description": "The Strands Agent component name"
23
+ }
24
+ },
25
+ "required": ["sourceProject", "targetProject"]
26
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { Tree } from '@nx/devkit';
6
+ import { ComponentMetadata } from '../../../utils/nx';
7
+ export interface StrandsAgentServeLocalOptions {
8
+ agentName: string;
9
+ agentNameClassName: string;
10
+ port: number;
11
+ targetComponent?: ComponentMetadata;
12
+ }
13
+ /**
14
+ * Adds the given strands agent target project to the source project's serve-local target
15
+ * Updates the runtime config provider (if it exists) to point to the local WebSocket URL
16
+ */
17
+ export declare const addStrandsAgentTargetToServeLocal: (tree: Tree, sourceProjectName: string, targetProjectName: string, options: StrandsAgentServeLocalOptions) => Promise<void>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addStrandsAgentTargetToServeLocal = void 0;
4
+ /**
5
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ const devkit_1 = require("@nx/devkit");
9
+ const ast_1 = require("../../../utils/ast");
10
+ const nx_1 = require("../../../utils/nx");
11
+ /**
12
+ * Adds the given strands agent target project to the source project's serve-local target
13
+ * Updates the runtime config provider (if it exists) to point to the local WebSocket URL
14
+ */
15
+ const addStrandsAgentTargetToServeLocal = async (tree, sourceProjectName, targetProjectName, options) => {
16
+ const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, sourceProjectName);
17
+ const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, targetProjectName);
18
+ // Determine the serve-local target name for the agent component
19
+ const agentServeLocalTargetName = options.targetComponent?.name
20
+ ? `${options.targetComponent.name}-serve-local`
21
+ : 'agent-serve-local';
22
+ // Target project must have the agent serve-local target which is continuous
23
+ if (!(targetProject.targets?.[agentServeLocalTargetName]?.continuous &&
24
+ sourceProject.targets?.['serve-local'])) {
25
+ return;
26
+ }
27
+ // Add a dependency on the agent serve-local target (so that the agent's
28
+ // own serve-local dependencies, such as MCP servers, are also started)
29
+ sourceProject.targets['serve-local'].dependsOn = [
30
+ ...(sourceProject.targets['serve-local'].dependsOn ?? []),
31
+ {
32
+ projects: [targetProject.name],
33
+ target: agentServeLocalTargetName,
34
+ },
35
+ ];
36
+ (0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
37
+ // Add an override to runtime-config for the serve-local target to use the local WebSocket url
38
+ const runtimeConfigProvider = (0, devkit_1.joinPathFragments)(sourceProject.root, 'src', 'components', 'RuntimeConfig', 'index.tsx');
39
+ if (tree.exists(runtimeConfigProvider)) {
40
+ const localUrl = `ws://localhost:${options.port}/ws`;
41
+ await (0, ast_1.applyGritQL)(tree, runtimeConfigProvider, `\`if ($cond) { $stmts }\` => raw\`if ($cond) {\n $stmts\n runtimeConfig.agentRuntimes.${options.agentNameClassName} = '${localUrl}';\n }\` where { $cond <: contains \`'serve-local'\`, $stmts <: within \`const applyOverrides = $_\` }`);
42
+ }
43
+ };
44
+ exports.addStrandsAgentTargetToServeLocal = addStrandsAgentTargetToServeLocal;
45
+ //# sourceMappingURL=serve-local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve-local.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/react-connection/serve-local.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAIoB;AACpB,4CAAiD;AACjD,0CAG2B;AAS3B;;;GAGG;AACI,MAAM,iCAAiC,GAAG,KAAK,EACpD,IAAU,EACV,iBAAyB,EACzB,iBAAyB,EACzB,OAAsC,EACtC,EAAE;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,iBAAiB,CAClB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,iBAAiB,CAClB,CAAC;IAEF,gEAAgE;IAChE,MAAM,yBAAyB,GAAG,OAAO,CAAC,eAAe,EAAE,IAAI;QAC7D,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,cAAc;QAC/C,CAAC,CAAC,mBAAmB,CAAC;IAExB,4EAA4E;IAC5E,IACE,CAAC,CACC,aAAa,CAAC,OAAO,EAAE,CAAC,yBAAyB,CAAC,EAAE,UAAU;QAC9D,aAAa,CAAC,OAAO,EAAE,CAAC,aAAa,CAAC,CACvC,EACD,CAAC;QACD,OAAO;IACT,CAAC;IAED,wEAAwE;IACxE,uEAAuE;IACvE,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,SAAS,GAAG;QAC/C,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;QACzD;YACE,QAAQ,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;YAC9B,MAAM,EAAE,yBAAyB;SAClC;KACF,CAAC;IACF,IAAA,mCAA0B,EAAC,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAEpE,8FAA8F;IAC9F,MAAM,qBAAqB,GAAG,IAAA,0BAAiB,EAC7C,aAAa,CAAC,IAAI,EAClB,KAAK,EACL,YAAY,EACZ,eAAe,EACf,WAAW,CACZ,CAAC;IACF,IAAI,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,kBAAkB,OAAO,CAAC,IAAI,KAAK,CAAC;QACrD,MAAM,IAAA,iBAAW,EACf,IAAI,EACJ,qBAAqB,EACrB,+FAA+F,OAAO,CAAC,kBAAkB,OAAO,QAAQ,yGAAyG,CAClP,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAzDW,QAAA,iCAAiC,qCAyD5C"}
@@ -7,9 +7,12 @@ import { IacProviderOption } from '../../utils/iac';
7
7
 
8
8
  export type TsStrandsAgentComputeType = 'BedrockAgentCoreRuntime' | 'None';
9
9
 
10
+ export type TsStrandsAgentAuth = 'IAM' | 'Cognito';
11
+
10
12
  export interface TsStrandsAgentGeneratorSchema {
11
13
  project: string;
12
14
  name?: string;
13
15
  computeType?: TsStrandsAgentComputeType;
16
+ auth?: TsStrandsAgentAuth;
14
17
  iacProvider: IacProviderOption;
15
18
  }
@@ -28,6 +28,14 @@
28
28
  "description": "The name of your Strands Agent (default: agent)",
29
29
  "x-prompt": "What would you like to call your Strands Agent? (default: agent)"
30
30
  },
31
+ "auth": {
32
+ "type": "string",
33
+ "description": "The method used to authenticate with your Strands Agent. Choose between IAM (default) or Cognito.",
34
+ "default": "IAM",
35
+ "enum": ["IAM", "Cognito"],
36
+ "x-prompt": "How would you like to authenticate with your Strands Agent?",
37
+ "x-priority": "important"
38
+ },
31
39
  "iacProvider": {
32
40
  "type": "string",
33
41
  "description": "The preferred IaC provider. By default this is inherited from your initial selection.",
@@ -7,6 +7,7 @@ import { IacProvider } from '../iac';
7
7
  type IACProvider = {
8
8
  iacProvider: IacProvider;
9
9
  };
10
+ export type AgentCoreAuth = 'IAM' | 'Cognito';
10
11
  export interface AddAgentCoreInfraProps {
11
12
  nameClassName: string;
12
13
  nameKebabCase: string;
@@ -14,12 +15,14 @@ export interface AddAgentCoreInfraProps {
14
15
  dockerImageTag: string;
15
16
  appDirectory: string;
16
17
  serverProtocol: 'MCP' | 'HTTP';
18
+ auth: AgentCoreAuth;
17
19
  }
18
20
  export interface AddMcpServerInfraProps {
19
21
  mcpServerNameClassName: string;
20
22
  mcpServerNameKebabCase: string;
21
23
  projectName: string;
22
24
  dockerImageTag: string;
25
+ auth: AgentCoreAuth;
23
26
  }
24
27
  /**
25
28
  * Add an MCP server CDK construct
@@ -30,6 +33,7 @@ export interface AddAgentInfraProps {
30
33
  agentNameKebabCase: string;
31
34
  projectName: string;
32
35
  dockerImageTag: string;
36
+ auth: AgentCoreAuth;
33
37
  }
34
38
  /**
35
39
  * Add an MCP server CDK construct
@@ -68,6 +68,7 @@ const addMcpServerInfra = async (tree, options) => {
68
68
  appDirectory: 'mcp-servers',
69
69
  serverProtocol: 'MCP',
70
70
  iacProvider: options.iacProvider,
71
+ auth: options.auth,
71
72
  });
72
73
  };
73
74
  exports.addMcpServerInfra = addMcpServerInfra;
@@ -83,6 +84,7 @@ const addAgentInfra = async (tree, options) => {
83
84
  appDirectory: 'agents',
84
85
  serverProtocol: 'HTTP',
85
86
  iacProvider: options.iacProvider,
87
+ auth: options.auth,
86
88
  });
87
89
  };
88
90
  exports.addAgentInfra = addAgentInfra;
@@ -1 +1 @@
1
- {"version":3,"file":"agent-core-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/agent-core-constructs/agent-core-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAQoB;AACpB,gFAIwC;AACxC,gCAAuC;AAEvC,0CAA2C;AAa3C,MAAM,iBAAiB,GAAG,KAAK,EAC7B,IAAU,EACV,OAA8D,EAC9D,EAAE;IACF,QAAQ,OAAO,CAAC,WAAW,EAAE,CAAC;QAC5B,KAAK,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QACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;AACJ,CAAC,CAAC;AASF;;GAEG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACpC,IAAU,EACV,OAA6C,EAC7C,EAAE;IACF,MAAM,iBAAiB,CAAC,IAAI,EAAE;QAC5B,aAAa,EAAE,OAAO,CAAC,sBAAsB;QAC7C,aAAa,EAAE,OAAO,CAAC,sBAAsB;QAC7C,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,YAAY,EAAE,aAAa;QAC3B,cAAc,EAAE,KAAK;QACrB,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAC;AACL,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B;AASF;;GAEG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,IAAU,EACV,OAAyC,EACzC,EAAE;IACF,MAAM,iBAAiB,CAAC,IAAI,EAAE;QAC5B,aAAa,EAAE,OAAO,CAAC,kBAAkB;QACzC,aAAa,EAAE,OAAO,CAAC,kBAAkB;QACzC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,YAAY,EAAE,QAAQ;QACtB,cAAc,EAAE,MAAM;QACtB,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAC;AACL,CAAC,CAAC;AAbW,QAAA,aAAa,iBAaxB"}
1
+ {"version":3,"file":"agent-core-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/agent-core-constructs/agent-core-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAQoB;AACpB,gFAIwC;AACxC,gCAAuC;AAEvC,0CAA2C;AAgB3C,MAAM,iBAAiB,GAAG,KAAK,EAC7B,IAAU,EACV,OAA8D,EAC9D,EAAE;IACF,QAAQ,OAAO,CAAC,WAAW,EAAE,CAAC;QAC5B,KAAK,KAAK;YACR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iB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;AACJ,CAAC,CAAC;AAUF;;GAEG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACpC,IAAU,EACV,OAA6C,EAC7C,EAAE;IACF,MAAM,iBAAiB,CAAC,IAAI,EAAE;QAC5B,aAAa,EAAE,OAAO,CAAC,sBAAsB;QAC7C,aAAa,EAAE,OAAO,CAAC,sBAAsB;QAC7C,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,YAAY,EAAE,aAAa;QAC3B,cAAc,EAAE,KAAK;QACrB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B;AAUF;;GAEG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,IAAU,EACV,OAAyC,EACzC,EAAE;IACF,MAAM,iBAAiB,CAAC,IAAI,EAAE;QAC5B,aAAa,EAAE,OAAO,CAAC,kBAAkB;QACzC,aAAa,EAAE,OAAO,CAAC,kBAAkB;QACzC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,YAAY,EAAE,QAAQ;QACtB,cAAc,EAAE,MAAM;QACtB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,aAAa,iBAcxB"}
@@ -9,19 +9,49 @@ import {
9
9
  ProtocolType,
10
10
  Runtime,
11
11
  RuntimeProps,
12
+ <%_ if (auth === 'Cognito') { _%>
13
+ RuntimeAuthorizerConfiguration,
14
+ <%_ } _%>
12
15
  } from '@aws-cdk/aws-bedrock-agentcore-alpha';
16
+ <%_ if (auth === 'IAM') { _%>
17
+ import { IGrantable } from 'aws-cdk-lib/aws-iam';
18
+ <%_ } _%>
19
+ <%_ if (auth === 'Cognito') { _%>
20
+ import { IUserPool, IUserPoolClient } from 'aws-cdk-lib/aws-cognito';
21
+ <%_ } _%>
13
22
  import { RuntimeConfig } from '../../../core/runtime-config.js';
14
23
 
24
+ <%_ if (auth === 'IAM') { _%>
15
25
  export type <%- nameClassName %>Props = Omit<
16
26
  RuntimeProps,
17
- 'runtimeName' | 'protocolConfiguration' | 'agentRuntimeArtifact'
27
+ | 'runtimeName'
28
+ | 'protocolConfiguration'
29
+ | 'agentRuntimeArtifact'
30
+ | 'authorizerConfiguration'
18
31
  >;
32
+ <%_ } else if (auth === 'Cognito') { _%>
33
+ export type <%- nameClassName %>Props = Omit<
34
+ RuntimeProps,
35
+ | 'runtimeName'
36
+ | 'protocolConfiguration'
37
+ | 'agentRuntimeArtifact'
38
+ | 'authorizerConfiguration'
39
+ > & {
40
+ /**
41
+ * Identity details for Cognito Authentication
42
+ */
43
+ identity: {
44
+ userPool: IUserPool;
45
+ userPoolClient: IUserPoolClient;
46
+ };
47
+ };
48
+ <%_ } _%>
19
49
 
20
50
  export class <%- nameClassName %> extends Construct {
21
51
  public readonly dockerImage: AgentRuntimeArtifact;
22
52
  public readonly agentCoreRuntime: Runtime;
23
53
 
24
- constructor(scope: Construct, id: string, props?: <%- nameClassName %>Props) {
54
+ constructor(scope: Construct, id: string, props<%_ if (auth !== 'Cognito') { _%>?<%_ } _%>: <%- nameClassName %>Props) {
25
55
  super(scope, id);
26
56
 
27
57
  const rc = RuntimeConfig.ensure(this);
@@ -37,6 +67,10 @@ export class <%- nameClassName %> extends Construct {
37
67
  },
38
68
  );
39
69
 
70
+ <%_ if (auth === 'Cognito') { _%>
71
+ const { identity, ...restProps } = props;
72
+
73
+ <%_ } _%>
40
74
  this.agentCoreRuntime = new Runtime(this, '<%- nameClassName %>', {
41
75
  runtimeName: Lazy.string({
42
76
  produce: () =>
@@ -44,10 +78,22 @@ export class <%- nameClassName %> extends Construct {
44
78
  }),
45
79
  protocolConfiguration: ProtocolType.<%- serverProtocol %>,
46
80
  agentRuntimeArtifact: this.dockerImage,
81
+ <%_ if (auth === 'Cognito') { _%>
82
+ authorizerConfiguration: RuntimeAuthorizerConfiguration.usingCognito(
83
+ identity.userPool,
84
+ [identity.userPoolClient],
85
+ ),
86
+ ...restProps,
87
+ <%_ } else { _%>
47
88
  ...props,
89
+ <%_ } _%>
48
90
  environmentVariables: {
49
91
  RUNTIME_CONFIG_APP_ID: rc.appConfigApplicationId,
92
+ <%_ if (auth === 'Cognito') { _%>
93
+ ...restProps?.environmentVariables,
94
+ <%_ } else { _%>
50
95
  ...props?.environmentVariables,
96
+ <%_ } _%>
51
97
  },
52
98
  });
53
99
 
@@ -58,4 +104,15 @@ export class <%- nameClassName %> extends Construct {
58
104
  <%- nameClassName %>: this.agentCoreRuntime.agentRuntimeArn,
59
105
  });
60
106
  }
107
+ <%_ if (auth === 'IAM') { _%>
108
+
109
+ /**
110
+ * Grants IAM permissions to invoke this agent runtime.
111
+ *
112
+ * @param grantee - The IAM principal to grant permissions to
113
+ */
114
+ public grantInvokeAccess(grantee: IGrantable) {
115
+ this.agentCoreRuntime.grantInvoke(grantee);
116
+ }
117
+ <%_ } _%>
61
118
  }
@@ -20,6 +20,24 @@ variable "tags" {
20
20
  default = {}
21
21
  }
22
22
 
23
+ <%_ if (auth === 'Cognito') { _%>
24
+ variable "user_pool_id" {
25
+ description = "ID of the user pool for cognito authentication"
26
+ type = string
27
+ }
28
+
29
+ variable "user_pool_client_ids" {
30
+ description = "IDs of the user pool clients for cognito authentication"
31
+ type = list(string)
32
+ }
33
+
34
+ data "aws_region" "current" {}
35
+
36
+ locals {
37
+ aws_region = data.aws_region.current.id
38
+ }
39
+
40
+ <%_ } _%>
23
41
  module "appconfig" {
24
42
  source = "../../../core/runtime-config/appconfig"
25
43
 
@@ -31,12 +49,14 @@ module "agent_core_runtime" {
31
49
  agent_runtime_name = "<%= nameClassName %>"
32
50
  docker_image_tag = "<%= dockerImageTag %>"
33
51
  server_protocol = "<%= serverProtocol %>"
34
- # authorizer_configuration = {
35
- # custom_jwt_authorizer = {
36
- # discovery_url = "https://xxx/.well-known/openid-configuration"
37
- # allowed_clients = [ "xxx" ]
38
- # }
39
- # }
52
+ <%_ if (auth === 'Cognito') { _%>
53
+ authorizer_configuration = {
54
+ custom_jwt_authorizer = {
55
+ discovery_url = "https://cognito-idp.${local.aws_region}.amazonaws.com/${var.user_pool_id}/.well-known/openid-configuration"
56
+ allowed_clients = var.user_pool_client_ids
57
+ }
58
+ }
59
+ <%_ } _%>
40
60
 
41
61
  env = merge({
42
62
  RUNTIME_CONFIG_APP_ID = module.appconfig.application_id