@aws/nx-plugin 0.99.1 → 0.101.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.
- package/LICENSE-THIRD-PARTY +14 -94
- package/generators.json +27 -19
- package/package.json +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +10 -10
- package/src/py/mcp-server/files/deploy/Dockerfile.template +1 -1
- package/src/py/mcp-server/generator.js +10 -2
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +43 -12
- package/src/py/strands-agent/files/ag-ui/main.py.template +19 -0
- package/src/py/strands-agent/files/deploy/Dockerfile.template +3 -1
- package/src/py/strands-agent/generator.js +20 -7
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/py/strands-agent/react-connection/__snapshots__/generator.spec.ts.snap +133 -0
- package/src/py/strands-agent/react-connection/generator.js +69 -56
- package/src/py/strands-agent/react-connection/generator.js.map +1 -1
- package/src/py/strands-agent/react-connection/serve-local.d.ts +6 -2
- package/src/py/strands-agent/react-connection/serve-local.js +11 -6
- package/src/py/strands-agent/react-connection/serve-local.js.map +1 -1
- package/src/py/strands-agent/schema.d.ts +1 -1
- package/src/py/strands-agent/schema.json +2 -2
- package/src/ts/astro-docs/__snapshots__/generator.spec.ts.snap +223 -0
- package/src/ts/astro-docs/files/base/README.md.template +63 -0
- package/src/ts/astro-docs/files/base/astro.config.mjs.template +47 -0
- package/src/ts/astro-docs/files/base/src/components/link.astro.template +25 -0
- package/src/ts/astro-docs/files/base/src/components/snippet.astro.template +20 -0
- package/src/ts/astro-docs/files/base/src/content/docs/en/blog/welcome.mdx.template +13 -0
- package/src/ts/astro-docs/files/base/src/content/docs/en/guides/getting-started.mdx.template +64 -0
- package/src/ts/astro-docs/files/base/src/content/docs/en/index.mdx.template +29 -0
- package/src/ts/astro-docs/files/base/src/content/docs/en/snippets/example.mdx.template +7 -0
- package/src/ts/astro-docs/files/base/src/content.config.ts.template +13 -0
- package/src/ts/astro-docs/files/base/src/styles/custom.css.template +1 -0
- package/src/ts/astro-docs/files/base/tsconfig.json.template +12 -0
- package/src/ts/astro-docs/files/translation/scripts/translate.config.json.template +10 -0
- package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +430 -0
- package/src/ts/astro-docs/generator.d.ts +10 -0
- package/src/ts/astro-docs/generator.js +113 -0
- package/src/ts/astro-docs/generator.js.map +1 -0
- package/src/ts/astro-docs/schema.d.ts +30 -0
- package/src/ts/astro-docs/schema.json +62 -0
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +10 -10
- package/src/ts/mcp-server/files/Dockerfile.template +1 -1
- package/src/ts/mcp-server/generator.js +9 -1
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/react-website/agui/files/src/components/AguiProvider.tsx.template +19 -0
- package/src/ts/react-website/agui/files/src/hooks/useAgui__agentNameClassName__.tsx.template +142 -0
- package/src/ts/react-website/agui/generator.d.ts +26 -0
- package/src/ts/react-website/agui/generator.js +98 -0
- package/src/ts/react-website/agui/generator.js.map +1 -0
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +49 -0
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +43 -12
- package/src/ts/strands-agent/files/deploy/Dockerfile.template +1 -1
- package/src/ts/strands-agent/generator.js +14 -1
- package/src/ts/strands-agent/generator.js.map +1 -1
- package/src/ts/strands-agent/schema.d.ts +1 -1
- package/src/ts/strands-agent/schema.json +2 -2
- package/src/utils/__snapshots__/shared-constructs.spec.ts.snap +24 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +3 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +26 -11
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +13 -1
- package/src/utils/files/common/constructs/src/core/index.ts.template +2 -1
- package/src/utils/files/common/constructs/src/core/workspace.ts.template +19 -0
- package/src/utils/versions.d.ts +18 -1
- package/src/utils/versions.js +17 -0
- package/src/utils/versions.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/Dockerfile.template +0 -1
|
@@ -9,6 +9,7 @@ exports[`ts#mcp-server generator > should match snapshot for BedrockAgentCoreRun
|
|
|
9
9
|
"export * from './app.js';
|
|
10
10
|
export * from './checkov.js';
|
|
11
11
|
export * from './runtime-config.js';
|
|
12
|
+
export * from './workspace.js';
|
|
12
13
|
"
|
|
13
14
|
`;
|
|
14
15
|
|
|
@@ -16,7 +17,6 @@ exports[`ts#mcp-server generator > should match snapshot for BedrockAgentCoreRun
|
|
|
16
17
|
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
17
18
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
18
19
|
import { Construct } from 'constructs';
|
|
19
|
-
import { execSync } from 'child_process';
|
|
20
20
|
import * as path from 'path';
|
|
21
21
|
import * as url from 'url';
|
|
22
22
|
import {
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from '@aws-cdk/aws-bedrock-agentcore-alpha';
|
|
28
28
|
import { IGrantable, IPrincipal, Grant } from 'aws-cdk-lib/aws-iam';
|
|
29
29
|
import { RuntimeConfig } from '../../../core/runtime-config.js';
|
|
30
|
+
import { findWorkspaceRoot } from '../../../core/workspace.js';
|
|
30
31
|
|
|
31
32
|
export type SnapshotBedrockServerProps = Omit<
|
|
32
33
|
RuntimeProps,
|
|
@@ -49,17 +50,16 @@ export class SnapshotBedrockServer extends Construct implements IGrantable {
|
|
|
49
50
|
|
|
50
51
|
const rc = RuntimeConfig.ensure(this);
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
extraHash: execSync(
|
|
57
|
-
\`docker inspect proj-snapshot-bedrock-server:latest --format '{{.Id}}'\`,
|
|
58
|
-
{ encoding: 'utf-8' },
|
|
59
|
-
).trim(),
|
|
60
|
-
},
|
|
53
|
+
// Resolve the bundle output directory containing the Dockerfile and built artifacts
|
|
54
|
+
const bundleDir = path.join(
|
|
55
|
+
findWorkspaceRoot(url.fileURLToPath(new URL(import.meta.url))),
|
|
56
|
+
'dist/apps/test-project/bundle/mcp/snapshot-bedrock-server',
|
|
61
57
|
);
|
|
62
58
|
|
|
59
|
+
this.dockerImage = AgentRuntimeArtifact.fromAsset(bundleDir, {
|
|
60
|
+
platform: Platform.LINUX_ARM64,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
63
|
this.agentCoreRuntime = new Runtime(this, 'SnapshotBedrockServer', {
|
|
64
64
|
runtimeName: Lazy.string({
|
|
65
65
|
produce: () =>
|
|
@@ -7,7 +7,7 @@ WORKDIR /app
|
|
|
7
7
|
RUN npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation@<%- adotVersion %>
|
|
8
8
|
|
|
9
9
|
# Copy bundled streamable http server
|
|
10
|
-
COPY
|
|
10
|
+
COPY index.js /app
|
|
11
11
|
|
|
12
12
|
EXPOSE 8000
|
|
13
13
|
|
|
@@ -17,6 +17,7 @@ const npm_scope_1 = require("../../utils/npm-scope");
|
|
|
17
17
|
const iac_1 = require("../../utils/iac");
|
|
18
18
|
const bundle_1 = require("../../utils/bundle/bundle");
|
|
19
19
|
const port_1 = require("../../utils/port");
|
|
20
|
+
const fs_1 = require("../../utils/fs");
|
|
20
21
|
exports.TS_MCP_SERVER_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
21
22
|
const tsMcpServerGenerator = async (tree, options) => {
|
|
22
23
|
const project = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.project);
|
|
@@ -82,12 +83,18 @@ const tsMcpServerGenerator = async (tree, options) => {
|
|
|
82
83
|
targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,
|
|
83
84
|
bundleOutputDir: (0, devkit_1.joinPathFragments)('mcp', name),
|
|
84
85
|
});
|
|
86
|
+
const dockerOutputDir = (0, devkit_1.joinPathFragments)('dist', project.root, 'bundle', 'mcp', name);
|
|
85
87
|
const dockerTargetName = `${mcpTargetPrefix}-docker`;
|
|
88
|
+
const fs = new fs_1.FsCommands(tree);
|
|
86
89
|
project.targets[dockerTargetName] = {
|
|
87
90
|
cache: true,
|
|
88
91
|
executor: 'nx:run-commands',
|
|
89
92
|
options: {
|
|
90
|
-
|
|
93
|
+
commands: [
|
|
94
|
+
fs.cp(`${targetSourceDir}/Dockerfile`, `${dockerOutputDir}/Dockerfile`),
|
|
95
|
+
`docker build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,
|
|
96
|
+
],
|
|
97
|
+
parallel: false,
|
|
91
98
|
},
|
|
92
99
|
dependsOn: ['bundle'],
|
|
93
100
|
};
|
|
@@ -102,6 +109,7 @@ const tsMcpServerGenerator = async (tree, options) => {
|
|
|
102
109
|
mcpServerNameClassName,
|
|
103
110
|
projectName: project.name,
|
|
104
111
|
dockerImageTag,
|
|
112
|
+
dockerOutputDir,
|
|
105
113
|
iacProvider,
|
|
106
114
|
auth,
|
|
107
115
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAYoB;AAEpB,uCAMwB;AACxB,iDAAsE;AACtE,+CAA0D;AAC1D,mDAAiE;AACjE,6CAA2D;AAC3D,qEAA0E;AAC1E,mGAA4F;AAE5F,qDAAoD;AACpD,yCAAqD;AACrD,sDAAsE;AACtE,2CAA8C;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin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AC;AAzNW,QAAA,oBAAoB,wBAyN/B;AAEF,kBAAe,4BAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CopilotKitProvider } from '@copilotkit/react-core/v2';
|
|
2
|
+
import '@copilotkit/react-core/v2/styles.css';
|
|
3
|
+
import { type FC, type PropsWithChildren, useMemo } from 'react';
|
|
4
|
+
import type { AbstractAgent } from '@ag-ui/client';
|
|
5
|
+
|
|
6
|
+
export const AguiProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
7
|
+
const selfManagedAgents = useMemo<Record<string, AbstractAgent>>(
|
|
8
|
+
() => ({}),
|
|
9
|
+
[],
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<CopilotKitProvider selfManagedAgents={selfManagedAgents}>
|
|
14
|
+
{children}
|
|
15
|
+
</CopilotKitProvider>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default AguiProvider;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<%_ if (auth === 'IAM') { _%>
|
|
2
|
+
import { HttpAgent } from '@ag-ui/client';
|
|
3
|
+
import type { AbstractAgent, RunAgentInput } from '@ag-ui/client';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { useRuntimeConfig } from './useRuntimeConfig';
|
|
7
|
+
import { useSigV4, type SigV4Client } from './useSigV4';
|
|
8
|
+
<%_ } else if (auth === 'Cognito') { _%>
|
|
9
|
+
import { HttpAgent } from '@ag-ui/client';
|
|
10
|
+
import type { AbstractAgent, RunAgentInput } from '@ag-ui/client';
|
|
11
|
+
import { useMemo } from 'react';
|
|
12
|
+
import { useAuth } from 'react-oidc-context';
|
|
13
|
+
import { useRuntimeConfig } from './useRuntimeConfig';
|
|
14
|
+
<%_ } else { _%>
|
|
15
|
+
import { HttpAgent } from '@ag-ui/client';
|
|
16
|
+
import type { AbstractAgent, RunAgentInput } from '@ag-ui/client';
|
|
17
|
+
import { useMemo } from 'react';
|
|
18
|
+
import { useRuntimeConfig } from './useRuntimeConfig';
|
|
19
|
+
<%_ } _%>
|
|
20
|
+
|
|
21
|
+
function buildAgentCoreUrl(agentRuntimeArn: string): string {
|
|
22
|
+
const region = agentRuntimeArn.split(':')[3];
|
|
23
|
+
return `https://bedrock-agentcore.${region}.amazonaws.com/runtimes/${encodeURIComponent(agentRuntimeArn)}/invocations?qualifier=DEFAULT`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// AgentCore session ids must be at least 33 characters.
|
|
27
|
+
function agentCoreSessionId(input: RunAgentInput): string {
|
|
28
|
+
return (input.threadId ?? '').padEnd(33, '0');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
<%_ if (auth === 'IAM') { _%>
|
|
32
|
+
class SigV4HttpAgent extends HttpAgent {
|
|
33
|
+
sigV4Client: SigV4Client;
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
config: ConstructorParameters<typeof HttpAgent>[0],
|
|
37
|
+
sigV4Client: SigV4Client,
|
|
38
|
+
) {
|
|
39
|
+
super(config);
|
|
40
|
+
this.sigV4Client = sigV4Client;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected override requestInit(input: RunAgentInput): RequestInit {
|
|
44
|
+
const init = super.requestInit(input);
|
|
45
|
+
init.headers = {
|
|
46
|
+
...(init.headers as Record<string, string>),
|
|
47
|
+
'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': agentCoreSessionId(input),
|
|
48
|
+
};
|
|
49
|
+
return init;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Remove this override once https://github.com/ag-ui-protocol/ag-ui/issues/1316 is fixed.
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
override run(input: RunAgentInput): any {
|
|
55
|
+
const sigV4Fetch = this.sigV4Client.fetch as typeof window.fetch;
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
return new Observable<any>((subscriber) => {
|
|
58
|
+
const originalFetch = window.fetch;
|
|
59
|
+
window.fetch = sigV4Fetch;
|
|
60
|
+
const sub = super.run(input).subscribe(subscriber);
|
|
61
|
+
window.fetch = originalFetch;
|
|
62
|
+
return () => sub.unsubscribe();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override clone(): SigV4HttpAgent {
|
|
67
|
+
const cloned = super.clone() as SigV4HttpAgent;
|
|
68
|
+
cloned.sigV4Client = this.sigV4Client;
|
|
69
|
+
return cloned;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
<%_ } else if (auth === 'Cognito') { _%>
|
|
73
|
+
class CognitoHttpAgent extends HttpAgent {
|
|
74
|
+
getAccessToken: () => string | undefined;
|
|
75
|
+
|
|
76
|
+
constructor(
|
|
77
|
+
config: ConstructorParameters<typeof HttpAgent>[0],
|
|
78
|
+
getAccessToken: () => string | undefined,
|
|
79
|
+
) {
|
|
80
|
+
super(config);
|
|
81
|
+
this.getAccessToken = getAccessToken;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected override requestInit(input: RunAgentInput): RequestInit {
|
|
85
|
+
const init = super.requestInit(input);
|
|
86
|
+
const token = this.getAccessToken();
|
|
87
|
+
init.headers = {
|
|
88
|
+
...(init.headers as Record<string, string>),
|
|
89
|
+
'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': agentCoreSessionId(input),
|
|
90
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
91
|
+
};
|
|
92
|
+
return init;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override clone(): CognitoHttpAgent {
|
|
96
|
+
const cloned = super.clone() as CognitoHttpAgent;
|
|
97
|
+
cloned.getAccessToken = this.getAccessToken;
|
|
98
|
+
return cloned;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
<%_ } else { _%>
|
|
102
|
+
class AgentCoreHttpAgent extends HttpAgent {
|
|
103
|
+
protected override requestInit(input: RunAgentInput): RequestInit {
|
|
104
|
+
const init = super.requestInit(input);
|
|
105
|
+
init.headers = {
|
|
106
|
+
...(init.headers as Record<string, string>),
|
|
107
|
+
'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id': agentCoreSessionId(input),
|
|
108
|
+
};
|
|
109
|
+
return init;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
<%_ } _%>
|
|
113
|
+
|
|
114
|
+
export const useAgui<%= agentNameClassName %> = (): Record<string, AbstractAgent> => {
|
|
115
|
+
const runtimeConfig = useRuntimeConfig();
|
|
116
|
+
const agentRuntimeValue = runtimeConfig.agentRuntimes.<%= agentNameClassName %>;
|
|
117
|
+
<%_ if (auth === 'IAM') { _%>
|
|
118
|
+
const sigv4 = useSigV4();
|
|
119
|
+
<%_ } else if (auth === 'Cognito') { _%>
|
|
120
|
+
const auth = useAuth();
|
|
121
|
+
<%_ } _%>
|
|
122
|
+
|
|
123
|
+
const url = useMemo(
|
|
124
|
+
() =>
|
|
125
|
+
agentRuntimeValue.startsWith('arn:')
|
|
126
|
+
? buildAgentCoreUrl(agentRuntimeValue)
|
|
127
|
+
: agentRuntimeValue,
|
|
128
|
+
[agentRuntimeValue],
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return useMemo((): Record<string, AbstractAgent> => {
|
|
132
|
+
<%_ if (auth === 'IAM') { _%>
|
|
133
|
+
const agent = new SigV4HttpAgent({ url }, sigv4);
|
|
134
|
+
<%_ } else if (auth === 'Cognito') { _%>
|
|
135
|
+
const agent = new CognitoHttpAgent({ url }, () => auth.user?.access_token);
|
|
136
|
+
<%_ } else { _%>
|
|
137
|
+
const agent = new AgentCoreHttpAgent({ url });
|
|
138
|
+
<%_ } _%>
|
|
139
|
+
|
|
140
|
+
return { '<%= agentName %>': agent };
|
|
141
|
+
}, [url<% if (auth === 'IAM') { %>, sigv4<% } else if (auth === 'Cognito') { %>, auth<% } %>]);
|
|
142
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
6
|
+
export type AgUiAuth = 'IAM' | 'Cognito' | 'None';
|
|
7
|
+
export interface AgUiReactConnectionOptions {
|
|
8
|
+
/** The React website project to connect FROM */
|
|
9
|
+
frontendProjectConfig: ProjectConfiguration;
|
|
10
|
+
/** The AG-UI agent's exposed name (used as CopilotKit's agent key) */
|
|
11
|
+
agentName: string;
|
|
12
|
+
/** PascalCase class name used for component names and runtime config keys */
|
|
13
|
+
agentNameClassName: string;
|
|
14
|
+
/** Auth scheme used by the agent */
|
|
15
|
+
auth: AgUiAuth;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wires a React website up to an AG-UI agent using CopilotKit and
|
|
19
|
+
* @ag-ui/client's HttpAgent. Agent-server-language agnostic.
|
|
20
|
+
*
|
|
21
|
+
* On first invocation creates a shared `AguiProvider` component (with an empty
|
|
22
|
+
* `selfManagedAgents` registry) and wraps `<App />` in it. Each invocation
|
|
23
|
+
* AST-patches `AguiProvider` to register one more agent hook — running the
|
|
24
|
+
* generator multiple times is idempotent and additive.
|
|
25
|
+
*/
|
|
26
|
+
export declare const addAgUiReactConnection: (tree: Tree, options: AgUiReactConnectionOptions) => Promise<void>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addAgUiReactConnection = 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 generator_1 = require("../runtime-config/generator");
|
|
10
|
+
const versions_1 = require("../../../utils/versions");
|
|
11
|
+
const ast_1 = require("../../../utils/ast");
|
|
12
|
+
const agent_runtime_config_1 = require("../../../connection/agent-runtime-config");
|
|
13
|
+
const names_1 = require("../../../utils/names");
|
|
14
|
+
/**
|
|
15
|
+
* Wires a React website up to an AG-UI agent using CopilotKit and
|
|
16
|
+
* @ag-ui/client's HttpAgent. Agent-server-language agnostic.
|
|
17
|
+
*
|
|
18
|
+
* On first invocation creates a shared `AguiProvider` component (with an empty
|
|
19
|
+
* `selfManagedAgents` registry) and wraps `<App />` in it. Each invocation
|
|
20
|
+
* AST-patches `AguiProvider` to register one more agent hook — running the
|
|
21
|
+
* generator multiple times is idempotent and additive.
|
|
22
|
+
*/
|
|
23
|
+
const addAgUiReactConnection = async (tree, options) => {
|
|
24
|
+
const { frontendProjectConfig, agentName, agentNameClassName, auth } = options;
|
|
25
|
+
// Generates `src/components/AguiProvider.tsx` (if absent) and
|
|
26
|
+
// `src/hooks/useAgui<AgentName>.tsx`. Existing files are kept so re-running
|
|
27
|
+
// the generator is idempotent.
|
|
28
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), frontendProjectConfig.root, { agentName, agentNameClassName, auth }, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
29
|
+
if (auth === 'IAM') {
|
|
30
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../../../utils/files/website/hooks/sigv4'), (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'hooks'), {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
31
|
+
}
|
|
32
|
+
await (0, generator_1.runtimeConfigGenerator)(tree, {
|
|
33
|
+
project: frontendProjectConfig.name,
|
|
34
|
+
});
|
|
35
|
+
// AST-patch AguiProvider to register this agent's hook
|
|
36
|
+
await registerAgentHookInProvider(tree, frontendProjectConfig, agentNameClassName);
|
|
37
|
+
// Wrap <App /> in <AguiProvider> in main.tsx (idempotent)
|
|
38
|
+
const mainTsxPath = (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'main.tsx');
|
|
39
|
+
await (0, ast_1.addSingleImport)(tree, mainTsxPath, 'AguiProvider', './components/AguiProvider');
|
|
40
|
+
await (0, ast_1.applyGritQL)(tree, mainTsxPath, `\`<App />\` => \`<AguiProvider><App /></AguiProvider>\` where { $program <: not contains \`<AguiProvider>$_</AguiProvider>\` }`);
|
|
41
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
42
|
+
'@copilotkit/react-core',
|
|
43
|
+
'@ag-ui/client',
|
|
44
|
+
...(auth === 'IAM'
|
|
45
|
+
? [
|
|
46
|
+
'oidc-client-ts',
|
|
47
|
+
'aws4fetch',
|
|
48
|
+
'@aws-sdk/credential-providers',
|
|
49
|
+
'react-oidc-context',
|
|
50
|
+
'rxjs',
|
|
51
|
+
]
|
|
52
|
+
: []),
|
|
53
|
+
...(auth === 'Cognito' ? ['react-oidc-context'] : []),
|
|
54
|
+
]), (0, versions_1.withVersions)([...(auth === 'IAM' ? ['@smithy/types'] : [])]));
|
|
55
|
+
// Agents only publish their runtime ARN to the 'agentcore' namespace by
|
|
56
|
+
// default, which isn't exposed to the website. Patch the agent's CDK/TF
|
|
57
|
+
// construct to also publish under 'connection' so the browser can read it
|
|
58
|
+
// from runtime-config.json.
|
|
59
|
+
await (0, agent_runtime_config_1.addAgentRuntimeToConnectionNamespace)(tree, {
|
|
60
|
+
agentNameKebabCase: (0, names_1.kebabCase)(agentNameClassName),
|
|
61
|
+
agentNameClassName,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.addAgUiReactConnection = addAgUiReactConnection;
|
|
65
|
+
/**
|
|
66
|
+
* Register this agent's hook in the shared `AguiProvider` using GritQL AST
|
|
67
|
+
* patches. The provider starts out with an empty `selfManagedAgents` registry
|
|
68
|
+
* (from the template); each call appends:
|
|
69
|
+
* - `import { useAgui<Name> } from '../hooks/useAgui<Name>';`
|
|
70
|
+
* - `const <varName> = useAgui<Name>();` before the `useMemo` call
|
|
71
|
+
* - `...<varName>` into the memoised object literal
|
|
72
|
+
* - `<varName>` into the `useMemo` deps array
|
|
73
|
+
*
|
|
74
|
+
* All steps are guarded so re-running produces byte-identical output.
|
|
75
|
+
*/
|
|
76
|
+
const registerAgentHookInProvider = async (tree, frontendProjectConfig, agentNameClassName) => {
|
|
77
|
+
const providerPath = (0, devkit_1.joinPathFragments)(frontendProjectConfig.sourceRoot, 'components', 'AguiProvider.tsx');
|
|
78
|
+
const hookName = `useAgui${agentNameClassName}`;
|
|
79
|
+
// useAguiStoryAgent -> storyAgentAgents
|
|
80
|
+
const varName = `${agentNameClassName.charAt(0).toLowerCase()}${agentNameClassName.slice(1)}Agents`;
|
|
81
|
+
// 1. Add the hook import
|
|
82
|
+
await (0, ast_1.addDestructuredImport)(tree, providerPath, [hookName], `../hooks/${hookName}`);
|
|
83
|
+
// 2. Insert `const <varName> = <hookName>();` before the useMemo declaration
|
|
84
|
+
await (0, ast_1.applyGritQL)(tree, providerPath, `\`const selfManagedAgents = useMemo<Record<string, AbstractAgent>>($body, $deps);\` => ` +
|
|
85
|
+
`\`const ${varName} = ${hookName}();\nconst selfManagedAgents = useMemo<Record<string, AbstractAgent>>($body, $deps);\` ` +
|
|
86
|
+
`where { $program <: not contains \`const ${varName} = ${hookName}()\` }`);
|
|
87
|
+
// 3. Spread `...<varName>` into the memoised object and add `<varName>` to
|
|
88
|
+
// the deps array. Branches on `{}`/`[]` vs populated so both the
|
|
89
|
+
// first-agent and nth-agent cases produce clean output.
|
|
90
|
+
await (0, ast_1.applyGritQL)(tree, providerPath, `\`useMemo<Record<string, AbstractAgent>>(() => ($obj), $deps)\` where {` +
|
|
91
|
+
` $obj <: not contains \`...${varName}\`,` +
|
|
92
|
+
` if ($obj <: \`{}\`) { $obj => \`{ ...${varName} }\` }` +
|
|
93
|
+
` else { $obj <: \`{$items}\` where { $items += \`, ...${varName}\` } },` +
|
|
94
|
+
` if ($deps <: \`[]\`) { $deps => \`[${varName}]\` }` +
|
|
95
|
+
` else { $deps <: \`[$dd]\` where { $dd += \`, ${varName}\` } }` +
|
|
96
|
+
` }`);
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/react-website/agui/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAOoB;AACpB,2DAAqE;AACrE,sDAAuD;AACvD,4CAI4B;AAC5B,mFAAgG;AAChG,gDAAiD;AAejD;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,IAAU,EACV,OAAmC,EACnC,EAAE;IACF,MAAM,EAAE,qBAAqB,EAAE,SAAS,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAClE,OAAO,CAAC;IAEV,8DAA8D;IAC9D,4EAA4E;IAC5E,+BAA+B;IAC/B,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EAAC,SAAS,EAAE,OAAO,CAAC,EACrC,qBAAqB,CAAC,IAAI,EAC1B,EAAE,SAAS,EAAE,kBAAkB,EAAE,IAAI,EAAE,EACvC,EAAE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY,EAAE,CACtD,CAAC;IAEF,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EAAC,SAAS,EAAE,0CAA0C,CAAC,EACxE,IAAA,0BAAiB,EAAC,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,EAC5D,EAAE,EACF,EAAE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY,EAAE,CACtD,CAAC;IACJ,CAAC;IAED,MAAM,IAAA,kCAAsB,EAAC,IAAI,EAAE;QACjC,OAAO,EA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AA0B,EAC1B,EAAE;IACF,MAAM,YAAY,GAAG,IAAA,0BAAiB,EACpC,qBAAqB,CAAC,UAAU,EAChC,YAAY,EACZ,kBAAkB,CACnB,CAAC;IACF,MAAM,QAAQ,GAAG,UAAU,kBAAkB,EAAE,CAAC;IAChD,wCAAwC;IACxC,MAAM,OAAO,GAAG,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;IAEpG,yBAAyB;IACzB,MAAM,IAAA,2BAAqB,EACzB,IAAI,EACJ,YAAY,EACZ,CAAC,QAAQ,CAAC,EACV,YAAY,QAAQ,EAAE,CACvB,CAAC;IAEF,6EAA6E;IAC7E,MAAM,IAAA,iBAAW,EACf,IAAI,EACJ,YAAY,EACZ,yFAAyF;QACvF,WAAW,OAAO,MAAM,QAAQ,yFAAyF;QACzH,4CAA4C,OAAO,MAAM,QAAQ,QAAQ,CAC5E,CAAC;IAEF,2EAA2E;IAC3E,oEAAoE;IACpE,2DAA2D;IAC3D,MAAM,IAAA,iBAAW,EACf,IAAI,EACJ,YAAY,EACZ,yEAAyE;QACvE,8BAA8B,OAAO,KAAK;QAC1C,yCAAyC,OAAO,QAAQ;QACxD,yDAAyD,OAAO,SAAS;QACzE,uCAAuC,OAAO,OAAO;QACrD,iDAAiD,OAAO,QAAQ;QAChE,IAAI,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1329,6 +1329,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
1329
1329
|
export * from './app.js';
|
|
1330
1330
|
export * from './checkov.js';
|
|
1331
1331
|
export * from './runtime-config.js';
|
|
1332
|
+
export * from './workspace.js';
|
|
1332
1333
|
"
|
|
1333
1334
|
`;
|
|
1334
1335
|
|
|
@@ -1770,6 +1771,29 @@ export class CloudfrontWebAcl extends Stack {
|
|
|
1770
1771
|
"
|
|
1771
1772
|
`;
|
|
1772
1773
|
|
|
1774
|
+
exports[`react-website generator > Tanstack router integration > should generate website with no router correctly > packages/common/constructs/src/core/workspace.ts 1`] = `
|
|
1775
|
+
"import * as fs from 'fs';
|
|
1776
|
+
import * as path from 'path';
|
|
1777
|
+
|
|
1778
|
+
/**
|
|
1779
|
+
* Find the workspace root by walking up from the given file path
|
|
1780
|
+
* until we find nx.json (the marker for an Nx workspace root).
|
|
1781
|
+
*/
|
|
1782
|
+
export const findWorkspaceRoot = (startPath: string): string => {
|
|
1783
|
+
let dir = fs.statSync(startPath).isDirectory()
|
|
1784
|
+
? startPath
|
|
1785
|
+
: path.dirname(startPath);
|
|
1786
|
+
while (dir !== path.dirname(dir)) {
|
|
1787
|
+
if (fs.existsSync(path.join(dir, 'nx.json'))) {
|
|
1788
|
+
return dir;
|
|
1789
|
+
}
|
|
1790
|
+
dir = path.dirname(dir);
|
|
1791
|
+
}
|
|
1792
|
+
throw new Error(\`Could not find workspace root (nx.json) from \${startPath}\`);
|
|
1793
|
+
};
|
|
1794
|
+
"
|
|
1795
|
+
`;
|
|
1796
|
+
|
|
1773
1797
|
exports[`react-website generator > Tanstack router integration > should generate website with no router correctly > packages/common/constructs/src/index.ts 1`] = `
|
|
1774
1798
|
"export * from './app/index.js';
|
|
1775
1799
|
export * from './core/index.js';
|
|
@@ -2925,6 +2949,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
2925
2949
|
export * from './app.js';
|
|
2926
2950
|
export * from './checkov.js';
|
|
2927
2951
|
export * from './runtime-config.js';
|
|
2952
|
+
export * from './workspace.js';
|
|
2928
2953
|
"
|
|
2929
2954
|
`;
|
|
2930
2955
|
|
|
@@ -3366,6 +3391,29 @@ export class CloudfrontWebAcl extends Stack {
|
|
|
3366
3391
|
"
|
|
3367
3392
|
`;
|
|
3368
3393
|
|
|
3394
|
+
exports[`react-website generator > Tanstack router integration > should generate website with router correctly > packages/common/constructs/src/core/workspace.ts 1`] = `
|
|
3395
|
+
"import * as fs from 'fs';
|
|
3396
|
+
import * as path from 'path';
|
|
3397
|
+
|
|
3398
|
+
/**
|
|
3399
|
+
* Find the workspace root by walking up from the given file path
|
|
3400
|
+
* until we find nx.json (the marker for an Nx workspace root).
|
|
3401
|
+
*/
|
|
3402
|
+
export const findWorkspaceRoot = (startPath: string): string => {
|
|
3403
|
+
let dir = fs.statSync(startPath).isDirectory()
|
|
3404
|
+
? startPath
|
|
3405
|
+
: path.dirname(startPath);
|
|
3406
|
+
while (dir !== path.dirname(dir)) {
|
|
3407
|
+
if (fs.existsSync(path.join(dir, 'nx.json'))) {
|
|
3408
|
+
return dir;
|
|
3409
|
+
}
|
|
3410
|
+
dir = path.dirname(dir);
|
|
3411
|
+
}
|
|
3412
|
+
throw new Error(\`Could not find workspace root (nx.json) from \${startPath}\`);
|
|
3413
|
+
};
|
|
3414
|
+
"
|
|
3415
|
+
`;
|
|
3416
|
+
|
|
3369
3417
|
exports[`react-website generator > Tanstack router integration > should generate website with router correctly > packages/common/constructs/src/index.ts 1`] = `
|
|
3370
3418
|
"export * from './app/index.js';
|
|
3371
3419
|
export * from './core/index.js';
|
|
@@ -4588,6 +4636,7 @@ exports[`react-website generator > should generate shared constructs > common/co
|
|
|
4588
4636
|
export * from './app.js';
|
|
4589
4637
|
export * from './checkov.js';
|
|
4590
4638
|
export * from './runtime-config.js';
|
|
4639
|
+
export * from './workspace.js';
|
|
4591
4640
|
"
|
|
4592
4641
|
`;
|
|
4593
4642
|
|
|
@@ -81,6 +81,7 @@ exports[`cognito-auth generator > should generate files > identity-index 1`] = `
|
|
|
81
81
|
export * from './app.js';
|
|
82
82
|
export * from './checkov.js';
|
|
83
83
|
export * from './runtime-config.js';
|
|
84
|
+
export * from './workspace.js';
|
|
84
85
|
"
|
|
85
86
|
`;
|
|
86
87
|
|
|
@@ -295,5 +296,6 @@ exports[`cognito-auth generator > should update shared constructs index.ts > com
|
|
|
295
296
|
export * from './app.js';
|
|
296
297
|
export * from './checkov.js';
|
|
297
298
|
export * from './runtime-config.js';
|
|
299
|
+
export * from './workspace.js';
|
|
298
300
|
"
|
|
299
301
|
`;
|
|
@@ -10,7 +10,7 @@ WORKDIR /app
|
|
|
10
10
|
RUN npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation@0.10.0
|
|
11
11
|
|
|
12
12
|
# Copy bundled agent
|
|
13
|
-
COPY
|
|
13
|
+
COPY index.js /app
|
|
14
14
|
|
|
15
15
|
EXPOSE 8080
|
|
16
16
|
|
|
@@ -24,7 +24,6 @@ exports[`ts#strands-agent generator > should match snapshot for BedrockAgentCore
|
|
|
24
24
|
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
25
25
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
26
26
|
import { Construct } from 'constructs';
|
|
27
|
-
import { execSync } from 'child_process';
|
|
28
27
|
import * as path from 'path';
|
|
29
28
|
import * as url from 'url';
|
|
30
29
|
import {
|
|
@@ -33,8 +32,14 @@ import {
|
|
|
33
32
|
Runtime,
|
|
34
33
|
RuntimeProps,
|
|
35
34
|
} from '@aws-cdk/aws-bedrock-agentcore-alpha';
|
|
36
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
PolicyStatement,
|
|
37
|
+
IGrantable,
|
|
38
|
+
IPrincipal,
|
|
39
|
+
Grant,
|
|
40
|
+
} from 'aws-cdk-lib/aws-iam';
|
|
37
41
|
import { RuntimeConfig } from '../../../core/runtime-config.js';
|
|
42
|
+
import { findWorkspaceRoot } from '../../../core/workspace.js';
|
|
38
43
|
|
|
39
44
|
export type SnapshotBedrockAgentProps = Omit<
|
|
40
45
|
RuntimeProps,
|
|
@@ -53,17 +58,16 @@ export class SnapshotBedrockAgent extends Construct implements IGrantable {
|
|
|
53
58
|
|
|
54
59
|
const rc = RuntimeConfig.ensure(this);
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
extraHash: execSync(
|
|
61
|
-
\`docker inspect proj-snapshot-bedrock-agent:latest --format '{{.Id}}'\`,
|
|
62
|
-
{ encoding: 'utf-8' },
|
|
63
|
-
).trim(),
|
|
64
|
-
},
|
|
61
|
+
// Resolve the bundle output directory containing the Dockerfile and built artifacts
|
|
62
|
+
const bundleDir = path.join(
|
|
63
|
+
findWorkspaceRoot(url.fileURLToPath(new URL(import.meta.url))),
|
|
64
|
+
'dist/apps/test-project/bundle/agent/snapshot-bedrock-agent',
|
|
65
65
|
);
|
|
66
66
|
|
|
67
|
+
this.dockerImage = AgentRuntimeArtifact.fromAsset(bundleDir, {
|
|
68
|
+
platform: Platform.LINUX_ARM64,
|
|
69
|
+
});
|
|
70
|
+
|
|
67
71
|
this.agentCoreRuntime = new Runtime(this, 'SnapshotBedrockAgent', {
|
|
68
72
|
runtimeName: Lazy.string({
|
|
69
73
|
produce: () =>
|
|
@@ -78,6 +82,20 @@ export class SnapshotBedrockAgent extends Construct implements IGrantable {
|
|
|
78
82
|
},
|
|
79
83
|
});
|
|
80
84
|
|
|
85
|
+
// Grant access for the agent to invoke bedrock models
|
|
86
|
+
this.agentCoreRuntime.addToRolePolicy(
|
|
87
|
+
new PolicyStatement({
|
|
88
|
+
actions: [
|
|
89
|
+
'bedrock:InvokeModel',
|
|
90
|
+
'bedrock:InvokeModelWithResponseStream',
|
|
91
|
+
],
|
|
92
|
+
resources: [
|
|
93
|
+
'arn:aws:bedrock:*:*:foundation-model/*',
|
|
94
|
+
'arn:aws:bedrock:*:*:inference-profile/*',
|
|
95
|
+
],
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
|
|
81
99
|
rc.grantReadAppConfig(this.agentCoreRuntime);
|
|
82
100
|
|
|
83
101
|
rc.set('agentcore', 'agentRuntimes', {
|
|
@@ -128,6 +146,7 @@ exports[`ts#strands-agent generator > should match snapshot for BedrockAgentCore
|
|
|
128
146
|
"export * from './app.js';
|
|
129
147
|
export * from './checkov.js';
|
|
130
148
|
export * from './runtime-config.js';
|
|
149
|
+
export * from './workspace.js';
|
|
131
150
|
"
|
|
132
151
|
`;
|
|
133
152
|
|
|
@@ -177,6 +196,18 @@ module "agent_core_runtime" {
|
|
|
177
196
|
"appconfig:GetLatestConfiguration"
|
|
178
197
|
]
|
|
179
198
|
Resource = ["\${module.appconfig.application_arn}/*"]
|
|
199
|
+
},
|
|
200
|
+
# Grant access for the agent to invoke bedrock models
|
|
201
|
+
{
|
|
202
|
+
Effect = "Allow"
|
|
203
|
+
Action = [
|
|
204
|
+
"bedrock:InvokeModel",
|
|
205
|
+
"bedrock:InvokeModelWithResponseStream"
|
|
206
|
+
]
|
|
207
|
+
Resource = [
|
|
208
|
+
"arn:aws:bedrock:*:*:foundation-model/*",
|
|
209
|
+
"arn:aws:bedrock:*:*:inference-profile/*"
|
|
210
|
+
]
|
|
180
211
|
}
|
|
181
212
|
], var.additional_iam_policy_statements)
|
|
182
213
|
tags = var.tags
|
|
@@ -7,7 +7,7 @@ WORKDIR /app
|
|
|
7
7
|
RUN npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation@<%- adotVersion %>
|
|
8
8
|
|
|
9
9
|
# Copy bundled agent
|
|
10
|
-
COPY
|
|
10
|
+
COPY index.js /app
|
|
11
11
|
|
|
12
12
|
<%_ if (protocol === 'A2A') { _%>
|
|
13
13
|
EXPOSE 9000
|