@aws/nx-plugin 0.98.0 → 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 +3 -3
- 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/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 +8 -0
- package/src/py/strands-agent/react-connection/generator.js.map +1 -1
- 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/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 +8 -0
- package/src/ts/strands-agent/react-connection/generator.js.map +1 -1
- 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/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +2 -2
- 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 +1 -0
- package/src/utils/versions.js +1 -0
- package/src/utils/versions.js.map +1 -1
|
@@ -83,33 +83,18 @@ export class AgentCoreMcpClient {
|
|
|
83
83
|
const {
|
|
84
84
|
url,
|
|
85
85
|
sessionId = randomUUID(),
|
|
86
|
-
buildHeaders = async () => ({}),
|
|
86
|
+
buildHeaders = async (): Promise<Record<string, string>> => ({}),
|
|
87
87
|
fetch: customFetch,
|
|
88
88
|
} = options;
|
|
89
89
|
|
|
90
90
|
// Create a custom fetch that adds required headers
|
|
91
91
|
const fetchWithHeaders: typeof fetch = async (input, init) => {
|
|
92
|
-
const headers =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const mergedInit = {
|
|
99
|
-
...init,
|
|
100
|
-
headers: !existingHeaders
|
|
101
|
-
? headers
|
|
102
|
-
: existingHeaders instanceof Headers
|
|
103
|
-
? (() => {
|
|
104
|
-
const h = new Headers(existingHeaders);
|
|
105
|
-
Object.entries(headers).forEach(([k, v]) => h.append(k, v));
|
|
106
|
-
return h;
|
|
107
|
-
})()
|
|
108
|
-
: Array.isArray(existingHeaders)
|
|
109
|
-
? [...existingHeaders, ...Object.entries(headers)]
|
|
110
|
-
: { ...existingHeaders, ...headers },
|
|
111
|
-
};
|
|
112
|
-
return (customFetch || fetch)(input, mergedInit);
|
|
92
|
+
const headers = new Headers(init?.headers);
|
|
93
|
+
headers.set('X-Amzn-Bedrock-AgentCore-Runtime-Session-Id', sessionId);
|
|
94
|
+
for (const [k, v] of Object.entries(await buildHeaders())) {
|
|
95
|
+
headers.set(k, v);
|
|
96
|
+
}
|
|
97
|
+
return (customFetch || fetch)(input, { ...init, headers });
|
|
113
98
|
};
|
|
114
99
|
|
|
115
100
|
// Create the transport
|
|
@@ -171,7 +156,7 @@ exports[`ts#strands-agent#mcp-connection generator > should match snapshot for a
|
|
|
171
156
|
"import { McpClient } from '@strands-agents/sdk';
|
|
172
157
|
import { AgentCoreMcpClient } from '../core/agentcore-mcp-client.js';
|
|
173
158
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
174
|
-
import {
|
|
159
|
+
import { getConnectedAgentRuntimeArn } from '../core/runtime-config.js';
|
|
175
160
|
|
|
176
161
|
/**
|
|
177
162
|
* Client for connecting to the InventoryMcp MCP server.
|
|
@@ -192,15 +177,8 @@ export class InventoryMcpClient {
|
|
|
192
177
|
return new McpClient({ transport });
|
|
193
178
|
}
|
|
194
179
|
|
|
195
|
-
// Deployed: resolve ARN from runtime config, use AgentCore transport
|
|
196
|
-
const config = (await getAppConfig('connection', {
|
|
197
|
-
application: process.env.RUNTIME_CONFIG_APP_ID!,
|
|
198
|
-
environment: 'default',
|
|
199
|
-
transform: 'json',
|
|
200
|
-
})) as Record<string, any>;
|
|
201
|
-
|
|
202
180
|
return AgentCoreMcpClient.withIamAuth({
|
|
203
|
-
agentRuntimeArn:
|
|
181
|
+
agentRuntimeArn: await getConnectedAgentRuntimeArn('InventoryMcp'),
|
|
204
182
|
sessionId,
|
|
205
183
|
});
|
|
206
184
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { McpClient } from '@strands-agents/sdk';
|
|
2
2
|
import { AgentCoreMcpClient } from '../core/agentcore-mcp-client.js';
|
|
3
3
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getConnectedAgentRuntimeArn } from '../core/runtime-config.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Client for connecting to the <%- mcpServerClassName %> MCP server.
|
|
@@ -22,15 +22,8 @@ export class <%- mcpServerClassName %>Client {
|
|
|
22
22
|
return new McpClient({ transport });
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// Deployed: resolve ARN from runtime config, use AgentCore transport
|
|
26
|
-
const config = (await getAppConfig('connection', {
|
|
27
|
-
application: process.env.RUNTIME_CONFIG_APP_ID!,
|
|
28
|
-
environment: 'default',
|
|
29
|
-
transform: 'json',
|
|
30
|
-
})) as Record<string, any>;
|
|
31
|
-
|
|
32
25
|
return AgentCoreMcpClient.withIamAuth({
|
|
33
|
-
agentRuntimeArn:
|
|
26
|
+
agentRuntimeArn: await getConnectedAgentRuntimeArn('<%- mcpServerClassName %>'),
|
|
34
27
|
sessionId,
|
|
35
28
|
});
|
|
36
29
|
}
|
|
@@ -31,8 +31,9 @@ const tsStrandsAgentMcpConnectionGenerator = async (tree, options) => {
|
|
|
31
31
|
const mcpServerKebabCase = (0, names_1.kebabCase)(mcpServerClassName);
|
|
32
32
|
const mcpServerPort = mcpComponent.port ?? 8000;
|
|
33
33
|
const npmScope = (0, npm_scope_1.getNpmScope)(tree);
|
|
34
|
-
// 1. Ensure the shared agent-connection project exists
|
|
34
|
+
// 1. Ensure the shared agent-connection project exists + has the MCP core client
|
|
35
35
|
await (0, agent_connection_1.ensureTypeScriptAgentConnectionProject)(tree);
|
|
36
|
+
(0, agent_connection_1.addTypeScriptCoreClient)(tree, 'mcp');
|
|
36
37
|
// 2. Generate the per-connection <Name>Client into app/
|
|
37
38
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'agent-connection', 'app'), (0, devkit_1.joinPathFragments)(agent_connection_1.AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
|
|
38
39
|
mcpServerKebabCase,
|
|
@@ -78,9 +79,10 @@ const tsStrandsAgentMcpConnectionGenerator = async (tree, options) => {
|
|
|
78
79
|
];
|
|
79
80
|
(0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
|
|
80
81
|
}
|
|
81
|
-
// 5. Add dependencies
|
|
82
|
+
// 5. Add dependencies required by the MCP core client + vended client
|
|
82
83
|
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
83
84
|
'@modelcontextprotocol/sdk',
|
|
85
|
+
'@strands-agents/sdk',
|
|
84
86
|
'@aws-lambda-powertools/parameters',
|
|
85
87
|
'@aws-sdk/client-appconfigdata',
|
|
86
88
|
'aws4fetch',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/mcp-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,0CAI2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAC7D,gDAAiD;AACjD,sDAAuD;AACvD,wDAAuD;AACvD,4CAI4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/mcp-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,0CAI2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAC7D,gDAAiD;AACjD,sDAAuD;AACvD,wDAAuD;AACvD,4CAI4B;AAC5B,uFAI0D;AAE7C,QAAA,8CAA8C,GACzD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,oCAAoC,GAAG,KAAK,EACvD,IAAU,EACV,OAAmD,EACvB,EAAE;IAC9B,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAC/C,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IAE7C,IAAI,CAAC,cAAc,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,mGAAmG,CACpG,CAAC;IACJ,CAAC;IAED,IAAI,YAAY,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,0EAA0E,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AE,aAAa,CAAC,CAAC;IACtE,CAAC;IAED,sEAAsE;IACtE,IAAA,qCAA4B,EAC1B,IAAI,EACJ,IAAA,uBAAY,EAAC;QACX,2BAA2B;QAC3B,qBAAqB;QACrB,mCAAmC;QACnC,+BAA+B;QAC/B,WAAW;QACX,+BAA+B;KAChC,CAAC,EACF,EAAE,CACH,CAAC;IAEF,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;QAC1C,sDAA8C;KAC/C,CAAC,CAAC;IAEH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC,CAAC;AA/IW,QAAA,oCAAoC,wCA+I/C;AAEF,kBAAe,4CAAoC,CAAC"}
|
|
@@ -16,6 +16,7 @@ const format_1 = require("../../../utils/format");
|
|
|
16
16
|
const nx_1 = require("../../../utils/nx");
|
|
17
17
|
const metrics_1 = require("../../../utils/metrics");
|
|
18
18
|
const serve_local_1 = require("./serve-local");
|
|
19
|
+
const agent_runtime_config_1 = require("../../../connection/agent-runtime-config");
|
|
19
20
|
exports.TS_STRANDS_AGENT_REACT_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
20
21
|
async function tsStrandsAgentReactConnectionGenerator(tree, options) {
|
|
21
22
|
const frontendProjectConfig = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
|
|
@@ -72,6 +73,13 @@ async function tsStrandsAgentReactConnectionGenerator(tree, options) {
|
|
|
72
73
|
port: agentPort,
|
|
73
74
|
targetComponent,
|
|
74
75
|
});
|
|
76
|
+
// Expose the agent's runtime ARN to the frontend via the 'connection'
|
|
77
|
+
// namespace (which is published to runtime-config.json). The agent construct
|
|
78
|
+
// itself only registers to the 'agentcore' namespace by default.
|
|
79
|
+
await (0, agent_runtime_config_1.addAgentRuntimeToConnectionNamespace)(tree, {
|
|
80
|
+
agentNameKebabCase: (0, names_1.kebabCase)(agentNameClassName),
|
|
81
|
+
agentNameClassName,
|
|
82
|
+
});
|
|
75
83
|
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
76
84
|
'@trpc/client',
|
|
77
85
|
'@tanstack/react-query',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/react-connection/generator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/react-connection/generator.ts"],"names":[],"mappings":";;;AAiCA,wFAwKC;AAzMD;;;GAGG;AACH,uCAQoB;AACpB,4EAAsF;AACtF,wDAAwD;AACxD,sDAAuD;AACvD,4CAAkE;AAClE,gDAA8D;AAC9D,kDAA6D;AAC7D,0CAK2B;AAC3B,oDAAyE;AACzE,+CAAkE;AAElE,mFAAgG;AAEnF,QAAA,gDAAgD,GAC3D,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,KAAK,UAAU,sCAAsC,CAC1D,IAAU,EACV,OAAkC;IAElC,MAAM,qBAAqB,GAAG,IAAA,wCAAmC,EAC/D,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IACF,MAAM,kBAAkB,GAAG,IAAA,wCAAmC,EAC5D,IAAI,EACJ,OAAO,CAAC,aAAa,CACtB,CAAC;IAEF,MAAM,eAAe,GACnB,OAAO,CAAC,eAAe,CAAC;IAE1B,uEAAuE;IACvE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAe,CAAC;IACpD,MAAM,SAAS,GAAG,eAAe,EAAE,IAAI,IAAI,OAAO,CAAC;IACnD,MAAM,kBAAkB,GAAG,eAAe,EAAE,EAAE,IAAI,IAAA,mBAAW,EAAC,SAAS,CAAC,CAAC;IACzE,MAAM,SAAS,GAAG,eAAe,EAAE,IAAI,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K,CAAC,gBAAgB,CAAC,GAAG,aAAa,CAAC;QAC1C,CAAC;QACD,6CAA6C;QAC7C,MAAM,cAAc,GAAG,GAAG,WAAW,IAAI,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;YAC3B,KAAK,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC;QACxC,CAAC;QACD,IAAI,CAAC,eAAe,GAAG;YACrB,GAAG,IAAI,CAAC,eAAe;YACvB,KAAK;SACN,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -17,15 +17,43 @@ export declare function getPythonAgentConnectionModuleName(tree: Tree): string;
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function getPythonAgentConnectionPackageName(tree: Tree): string;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Directories (relative to this file) holding per-protocol core client
|
|
21
|
+
* template files. Per-connection generators select which set to emit so
|
|
22
|
+
* the MCP connection doesn't pull in the A2A client (or vice versa).
|
|
23
|
+
*/
|
|
24
|
+
export declare const TS_CORE_TEMPLATES: {
|
|
25
|
+
readonly mcp: "core-mcp";
|
|
26
|
+
readonly a2a: "core-a2a";
|
|
27
|
+
};
|
|
28
|
+
export declare const PY_CORE_TEMPLATES: {
|
|
29
|
+
readonly mcp: "py-core-mcp";
|
|
30
|
+
readonly a2a: "py-core-a2a";
|
|
31
|
+
/** Shared SigV4 `httpx.Auth` used by both MCP and A2A clients. */
|
|
32
|
+
readonly auth: "py-core-auth";
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Ensure the shared TypeScript agent-connection project exists and has the
|
|
36
|
+
* shared core helpers (runtime-config loader). Per-connection generators
|
|
37
|
+
* are responsible for emitting their own per-protocol core client templates.
|
|
22
38
|
*/
|
|
23
39
|
export declare function ensureTypeScriptAgentConnectionProject(tree: Tree): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Emit one of the TypeScript core client templates (mcp or a2a) into the
|
|
42
|
+
* agent-connection project's `src/core/` directory. Safe to call multiple
|
|
43
|
+
* times — `KeepExisting` preserves customised files.
|
|
44
|
+
*/
|
|
45
|
+
export declare function addTypeScriptCoreClient(tree: Tree, kind: keyof typeof TS_CORE_TEMPLATES): void;
|
|
24
46
|
/**
|
|
25
47
|
* Ensure the shared Python agent-connection project exists.
|
|
26
|
-
*
|
|
48
|
+
* Only creates the project shell — per-connection generators are responsible
|
|
49
|
+
* for emitting their own core client templates.
|
|
27
50
|
*/
|
|
28
51
|
export declare function ensurePythonAgentConnectionProject(tree: Tree): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Emit a Python core client template (mcp / a2a / shared auth) into the
|
|
54
|
+
* agent-connection project's core directory.
|
|
55
|
+
*/
|
|
56
|
+
export declare function addPythonCoreClient(tree: Tree, kind: keyof typeof PY_CORE_TEMPLATES): void;
|
|
29
57
|
/**
|
|
30
58
|
* Add a re-export to the Python agent-connection module's __init__.py.
|
|
31
59
|
* Equivalent to addStarExport for TS.
|
|
@@ -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;AAC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,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
|
+
};
|