@aws/nx-plugin 0.97.1 → 0.99.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/generators.json +17 -1
- package/package.json +1 -1
- package/src/connection/agent-runtime-config.d.ts +19 -0
- package/src/connection/agent-runtime-config.js +52 -0
- package/src/connection/agent-runtime-config.js.map +1 -0
- package/src/connection/generator.js +15 -5
- package/src/connection/generator.js.map +1 -1
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +3 -17
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +8 -5
- package/src/py/strands-agent/a2a-connection/files/agent-connection/app/__targetAgentSnakeCase___client.py.template +29 -0
- package/src/py/strands-agent/a2a-connection/generator.d.ts +10 -0
- package/src/py/strands-agent/a2a-connection/generator.js +164 -0
- package/src/py/strands-agent/a2a-connection/generator.js.map +1 -0
- package/src/py/strands-agent/a2a-connection/schema.d.ts +15 -0
- package/src/py/strands-agent/a2a-connection/schema.json +26 -0
- package/src/py/strands-agent/files/a2a/main.py.template +33 -0
- package/src/py/strands-agent/files/{app → common}/agent.py.template +2 -0
- package/src/py/strands-agent/files/deploy/Dockerfile.template +9 -0
- package/src/py/strands-agent/generator.js +29 -16
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/py/strands-agent/mcp-connection/__snapshots__/generator.spec.ts.snap +9 -63
- package/src/py/strands-agent/mcp-connection/files/agent-connection/app/__mcpServerSnakeCase___client.py.template +4 -19
- package/src/py/strands-agent/mcp-connection/generator.js +16 -19
- package/src/py/strands-agent/mcp-connection/generator.js.map +1 -1
- package/src/py/strands-agent/react-connection/__snapshots__/generator.spec.ts.snap +3 -17
- package/src/py/strands-agent/react-connection/generator.js +12 -0
- package/src/py/strands-agent/react-connection/generator.js.map +1 -1
- package/src/py/strands-agent/schema.d.ts +2 -0
- package/src/py/strands-agent/schema.json +8 -0
- package/src/smithy/react-connection/__snapshots__/generator.spec.ts.snap +3 -17
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/ts/strands-agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client.ts.template +27 -0
- package/src/ts/strands-agent/a2a-connection/generator.d.ts +10 -0
- package/src/ts/strands-agent/a2a-connection/generator.js +119 -0
- package/src/ts/strands-agent/a2a-connection/generator.js.map +1 -0
- package/src/ts/strands-agent/a2a-connection/schema.d.ts +15 -0
- package/src/ts/strands-agent/a2a-connection/schema.json +26 -0
- package/src/ts/strands-agent/files/a2a/index.ts.template +28 -0
- package/src/ts/strands-agent/files/deploy/Dockerfile.template +4 -0
- package/src/ts/strands-agent/generator.js +30 -14
- package/src/ts/strands-agent/generator.js.map +1 -1
- package/src/ts/strands-agent/mcp-connection/__snapshots__/generator.spec.ts.snap +9 -31
- package/src/ts/strands-agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client.ts.template +2 -9
- package/src/ts/strands-agent/mcp-connection/generator.js +4 -2
- package/src/ts/strands-agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/strands-agent/react-connection/generator.js +12 -0
- package/src/ts/strands-agent/react-connection/generator.js.map +1 -1
- package/src/ts/strands-agent/schema.d.ts +2 -0
- package/src/ts/strands-agent/schema.json +8 -0
- package/src/utils/agent-connection/agent-connection.d.ts +31 -3
- package/src/utils/agent-connection/agent-connection.js +62 -30
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client.ts.template +134 -0
- package/src/utils/agent-connection/files/{core → core-mcp}/agentcore-mcp-client.ts.template +7 -22
- package/src/utils/agent-connection/files/core-runtime-config/runtime-config.ts.template +40 -0
- package/src/utils/agent-connection/files/py-core-a2a/agentcore_a2a_client.py.template +91 -0
- package/src/utils/agent-connection/files/py-core-auth/auth/__init__.py.template +3 -0
- package/src/utils/agent-connection/files/py-core-auth/auth/sigv4.py.template +48 -0
- package/src/utils/agent-connection/files/{py-core → py-core-mcp}/agentcore_mcp_client.py.template +2 -36
- package/src/utils/agent-connection/files/py-core-runtime-config/runtime_config.py.template +44 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +3 -2
- package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -2
- 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 +8 -3
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +1 -1
- package/src/utils/ast.d.ts +18 -0
- package/src/utils/ast.js +58 -9
- package/src/utils/ast.js.map +1 -1
- package/src/utils/connection/open-api/files/components/__apiNameClassName__Provider.tsx.template +3 -16
- package/src/utils/versions.d.ts +6 -3
- package/src/utils/versions.js +5 -2
- package/src/utils/versions.js.map +1 -1
- /package/src/py/strands-agent/files/{app → common}/__init__.py.template +0 -0
- /package/src/py/strands-agent/files/{app → http}/init.py.template +0 -0
- /package/src/py/strands-agent/files/{app → http}/main.py.template +0 -0
- /package/src/ts/strands-agent/files/{app → common}/agent.ts.template +0 -0
- /package/src/ts/strands-agent/files/{app → http}/agent-core-trpc-client.ts.template +0 -0
- /package/src/ts/strands-agent/files/{app → http}/client.ts.template +0 -0
- /package/src/ts/strands-agent/files/{app → http}/index.ts.template +0 -0
- /package/src/ts/strands-agent/files/{app → http}/init.ts.template +0 -0
- /package/src/ts/strands-agent/files/{app → http}/router.ts.template +0 -0
- /package/src/ts/strands-agent/files/{app → http}/schema/z-async-iterable.ts.template +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AGENT_CONNECTION_PROJECT_DIR = void 0;
|
|
3
|
+
exports.PY_CORE_TEMPLATES = exports.TS_CORE_TEMPLATES = exports.AGENT_CONNECTION_PROJECT_DIR = void 0;
|
|
4
4
|
exports.getPythonAgentConnectionProjectDir = getPythonAgentConnectionProjectDir;
|
|
5
5
|
exports.getPythonAgentConnectionModuleName = getPythonAgentConnectionModuleName;
|
|
6
6
|
exports.getPythonAgentConnectionPackageName = getPythonAgentConnectionPackageName;
|
|
7
7
|
exports.ensureTypeScriptAgentConnectionProject = ensureTypeScriptAgentConnectionProject;
|
|
8
|
+
exports.addTypeScriptCoreClient = addTypeScriptCoreClient;
|
|
8
9
|
exports.ensurePythonAgentConnectionProject = ensurePythonAgentConnectionProject;
|
|
10
|
+
exports.addPythonCoreClient = addPythonCoreClient;
|
|
9
11
|
exports.addPythonReExport = addPythonReExport;
|
|
10
12
|
const tslib_1 = require("tslib");
|
|
11
13
|
/**
|
|
@@ -55,50 +57,65 @@ function getPythonAgentConnectionPackageName(tree) {
|
|
|
55
57
|
return fullyQualifiedName;
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
+
* Directories (relative to this file) holding per-protocol core client
|
|
61
|
+
* template files. Per-connection generators select which set to emit so
|
|
62
|
+
* the MCP connection doesn't pull in the A2A client (or vice versa).
|
|
63
|
+
*/
|
|
64
|
+
exports.TS_CORE_TEMPLATES = {
|
|
65
|
+
mcp: 'core-mcp',
|
|
66
|
+
a2a: 'core-a2a',
|
|
67
|
+
};
|
|
68
|
+
exports.PY_CORE_TEMPLATES = {
|
|
69
|
+
mcp: 'py-core-mcp',
|
|
70
|
+
a2a: 'py-core-a2a',
|
|
71
|
+
/** Shared SigV4 `httpx.Auth` used by both MCP and A2A clients. */
|
|
72
|
+
auth: 'py-core-auth',
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Ensure the shared TypeScript agent-connection project exists and has the
|
|
76
|
+
* shared core helpers (runtime-config loader). Per-connection generators
|
|
77
|
+
* are responsible for emitting their own per-protocol core client templates.
|
|
60
78
|
*/
|
|
61
79
|
async function ensureTypeScriptAgentConnectionProject(tree) {
|
|
62
80
|
const projectJsonPath = (0, devkit_1.joinPathFragments)(exports.AGENT_CONNECTION_PROJECT_DIR, 'project.json');
|
|
63
|
-
if (tree.exists(projectJsonPath)) {
|
|
64
|
-
|
|
81
|
+
if (!tree.exists(projectJsonPath)) {
|
|
82
|
+
await (0, generator_1.default)(tree, {
|
|
83
|
+
name: AGENT_CONNECTION_DIR,
|
|
84
|
+
directory: (0, devkit_1.joinPathFragments)(PACKAGES_DIR, COMMON_DIR),
|
|
85
|
+
});
|
|
65
86
|
}
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
87
|
+
// Shared core helpers — emitted regardless of which per-protocol core
|
|
88
|
+
// client the caller needs, so both MCP and A2A clients can import from them.
|
|
89
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'core-runtime-config'), (0, devkit_1.joinPathFragments)(exports.AGENT_CONNECTION_PROJECT_DIR, 'src', 'core'), {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Emit one of the TypeScript core client templates (mcp or a2a) into the
|
|
93
|
+
* agent-connection project's `src/core/` directory. Safe to call multiple
|
|
94
|
+
* times — `KeepExisting` preserves customised files.
|
|
95
|
+
*/
|
|
96
|
+
function addTypeScriptCoreClient(tree, kind) {
|
|
97
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', exports.TS_CORE_TEMPLATES[kind]), (0, devkit_1.joinPathFragments)(exports.AGENT_CONNECTION_PROJECT_DIR, 'src', 'core'), {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
73
98
|
}
|
|
74
99
|
/**
|
|
75
100
|
* Ensure the shared Python agent-connection project exists.
|
|
76
|
-
*
|
|
101
|
+
* Only creates the project shell — per-connection generators are responsible
|
|
102
|
+
* for emitting their own core client templates.
|
|
77
103
|
*/
|
|
78
104
|
async function ensurePythonAgentConnectionProject(tree) {
|
|
79
105
|
const projectDir = getPythonAgentConnectionProjectDir(tree);
|
|
80
106
|
const moduleName = getPythonAgentConnectionModuleName(tree);
|
|
81
107
|
const projectJsonPath = (0, devkit_1.joinPathFragments)(projectDir, 'project.json');
|
|
82
|
-
if (tree.exists(projectJsonPath)) {
|
|
83
|
-
|
|
108
|
+
if (!tree.exists(projectJsonPath)) {
|
|
109
|
+
// Create the Python project using the standard py#project generator
|
|
110
|
+
await (0, generator_2.default)(tree, {
|
|
111
|
+
name: PY_AGENT_CONNECTION_NAME,
|
|
112
|
+
directory: (0, devkit_1.joinPathFragments)(PACKAGES_DIR, COMMON_DIR),
|
|
113
|
+
projectType: 'library',
|
|
114
|
+
});
|
|
84
115
|
}
|
|
85
|
-
// Create the Python project using the standard py#project generator
|
|
86
|
-
await (0, generator_2.default)(tree, {
|
|
87
|
-
name: PY_AGENT_CONNECTION_NAME,
|
|
88
|
-
directory: (0, devkit_1.joinPathFragments)(PACKAGES_DIR, COMMON_DIR),
|
|
89
|
-
projectType: 'library',
|
|
90
|
-
});
|
|
91
|
-
// Add dependencies needed by the core agentcore_mcp_client
|
|
92
|
-
(0, py_1.addDependenciesToPyProjectToml)(tree, projectDir, [
|
|
93
|
-
'boto3',
|
|
94
|
-
'mcp',
|
|
95
|
-
'strands-agents',
|
|
96
|
-
]);
|
|
97
116
|
const moduleDir = (0, devkit_1.joinPathFragments)(projectDir, moduleName);
|
|
98
|
-
// Generate the core files (agentcore_mcp_client.py)
|
|
99
|
-
const coreDir = (0, devkit_1.joinPathFragments)(moduleDir, 'core');
|
|
100
|
-
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'py-core'), coreDir, {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
101
117
|
// Ensure core/__init__.py exists
|
|
118
|
+
const coreDir = (0, devkit_1.joinPathFragments)(moduleDir, 'core');
|
|
102
119
|
if (!tree.exists((0, devkit_1.joinPathFragments)(coreDir, '__init__.py'))) {
|
|
103
120
|
tree.write((0, devkit_1.joinPathFragments)(coreDir, '__init__.py'), '');
|
|
104
121
|
}
|
|
@@ -107,6 +124,21 @@ async function ensurePythonAgentConnectionProject(tree) {
|
|
|
107
124
|
if (!tree.exists(appInitPath)) {
|
|
108
125
|
tree.write(appInitPath, '');
|
|
109
126
|
}
|
|
127
|
+
// Shared core helpers — emitted regardless of which per-protocol core
|
|
128
|
+
// client the caller needs, so both MCP and A2A clients can import them.
|
|
129
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'py-core-runtime-config'), coreDir, {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
130
|
+
// Shared core helpers depend on aws-lambda-powertools for AppConfig access.
|
|
131
|
+
(0, py_1.addDependenciesToPyProjectToml)(tree, projectDir, ['aws-lambda-powertools']);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Emit a Python core client template (mcp / a2a / shared auth) into the
|
|
135
|
+
* agent-connection project's core directory.
|
|
136
|
+
*/
|
|
137
|
+
function addPythonCoreClient(tree, kind) {
|
|
138
|
+
const projectDir = getPythonAgentConnectionProjectDir(tree);
|
|
139
|
+
const moduleName = getPythonAgentConnectionModuleName(tree);
|
|
140
|
+
const coreDir = (0, devkit_1.joinPathFragments)(projectDir, moduleName, 'core');
|
|
141
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', exports.PY_CORE_TEMPLATES[kind]), coreDir, {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
110
142
|
}
|
|
111
143
|
/**
|
|
112
144
|
* Add a re-export to the Python agent-connection module's __init__.py.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-connection.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/agent-connection/agent-connection.ts"],"names":[],"mappings":";;;AAmCA,gFAMC;AAKD,gFAMC;AAKD,kFAMC;
|
|
1
|
+
{"version":3,"file":"agent-connection.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/agent-connection/agent-connection.ts"],"names":[],"mappings":";;;AAmCA,gFAMC;AAKD,gFAMC;AAKD,kFAMC;AAwBD,wFAuBC;AAOD,0DAWC;AAOD,gFA0CC;AAMD,kDAcC;AAQD,8CAiDC;;AA9PD;;;GAGG;AACH,uCAKoB;AACpB,+EAAwD;AACxD,gFAEoC;AACpC,8BAAuD;AACvD,gCAAkD;AAElD,qDAAqD;AACrD,MAAM,EAAE,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,oBAAoB,OAAO,EAAE,CAAC;AAE9D,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAChD,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAEf,QAAA,4BAA4B,GAAG,IAAA,0BAAiB,EAC3D,YAAY,EACZ,UAAU,EACV,oBAAoB,CACrB,CAAC;AAEF,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;AAEpD;;GAEG;AACH,SAAgB,kCAAkC,CAAC,IAAU;IAC3D,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,+BAAmB,EAAC,IAAI,EAAE;QACxC,IAAI,EAAE,wBAAwB;QAC9B,SAAS,EAAE,IAAA,0BAAiB,EAAC,YAAY,EAAE,UAAU,CAAC;KACvD,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,SAAgB,kCAAkC,CAAC,IAAU;IAC3D,MAAM,EAAE,oBAAoB,EAAE,GAAG,IAAA,+BAAmB,EAAC,IAAI,EAAE;QACzD,IAAI,EAAE,wBAAwB;QAC9B,SAAS,EAAE,IAAA,0BAAiB,EAAC,YAAY,EAAE,UAAU,CAAC;KACvD,CAAC,CAAC;IACH,OAAO,o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,CAAC;IAC7D,MAAM,QAAQ,GAAG,IAAI,UAAU,GAAG,CAAC;IAEnC,sDAAsD;IACtD,MAAM,cAAc,GAAG,MAAM,IAAA,iBAAW,EACtC,IAAI,EACJ,YAAY,EACZ,EAAE,CACA;+BACyB,UAAU;iBACxB,UAAU;EACzB,CACG,CACF,CAAC;IAEF,IAAI,cAAc,EAAE,CAAC;QACnB,kCAAkC;QAClC,MAAM,IAAA,iBAAW,EACf,IAAI,EACJ,YAAY,EACZ,EAAE,CAAC,gDAAgD,QAAQ,MAAM,CAAC,CACnE,CAAC;QACF,OAAO;IACT,CAAC;IAED,wEAAwE;IACxE,MAAM,cAAc,GAAG,MAAM,IAAA,iBAAW,EACtC,IAAI,EACJ,YAAY,EACZ,EAAE,CACA,+DAA+D,UAAU,kBAAkB,QAAQ,KAAK,CACzG,CACF,CAAC;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,yDAAyD;QACzD,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,UAAU,kBAAkB,QAAQ,KAAK,CAAC,CAAC;IACzE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientFactory,
|
|
3
|
+
ClientFactoryOptions,
|
|
4
|
+
DefaultAgentCardResolver,
|
|
5
|
+
JsonRpcTransportFactory,
|
|
6
|
+
} from '@a2a-js/sdk/client';
|
|
7
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
8
|
+
import { A2AAgent } from '@strands-agents/sdk/a2a';
|
|
9
|
+
import { AwsClient } from 'aws4fetch';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Common options for creating an AgentCore A2A client
|
|
13
|
+
*/
|
|
14
|
+
export interface AgentCoreA2aClientOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The ARN of the Bedrock AgentCore Runtime to connect to
|
|
17
|
+
*/
|
|
18
|
+
agentRuntimeArn: string;
|
|
19
|
+
/**
|
|
20
|
+
* Session ID to include in request headers.
|
|
21
|
+
*/
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Optional description for the remote agent.
|
|
25
|
+
*/
|
|
26
|
+
description?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional friendly name for the remote agent.
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Options for creating an AgentCore A2A client with IAM authentication
|
|
35
|
+
*/
|
|
36
|
+
export interface AgentCoreA2aClientIamOptions
|
|
37
|
+
extends AgentCoreA2aClientOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Optional AWS credential provider. If not provided, uses the default
|
|
40
|
+
* credential provider chain from the AWS SDK.
|
|
41
|
+
*/
|
|
42
|
+
credentialProvider?: ReturnType<typeof fromNodeProviderChain>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Options for creating an AgentCore A2A client with JWT authentication
|
|
47
|
+
*/
|
|
48
|
+
export interface AgentCoreA2aClientJwtOptions
|
|
49
|
+
extends AgentCoreA2aClientOptions {
|
|
50
|
+
/**
|
|
51
|
+
* A function which returns the JWT access token used to authenticate
|
|
52
|
+
*/
|
|
53
|
+
accessTokenProvider: () => Promise<string>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Factory for clients to call A2A agents hosted on Bedrock AgentCore Runtime
|
|
58
|
+
*/
|
|
59
|
+
export class AgentCoreA2aClient {
|
|
60
|
+
/**
|
|
61
|
+
* Construct the A2A invocations URL for an AgentCore runtime ARN and extract the region.
|
|
62
|
+
* ARN format: arn:partition:service:region:account-id:resource
|
|
63
|
+
* A2A on AgentCore is mounted at `/invocations/` (trailing slash matters).
|
|
64
|
+
*/
|
|
65
|
+
private static buildUrl(agentRuntimeArn: string): {
|
|
66
|
+
region: string;
|
|
67
|
+
url: string;
|
|
68
|
+
} {
|
|
69
|
+
const region = agentRuntimeArn.split(':')[3];
|
|
70
|
+
const url = `https://bedrock-agentcore.${region}.amazonaws.com/runtimes/${encodeURIComponent(agentRuntimeArn)}/invocations/`;
|
|
71
|
+
return { region, url };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Build a Strands `A2AAgent` for a URL plus a fetch that is already
|
|
76
|
+
* authenticated (SigV4-signing or Bearer-adding).
|
|
77
|
+
*/
|
|
78
|
+
private static build(
|
|
79
|
+
url: string,
|
|
80
|
+
authFetch: typeof fetch,
|
|
81
|
+
options: Pick<AgentCoreA2aClientOptions, 'name' | 'description'>,
|
|
82
|
+
): A2AAgent {
|
|
83
|
+
const clientFactory = new ClientFactory({
|
|
84
|
+
...ClientFactoryOptions.default,
|
|
85
|
+
transports: [new JsonRpcTransportFactory({ fetchImpl: authFetch })],
|
|
86
|
+
cardResolver: new DefaultAgentCardResolver({ fetchImpl: authFetch }),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return new A2AAgent({
|
|
90
|
+
url,
|
|
91
|
+
clientFactory,
|
|
92
|
+
...(options.name ? { name: options.name } : {}),
|
|
93
|
+
...(options.description ? { description: options.description } : {}),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create an `A2AAgent` with IAM (SigV4) authentication.
|
|
99
|
+
*/
|
|
100
|
+
static withIamAuth(options: AgentCoreA2aClientIamOptions): A2AAgent {
|
|
101
|
+
const credentialProvider =
|
|
102
|
+
options.credentialProvider ?? fromNodeProviderChain();
|
|
103
|
+
const { region, url } = AgentCoreA2aClient.buildUrl(options.agentRuntimeArn);
|
|
104
|
+
|
|
105
|
+
const sigv4Fetch: typeof fetch = async (...args) => {
|
|
106
|
+
const credentials = await credentialProvider();
|
|
107
|
+
const client = new AwsClient({
|
|
108
|
+
...credentials,
|
|
109
|
+
service: 'bedrock-agentcore',
|
|
110
|
+
region,
|
|
111
|
+
});
|
|
112
|
+
return client.fetch(...args);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return AgentCoreA2aClient.build(url, sigv4Fetch, options);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Create an `A2AAgent` with JWT authentication.
|
|
120
|
+
*/
|
|
121
|
+
static withJwtAuth(options: AgentCoreA2aClientJwtOptions): A2AAgent {
|
|
122
|
+
const { accessTokenProvider } = options;
|
|
123
|
+
const { url } = AgentCoreA2aClient.buildUrl(options.agentRuntimeArn);
|
|
124
|
+
|
|
125
|
+
const bearerFetch: typeof fetch = async (input, init) => {
|
|
126
|
+
const token = await accessTokenProvider();
|
|
127
|
+
const headers = new Headers(init?.headers);
|
|
128
|
+
headers.set('Authorization', `Bearer ${token}`);
|
|
129
|
+
return fetch(input, { ...init, headers });
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return AgentCoreA2aClient.build(url, bearerFetch, options);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -76,33 +76,18 @@ export class AgentCoreMcpClient {
|
|
|
76
76
|
const {
|
|
77
77
|
url,
|
|
78
78
|
sessionId = randomUUID(),
|
|
79
|
-
buildHeaders = async () => ({}),
|
|
79
|
+
buildHeaders = async (): Promise<Record<string, string>> => ({}),
|
|
80
80
|
fetch: customFetch,
|
|
81
81
|
} = options;
|
|
82
82
|
|
|
83
83
|
// Create a custom fetch that adds required headers
|
|
84
84
|
const fetchWithHeaders: typeof fetch = async (input, init) => {
|
|
85
|
-
const headers =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const mergedInit = {
|
|
92
|
-
...init,
|
|
93
|
-
headers: !existingHeaders
|
|
94
|
-
? headers
|
|
95
|
-
: existingHeaders instanceof Headers
|
|
96
|
-
? (() => {
|
|
97
|
-
const h = new Headers(existingHeaders);
|
|
98
|
-
Object.entries(headers).forEach(([k, v]) => h.append(k, v));
|
|
99
|
-
return h;
|
|
100
|
-
})()
|
|
101
|
-
: Array.isArray(existingHeaders)
|
|
102
|
-
? [...existingHeaders, ...Object.entries(headers)]
|
|
103
|
-
: { ...existingHeaders, ...headers },
|
|
104
|
-
};
|
|
105
|
-
return (customFetch || fetch)(input, mergedInit);
|
|
85
|
+
const headers = new Headers(init?.headers);
|
|
86
|
+
headers.set('X-Amzn-Bedrock-AgentCore-Runtime-Session-Id', sessionId);
|
|
87
|
+
for (const [k, v] of Object.entries(await buildHeaders())) {
|
|
88
|
+
headers.set(k, v);
|
|
89
|
+
}
|
|
90
|
+
return (customFetch || fetch)(input, { ...init, headers });
|
|
106
91
|
};
|
|
107
92
|
|
|
108
93
|
// Create the transport
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read the runtime-config `agentcore` namespace from AppConfig.
|
|
5
|
+
* `RUNTIME_CONFIG_APP_ID` is set on the AgentCore runtime by the generated
|
|
6
|
+
* CDK/Terraform construct for this project.
|
|
7
|
+
*/
|
|
8
|
+
const getAgentCoreRuntimeConfig = async (): Promise<{
|
|
9
|
+
agentRuntimes?: Record<string, string>;
|
|
10
|
+
}> => {
|
|
11
|
+
const application = process.env.RUNTIME_CONFIG_APP_ID;
|
|
12
|
+
if (!application) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
'RUNTIME_CONFIG_APP_ID is not set — cannot resolve connected agent ARNs from AppConfig.',
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return (await getAppConfig('agentcore', {
|
|
18
|
+
application,
|
|
19
|
+
environment: 'default',
|
|
20
|
+
transform: 'json',
|
|
21
|
+
})) as { agentRuntimes?: Record<string, string> };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the AgentCore runtime ARN for a connected agent or MCP server
|
|
26
|
+
* from this project's runtime configuration. `name` must match the class
|
|
27
|
+
* name of the target construct (e.g. `MyAgent`, `InventoryMcpServer`).
|
|
28
|
+
*/
|
|
29
|
+
export const getConnectedAgentRuntimeArn = async (
|
|
30
|
+
name: string,
|
|
31
|
+
): Promise<string> => {
|
|
32
|
+
const config = await getAgentCoreRuntimeConfig();
|
|
33
|
+
const arn = config.agentRuntimes?.[name];
|
|
34
|
+
if (!arn) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`No connected agent runtime named '${name}' found in runtime configuration.`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return arn;
|
|
40
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
import boto3
|
|
5
|
+
import httpx
|
|
6
|
+
from a2a.client import ClientConfig
|
|
7
|
+
from strands.agent.a2a_agent import A2AAgent
|
|
8
|
+
|
|
9
|
+
from .auth import SigV4HTTPXAuth
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AgentCoreA2aClient:
|
|
13
|
+
"""Factory for clients to call A2A agents hosted on Bedrock AgentCore Runtime."""
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def _build_url(agent_runtime_arn: str) -> tuple[str, str]:
|
|
17
|
+
"""Extract region from ARN and construct the A2A invocations URL.
|
|
18
|
+
|
|
19
|
+
ARN format: arn:partition:service:region:account-id:resource
|
|
20
|
+
A2A on AgentCore is mounted at `/invocations/` (trailing slash matters).
|
|
21
|
+
"""
|
|
22
|
+
region = agent_runtime_arn.split(":")[3]
|
|
23
|
+
encoded_arn = quote(agent_runtime_arn, safe="")
|
|
24
|
+
url = f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/{encoded_arn}/invocations/"
|
|
25
|
+
return region, url
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _build(
|
|
29
|
+
url: str,
|
|
30
|
+
auth: httpx.Auth | None,
|
|
31
|
+
headers: dict | None,
|
|
32
|
+
*,
|
|
33
|
+
name: str | None,
|
|
34
|
+
description: str | None,
|
|
35
|
+
) -> A2AAgent:
|
|
36
|
+
httpx_client = httpx.AsyncClient(
|
|
37
|
+
auth=auth,
|
|
38
|
+
headers=headers or {},
|
|
39
|
+
timeout=120,
|
|
40
|
+
)
|
|
41
|
+
client_config = ClientConfig(httpx_client=httpx_client, streaming=False)
|
|
42
|
+
kwargs: dict = {"endpoint": url, "client_config": client_config}
|
|
43
|
+
if name:
|
|
44
|
+
kwargs["name"] = name
|
|
45
|
+
if description:
|
|
46
|
+
kwargs["description"] = description
|
|
47
|
+
return A2AAgent(**kwargs)
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def with_iam_auth(
|
|
51
|
+
agent_runtime_arn: str,
|
|
52
|
+
*,
|
|
53
|
+
name: str | None = None,
|
|
54
|
+
description: str | None = None,
|
|
55
|
+
session_id: str | None = None,
|
|
56
|
+
) -> A2AAgent:
|
|
57
|
+
"""Create an `A2AAgent` with IAM (SigV4) authentication."""
|
|
58
|
+
region, url = AgentCoreA2aClient._build_url(agent_runtime_arn)
|
|
59
|
+
credentials = boto3.Session(region_name=region).get_credentials()
|
|
60
|
+
headers = {}
|
|
61
|
+
if session_id:
|
|
62
|
+
headers["X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"] = session_id
|
|
63
|
+
return AgentCoreA2aClient._build(
|
|
64
|
+
url,
|
|
65
|
+
SigV4HTTPXAuth(credentials, "bedrock-agentcore", region),
|
|
66
|
+
headers,
|
|
67
|
+
name=name,
|
|
68
|
+
description=description,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def with_jwt_auth(
|
|
73
|
+
agent_runtime_arn: str,
|
|
74
|
+
access_token_provider: Callable[[], str],
|
|
75
|
+
*,
|
|
76
|
+
name: str | None = None,
|
|
77
|
+
description: str | None = None,
|
|
78
|
+
session_id: str | None = None,
|
|
79
|
+
) -> A2AAgent:
|
|
80
|
+
"""Create an `A2AAgent` with JWT Bearer authentication."""
|
|
81
|
+
_, url = AgentCoreA2aClient._build_url(agent_runtime_arn)
|
|
82
|
+
headers = {"Authorization": f"Bearer {access_token_provider()}"}
|
|
83
|
+
if session_id:
|
|
84
|
+
headers["X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"] = session_id
|
|
85
|
+
return AgentCoreA2aClient._build(
|
|
86
|
+
url,
|
|
87
|
+
None,
|
|
88
|
+
headers,
|
|
89
|
+
name=name,
|
|
90
|
+
description=description,
|
|
91
|
+
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
from collections.abc import Generator
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from botocore.auth import SigV4Auth
|
|
7
|
+
from botocore.awsrequest import AWSRequest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SigV4HTTPXAuth(httpx.Auth):
|
|
11
|
+
"""HTTPX Auth class that signs requests with AWS SigV4.
|
|
12
|
+
|
|
13
|
+
The target AWS service (e.g. ``bedrock-agentcore``) is passed as a
|
|
14
|
+
parameter so the same auth class can be reused across different
|
|
15
|
+
AgentCore resource types (A2A agents, MCP servers, etc.).
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
requires_request_body = True
|
|
19
|
+
|
|
20
|
+
def __init__(self, credentials: Any, service: str, region: str):
|
|
21
|
+
self.credentials = credentials
|
|
22
|
+
self.service = service
|
|
23
|
+
self.region = region
|
|
24
|
+
self.signer = SigV4Auth(credentials, service, region)
|
|
25
|
+
|
|
26
|
+
def auth_flow(
|
|
27
|
+
self, request: httpx.Request
|
|
28
|
+
) -> Generator[httpx.Request, httpx.Response, None]:
|
|
29
|
+
headers = dict(request.headers)
|
|
30
|
+
|
|
31
|
+
headers.pop("connection", None)
|
|
32
|
+
headers["x-amz-content-sha256"] = hashlib.sha256(
|
|
33
|
+
request.content if request.content else b""
|
|
34
|
+
).hexdigest()
|
|
35
|
+
|
|
36
|
+
aws_request = AWSRequest(
|
|
37
|
+
method=request.method,
|
|
38
|
+
url=str(request.url),
|
|
39
|
+
data=request.content,
|
|
40
|
+
headers=headers,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
self.signer.add_auth(aws_request)
|
|
44
|
+
|
|
45
|
+
request.headers.clear()
|
|
46
|
+
request.headers.update(dict(aws_request.headers))
|
|
47
|
+
|
|
48
|
+
yield request
|
package/src/utils/agent-connection/files/{py-core → py-core-mcp}/agentcore_mcp_client.py.template
RENAMED
|
@@ -1,43 +1,9 @@
|
|
|
1
|
-
import hashlib
|
|
2
|
-
from collections.abc import Generator
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
1
|
import boto3
|
|
6
2
|
import httpx
|
|
7
|
-
from botocore.auth import SigV4Auth
|
|
8
|
-
from botocore.awsrequest import AWSRequest
|
|
9
3
|
from mcp.client.streamable_http import streamablehttp_client
|
|
10
4
|
from strands.tools.mcp.mcp_client import MCPClient
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
class SigV4HTTPXAuth(httpx.Auth):
|
|
14
|
-
"""HTTPX Auth class that signs requests with AWS SigV4."""
|
|
15
|
-
|
|
16
|
-
def __init__(self, credentials: Any, region: str):
|
|
17
|
-
self.credentials = credentials
|
|
18
|
-
self.service = "bedrock-agentcore"
|
|
19
|
-
self.region = region
|
|
20
|
-
self.signer = SigV4Auth(credentials, self.service, region)
|
|
21
|
-
|
|
22
|
-
def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
|
|
23
|
-
headers = dict(request.headers)
|
|
24
|
-
|
|
25
|
-
headers.pop("connection", None)
|
|
26
|
-
headers["x-amz-content-sha256"] = hashlib.sha256(request.content if request.content else b"").hexdigest()
|
|
27
|
-
|
|
28
|
-
aws_request = AWSRequest(
|
|
29
|
-
method=request.method,
|
|
30
|
-
url=str(request.url),
|
|
31
|
-
data=request.content,
|
|
32
|
-
headers=headers,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
self.signer.add_auth(aws_request)
|
|
36
|
-
|
|
37
|
-
request.headers.clear()
|
|
38
|
-
request.headers.update(dict(aws_request.headers))
|
|
39
|
-
|
|
40
|
-
yield request
|
|
6
|
+
from .auth import SigV4HTTPXAuth
|
|
41
7
|
|
|
42
8
|
|
|
43
9
|
class AgentCoreMCPClient:
|
|
@@ -88,7 +54,7 @@ class AgentCoreMCPClient:
|
|
|
88
54
|
return AgentCoreMCPClient._create(
|
|
89
55
|
agent_runtime_arn=agent_runtime_arn,
|
|
90
56
|
session_id=session_id,
|
|
91
|
-
auth_handler=SigV4HTTPXAuth(credentials, region),
|
|
57
|
+
auth_handler=SigV4HTTPXAuth(credentials, "bedrock-agentcore", region),
|
|
92
58
|
)
|
|
93
59
|
|
|
94
60
|
@staticmethod
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from aws_lambda_powertools.utilities import parameters
|
|
4
|
+
from botocore.config import Config
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _get_agentcore_runtime_config() -> dict:
|
|
8
|
+
"""Read the runtime-config ``agentcore`` namespace from AppConfig.
|
|
9
|
+
|
|
10
|
+
``RUNTIME_CONFIG_APP_ID`` is set on the AgentCore runtime by the generated
|
|
11
|
+
CDK/Terraform construct for this project.
|
|
12
|
+
"""
|
|
13
|
+
application = os.environ.get("RUNTIME_CONFIG_APP_ID")
|
|
14
|
+
if not application:
|
|
15
|
+
raise RuntimeError(
|
|
16
|
+
"RUNTIME_CONFIG_APP_ID is not set — cannot resolve connected agent ARNs from AppConfig."
|
|
17
|
+
)
|
|
18
|
+
region = os.environ.get("AWS_REGION", os.environ.get("AWS_DEFAULT_REGION"))
|
|
19
|
+
provider_kwargs = {}
|
|
20
|
+
if region:
|
|
21
|
+
provider_kwargs["config"] = Config(region_name=region)
|
|
22
|
+
provider = parameters.AppConfigProvider(
|
|
23
|
+
environment="default",
|
|
24
|
+
application=application,
|
|
25
|
+
**provider_kwargs,
|
|
26
|
+
)
|
|
27
|
+
return provider.get("agentcore", transform="json")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_connected_agent_runtime_arn(name: str) -> str:
|
|
31
|
+
"""Resolve the AgentCore runtime ARN for a connected agent or MCP server
|
|
32
|
+
from this project's runtime configuration.
|
|
33
|
+
|
|
34
|
+
``name`` must match the class name of the target construct
|
|
35
|
+
(e.g. ``MyAgent``, ``InventoryMcpServer``).
|
|
36
|
+
"""
|
|
37
|
+
config = _get_agentcore_runtime_config()
|
|
38
|
+
agent_runtimes = config.get("agentRuntimes", {}) if config else {}
|
|
39
|
+
arn = agent_runtimes.get(name)
|
|
40
|
+
if not arn:
|
|
41
|
+
raise RuntimeError(
|
|
42
|
+
f"No connected agent runtime named '{name}' found in runtime configuration."
|
|
43
|
+
)
|
|
44
|
+
return arn
|
|
@@ -14,7 +14,7 @@ export interface AddAgentCoreInfraProps {
|
|
|
14
14
|
projectName: string;
|
|
15
15
|
dockerImageTag: string;
|
|
16
16
|
appDirectory: string;
|
|
17
|
-
serverProtocol: 'MCP' | 'HTTP';
|
|
17
|
+
serverProtocol: 'MCP' | 'HTTP' | 'A2A';
|
|
18
18
|
auth: AgentCoreAuth;
|
|
19
19
|
}
|
|
20
20
|
export interface AddMcpServerInfraProps {
|
|
@@ -34,9 +34,10 @@ export interface AddAgentInfraProps {
|
|
|
34
34
|
projectName: string;
|
|
35
35
|
dockerImageTag: string;
|
|
36
36
|
auth: AgentCoreAuth;
|
|
37
|
+
serverProtocol?: 'HTTP' | 'A2A';
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
|
-
* Add an
|
|
40
|
+
* Add an agent CDK construct
|
|
40
41
|
*/
|
|
41
42
|
export declare const addAgentInfra: (tree: Tree, options: AddAgentInfraProps & IACProvider) => Promise<void>;
|
|
42
43
|
export {};
|
|
@@ -73,7 +73,7 @@ const addMcpServerInfra = async (tree, options) => {
|
|
|
73
73
|
};
|
|
74
74
|
exports.addMcpServerInfra = addMcpServerInfra;
|
|
75
75
|
/**
|
|
76
|
-
* Add an
|
|
76
|
+
* Add an agent CDK construct
|
|
77
77
|
*/
|
|
78
78
|
const addAgentInfra = async (tree, options) => {
|
|
79
79
|
await addAgentCoreInfra(tree, {
|
|
@@ -82,7 +82,7 @@ const addAgentInfra = async (tree, options) => {
|
|
|
82
82
|
projectName: options.projectName,
|
|
83
83
|
dockerImageTag: options.dockerImageTag,
|
|
84
84
|
appDirectory: 'agents',
|
|
85
|
-
serverProtocol: 'HTTP',
|
|
85
|
+
serverProtocol: options.serverProtocol ?? 'HTTP',
|
|
86
86
|
iacProvider: options.iacProvider,
|
|
87
87
|
auth: options.auth,
|
|
88
88
|
});
|