@aws/nx-plugin 0.108.0 → 0.109.1
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 +2 -2
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +167 -89
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +72 -16
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +11 -9
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +11 -9
- package/src/py/strands-agent/generator.js +95 -2
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/py/strands-agent/scripts/http/chat.ts.template +38 -0
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +113 -61
- package/src/terraform/project/files/application/scripts/aws-config.ts.template +41 -0
- package/src/terraform/project/files/application/scripts/bootstrap.ts.template +91 -0
- package/src/terraform/project/files/application/scripts/init.ts.template +44 -0
- package/src/terraform/project/generator.js +16 -11
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +167 -89
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +72 -16
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +11 -9
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +7 -0
- package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +11 -9
- package/src/ts/strands-agent/generator.js +31 -0
- package/src/ts/strands-agent/generator.js.map +1 -1
- package/src/ts/strands-agent/scripts/http/chat.ts.template +35 -0
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +14 -12
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +28 -15
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +29 -16
- package/src/utils/files/terraform/scripts/reset-runtime-config.ts.template +25 -0
- package/src/utils/files/terraform/src/core/asset-bucket/asset-bucket.tf.template +203 -0
- package/src/utils/files/terraform/src/core/runtime-config/appconfig/appconfig.tf.template +42 -39
- package/src/utils/files/terraform/src/core/runtime-config/appconfig-deployment/appconfig-deployment.tf.template +138 -0
- package/src/utils/files/terraform/src/core/runtime-config/entry/entry.tf.template +26 -90
- package/src/utils/files/terraform/src/core/runtime-config/read/read.tf.template +61 -5
- package/src/utils/function-constructs/files/terraform/app/lambda-functions/__functionNameKebabCase__/__functionNameKebabCase__.tf.template +35 -7
- package/src/utils/shared-constructs.js +4 -2
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/versions.d.ts +7 -3
- package/src/utils/versions.js +6 -2
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +7 -0
|
@@ -66,7 +66,20 @@ export class TestProjectTestFunction extends Function {
|
|
|
66
66
|
|
|
67
67
|
exports[`lambda-handler project generator > terraform iacProvider > should generate terraform files for python lambda function and snapshot them > terraform-python-lambda-files 1`] = `
|
|
68
68
|
{
|
|
69
|
-
"test-project-test-function.tf": "
|
|
69
|
+
"test-project-test-function.tf": "terraform {
|
|
70
|
+
required_providers {
|
|
71
|
+
aws = {
|
|
72
|
+
source = "hashicorp/aws"
|
|
73
|
+
version = "~> 6.0"
|
|
74
|
+
}
|
|
75
|
+
archive = {
|
|
76
|
+
source = "hashicorp/archive"
|
|
77
|
+
version = "~> 2.0"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
variable "tags" {
|
|
70
83
|
description = "Tags to apply to resources"
|
|
71
84
|
type = map(string)
|
|
72
85
|
default = {}
|
|
@@ -88,6 +101,11 @@ variable "additional_iam_policy_statements" {
|
|
|
88
101
|
default = []
|
|
89
102
|
}
|
|
90
103
|
|
|
104
|
+
variable "asset_bucket_name" {
|
|
105
|
+
description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
|
|
106
|
+
type = string
|
|
107
|
+
}
|
|
108
|
+
|
|
91
109
|
data "aws_caller_identity" "current" {}
|
|
92
110
|
data "aws_region" "current" {}
|
|
93
111
|
|
|
@@ -168,19 +186,29 @@ data "archive_file" "lambda_zip" {
|
|
|
168
186
|
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/lambda-functions/test-project-test-function/lambda.zip"
|
|
169
187
|
}
|
|
170
188
|
|
|
189
|
+
resource "aws_s3_object" "lambda_zip" {
|
|
190
|
+
bucket = var.asset_bucket_name
|
|
191
|
+
key = "lambdas/test-project-test-function/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
|
|
192
|
+
source = data.archive_file.lambda_zip.output_path
|
|
193
|
+
source_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
194
|
+
etag = data.archive_file.lambda_zip.output_md5
|
|
195
|
+
}
|
|
196
|
+
|
|
171
197
|
resource "aws_lambda_function" "lambda_function" {
|
|
172
198
|
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
173
199
|
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple use case
|
|
174
200
|
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
175
201
|
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
176
202
|
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
203
|
+
s3_bucket = aws_s3_object.lambda_zip.bucket
|
|
204
|
+
s3_key = aws_s3_object.lambda_zip.key
|
|
205
|
+
s3_object_version = aws_s3_object.lambda_zip.version_id
|
|
206
|
+
function_name = "test-project-test-function-\${random_string.suffix.result}"
|
|
207
|
+
role = aws_iam_role.lambda_role.arn
|
|
208
|
+
handler = "test_project.test_function.lambda_handler"
|
|
209
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
210
|
+
runtime = "python3.14"
|
|
211
|
+
timeout = 30
|
|
184
212
|
|
|
185
213
|
tracing_config {
|
|
186
214
|
mode = "Active"
|
|
@@ -219,7 +247,20 @@ output "role_name" {
|
|
|
219
247
|
`;
|
|
220
248
|
|
|
221
249
|
exports[`lambda-handler project generator > terraform iacProvider > should match snapshot for terraform generated files with different configurations > terraform-python-lambda-snapshot-function.tf 1`] = `
|
|
222
|
-
"
|
|
250
|
+
"terraform {
|
|
251
|
+
required_providers {
|
|
252
|
+
aws = {
|
|
253
|
+
source = "hashicorp/aws"
|
|
254
|
+
version = "~> 6.0"
|
|
255
|
+
}
|
|
256
|
+
archive = {
|
|
257
|
+
source = "hashicorp/archive"
|
|
258
|
+
version = "~> 2.0"
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
variable "tags" {
|
|
223
264
|
description = "Tags to apply to resources"
|
|
224
265
|
type = map(string)
|
|
225
266
|
default = {}
|
|
@@ -241,6 +282,11 @@ variable "additional_iam_policy_statements" {
|
|
|
241
282
|
default = []
|
|
242
283
|
}
|
|
243
284
|
|
|
285
|
+
variable "asset_bucket_name" {
|
|
286
|
+
description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
|
|
287
|
+
type = string
|
|
288
|
+
}
|
|
289
|
+
|
|
244
290
|
data "aws_caller_identity" "current" {}
|
|
245
291
|
data "aws_region" "current" {}
|
|
246
292
|
|
|
@@ -321,19 +367,29 @@ data "archive_file" "lambda_zip" {
|
|
|
321
367
|
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/lambda-functions/test-project-snapshot-function/lambda.zip"
|
|
322
368
|
}
|
|
323
369
|
|
|
370
|
+
resource "aws_s3_object" "lambda_zip" {
|
|
371
|
+
bucket = var.asset_bucket_name
|
|
372
|
+
key = "lambdas/test-project-snapshot-function/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
|
|
373
|
+
source = data.archive_file.lambda_zip.output_path
|
|
374
|
+
source_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
375
|
+
etag = data.archive_file.lambda_zip.output_md5
|
|
376
|
+
}
|
|
377
|
+
|
|
324
378
|
resource "aws_lambda_function" "lambda_function" {
|
|
325
379
|
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
326
380
|
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple use case
|
|
327
381
|
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
328
382
|
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
329
383
|
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
384
|
+
s3_bucket = aws_s3_object.lambda_zip.bucket
|
|
385
|
+
s3_key = aws_s3_object.lambda_zip.key
|
|
386
|
+
s3_object_version = aws_s3_object.lambda_zip.version_id
|
|
387
|
+
function_name = "test-project-snapshot-function-\${random_string.suffix.result}"
|
|
388
|
+
role = aws_iam_role.lambda_role.arn
|
|
389
|
+
handler = "test_project.snapshot_function.lambda_handler"
|
|
390
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
391
|
+
runtime = "python3.14"
|
|
392
|
+
timeout = 30
|
|
337
393
|
|
|
338
394
|
tracing_config {
|
|
339
395
|
mode = "Active"
|
|
@@ -520,10 +520,14 @@ variable "tags" {
|
|
|
520
520
|
default = {}
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
|
|
524
|
-
|
|
523
|
+
variable "appconfig_application_id" {
|
|
524
|
+
description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). The agent reads its runtime configuration from this application."
|
|
525
|
+
type = string
|
|
526
|
+
}
|
|
525
527
|
|
|
526
|
-
|
|
528
|
+
variable "appconfig_application_arn" {
|
|
529
|
+
description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the agent runtime."
|
|
530
|
+
type = string
|
|
527
531
|
}
|
|
528
532
|
|
|
529
533
|
module "agent_core_runtime" {
|
|
@@ -533,7 +537,7 @@ module "agent_core_runtime" {
|
|
|
533
537
|
server_protocol = "MCP"
|
|
534
538
|
|
|
535
539
|
env = merge({
|
|
536
|
-
RUNTIME_CONFIG_APP_ID =
|
|
540
|
+
RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
|
|
537
541
|
}, var.env)
|
|
538
542
|
additional_iam_policy_statements = concat([
|
|
539
543
|
{
|
|
@@ -542,12 +546,10 @@ module "agent_core_runtime" {
|
|
|
542
546
|
"appconfig:StartConfigurationSession",
|
|
543
547
|
"appconfig:GetLatestConfiguration"
|
|
544
548
|
]
|
|
545
|
-
Resource = ["\${
|
|
549
|
+
Resource = ["\${var.appconfig_application_arn}/*"]
|
|
546
550
|
}
|
|
547
551
|
], var.additional_iam_policy_statements)
|
|
548
552
|
tags = var.tags
|
|
549
|
-
|
|
550
|
-
depends_on = [module.appconfig]
|
|
551
553
|
}
|
|
552
554
|
|
|
553
555
|
# Add agent runtime ARN to runtime config
|
|
@@ -572,8 +574,8 @@ output "agent_core_runtime_arn" {
|
|
|
572
574
|
}
|
|
573
575
|
|
|
574
576
|
output "appconfig_application_id" {
|
|
575
|
-
description = "AppConfig Application ID for runtime config"
|
|
576
|
-
value =
|
|
577
|
+
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
578
|
+
value = var.appconfig_application_id
|
|
577
579
|
}
|
|
578
580
|
"
|
|
579
581
|
`;
|
|
@@ -183,10 +183,14 @@ variable "tags" {
|
|
|
183
183
|
default = {}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
variable "appconfig_application_id" {
|
|
187
|
+
description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). The agent reads its runtime configuration from this application."
|
|
188
|
+
type = string
|
|
189
|
+
}
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
variable "appconfig_application_arn" {
|
|
192
|
+
description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the agent runtime."
|
|
193
|
+
type = string
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
module "agent_core_runtime" {
|
|
@@ -196,7 +200,7 @@ module "agent_core_runtime" {
|
|
|
196
200
|
server_protocol = "HTTP"
|
|
197
201
|
|
|
198
202
|
env = merge({
|
|
199
|
-
RUNTIME_CONFIG_APP_ID =
|
|
203
|
+
RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
|
|
200
204
|
}, var.env)
|
|
201
205
|
additional_iam_policy_statements = concat([
|
|
202
206
|
{
|
|
@@ -205,7 +209,7 @@ module "agent_core_runtime" {
|
|
|
205
209
|
"appconfig:StartConfigurationSession",
|
|
206
210
|
"appconfig:GetLatestConfiguration"
|
|
207
211
|
]
|
|
208
|
-
Resource = ["\${
|
|
212
|
+
Resource = ["\${var.appconfig_application_arn}/*"]
|
|
209
213
|
},
|
|
210
214
|
# Grant access for the agent to invoke bedrock models
|
|
211
215
|
{
|
|
@@ -221,8 +225,6 @@ module "agent_core_runtime" {
|
|
|
221
225
|
}
|
|
222
226
|
], var.additional_iam_policy_statements)
|
|
223
227
|
tags = var.tags
|
|
224
|
-
|
|
225
|
-
depends_on = [module.appconfig]
|
|
226
228
|
}
|
|
227
229
|
|
|
228
230
|
# Add agent runtime ARN to runtime config
|
|
@@ -247,8 +249,8 @@ output "agent_core_runtime_arn" {
|
|
|
247
249
|
}
|
|
248
250
|
|
|
249
251
|
output "appconfig_application_id" {
|
|
250
|
-
description = "AppConfig Application ID for runtime config"
|
|
251
|
-
value =
|
|
252
|
+
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
253
|
+
value = var.appconfig_application_id
|
|
252
254
|
}
|
|
253
255
|
"
|
|
254
256
|
`;
|
|
@@ -6,6 +6,9 @@ exports.pyStrandsAgentGenerator = exports.PY_STRANDS_AGENT_GENERATOR_INFO = void
|
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const versions_1 = require("../../utils/versions");
|
|
10
|
+
const git_1 = require("../../utils/git");
|
|
11
|
+
const object_1 = require("../../utils/object");
|
|
9
12
|
const nx_1 = require("../../utils/nx");
|
|
10
13
|
const metrics_1 = require("../../utils/metrics");
|
|
11
14
|
const format_1 = require("../../utils/format");
|
|
@@ -130,10 +133,86 @@ const pyStrandsAgentGenerator = async (tree, options) => {
|
|
|
130
133
|
// - A2A: A2AServer.to_fastapi_app() creates a FastAPI app in main.py
|
|
131
134
|
// - AG-UI: create_strands_app() creates a FastAPI app in main.py
|
|
132
135
|
const serveCommand = `uv run fastapi dev ${moduleName}/${agentNameSnakeCase}/main.py --port ${localDevPort}`;
|
|
136
|
+
// HTTP chat uses the type-safe TypeScript client generated from the
|
|
137
|
+
// agent's OpenAPI spec (same generated client the react-connection
|
|
138
|
+
// generator produces). A2A and AG-UI speak standard protocols, so
|
|
139
|
+
// we can run `agent-chat-cli` directly as a binary.
|
|
140
|
+
const openApiTargetName = `${agentTargetPrefix}-openapi`;
|
|
141
|
+
const clientGenTargetName = `${agentTargetPrefix}-generate-client`;
|
|
142
|
+
if (protocol === 'HTTP') {
|
|
143
|
+
// Emit the OpenAPI spec generator script (shared with react-connection)
|
|
144
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'react-connection', 'files', 'agent'), project.root, {
|
|
145
|
+
moduleName,
|
|
146
|
+
agentNameSnakeCase,
|
|
147
|
+
}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
148
|
+
// Emit the chat CLI adapter script
|
|
149
|
+
const scriptsDir = (0, devkit_1.joinPathFragments)(project.root, 'scripts', agentTargetPrefix);
|
|
150
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'scripts', 'http'), scriptsDir, {
|
|
151
|
+
agentNameClassName,
|
|
152
|
+
agentTargetPrefix,
|
|
153
|
+
localDevPort,
|
|
154
|
+
}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
155
|
+
// Ignore the generated client directory
|
|
156
|
+
(0, git_1.updateGitIgnore)(tree, project.root, (patterns) => [
|
|
157
|
+
...patterns,
|
|
158
|
+
`scripts/${agentTargetPrefix}/generated/`,
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
// Add TypeScript deps for the chat CLI. `agent-chat-cli` transitively
|
|
162
|
+
// bundles the protocol clients (@a2a-js/sdk, @ag-ui/client) and
|
|
163
|
+
// @clack/prompts, so nothing else is needed. HTTP also needs tsx to
|
|
164
|
+
// run the adapter script.
|
|
165
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, (0, versions_1.withVersions)([
|
|
166
|
+
'agent-chat-cli',
|
|
167
|
+
...(protocol === 'HTTP'
|
|
168
|
+
? ['tsx', '@types/node']
|
|
169
|
+
: []),
|
|
170
|
+
]));
|
|
171
|
+
const chatUrl = protocol === 'AG-UI'
|
|
172
|
+
? `http://localhost:${localDevPort}/invocations`
|
|
173
|
+
: `http://localhost:${localDevPort}`;
|
|
174
|
+
const chatCommand = protocol === 'HTTP'
|
|
175
|
+
? `tsx ./scripts/${agentTargetPrefix}/chat.ts`
|
|
176
|
+
: protocol === 'AG-UI'
|
|
177
|
+
? `agent-chat-cli agui ${chatUrl}`
|
|
178
|
+
: `agent-chat-cli a2a ${chatUrl}`;
|
|
179
|
+
const httpOnlyTargets = protocol === 'HTTP'
|
|
180
|
+
? {
|
|
181
|
+
[openApiTargetName]: {
|
|
182
|
+
cache: true,
|
|
183
|
+
executor: 'nx:run-commands',
|
|
184
|
+
outputs: [
|
|
185
|
+
`{workspaceRoot}/dist/{projectRoot}/openapi/${agentNameSnakeCase}`,
|
|
186
|
+
],
|
|
187
|
+
options: {
|
|
188
|
+
commands: [
|
|
189
|
+
`uv run python {projectRoot}/scripts/${agentNameSnakeCase}_openapi.py "dist/{projectRoot}/openapi/${agentNameSnakeCase}/openapi.json"`,
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
[clientGenTargetName]: {
|
|
194
|
+
cache: true,
|
|
195
|
+
executor: 'nx:run-commands',
|
|
196
|
+
inputs: [
|
|
197
|
+
{
|
|
198
|
+
dependentTasksOutputFiles: '**/*.json',
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
outputs: [`{projectRoot}/scripts/${agentTargetPrefix}/generated`],
|
|
202
|
+
options: {
|
|
203
|
+
commands: [
|
|
204
|
+
`nx g @aws/nx-plugin:open-api#ts-client --openApiSpecPath="dist/${project.root}/openapi/${agentNameSnakeCase}/openapi.json" --outputPath="${project.root}/scripts/${agentTargetPrefix}/generated" --no-interactive`,
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
dependsOn: [openApiTargetName],
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
: {};
|
|
133
211
|
(0, devkit_1.updateProjectConfiguration)(tree, project.name, {
|
|
134
212
|
...project,
|
|
135
|
-
targets: {
|
|
213
|
+
targets: (0, object_1.sortObjectKeys)({
|
|
136
214
|
...project.targets,
|
|
215
|
+
...httpOnlyTargets,
|
|
137
216
|
[`${agentTargetPrefix}-serve`]: {
|
|
138
217
|
executor: 'nx:run-commands',
|
|
139
218
|
options: {
|
|
@@ -157,7 +236,21 @@ const pyStrandsAgentGenerator = async (tree, options) => {
|
|
|
157
236
|
},
|
|
158
237
|
continuous: true,
|
|
159
238
|
},
|
|
160
|
-
|
|
239
|
+
[`${agentTargetPrefix}-chat`]: {
|
|
240
|
+
executor: 'nx:run-commands',
|
|
241
|
+
options: {
|
|
242
|
+
commands: [chatCommand],
|
|
243
|
+
cwd: '{projectRoot}',
|
|
244
|
+
env: {
|
|
245
|
+
URL: chatUrl,
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
dependsOn: [
|
|
249
|
+
...(protocol === 'HTTP' ? [clientGenTargetName] : []),
|
|
250
|
+
`${agentTargetPrefix}-serve-local`,
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
161
254
|
});
|
|
162
255
|
(0, nx_1.addComponentGeneratorMetadata)(tree, project.name, exports.PY_STRANDS_AGENT_GENERATOR_INFO, (0, paths_1.toProjectRelativePath)(project, targetSourceDir), agentTargetPrefix, {
|
|
163
256
|
port: localDevPort,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/py/strands-agent/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/py/strands-agent/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AACpB,mDAAoD;AACpD,yCAAkD;AAClD,+CAAoD;AAEpD,uCAMwB;AACxB,iDAAsE;AACtE,+CAA0D;AAC1D,6CAAwE;AACxE,uCAGwB;AACxB,mGAAwF;AAExF,sDAAkE;AAClE,uCAA4C;AAC5C,qDAAoD;AACpD,qEAA0E;AAC1E,yDAA6D;AAC7D,yCAAqD;AACrD,2CAA8C;AAC9C,6CAA0D;AAE7C,QAAA,+BAA+B,GAC1C,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,uBAAuB,GAAG,KAAK,EAC1C,IAAU,EACV,OAAsC,EACV,EAAE;IAC9B,MAAM,OAAO,GAAG,IAAA,wCAAmC,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3E,MAAM,aAAa,GAAG,IAAA,0BAAiB,EAAC,OAAO,CAAC,IAA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
|
+
*
|
|
4
|
+
* Uses the type-safe TypeScript client generated from the agent's OpenAPI
|
|
5
|
+
* spec. Connects to the agent at `process.env.URL` (set by the Nx
|
|
6
|
+
* `<%- agentTargetPrefix %>-chat` target).
|
|
7
|
+
*/
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { chatLoop, type ChatAdapter } from 'agent-chat-cli';
|
|
10
|
+
import { <%- agentNameClassName %> } from './generated/client.gen.js';
|
|
11
|
+
|
|
12
|
+
const SESSION_ID_HEADER = 'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id';
|
|
13
|
+
|
|
14
|
+
class <%- agentNameClassName %>Adapter implements ChatAdapter {
|
|
15
|
+
private client!: <%- agentNameClassName %>;
|
|
16
|
+
// AgentCore session IDs must be at least 33 characters.
|
|
17
|
+
private readonly sessionId = randomUUID().replaceAll('-', '').padEnd(33, '0');
|
|
18
|
+
|
|
19
|
+
async connect(url: string) {
|
|
20
|
+
this.client = new <%- agentNameClassName %>({
|
|
21
|
+
url,
|
|
22
|
+
fetch: (input, init) => {
|
|
23
|
+
const headers = new Headers(init?.headers);
|
|
24
|
+
headers.set(SESSION_ID_HEADER, this.sessionId);
|
|
25
|
+
return fetch(input, { ...init, headers });
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return { agentName: '<%- agentNameClassName %>' };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async *sendMessage(text: string): AsyncIterable<string> {
|
|
32
|
+
for await (const chunk of this.client.invoke({ message: text })) {
|
|
33
|
+
if (typeof chunk.content === 'string') yield chunk.content;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await chatLoop(new <%- agentNameClassName %>Adapter(), process.env.URL!);
|