@aws/nx-plugin 1.0.0-rc.36 → 1.0.0-rc.37
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/package.json +1 -1
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +19 -3
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +2 -2
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +17 -1
- package/src/py/agent/files/http/main.py.template +2 -2
- package/src/py/agent/files/http-langchain/main.py.template +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +35 -2
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +38 -6
- package/src/ts/agent/files/http/router.ts.template +2 -2
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +35 -2
- package/src/utils/agent-chat/files/http-py/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +24 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +5 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +12 -1
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ CMD ["python", "bin/opentelemetry-instrument", "python", "-m", "proj_test_projec
|
|
|
20
20
|
`;
|
|
21
21
|
|
|
22
22
|
exports[`py#agent generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > agent-construct.ts 1`] = `
|
|
23
|
-
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
23
|
+
"import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
24
24
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
25
25
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
26
26
|
import { Construct } from 'constructs';
|
|
@@ -121,6 +121,22 @@ export class SnapshotBedrockAgent
|
|
|
121
121
|
return this.agentCoreRuntime.connections;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* The HTTPS invocation URL of the runtime.
|
|
126
|
+
*/
|
|
127
|
+
public get invocationUrl(): string {
|
|
128
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
129
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
130
|
+
const encodedArn = Fn.join(
|
|
131
|
+
'%2F',
|
|
132
|
+
Fn.split(
|
|
133
|
+
'/',
|
|
134
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
|
|
138
|
+
}
|
|
139
|
+
|
|
124
140
|
/**
|
|
125
141
|
* Grants IAM permissions to invoke this agent runtime.
|
|
126
142
|
*
|
|
@@ -215,7 +231,7 @@ _agent = _agent_ctx.__enter__()
|
|
|
215
231
|
|
|
216
232
|
|
|
217
233
|
class InvokeInput(BaseModel):
|
|
218
|
-
|
|
234
|
+
prompt: str = Field(max_length=100000)
|
|
219
235
|
|
|
220
236
|
|
|
221
237
|
class StreamChunk(BaseModel):
|
|
@@ -224,7 +240,7 @@ class StreamChunk(BaseModel):
|
|
|
224
240
|
|
|
225
241
|
async def handle_invoke(input: InvokeInput):
|
|
226
242
|
"""Streaming handler for agent invocation"""
|
|
227
|
-
stream = _agent.stream_async(input.
|
|
243
|
+
stream = _agent.stream_async(input.prompt)
|
|
228
244
|
async for event in stream:
|
|
229
245
|
text = (
|
|
230
246
|
event.get("event", {})
|
|
@@ -454,7 +454,7 @@ class TestProjectAgentAdapter implements ChatAdapter {
|
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
async *sendMessage(text: string): AsyncIterable<string> {
|
|
457
|
-
for await (const chunk of this.client.invoke({
|
|
457
|
+
for await (const chunk of this.client.invoke({ prompt: text })) {
|
|
458
458
|
if (typeof chunk.content === 'string') yield chunk.content;
|
|
459
459
|
}
|
|
460
460
|
}
|
|
@@ -559,7 +559,7 @@ class TestProjectAgentAdapter implements ChatAdapter {
|
|
|
559
559
|
}
|
|
560
560
|
|
|
561
561
|
async *sendMessage(text: string): AsyncIterable<string> {
|
|
562
|
-
for await (const chunk of this.client.invoke({
|
|
562
|
+
for await (const chunk of this.client.invoke({ prompt: text })) {
|
|
563
563
|
if (typeof chunk.content === 'string') yield chunk.content;
|
|
564
564
|
}
|
|
565
565
|
}
|
|
@@ -110,6 +110,11 @@ output "agent_core_runtime_arn" {
|
|
|
110
110
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
output "invocation_url" {
|
|
114
|
+
description = "HTTPS invocation URL of the runtime"
|
|
115
|
+
value = module.agent_core_runtime.invocation_url
|
|
116
|
+
}
|
|
117
|
+
|
|
113
118
|
output "appconfig_application_id" {
|
|
114
119
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
115
120
|
value = var.appconfig_application_id
|
|
@@ -583,6 +588,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
583
588
|
}
|
|
584
589
|
|
|
585
590
|
# Outputs
|
|
591
|
+
locals {
|
|
592
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
593
|
+
# wait until the runtime serves MCP.
|
|
594
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
595
|
+
}
|
|
596
|
+
|
|
586
597
|
output "agent_core_runtime_role_arn" {
|
|
587
598
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
588
599
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -600,7 +611,12 @@ output "agent_runtime_name" {
|
|
|
600
611
|
|
|
601
612
|
output "agent_core_runtime_arn" {
|
|
602
613
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
603
|
-
value =
|
|
614
|
+
value = local.ready_runtime_arn
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
output "invocation_url" {
|
|
618
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
619
|
+
value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
604
620
|
}
|
|
605
621
|
|
|
606
622
|
output "agent_runtime_id" {
|
|
@@ -21,7 +21,7 @@ _agent = _agent_ctx.__enter__()
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class InvokeInput(BaseModel):
|
|
24
|
-
|
|
24
|
+
prompt: str = Field(max_length=100000)
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class StreamChunk(BaseModel):
|
|
@@ -30,7 +30,7 @@ class StreamChunk(BaseModel):
|
|
|
30
30
|
|
|
31
31
|
async def handle_invoke(input: InvokeInput):
|
|
32
32
|
"""Streaming handler for agent invocation"""
|
|
33
|
-
stream = _agent.stream_async(input.
|
|
33
|
+
stream = _agent.stream_async(input.prompt)
|
|
34
34
|
async for event in stream:
|
|
35
35
|
text = event.get("event", {}).get("contentBlockDelta", {}).get("delta", {}).get("text")
|
|
36
36
|
if text is not None:
|
|
@@ -16,7 +16,7 @@ _graph = get_agent()
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class InvokeInput(BaseModel):
|
|
19
|
-
|
|
19
|
+
prompt: str = Field(max_length=100000)
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class StreamChunk(BaseModel):
|
|
@@ -41,7 +41,7 @@ async def handle_invoke(input: InvokeInput, session_id: str):
|
|
|
41
41
|
# Re-bind the session: the streaming body runs outside the middleware scope.
|
|
42
42
|
with session_id_context(session_id):
|
|
43
43
|
stream = _graph.astream(
|
|
44
|
-
{"messages": [{"role": "user", "content": input.
|
|
44
|
+
{"messages": [{"role": "user", "content": input.prompt}]},
|
|
45
45
|
config,
|
|
46
46
|
stream_mode="messages",
|
|
47
47
|
)
|
|
@@ -14,7 +14,7 @@ export * from './workspace.js';
|
|
|
14
14
|
`;
|
|
15
15
|
|
|
16
16
|
exports[`py#mcp-server generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > mcp-server-construct.ts 1`] = `
|
|
17
|
-
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
17
|
+
"import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
18
18
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
19
19
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
20
20
|
import { Construct } from 'constructs';
|
|
@@ -102,6 +102,23 @@ export class SnapshotBedrockServer
|
|
|
102
102
|
return this.agentCoreRuntime.connections;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The MCP endpoint URL of the runtime, e.g. for use as a Gateway target
|
|
107
|
+
* endpoint.
|
|
108
|
+
*/
|
|
109
|
+
public get invocationUrl(): string {
|
|
110
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
111
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
112
|
+
const encodedArn = Fn.join(
|
|
113
|
+
'%2F',
|
|
114
|
+
Fn.split(
|
|
115
|
+
'/',
|
|
116
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
|
|
120
|
+
}
|
|
121
|
+
|
|
105
122
|
/**
|
|
106
123
|
* Grants IAM permissions to invoke this agent runtime.
|
|
107
124
|
*
|
|
@@ -589,6 +606,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
589
606
|
}
|
|
590
607
|
|
|
591
608
|
# Outputs
|
|
609
|
+
locals {
|
|
610
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
611
|
+
# wait until the runtime serves MCP.
|
|
612
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
613
|
+
}
|
|
614
|
+
|
|
592
615
|
output "agent_core_runtime_role_arn" {
|
|
593
616
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
594
617
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -606,7 +629,12 @@ output "agent_runtime_name" {
|
|
|
606
629
|
|
|
607
630
|
output "agent_core_runtime_arn" {
|
|
608
631
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
609
|
-
value =
|
|
632
|
+
value = local.ready_runtime_arn
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
output "invocation_url" {
|
|
636
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
637
|
+
value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
610
638
|
}
|
|
611
639
|
|
|
612
640
|
output "agent_runtime_id" {
|
|
@@ -724,6 +752,11 @@ output "agent_core_runtime_arn" {
|
|
|
724
752
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
725
753
|
}
|
|
726
754
|
|
|
755
|
+
output "invocation_url" {
|
|
756
|
+
description = "HTTPS invocation URL of the runtime (the MCP endpoint, e.g. for use as a Gateway target endpoint)"
|
|
757
|
+
value = module.agent_core_runtime.invocation_url
|
|
758
|
+
}
|
|
759
|
+
|
|
727
760
|
output "appconfig_application_id" {
|
|
728
761
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
729
762
|
value = var.appconfig_application_id
|
|
@@ -444,7 +444,7 @@ class TrpcWebSocketAdapter implements ChatAdapter {
|
|
|
444
444
|
const stream = new ReadableStream<string>({
|
|
445
445
|
start: (controller) => {
|
|
446
446
|
this.client.invoke.subscribe(
|
|
447
|
-
{
|
|
447
|
+
{ prompt: text },
|
|
448
448
|
{
|
|
449
449
|
onData: (chunk: string) => controller.enqueue(chunk),
|
|
450
450
|
onComplete: () => controller.close(),
|
|
@@ -546,7 +546,7 @@ class TrpcWebSocketAdapter implements ChatAdapter {
|
|
|
546
546
|
const stream = new ReadableStream<string>({
|
|
547
547
|
start: (controller) => {
|
|
548
548
|
this.client.invoke.subscribe(
|
|
549
|
-
{
|
|
549
|
+
{ prompt: text },
|
|
550
550
|
{
|
|
551
551
|
onData: (chunk: string) => controller.enqueue(chunk),
|
|
552
552
|
onComplete: () => controller.close(),
|
|
@@ -585,7 +585,7 @@ CMD [ "node", "--require", "@aws/aws-distro-opentelemetry-node-autoinstrumentati
|
|
|
585
585
|
`;
|
|
586
586
|
|
|
587
587
|
exports[`ts#agent generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > agent-construct.ts 1`] = `
|
|
588
|
-
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
588
|
+
"import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
589
589
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
590
590
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
591
591
|
import { Construct } from 'constructs';
|
|
@@ -686,6 +686,22 @@ export class SnapshotBedrockAgent
|
|
|
686
686
|
return this.agentCoreRuntime.connections;
|
|
687
687
|
}
|
|
688
688
|
|
|
689
|
+
/**
|
|
690
|
+
* The HTTPS invocation URL of the runtime.
|
|
691
|
+
*/
|
|
692
|
+
public get invocationUrl(): string {
|
|
693
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
694
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
695
|
+
const encodedArn = Fn.join(
|
|
696
|
+
'%2F',
|
|
697
|
+
Fn.split(
|
|
698
|
+
'/',
|
|
699
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
700
|
+
),
|
|
701
|
+
);
|
|
702
|
+
return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
|
|
703
|
+
}
|
|
704
|
+
|
|
689
705
|
/**
|
|
690
706
|
* Grants IAM permissions to invoke this agent runtime.
|
|
691
707
|
*
|
|
@@ -835,6 +851,11 @@ output "agent_core_runtime_arn" {
|
|
|
835
851
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
836
852
|
}
|
|
837
853
|
|
|
854
|
+
output "invocation_url" {
|
|
855
|
+
description = "HTTPS invocation URL of the runtime"
|
|
856
|
+
value = module.agent_core_runtime.invocation_url
|
|
857
|
+
}
|
|
858
|
+
|
|
838
859
|
output "appconfig_application_id" {
|
|
839
860
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
840
861
|
value = var.appconfig_application_id
|
|
@@ -1308,6 +1329,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
1308
1329
|
}
|
|
1309
1330
|
|
|
1310
1331
|
# Outputs
|
|
1332
|
+
locals {
|
|
1333
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
1334
|
+
# wait until the runtime serves MCP.
|
|
1335
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1311
1338
|
output "agent_core_runtime_role_arn" {
|
|
1312
1339
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
1313
1340
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -1325,7 +1352,12 @@ output "agent_runtime_name" {
|
|
|
1325
1352
|
|
|
1326
1353
|
output "agent_core_runtime_arn" {
|
|
1327
1354
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
1328
|
-
value =
|
|
1355
|
+
value = local.ready_runtime_arn
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
output "invocation_url" {
|
|
1359
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
1360
|
+
value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
1329
1361
|
}
|
|
1330
1362
|
|
|
1331
1363
|
output "agent_runtime_id" {
|
|
@@ -1661,7 +1693,7 @@ const agent = withSessionId(getAgent);
|
|
|
1661
1693
|
|
|
1662
1694
|
export const appRouter = router({
|
|
1663
1695
|
invoke: publicProcedure
|
|
1664
|
-
.input(z.object({
|
|
1696
|
+
.input(z.object({ prompt: z.string().max(100000) }))
|
|
1665
1697
|
.output(
|
|
1666
1698
|
zAsyncIterable({
|
|
1667
1699
|
yield: z.string(),
|
|
@@ -1671,7 +1703,7 @@ export const appRouter = router({
|
|
|
1671
1703
|
.subscription(async function* (opts) {
|
|
1672
1704
|
// Bind the session ID for this subscription so downstream MCP / A2A clients forward it on outbound calls.
|
|
1673
1705
|
enterSessionContext(opts.ctx.sessionId);
|
|
1674
|
-
for await (const event of agent.stream(opts.input.
|
|
1706
|
+
for await (const event of agent.stream(opts.input.prompt)) {
|
|
1675
1707
|
if (
|
|
1676
1708
|
event.type === 'modelStreamUpdateEvent' &&
|
|
1677
1709
|
event.event.type === 'modelContentBlockDeltaEvent' &&
|
|
@@ -10,7 +10,7 @@ const agent = withSessionId(getAgent);
|
|
|
10
10
|
|
|
11
11
|
export const appRouter = router({
|
|
12
12
|
invoke: publicProcedure
|
|
13
|
-
.input(z.object({
|
|
13
|
+
.input(z.object({ prompt: z.string().max(100000) }))
|
|
14
14
|
.output(
|
|
15
15
|
zAsyncIterable({
|
|
16
16
|
yield: z.string(),
|
|
@@ -20,7 +20,7 @@ export const appRouter = router({
|
|
|
20
20
|
.subscription(async function* (opts) {
|
|
21
21
|
// Bind the session ID for this subscription so downstream MCP / A2A clients forward it on outbound calls.
|
|
22
22
|
enterSessionContext(opts.ctx.sessionId);
|
|
23
|
-
for await (const event of agent.stream(opts.input.
|
|
23
|
+
for await (const event of agent.stream(opts.input.prompt)) {
|
|
24
24
|
if (
|
|
25
25
|
event.type === 'modelStreamUpdateEvent' &&
|
|
26
26
|
event.event.type === 'modelContentBlockDeltaEvent' &&
|
|
@@ -14,7 +14,7 @@ export * from './workspace.js';
|
|
|
14
14
|
`;
|
|
15
15
|
|
|
16
16
|
exports[`ts#mcp-server generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > mcp-server-construct.ts 1`] = `
|
|
17
|
-
"import { Lazy, Names } from 'aws-cdk-lib';
|
|
17
|
+
"import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
18
18
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
19
19
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
20
20
|
import { Construct } from 'constructs';
|
|
@@ -102,6 +102,23 @@ export class SnapshotBedrockServer
|
|
|
102
102
|
return this.agentCoreRuntime.connections;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The MCP endpoint URL of the runtime, e.g. for use as a Gateway target
|
|
107
|
+
* endpoint.
|
|
108
|
+
*/
|
|
109
|
+
public get invocationUrl(): string {
|
|
110
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
111
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
112
|
+
const encodedArn = Fn.join(
|
|
113
|
+
'%2F',
|
|
114
|
+
Fn.split(
|
|
115
|
+
'/',
|
|
116
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
return \`https://bedrock-agentcore.\${Stack.of(this).region}.amazonaws.com/runtimes/\${encodedArn}/invocations?qualifier=DEFAULT\`;
|
|
120
|
+
}
|
|
121
|
+
|
|
105
122
|
/**
|
|
106
123
|
* Grants IAM permissions to invoke this agent runtime.
|
|
107
124
|
*
|
|
@@ -589,6 +606,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
589
606
|
}
|
|
590
607
|
|
|
591
608
|
# Outputs
|
|
609
|
+
locals {
|
|
610
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
611
|
+
# wait until the runtime serves MCP.
|
|
612
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
613
|
+
}
|
|
614
|
+
|
|
592
615
|
output "agent_core_runtime_role_arn" {
|
|
593
616
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
594
617
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -606,7 +629,12 @@ output "agent_runtime_name" {
|
|
|
606
629
|
|
|
607
630
|
output "agent_core_runtime_arn" {
|
|
608
631
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
609
|
-
value =
|
|
632
|
+
value = local.ready_runtime_arn
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
output "invocation_url" {
|
|
636
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
637
|
+
value = "https://bedrock-agentcore.\${local.aws_region}.amazonaws.com/runtimes/\${urlencode(local.ready_runtime_arn)}/invocations\${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
610
638
|
}
|
|
611
639
|
|
|
612
640
|
output "agent_runtime_id" {
|
|
@@ -724,6 +752,11 @@ output "agent_core_runtime_arn" {
|
|
|
724
752
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
725
753
|
}
|
|
726
754
|
|
|
755
|
+
output "invocation_url" {
|
|
756
|
+
description = "HTTPS invocation URL of the runtime (the MCP endpoint, e.g. for use as a Gateway target endpoint)"
|
|
757
|
+
value = module.agent_core_runtime.invocation_url
|
|
758
|
+
}
|
|
759
|
+
|
|
727
760
|
output "appconfig_application_id" {
|
|
728
761
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
729
762
|
value = var.appconfig_application_id
|
|
@@ -34,7 +34,7 @@ class <%- agentNameClassName %>Adapter implements ChatAdapter {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
async *sendMessage(text: string): AsyncIterable<string> {
|
|
37
|
-
for await (const chunk of this.client.invoke({
|
|
37
|
+
for await (const chunk of this.client.invoke({ prompt: text })) {
|
|
38
38
|
if (typeof chunk.content === 'string') yield chunk.content;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -37,7 +37,7 @@ class TrpcWebSocketAdapter implements ChatAdapter {
|
|
|
37
37
|
const stream = new ReadableStream<string>({
|
|
38
38
|
start: (controller) => {
|
|
39
39
|
this.client.invoke.subscribe(
|
|
40
|
-
{
|
|
40
|
+
{ prompt: text },
|
|
41
41
|
{
|
|
42
42
|
onData: (chunk: string) => controller.enqueue(chunk),
|
|
43
43
|
onComplete: () => controller.close(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lazy, Names } from 'aws-cdk-lib';
|
|
1
|
+
import { Fn, Lazy, Names, Stack } from 'aws-cdk-lib';
|
|
2
2
|
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
3
3
|
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
|
|
4
4
|
import { Construct } from 'constructs';
|
|
@@ -136,6 +136,29 @@ export class <%- nameClassName %> extends Construct implements IGrantable, IConn
|
|
|
136
136
|
public get connections(): Connections {
|
|
137
137
|
return this.agentCoreRuntime.connections;
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
<%_ if (serverProtocol === 'mcp') { _%>
|
|
142
|
+
* The MCP endpoint URL of the runtime, e.g. for use as a Gateway target
|
|
143
|
+
* endpoint.
|
|
144
|
+
<%_ } else if (serverProtocol === 'a2a') { _%>
|
|
145
|
+
* The A2A endpoint URL of the runtime (the trailing slash is required).
|
|
146
|
+
<%_ } else { _%>
|
|
147
|
+
* The HTTPS invocation URL of the runtime.
|
|
148
|
+
<%_ } _%>
|
|
149
|
+
*/
|
|
150
|
+
public get invocationUrl(): string {
|
|
151
|
+
// The URL must URL-encode the runtime ARN (':' -> '%3A', '/' -> '%2F').
|
|
152
|
+
// The ARN is a CDK token, so encode at deploy time via Fn.join/Fn.split.
|
|
153
|
+
const encodedArn = Fn.join(
|
|
154
|
+
'%2F',
|
|
155
|
+
Fn.split(
|
|
156
|
+
'/',
|
|
157
|
+
Fn.join('%3A', Fn.split(':', this.agentCoreRuntime.agentRuntimeArn)),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
return `https://bedrock-agentcore.${Stack.of(this).region}.amazonaws.com/runtimes/${encodedArn}/invocations<%- serverProtocol === 'a2a' ? '/' : '?qualifier=DEFAULT' %>`;
|
|
161
|
+
}
|
|
139
162
|
<%_ if (auth === 'iam') { _%>
|
|
140
163
|
|
|
141
164
|
/**
|
|
@@ -133,6 +133,11 @@ output "agent_core_runtime_arn" {
|
|
|
133
133
|
value = module.agent_core_runtime.agent_core_runtime_arn
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
output "invocation_url" {
|
|
137
|
+
description = "HTTPS invocation URL of the runtime<% if (serverProtocol === 'mcp') { %> (the MCP endpoint, e.g. for use as a Gateway target endpoint)<% } else if (serverProtocol === 'a2a') { %> (the A2A endpoint)<% } %>"
|
|
138
|
+
value = module.agent_core_runtime.invocation_url
|
|
139
|
+
}
|
|
140
|
+
|
|
136
141
|
output "appconfig_application_id" {
|
|
137
142
|
description = "AppConfig Application ID for runtime config (passthrough of the shared `appconfig_application_id` input)."
|
|
138
143
|
value = var.appconfig_application_id
|
|
@@ -458,6 +458,12 @@ print(f'Runtime {runtime_arn} is serving MCP')
|
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
# Outputs
|
|
461
|
+
locals {
|
|
462
|
+
# For MCP runtimes the ARN flows through the readiness probe, so consumers
|
|
463
|
+
# wait until the runtime serves MCP.
|
|
464
|
+
ready_runtime_arn = var.server_protocol == "MCP" ? null_resource.runtime_ready[0].triggers.runtime_arn : aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
465
|
+
}
|
|
466
|
+
|
|
461
467
|
output "agent_core_runtime_role_arn" {
|
|
462
468
|
description = "ARN of the Agent Core Runtime IAM role"
|
|
463
469
|
value = aws_iam_role.agent_core_runtime_role.arn
|
|
@@ -475,7 +481,12 @@ output "agent_runtime_name" {
|
|
|
475
481
|
|
|
476
482
|
output "agent_core_runtime_arn" {
|
|
477
483
|
description = "ARN of the Bedrock Agent Core runtime. For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
478
|
-
value =
|
|
484
|
+
value = local.ready_runtime_arn
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
output "invocation_url" {
|
|
488
|
+
description = "HTTPS invocation URL of the runtime. MCP runtimes get the MCP endpoint (e.g. for use as a Gateway target endpoint), A2A runtimes the A2A endpoint (trailing slash required). For MCP runtimes the value flows through the readiness probe, so consumers wait until the runtime serves MCP."
|
|
489
|
+
value = "https://bedrock-agentcore.${local.aws_region}.amazonaws.com/runtimes/${urlencode(local.ready_runtime_arn)}/invocations${var.server_protocol == "A2A" ? "/" : "?qualifier=DEFAULT"}"
|
|
479
490
|
}
|
|
480
491
|
|
|
481
492
|
output "agent_runtime_id" {
|