Skip to content

Commit 7c08566

Browse files
committed
style: fix prettier formatting across all changed files
1 parent 3264cf0 commit 7c08566

13 files changed

Lines changed: 94 additions & 125 deletions

File tree

src/cli/aws/__tests__/bedrock-import.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { describe, expect, it, vi, beforeEach } from 'vitest';
1+
import { getBedrockAgentConfig, listBedrockAgentAliases, listBedrockAgents } from '../bedrock-import';
2+
import { beforeEach, describe, expect, it, vi } from 'vitest';
23

34
const mockAgentSend = vi.fn();
45
const mockBedrockSend = vi.fn();
@@ -7,7 +8,9 @@ const mockS3Send = vi.fn();
78
// Mock the AWS SDK clients using class syntax for proper `new` support
89
vi.mock('@aws-sdk/client-bedrock-agent', () => {
910
return {
10-
BedrockAgentClient: class { send = mockAgentSend; },
11+
BedrockAgentClient: class {
12+
send = mockAgentSend;
13+
},
1114
ListAgentsCommand: class {},
1215
ListAgentAliasesCommand: class {},
1316
GetAgentCommand: class {},
@@ -22,15 +25,19 @@ vi.mock('@aws-sdk/client-bedrock-agent', () => {
2225

2326
vi.mock('@aws-sdk/client-bedrock', () => {
2427
return {
25-
BedrockClient: class { send = mockBedrockSend; },
28+
BedrockClient: class {
29+
send = mockBedrockSend;
30+
},
2631
GetFoundationModelCommand: class {},
2732
GetGuardrailCommand: class {},
2833
};
2934
});
3035

3136
vi.mock('@aws-sdk/client-s3', () => {
3237
return {
33-
S3Client: class { send = mockS3Send; },
38+
S3Client: class {
39+
send = mockS3Send;
40+
},
3441
GetObjectCommand: class {},
3542
};
3643
});
@@ -43,8 +50,6 @@ vi.mock('js-yaml', () => ({
4350
default: { load: vi.fn((s: string) => JSON.parse(s)) },
4451
}));
4552

46-
import { listBedrockAgents, listBedrockAgentAliases, getBedrockAgentConfig } from '../bedrock-import';
47-
4853
describe('bedrock-import', () => {
4954
beforeEach(() => {
5055
vi.clearAllMocks();
@@ -77,15 +82,11 @@ describe('bedrock-import', () => {
7782
describe('listBedrockAgentAliases', () => {
7883
it('returns mapped alias summaries', async () => {
7984
mockAgentSend.mockResolvedValueOnce({
80-
agentAliasSummaries: [
81-
{ agentAliasId: 'alias-1', agentAliasName: 'prod', description: 'Production' },
82-
],
85+
agentAliasSummaries: [{ agentAliasId: 'alias-1', agentAliasName: 'prod', description: 'Production' }],
8386
});
8487

8588
const result = await listBedrockAgentAliases('us-east-1', 'agent-1');
86-
expect(result).toEqual([
87-
{ aliasId: 'alias-1', aliasName: 'prod', description: 'Production' },
88-
]);
89+
expect(result).toEqual([{ aliasId: 'alias-1', aliasName: 'prod', description: 'Production' }]);
8990
});
9091
});
9192

src/cli/aws/bedrock-import.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* AWS SDK v3 wrapper for fetching Bedrock Agent configurations.
33
* Port of the starter toolkit's agent_info.py.
44
*/
5-
5+
import { getCredentialProvider } from './account';
66
import type {
77
ActionGroupInfo,
88
BedrockAgentConfig,
@@ -12,21 +12,20 @@ import type {
1212
CollaboratorInfo,
1313
KnowledgeBaseInfo,
1414
} from './bedrock-import-types';
15+
import { BedrockClient, GetFoundationModelCommand, GetGuardrailCommand } from '@aws-sdk/client-bedrock';
1516
import {
1617
BedrockAgentClient,
18+
GetAgentActionGroupCommand,
1719
GetAgentAliasCommand,
1820
GetAgentCommand,
19-
GetAgentActionGroupCommand,
2021
GetKnowledgeBaseCommand,
2122
ListAgentActionGroupsCommand,
2223
ListAgentAliasesCommand,
2324
ListAgentCollaboratorsCommand,
2425
ListAgentKnowledgeBasesCommand,
2526
ListAgentsCommand,
2627
} from '@aws-sdk/client-bedrock-agent';
27-
import { BedrockClient, GetFoundationModelCommand, GetGuardrailCommand } from '@aws-sdk/client-bedrock';
2828
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
29-
import { getCredentialProvider } from './account';
3029
import yaml from 'js-yaml';
3130

3231
function createBedrockAgentClient(region: string): BedrockAgentClient {
@@ -172,9 +171,7 @@ async function fetchActionGroups(
172171
agentId: string,
173172
agentVersion: string
174173
): Promise<ActionGroupInfo[]> {
175-
const listResponse = await client.send(
176-
new ListAgentActionGroupsCommand({ agentId, agentVersion })
177-
);
174+
const listResponse = await client.send(new ListAgentActionGroupsCommand({ agentId, agentVersion }));
178175
const summaries = listResponse.actionGroupSummaries ?? [];
179176
const actionGroups: ActionGroupInfo[] = [];
180177

@@ -230,17 +227,13 @@ async function fetchKnowledgeBases(
230227
agentId: string,
231228
agentVersion: string
232229
): Promise<KnowledgeBaseInfo[]> {
233-
const listResponse = await client.send(
234-
new ListAgentKnowledgeBasesCommand({ agentId, agentVersion })
235-
);
230+
const listResponse = await client.send(new ListAgentKnowledgeBasesCommand({ agentId, agentVersion }));
236231
const summaries = listResponse.agentKnowledgeBaseSummaries ?? [];
237232
const knowledgeBases: KnowledgeBaseInfo[] = [];
238233

239234
for (const summary of summaries) {
240235
try {
241-
const kbDetail = await client.send(
242-
new GetKnowledgeBaseCommand({ knowledgeBaseId: summary.knowledgeBaseId! })
243-
);
236+
const kbDetail = await client.send(new GetKnowledgeBaseCommand({ knowledgeBaseId: summary.knowledgeBaseId! }));
244237
const kb = kbDetail.knowledgeBase;
245238
knowledgeBases.push({
246239
knowledgeBaseId: summary.knowledgeBaseId!,
@@ -276,9 +269,7 @@ async function fetchCollaborators(
276269
}
277270

278271
try {
279-
const listResponse = await agentClient.send(
280-
new ListAgentCollaboratorsCommand({ agentId, agentVersion })
281-
);
272+
const listResponse = await agentClient.send(new ListAgentCollaboratorsCommand({ agentId, agentVersion }));
282273
const summaries = listResponse.agentCollaboratorSummaries ?? [];
283274
const collaborators: CollaboratorInfo[] = [];
284275

@@ -295,9 +286,13 @@ async function fetchCollaborators(
295286
const collabConfig = await getBedrockAgentConfig(region, collabAgentId, collabAliasId);
296287
const collabInfo: CollaboratorInfo = {
297288
...collabConfig,
298-
collaboratorName: cleanVariableName((summary as unknown as { collaboratorName?: string }).collaboratorName ?? ''),
299-
collaborationInstruction: (summary as unknown as { collaborationInstruction?: string }).collaborationInstruction ?? '',
300-
relayConversationHistory: (summary as unknown as { relayConversationHistory?: string }).relayConversationHistory ?? 'DISABLED',
289+
collaboratorName: cleanVariableName(
290+
(summary as unknown as { collaboratorName?: string }).collaboratorName ?? ''
291+
),
292+
collaborationInstruction:
293+
(summary as unknown as { collaborationInstruction?: string }).collaborationInstruction ?? '',
294+
relayConversationHistory:
295+
(summary as unknown as { relayConversationHistory?: string }).relayConversationHistory ?? 'DISABLED',
301296
};
302297
collaborators.push(collabInfo);
303298
}

src/cli/commands/create/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { APP_DIR, CONFIG_DIR, ConfigIO, setEnvVar, setSessionProjectRoot } from '../../../lib';
2-
import { executeImportAgent } from '../../operations/agent/import';
32
import type {
43
AgentCoreProjectSpec,
54
BuildType,
@@ -18,6 +17,7 @@ import {
1817
mapModelProviderToIdentityProviders,
1918
writeAgentToProject,
2019
} from '../../operations/agent/generate';
20+
import { executeImportAgent } from '../../operations/agent/import';
2121
import { credentialPrimitive } from '../../primitives/registry';
2222
import { CDKRenderer, createRenderer } from '../../templates';
2323
import type { CreateResult } from './types';

src/cli/commands/create/validate.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ export function validateCreateOptions(options: CreateOptions, cwd?: string): Val
6060
if (!options.agentId) return { valid: false, error: '--agent-id is required for import' };
6161
if (!options.agentAliasId) return { valid: false, error: '--agent-alias-id is required for import' };
6262
if (!options.region) return { valid: false, error: '--region is required for import' };
63-
if (!options.framework) return { valid: false, error: '--framework is required for import (Strands or LangChain_LangGraph)' };
63+
if (!options.framework)
64+
return { valid: false, error: '--framework is required for import (Strands or LangChain_LangGraph)' };
6465
const fw = matchEnumValue(SDKFrameworkSchema, options.framework) ?? options.framework;
6566
options.framework = fw;
6667
if (fw !== 'Strands' && fw !== 'LangChain_LangGraph') {
6768
return { valid: false, error: `Import only supports Strands or LangChain_LangGraph, got: ${options.framework}` };
6869
}
6970
options.memory ??= 'none';
7071
if (!MEMORY_OPTIONS.includes(options.memory as (typeof MEMORY_OPTIONS)[number])) {
71-
return { valid: false, error: `Invalid memory option: ${options.memory}. Use none, shortTerm, or longAndShortTerm` };
72+
return {
73+
valid: false,
74+
error: `Invalid memory option: ${options.memory}. Use none, shortTerm, or longAndShortTerm`,
75+
};
7276
}
7377
return { valid: true };
7478
}

src/cli/operations/agent/import/__tests__/translator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { describe, expect, it } from 'vitest';
21
import type { BedrockAgentConfig } from '../../../../aws/bedrock-import-types';
3-
import { StrandsTranslator } from '../strands-translator';
42
import { LangGraphTranslator } from '../langgraph-translator';
53
import { generatePyprojectToml } from '../pyproject-generator';
4+
import { StrandsTranslator } from '../strands-translator';
5+
import { describe, expect, it } from 'vitest';
66

77
function makeSimpleAgentConfig(overrides: Partial<BedrockAgentConfig> = {}): BedrockAgentConfig {
88
return {

src/cli/operations/agent/import/base-translator.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Generates Python code strings for action groups, KBs, multi-agent collaboration,
66
* code interpreter, user input, guardrails, prompts, and memory wiring.
77
*/
8-
98
import type {
109
ActionGroupInfo,
1110
BedrockAgentConfig,
@@ -76,18 +75,15 @@ export abstract class BaseBedrockTranslator {
7675
protected readonly collaboratorContext?: { name: string; instruction: string; relayHistory: string }
7776
) {
7877
this.agentInfo = config.agent;
79-
this.actionGroups = (config.action_groups ?? []).filter(
80-
ag => (ag.actionGroupState ?? 'ENABLED') === 'ENABLED'
81-
);
78+
this.actionGroups = (config.action_groups ?? []).filter(ag => (ag.actionGroupState ?? 'ENABLED') === 'ENABLED');
8279
this.customActionGroups = this.actionGroups.filter(ag => !ag.parentActionSignature);
8380
this.knowledgeBases = config.knowledge_bases ?? [];
8481
this.collaborators = config.collaborators ?? [];
8582

8683
this.modelId = this.agentInfo.foundationModel ?? '';
8784
this.agentRegion = this.agentInfo.agentArn?.split(':')[3] ?? 'us-east-1';
8885
this.instruction = this.agentInfo.instruction ?? '';
89-
this.promptConfigs =
90-
this.agentInfo.promptOverrideConfiguration?.promptConfigurations ?? [];
86+
this.promptConfigs = this.agentInfo.promptOverrideConfiguration?.promptConfigurations ?? [];
9187
this.enabledPrompts = [];
9288

9389
// Memory
@@ -111,7 +107,8 @@ export abstract class BaseBedrockTranslator {
111107
this.guardrailConfig = {};
112108
const gc = this.agentInfo.guardrailConfiguration;
113109
if (gc) {
114-
const gId = (gc as Record<string, string>).guardrailId ?? (gc as Record<string, string>).guardrailIdentifier ?? '';
110+
const gId =
111+
(gc as Record<string, string>).guardrailId ?? (gc as Record<string, string>).guardrailIdentifier ?? '';
115112
const gVersion = (gc as Record<string, string>).version ?? (gc as Record<string, string>).guardrailVersion ?? '';
116113
if (gId) {
117114
this.guardrailConfig = { guardrailIdentifier: gId, guardrailVersion: gVersion };
@@ -221,7 +218,16 @@ load_dotenv()
221218
const params = fn.parameters ?? {};
222219
const paramList = Object.entries(params)
223220
.map(([name, info]) => {
224-
const pyType = info.type === 'string' ? 'str' : info.type === 'integer' ? 'int' : info.type === 'number' ? 'float' : info.type === 'boolean' ? 'bool' : 'str';
221+
const pyType =
222+
info.type === 'string'
223+
? 'str'
224+
: info.type === 'integer'
225+
? 'int'
226+
: info.type === 'number'
227+
? 'float'
228+
: info.type === 'boolean'
229+
? 'bool'
230+
: 'str';
225231
return `${name}: ${pyType}`;
226232
})
227233
.join(', ');
@@ -286,13 +292,9 @@ memory_id = os.environ.get("MEMORY_ID", "")
286292
platform === 'strands'
287293
? 'tools_used.update(list(agent_result.metrics.tool_metrics.keys()))'
288294
: 'tools_used.update([msg.name for msg in agent_result if isinstance(msg, ToolMessage)])';
289-
const responseContent =
290-
platform === 'strands' ? 'str(agent_result)' : 'agent_result[-1].content';
295+
const responseContent = platform === 'strands' ? 'str(agent_result)' : 'agent_result[-1].content';
291296

292-
const lines = [
293-
'def endpoint(payload, context):',
294-
' try:',
295-
];
297+
const lines = ['def endpoint(payload, context):', ' try:'];
296298
if (this.agentcoreMemoryEnabled) {
297299
lines.push(' global user_id');
298300
lines.push(' user_id = user_id or payload.get("userId", uuid.uuid4().hex[:8])');
@@ -303,30 +305,30 @@ memory_id = os.environ.get("MEMORY_ID", "")
303305
' tools_used.clear()',
304306
' agent_query = payload.get("prompt", "")',
305307
' if not agent_query:',
306-
' return {\'error\': "No query provided, please provide a \'prompt\' field in the payload."}',
308+
" return {'error': \"No query provided, please provide a 'prompt' field in the payload.\"}",
307309
'',
308310
' agent_result = invoke_agent(agent_query)',
309311
'',
310312
' ' + toolsUsedUpdate,
311313
' response_content = ' + responseContent,
312314
'',
313315
' sources = []',
314-
' urls = re.findall(r\'https?://[^\\s<>"{}|\\\\^`\\[\\]]+\', response_content)',
316+
" urls = re.findall(r'https?://[^\\s<>\"{}|\\\\^`\\[\\]]+', response_content)",
315317
' source_tags = re.findall(r"<source>(.*?)</source>", response_content)',
316318
' sources.extend(urls)',
317319
' sources.extend(source_tags)',
318320
' sources = list(set(sources))',
319321
'',
320-
' formatted_messages = [(agent_query, "USER"), (response_content if response_content else "No Response.", "ASSISTANT")]',
322+
' formatted_messages = [(agent_query, "USER"), (response_content if response_content else "No Response.", "ASSISTANT")]'
321323
);
322324
if (memoryEventCode) {
323325
lines.push(memoryEventCode);
324326
}
325327
lines.push(
326328
'',
327-
' return {\'result\': {\'response\': response_content, \'sources\': sources, \'tools_used\': list(tools_used), \'sessionId\': session_id, \'messages\': formatted_messages}}',
329+
" return {'result': {'response': response_content, 'sources': sources, 'tools_used': list(tools_used), 'sessionId': session_id, 'messages': formatted_messages}}",
328330
' except Exception as e:',
329-
' return {\'error\': str(e)}',
331+
" return {'error': str(e)}"
330332
);
331333
code += lines.join('\n');
332334
return code;

src/cli/operations/agent/import/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
* Provides executeImportAgent() as the shared handler called by both
44
* the TUI hook (useAddAgent) and the non-interactive CLI (AgentPrimitive).
55
*/
6-
76
import { APP_DIR } from '../../../../lib';
87
import type { SDKFramework } from '../../../../schema';
98
import { getBedrockAgentConfig } from '../../../aws/bedrock-import';
9+
import { getErrorMessage } from '../../../errors';
10+
import type { AddResult } from '../../../primitives/types';
1011
import type { MemoryOption } from '../../../tui/screens/generate/types';
11-
import { writeAgentToProject } from '../generate/write-agent-to-project';
1212
import { setupPythonProject } from '../../python';
13+
import { writeAgentToProject } from '../generate/write-agent-to-project';
1314
import { LangGraphTranslator } from './langgraph-translator';
1415
import { generatePyprojectToml } from './pyproject-generator';
1516
import { StrandsTranslator } from './strands-translator';
16-
import type { AddResult } from '../../../primitives/types';
17-
import { getErrorMessage } from '../../../errors';
1817
import { mkdirSync, writeFileSync } from 'fs';
1918
import { dirname, join } from 'path';
2019

src/cli/operations/agent/import/langgraph-translator.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
* LangChain/LangGraph-specific translator for Bedrock Agent import.
33
* Port of the starter toolkit's bedrock_to_langchain.py.
44
*/
5-
5+
import type { BedrockAgentConfig } from '../../../aws/bedrock-import-types';
66
import type { TranslationResult, TranslatorOptions } from './base-translator';
77
import { BaseBedrockTranslator } from './base-translator';
8-
import type { BedrockAgentConfig } from '../../../aws/bedrock-import-types';
98

109
export class LangGraphTranslator extends BaseBedrockTranslator {
1110
constructor(
@@ -164,15 +163,11 @@ retriever_tool_${kbName} = retriever_${kbName}.as_tool(name="kb_${kbName}", desc
164163
const fileName = `langchain_collaborator_${collabName}`;
165164

166165
// Recursively translate collaborator
167-
const collabTranslator = new LangGraphTranslator(
168-
collaborator as unknown as BedrockAgentConfig,
169-
this.options,
170-
{
171-
name: collabName,
172-
instruction: collaborator.collaborationInstruction ?? '',
173-
relayHistory: collaborator.relayConversationHistory ?? 'DISABLED',
174-
}
175-
);
166+
const collabTranslator = new LangGraphTranslator(collaborator as unknown as BedrockAgentConfig, this.options, {
167+
name: collabName,
168+
instruction: collaborator.collaborationInstruction ?? '',
169+
relayHistory: collaborator.relayConversationHistory ?? 'DISABLED',
170+
});
176171
const collabResult = collabTranslator.translate();
177172
collaboratorFiles.set(`${fileName}.py`, collabResult.mainPyContent);
178173
for (const [k, v] of collabResult.collaboratorFiles) {

0 commit comments

Comments
 (0)