@aws/nx-plugin 0.112.1 → 0.114.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-THIRD-PARTY +957 -429
- package/generators.json +33 -1
- package/package.json +1 -1
- package/src/connection/generator.d.ts +2 -2
- package/src/connection/generator.js +19 -0
- package/src/connection/generator.js.map +1 -1
- package/src/py/project/generator.js +4 -0
- package/src/py/project/generator.js.map +1 -1
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +42 -20
- package/src/py/strands-agent/a2a-connection/files/agent-connection/app/__targetAgentSnakeCase___client.py.template +6 -13
- package/src/py/strands-agent/a2a-connection/generator.js +1 -1
- package/src/py/strands-agent/files/a2a/main.py.template +24 -3
- package/src/py/strands-agent/files/ag-ui/main.py.template +3 -2
- package/src/py/strands-agent/files/common/agent.py.template +1 -2
- package/src/py/strands-agent/files/http/main.py.template +32 -13
- package/src/py/strands-agent/generator.js +11 -0
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/py/strands-agent/mcp-connection/__snapshots__/generator.spec.ts.snap +66 -59
- package/src/py/strands-agent/mcp-connection/files/agent-connection/app/__mcpServerSnakeCase___client.py.template +6 -14
- package/src/py/strands-agent/mcp-connection/generator.js +3 -3
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/smithy/project/files/build.Dockerfile.template +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +4 -3
- package/src/ts/mcp-server/files/http.ts.template +1 -1
- package/src/ts/mcp-server/files/server.ts.template +1 -1
- package/src/ts/mcp-server/files/stdio.ts.template +2 -1
- package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +3 -2
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +54 -44
- package/src/ts/rdb/files/src/prisma.ts.template +54 -46
- package/src/ts/rdb/generator.js +3 -0
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +117 -0
- package/src/ts/rdb/mcp-server-connection/generator.d.ts +10 -0
- package/src/ts/rdb/mcp-server-connection/generator.js +59 -0
- package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -0
- package/src/ts/rdb/mcp-server-connection/schema.d.ts +14 -0
- package/src/ts/rdb/mcp-server-connection/schema.json +22 -0
- package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +286 -0
- package/src/ts/rdb/smithy-connection/generator.d.ts +10 -0
- package/src/ts/rdb/smithy-connection/generator.js +72 -0
- package/src/ts/rdb/smithy-connection/generator.js.map +1 -0
- package/src/ts/rdb/smithy-connection/schema.d.ts +12 -0
- package/src/ts/rdb/smithy-connection/schema.json +18 -0
- package/src/ts/rdb/strands-agent-connection/__snapshots__/generator.spec.ts.snap +183 -0
- package/src/ts/rdb/strands-agent-connection/generator.d.ts +10 -0
- package/src/ts/rdb/strands-agent-connection/generator.js +65 -0
- package/src/ts/rdb/strands-agent-connection/generator.js.map +1 -0
- package/src/ts/rdb/strands-agent-connection/schema.d.ts +14 -0
- package/src/ts/rdb/strands-agent-connection/schema.json +22 -0
- package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +75 -0
- package/src/ts/rdb/trpc-connection/files/src/middleware/__rdbNameKebab__.ts.template +32 -0
- package/src/ts/rdb/trpc-connection/generator.d.ts +10 -0
- package/src/ts/rdb/trpc-connection/generator.js +41 -0
- package/src/ts/rdb/trpc-connection/generator.js.map +1 -0
- package/src/ts/rdb/trpc-connection/schema.d.ts +12 -0
- package/src/ts/rdb/trpc-connection/schema.json +18 -0
- package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +17 -7
- package/src/ts/strands-agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client.ts.template +6 -14
- package/src/ts/strands-agent/a2a-connection/generator.js +2 -3
- package/src/ts/strands-agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/strands-agent/files/a2a/index.ts.template +12 -2
- package/src/ts/strands-agent/files/common/agent.ts.template +2 -4
- package/src/ts/strands-agent/files/http/init.ts.template +12 -1
- package/src/ts/strands-agent/files/http/router.ts.template +3 -2
- package/src/ts/strands-agent/generator.js +7 -0
- package/src/ts/strands-agent/generator.js.map +1 -1
- package/src/ts/strands-agent/mcp-connection/__snapshots__/generator.spec.ts.snap +46 -71
- package/src/ts/strands-agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client.ts.template +8 -19
- package/src/ts/strands-agent/mcp-connection/generator.js +1 -1
- package/src/ts/strands-agent/mcp-connection/generator.js.map +1 -1
- package/src/utils/agent-connection/agent-connection.js +22 -0
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client.ts.template +46 -57
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-client.ts.template +35 -51
- package/src/utils/agent-connection/files/core-runtime-config/session-context.ts.template +21 -0
- package/src/utils/agent-connection/files/core-runtime-config/with-session-id.ts.template +27 -0
- package/src/utils/agent-connection/files/py-core-a2a/agentcore_a2a_client.py.template +44 -15
- package/src/utils/agent-connection/files/py-core-mcp/agentcore_mcp_client.py.template +50 -43
- package/src/utils/agent-connection/files/py-core-runtime-config/session_context.py.template +22 -0
- package/src/utils/agent-connection/files/py-core-runtime-config/with_session_id.py.template +44 -0
- package/src/utils/ast.js +9 -2
- package/src/utils/ast.js.map +1 -1
- package/src/utils/bundle/bundle.js +1 -0
- package/src/utils/bundle/bundle.js.map +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#rdb#smithy-connection",
|
|
4
|
+
"title": "ts#rdb#smithy-connection",
|
|
5
|
+
"description": "Connect a Smithy backend to a ts#rdb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The TypeScript project to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#rdb project to connect to"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["sourceProject", "targetProject"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`ts#rdb strands-agent-connection generator > should add rdb serve-local dependency to the agent prefixed serve-local 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
6
|
+
"metadata": {
|
|
7
|
+
"components": [
|
|
8
|
+
{
|
|
9
|
+
"generator": "ts#strands-agent",
|
|
10
|
+
"name": "my-agent",
|
|
11
|
+
"path": "src/my-agent",
|
|
12
|
+
"protocol": "HTTP",
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
"name": "my-service",
|
|
17
|
+
"root": "packages/my-service",
|
|
18
|
+
"targets": {
|
|
19
|
+
"my-agent-serve-local": {
|
|
20
|
+
"continuous": true,
|
|
21
|
+
"dependsOn": [
|
|
22
|
+
{
|
|
23
|
+
"projects": [
|
|
24
|
+
"db",
|
|
25
|
+
],
|
|
26
|
+
"target": "serve-local",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
"executor": "nx:run-commands",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
exports[`ts#rdb strands-agent-connection generator > should be idempotent for A2A agent.ts injection 1`] = `
|
|
36
|
+
"import { getPrisma as getDb } from 'db';
|
|
37
|
+
import { Agent, tool } from '@strands-agents/sdk';
|
|
38
|
+
import { z } from 'zod';
|
|
39
|
+
|
|
40
|
+
const multiply = tool({
|
|
41
|
+
name: 'Multiply',
|
|
42
|
+
description: 'Multiply two numbers',
|
|
43
|
+
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
44
|
+
callback: ({ a, b }) => a * b,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const getAgent = async () => {
|
|
48
|
+
const db = await getDb();
|
|
49
|
+
db.$on('error', console.error);
|
|
50
|
+
return new Agent({
|
|
51
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
52
|
+
tools: [multiply],
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
"
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
exports[`ts#rdb strands-agent-connection generator > should be idempotent for agent.ts injection 1`] = `
|
|
59
|
+
"import { getPrisma as getDb } from 'db';
|
|
60
|
+
import { Agent, tool } from '@strands-agents/sdk';
|
|
61
|
+
import { z } from 'zod';
|
|
62
|
+
|
|
63
|
+
const multiply = tool({
|
|
64
|
+
name: 'Multiply',
|
|
65
|
+
description: 'Multiply two numbers',
|
|
66
|
+
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
67
|
+
callback: ({ a, b }) => a * b,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const getAgent = async () => {
|
|
71
|
+
const db = await getDb();
|
|
72
|
+
db.$on('error', console.error);
|
|
73
|
+
return new Agent({
|
|
74
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
75
|
+
tools: [multiply],
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
"
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
exports[`ts#rdb strands-agent-connection generator > should fall back to agent-serve-local when no component name 1`] = `
|
|
82
|
+
{
|
|
83
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
84
|
+
"metadata": {
|
|
85
|
+
"components": [
|
|
86
|
+
{
|
|
87
|
+
"generator": "ts#strands-agent",
|
|
88
|
+
"name": "agent",
|
|
89
|
+
"path": "src/agent",
|
|
90
|
+
"protocol": "HTTP",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
"name": "my-service",
|
|
95
|
+
"root": "packages/my-service",
|
|
96
|
+
"targets": {
|
|
97
|
+
"agent-serve-local": {
|
|
98
|
+
"continuous": true,
|
|
99
|
+
"dependsOn": [
|
|
100
|
+
{
|
|
101
|
+
"projects": [
|
|
102
|
+
"db",
|
|
103
|
+
],
|
|
104
|
+
"target": "serve-local",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
"executor": "nx:run-commands",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
exports[`ts#rdb strands-agent-connection generator > should inject db into agent.ts 1`] = `
|
|
114
|
+
"import { getPrisma as getDb } from 'db';
|
|
115
|
+
import { Agent, tool } from '@strands-agents/sdk';
|
|
116
|
+
import { z } from 'zod';
|
|
117
|
+
|
|
118
|
+
const multiply = tool({
|
|
119
|
+
name: 'Multiply',
|
|
120
|
+
description: 'Multiply two numbers',
|
|
121
|
+
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
122
|
+
callback: ({ a, b }) => a * b,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const getAgent = async () => {
|
|
126
|
+
const db = await getDb();
|
|
127
|
+
db.$on('error', console.error);
|
|
128
|
+
return new Agent({
|
|
129
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
130
|
+
tools: [multiply],
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
"
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
exports[`ts#rdb strands-agent-connection generator > should inject db into agent.ts for A2A 1`] = `
|
|
137
|
+
"import { getPrisma as getDb } from 'db';
|
|
138
|
+
import { Agent, tool } from '@strands-agents/sdk';
|
|
139
|
+
import { z } from 'zod';
|
|
140
|
+
|
|
141
|
+
const multiply = tool({
|
|
142
|
+
name: 'Multiply',
|
|
143
|
+
description: 'Multiply two numbers',
|
|
144
|
+
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
145
|
+
callback: ({ a, b }) => a * b,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
export const getAgent = async () => {
|
|
149
|
+
const db = await getDb();
|
|
150
|
+
db.$on('error', console.error);
|
|
151
|
+
return new Agent({
|
|
152
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
153
|
+
tools: [multiply],
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
"
|
|
157
|
+
`;
|
|
158
|
+
|
|
159
|
+
exports[`ts#rdb strands-agent-connection generator > should support multiple rdb connections in agent.ts 1`] = `
|
|
160
|
+
"import { getPrisma as getMysqlDb } from 'mysql-db';
|
|
161
|
+
import { getPrisma as getPostgresDb } from 'postgres-db';
|
|
162
|
+
import { Agent, tool } from '@strands-agents/sdk';
|
|
163
|
+
import { z } from 'zod';
|
|
164
|
+
|
|
165
|
+
const multiply = tool({
|
|
166
|
+
name: 'Multiply',
|
|
167
|
+
description: 'Multiply two numbers',
|
|
168
|
+
inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
169
|
+
callback: ({ a, b }) => a * b,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
export const getAgent = async () => {
|
|
173
|
+
const mysqlDb = await getMysqlDb();
|
|
174
|
+
mysqlDb.$on('error', console.error);
|
|
175
|
+
const postgresDb = await getPostgresDb();
|
|
176
|
+
postgresDb.$on('error', console.error);
|
|
177
|
+
return new Agent({
|
|
178
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
179
|
+
tools: [multiply],
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
"
|
|
183
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { TsRdbStrandsAgentConnectionGeneratorSchema } from './schema';
|
|
7
|
+
import { NxGeneratorInfo } from '../../../utils/nx';
|
|
8
|
+
export declare const TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
export declare const tsRdbStrandsAgentConnectionGenerator: (tree: Tree, options: TsRdbStrandsAgentConnectionGeneratorSchema) => Promise<void>;
|
|
10
|
+
export default tsRdbStrandsAgentConnectionGenerator;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsRdbStrandsAgentConnectionGenerator = exports.TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
*/
|
|
9
|
+
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const nx_1 = require("../../../utils/nx");
|
|
11
|
+
const metrics_1 = require("../../../utils/metrics");
|
|
12
|
+
const format_1 = require("../../../utils/format");
|
|
13
|
+
const names_1 = require("../../../utils/names");
|
|
14
|
+
const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
|
|
15
|
+
const npm_scope_1 = require("../../../utils/npm-scope");
|
|
16
|
+
const ast_1 = require("../../../utils/ast");
|
|
17
|
+
exports.TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
18
|
+
const tsRdbStrandsAgentConnectionGenerator = async (tree, options) => {
|
|
19
|
+
const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
|
|
20
|
+
const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
|
|
21
|
+
const agentName = options.sourceComponent?.name ?? 'agent';
|
|
22
|
+
const serveLocalTarget = `${agentName}-serve-local`;
|
|
23
|
+
if (sourceProject.targets?.[serveLocalTarget]) {
|
|
24
|
+
(0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, serveLocalTarget, {
|
|
25
|
+
projects: [targetProject.name],
|
|
26
|
+
target: 'serve-local',
|
|
27
|
+
});
|
|
28
|
+
(0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
|
|
29
|
+
}
|
|
30
|
+
const rdbBaseName = targetProject.name.split('/').pop();
|
|
31
|
+
const rdbNameCamel = (0, lodash_camelcase_1.default)(rdbBaseName);
|
|
32
|
+
const rdbNamePascal = (0, names_1.pascalCase)(rdbBaseName);
|
|
33
|
+
const rdbPackageAlias = (0, npm_scope_1.toScopeAlias)(targetProject.name);
|
|
34
|
+
const getterAlias = `getPrisma as get${rdbNamePascal}`;
|
|
35
|
+
const agentSourceDir = (0, devkit_1.joinPathFragments)(sourceProject.root, 'src', agentName);
|
|
36
|
+
const agentPath = (0, devkit_1.joinPathFragments)(agentSourceDir, 'agent.ts');
|
|
37
|
+
if (tree.exists(agentPath)) {
|
|
38
|
+
await (0, ast_1.addDestructuredImport)(tree, agentPath, [getterAlias], rdbPackageAlias);
|
|
39
|
+
// Block body form: export const getAgent = async () => { ... }
|
|
40
|
+
await (0, ast_1.applyGritQL)(tree, agentPath, `\`export const getAgent = async () => { $body }\` => raw\`export const getAgent = async () => {
|
|
41
|
+
const ${rdbNameCamel} = await get${rdbNamePascal}();
|
|
42
|
+
$body
|
|
43
|
+
}\` where { $body <: not some \`const ${rdbNameCamel} = await get${rdbNamePascal}()\` }`);
|
|
44
|
+
// Expression body form: export const getAgent = async () => expr
|
|
45
|
+
await (0, ast_1.applyGritQL)(tree, agentPath, `\`export const getAgent = async () => $expr\` => raw\`export const getAgent = async () => {
|
|
46
|
+
const ${rdbNameCamel} = await get${rdbNamePascal}();
|
|
47
|
+
return $expr;
|
|
48
|
+
}\` where { $expr <: not \`{ $_ }\` }`);
|
|
49
|
+
// Add $on error handler after the db declaration.
|
|
50
|
+
// Done via string replacement because GritQL treats $on as a metavariable.
|
|
51
|
+
const dbDecl = `const ${rdbNameCamel} = await get${rdbNamePascal}();`;
|
|
52
|
+
const onCall = `${rdbNameCamel}.$on('error', console.error);`;
|
|
53
|
+
const content = tree.read(agentPath, 'utf-8');
|
|
54
|
+
if (content.includes(dbDecl) && !content.includes(`${rdbNameCamel}.$on`)) {
|
|
55
|
+
tree.write(agentPath, content.replace(dbDecl, `${dbDecl}\n ${onCall}`));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
|
|
59
|
+
exports.TS_RDB_STRANDS_AGENT_CONNECTION_GENERATOR_INFO,
|
|
60
|
+
]);
|
|
61
|
+
await (0, format_1.formatFilesInSubtree)(tree);
|
|
62
|
+
};
|
|
63
|
+
exports.tsRdbStrandsAgentConnectionGenerator = tsRdbStrandsAgentConnectionGenerator;
|
|
64
|
+
exports.default = exports.tsRdbStrandsAgentConnectionGenerator;
|
|
65
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/rdb/strands-agent-connection/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAIoB;AAEpB,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAC7D,gDAAkD;AAClD,gFAAyC;AACzC,wDAAwD;AACxD,4CAAwE;AAE3D,QAAA,8CAA8C,GACzD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,oCAAoC,GAAG,KAAK,EACvD,IAAU,EACV,OAAmD,EACpC,EAAE;IACjB,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,SAAS,GAAG,O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QACjE,MAAM,IAAA,iBAAW,EACf,IAAI,EACJ,SAAS,EACT;UACI,YAAY,eAAe,aAAa;;sCAEZ,CACjC,CAAC;QAEF,kDAAkD;QAClD,2EAA2E;QAC3E,MAAM,MAAM,GAAG,SAAS,YAAY,eAAe,aAAa,KAAK,CAAC;QACtE,MAAM,MAAM,GAAG,GAAG,YAAY,+BAA+B,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAE,CAAC;QAC/C,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,YAAY,MAAM,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;QAC1C,sDAA8C;KAC/C,CAAC,CAAC;IACH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AA/EW,QAAA,oCAAoC,wCA+E/C;AAEF,kBAAe,4CAAoC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { ComponentMetadata } from '../../../utils/nx';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript types for options defined in schema.json
|
|
9
|
+
*/
|
|
10
|
+
export interface TsRdbStrandsAgentConnectionGeneratorSchema {
|
|
11
|
+
sourceProject: string;
|
|
12
|
+
targetProject: string;
|
|
13
|
+
sourceComponent?: ComponentMetadata;
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#rdb#strands-agent-connection",
|
|
4
|
+
"title": "ts#rdb#strands-agent-connection",
|
|
5
|
+
"description": "Connect a ts#strands-agent to a ts#rdb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project containing the ts#strands-agent to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#rdb project to connect to"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The agent component name"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["sourceProject", "targetProject"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`ts#rdb trpc-connection generator > should add rdb serve-local dependency to trpc serve-local 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
6
|
+
"name": "api",
|
|
7
|
+
"root": "packages/api",
|
|
8
|
+
"targets": {
|
|
9
|
+
"serve-local": {
|
|
10
|
+
"continuous": true,
|
|
11
|
+
"dependsOn": [
|
|
12
|
+
{
|
|
13
|
+
"projects": [
|
|
14
|
+
"db",
|
|
15
|
+
],
|
|
16
|
+
"target": "serve-local",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
"executor": "nx:run-commands",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
exports[`ts#rdb trpc-connection generator > should generate middleware file for PostgreSQL engine 1`] = `
|
|
26
|
+
"import { getPrisma } from 'db';
|
|
27
|
+
import { initTRPC } from '@trpc/server';
|
|
28
|
+
|
|
29
|
+
export interface IDbContext {
|
|
30
|
+
db?: Awaited<ReturnType<typeof getPrisma>>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const createDbPlugin = () => {
|
|
34
|
+
const t = initTRPC.context<IDbContext>().create();
|
|
35
|
+
return t.procedure.use(async (opts) => {
|
|
36
|
+
const db = await getPrisma();
|
|
37
|
+
|
|
38
|
+
return await opts.next({
|
|
39
|
+
ctx: {
|
|
40
|
+
...opts.ctx,
|
|
41
|
+
db,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
"
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
exports[`ts#rdb trpc-connection generator > should generate middleware file with try/finally for MySQL engine 1`] = `
|
|
50
|
+
"import { getPrisma } from 'db';
|
|
51
|
+
import { initTRPC } from '@trpc/server';
|
|
52
|
+
|
|
53
|
+
export interface IDbContext {
|
|
54
|
+
db?: Awaited<ReturnType<typeof getPrisma>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const createDbPlugin = () => {
|
|
58
|
+
const t = initTRPC.context<IDbContext>().create();
|
|
59
|
+
return t.procedure.use(async (opts) => {
|
|
60
|
+
const db = await getPrisma();
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
return await opts.next({
|
|
64
|
+
ctx: {
|
|
65
|
+
...opts.ctx,
|
|
66
|
+
db,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
} finally {
|
|
70
|
+
await db.$disconnect();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
"
|
|
75
|
+
`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getPrisma } from '<%= rdbPackageAlias %>';
|
|
2
|
+
import { initTRPC } from '@trpc/server';
|
|
3
|
+
|
|
4
|
+
export interface I<%= rdbNamePascal %>Context {
|
|
5
|
+
<%= rdbNameCamel %>?: Awaited<ReturnType<typeof getPrisma>>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const create<%= rdbNamePascal %>Plugin = () => {
|
|
9
|
+
const t = initTRPC.context<I<%= rdbNamePascal %>Context>().create();
|
|
10
|
+
return t.procedure.use(async (opts) => {
|
|
11
|
+
const <%= rdbNameCamel %> = await getPrisma();
|
|
12
|
+
<% if (engine === 'MySQL') { %>
|
|
13
|
+
try {
|
|
14
|
+
return await opts.next({
|
|
15
|
+
ctx: {
|
|
16
|
+
...opts.ctx,
|
|
17
|
+
<%= rdbNameCamel %>,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
} finally {
|
|
21
|
+
await <%= rdbNameCamel %>.$disconnect();
|
|
22
|
+
}
|
|
23
|
+
<% } else { %>
|
|
24
|
+
return await opts.next({
|
|
25
|
+
ctx: {
|
|
26
|
+
...opts.ctx,
|
|
27
|
+
<%= rdbNameCamel %>,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
<% } %>
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { Tree } from '@nx/devkit';
|
|
6
|
+
import { TsRdbTrpcConnectionGeneratorSchema } from './schema';
|
|
7
|
+
import { NxGeneratorInfo } from '../../../utils/nx';
|
|
8
|
+
export declare const TS_RDB_TRPC_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
export declare const tsRdbTrpcConnectionGenerator: (tree: Tree, options: TsRdbTrpcConnectionGeneratorSchema) => Promise<void>;
|
|
10
|
+
export default tsRdbTrpcConnectionGenerator;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsRdbTrpcConnectionGenerator = exports.TS_RDB_TRPC_CONNECTION_GENERATOR_INFO = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
*/
|
|
9
|
+
const devkit_1 = require("@nx/devkit");
|
|
10
|
+
const nx_1 = require("../../../utils/nx");
|
|
11
|
+
const metrics_1 = require("../../../utils/metrics");
|
|
12
|
+
const format_1 = require("../../../utils/format");
|
|
13
|
+
const names_1 = require("../../../utils/names");
|
|
14
|
+
const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
|
|
15
|
+
const npm_scope_1 = require("../../../utils/npm-scope");
|
|
16
|
+
exports.TS_RDB_TRPC_CONNECTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
17
|
+
const tsRdbTrpcConnectionGenerator = async (tree, options) => {
|
|
18
|
+
const sourceProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.sourceProject);
|
|
19
|
+
const targetProject = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.targetProject);
|
|
20
|
+
if (sourceProject.targets?.['serve-local']) {
|
|
21
|
+
(0, nx_1.addDependencyToTargetIfNotPresent)(sourceProject, 'serve-local', {
|
|
22
|
+
projects: [targetProject.name],
|
|
23
|
+
target: 'serve-local',
|
|
24
|
+
});
|
|
25
|
+
(0, devkit_1.updateProjectConfiguration)(tree, sourceProject.name, sourceProject);
|
|
26
|
+
}
|
|
27
|
+
const rdbBaseName = targetProject.name.split('/').pop();
|
|
28
|
+
const rdbNameKebab = (0, names_1.kebabCase)(rdbBaseName);
|
|
29
|
+
const rdbNameCamel = (0, lodash_camelcase_1.default)(rdbBaseName);
|
|
30
|
+
const rdbNamePascal = (0, names_1.pascalCase)(rdbBaseName);
|
|
31
|
+
const rdbPackageAlias = (0, npm_scope_1.toScopeAlias)(targetProject.name);
|
|
32
|
+
const engine = (targetProject.metadata ?? {}).engine ?? 'PostgreSQL';
|
|
33
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), sourceProject.root, { rdbNameKebab, rdbNameCamel, rdbNamePascal, rdbPackageAlias, engine }, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
34
|
+
await (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [
|
|
35
|
+
exports.TS_RDB_TRPC_CONNECTION_GENERATOR_INFO,
|
|
36
|
+
]);
|
|
37
|
+
await (0, format_1.formatFilesInSubtree)(tree);
|
|
38
|
+
};
|
|
39
|
+
exports.tsRdbTrpcConnectionGenerator = tsRdbTrpcConnectionGenerator;
|
|
40
|
+
exports.default = exports.tsRdbTrpcConnectionGenerator;
|
|
41
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/rdb/trpc-connection/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAMoB;AAEpB,0CAK2B;AAC3B,oDAAyE;AACzE,kDAA6D;AAC7D,gDAA6D;AAC7D,gFAAyC;AACzC,wDAAwD;AAE3C,QAAA,qCAAqC,GAChD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,4BAA4B,GAAG,KAAK,EAC/C,IAAU,EACV,OAA2C,EAC5B,EAAE;IACjB,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,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3C,IAAA,sCAAiC,EAAC,aAAa,EAAE,aAAa,EAAE;YAC9D,QAAQ,EAAE,CAAC,aAAa,CAAC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
|
+
* TypeScript types for options defined in schema.json
|
|
8
|
+
*/
|
|
9
|
+
export interface TsRdbTrpcConnectionGeneratorSchema {
|
|
10
|
+
sourceProject: string;
|
|
11
|
+
targetProject: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#rdb#trpc-connection",
|
|
4
|
+
"title": "ts#rdb#trpc-connection",
|
|
5
|
+
"description": "Connect a ts#trpc-api project to a ts#rdb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The ts#trpc-api project to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#rdb project to connect to"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["sourceProject", "targetProject"]
|
|
18
|
+
}
|
|
@@ -641,15 +641,13 @@ const multiply = tool({
|
|
|
641
641
|
callback: ({ a, b }) => a * b,
|
|
642
642
|
});
|
|
643
643
|
|
|
644
|
-
export const getAgent = async (
|
|
645
|
-
|
|
646
|
-
return new Agent({
|
|
644
|
+
export const getAgent = async () =>
|
|
645
|
+
new Agent({
|
|
647
646
|
systemPrompt: \`You are a mathematical wizard.
|
|
648
647
|
Use your tools for mathematical tasks.
|
|
649
648
|
Refer to tools as your 'spellbook'.\`,
|
|
650
649
|
tools: [multiply],
|
|
651
650
|
});
|
|
652
|
-
};
|
|
653
651
|
"
|
|
654
652
|
`;
|
|
655
653
|
|
|
@@ -915,6 +913,7 @@ console.log(\`TRPC server listening on port \${PORT}\`);
|
|
|
915
913
|
|
|
916
914
|
exports[`ts#strands-agent generator > should match snapshot for generated files > strands-agent-init.ts 1`] = `
|
|
917
915
|
"import { initTRPC } from '@trpc/server';
|
|
916
|
+
import { enterSessionContext } from ':proj/agent-connection';
|
|
918
917
|
|
|
919
918
|
export interface Context {
|
|
920
919
|
sessionId: string;
|
|
@@ -922,7 +921,17 @@ export interface Context {
|
|
|
922
921
|
|
|
923
922
|
export const t = initTRPC.context<Context>().create();
|
|
924
923
|
|
|
925
|
-
|
|
924
|
+
/**
|
|
925
|
+
* Bind the inbound session onto the current async flow so downstream MCP /
|
|
926
|
+
* A2A clients forward it on outbound calls. Uses \`enterWith\` so the binding
|
|
927
|
+
* persists across subscription iterations.
|
|
928
|
+
*/
|
|
929
|
+
const sessionMiddleware = t.middleware(({ ctx, next }) => {
|
|
930
|
+
enterSessionContext(ctx.sessionId);
|
|
931
|
+
return next();
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
export const publicProcedure = t.procedure.use(sessionMiddleware);
|
|
926
935
|
"
|
|
927
936
|
`;
|
|
928
937
|
|
|
@@ -930,10 +939,13 @@ exports[`ts#strands-agent generator > should match snapshot for generated files
|
|
|
930
939
|
"import { publicProcedure, t } from './init.js';
|
|
931
940
|
import { z } from 'zod';
|
|
932
941
|
import { zAsyncIterable } from './schema/z-async-iterable.js';
|
|
942
|
+
import { withSessionId } from ':proj/agent-connection';
|
|
933
943
|
import { getAgent } from './agent.js';
|
|
934
944
|
|
|
935
945
|
export const router = t.router;
|
|
936
946
|
|
|
947
|
+
const agent = withSessionId(getAgent);
|
|
948
|
+
|
|
937
949
|
export const appRouter = router({
|
|
938
950
|
invoke: publicProcedure
|
|
939
951
|
.input(z.object({ message: z.string() }))
|
|
@@ -944,8 +956,6 @@ export const appRouter = router({
|
|
|
944
956
|
}),
|
|
945
957
|
)
|
|
946
958
|
.subscription(async function* (opts) {
|
|
947
|
-
const agent = await getAgent(opts.ctx.sessionId);
|
|
948
|
-
|
|
949
959
|
for await (const event of agent.stream(opts.input.message)) {
|
|
950
960
|
if (
|
|
951
961
|
event.type === 'modelStreamUpdateEvent' &&
|
|
@@ -2,26 +2,18 @@ import { A2AAgent } from '@strands-agents/sdk/a2a';
|
|
|
2
2
|
import { AgentCoreA2aClient } from '../core/agentcore-a2a-client.js';
|
|
3
3
|
import { getConnectedAgentRuntimeArn } from '../core/runtime-config.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Client for connecting to the <%- targetAgentClassName %> A2A agent.
|
|
7
|
-
*
|
|
8
|
-
* In deployed mode: resolves the AgentCore runtime ARN from runtime config
|
|
9
|
-
* and uses a SigV4-authenticated A2A transport.
|
|
10
|
-
*
|
|
11
|
-
* In local mode (SERVE_LOCAL env var set): connects directly to the local
|
|
12
|
-
* A2A server over plain HTTP.
|
|
13
|
-
*/
|
|
5
|
+
/** Client for the <%- targetAgentClassName %> A2A agent. */
|
|
14
6
|
export class <%- targetAgentClassName %>Client {
|
|
15
|
-
static async create(
|
|
7
|
+
static async create(): Promise<A2AAgent> {
|
|
16
8
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
17
|
-
return
|
|
9
|
+
return AgentCoreA2aClient.withoutAuth({
|
|
18
10
|
url: 'http://localhost:<%- targetAgentPort %>/',
|
|
19
11
|
});
|
|
20
12
|
}
|
|
21
|
-
|
|
22
13
|
return AgentCoreA2aClient.withIamAuth({
|
|
23
|
-
agentRuntimeArn: await getConnectedAgentRuntimeArn(
|
|
24
|
-
|
|
14
|
+
agentRuntimeArn: await getConnectedAgentRuntimeArn(
|
|
15
|
+
'<%- targetAgentClassName %>',
|
|
16
|
+
),
|
|
25
17
|
});
|
|
26
18
|
}
|
|
27
19
|
}
|
|
@@ -58,9 +58,8 @@ const tsStrandsAgentA2aConnectionGenerator = async (tree, options) => {
|
|
|
58
58
|
await (0, ast_1.addDestructuredImport)(tree, agentFilePath, ['tool'], '@strands-agents/sdk');
|
|
59
59
|
await (0, ast_1.addDestructuredImport)(tree, agentFilePath, ['z'], 'zod');
|
|
60
60
|
await (0, ast_1.addDestructuredImport)(tree, agentFilePath, [clientClassName], `:${npmScope}/agent-connection`);
|
|
61
|
-
// Build the tool creation + Agent wiring.
|
|
62
|
-
|
|
63
|
-
const toolCreationBlock = `const ${clientVarName} = await ${clientClassName}.create(sessionId);
|
|
61
|
+
// Build the tool creation + Agent wiring.
|
|
62
|
+
const toolCreationBlock = `const ${clientVarName} = await ${clientClassName}.create();
|
|
64
63
|
const ${toolVarName} = tool({
|
|
65
64
|
name: '${toolName}',
|
|
66
65
|
description: 'Delegate a question to the remote ${targetAgentClassName} A2A agent and return its reply.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/a2a-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,0CAK2B;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,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAErD,IAAI,CAAC,cAAc,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,mGAAmG,CACpG,CAAC;IACJ,CAAC;IAED,IAAI,oBAAoB,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACb,iBAAiB,oBAAoB,CAAC,IAAI,cAAc,oBAAoB,CAAC,QAAQ,IAAI,MAAM,wDAAwD,CACxJ,CAAC;IACJ,CA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AM,aAAa,GAAG,IAAA,0BAAiB,EAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAEpE,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAC/B,MAAM,eAAe,GAAG,GAAG,oBAAoB,QAAQ,CAAC;QACxD,MAAM,aAAa,GACjB,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;YAC5C,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAG,MAAM,oBAAoB,EAAE,CAAC;QAC9C,MAAM,WAAW,GAAG,GAAG,aAAa,MAAM,CAAC;QAE3C,wCAAwC;QACxC,MAAM,IAAA,2BAAqB,EACzB,IAAI,EACJ,aAAa,EACb,CAAC,MAAM,CAAC,EACR,qBAAqB,CACtB,CAAC;QACF,MAAM,IAAA,2BAAqB,EAAC,IAAI,EAAE,aAAa,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QAC/D,MAAM,IAAA,2BAAqB,EACzB,IAAI,EACJ,aAAa,EACb,CAAC,eAAe,CAAC,EACjB,IAAI,QAAQ,mBAAmB,CAChC,CAAC;QAEF,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/nx-plugin/src/ts/strands-agent/a2a-connection/generator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,0CAK2B;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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