forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.ts
More file actions
164 lines (147 loc) · 5.98 KB
/
Copy pathcommand.ts
File metadata and controls
164 lines (147 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { ValidationError } from '../../../lib';
import { ANSI } from '../../constants';
import { withCommandRunTelemetry } from '../../telemetry/cli-command-run.js';
import { handleImport } from './actions';
import { registerImportEvaluator } from './import-evaluator';
import { registerImportGateway } from './import-gateway';
import { registerImportMemory } from './import-memory';
import { registerImportOnlineEval } from './import-online-eval';
import { registerImportRuntime } from './import-runtime';
import type { Command } from '@commander-js/extra-typings';
import * as fs from 'node:fs';
const { red, green, yellow, cyan, dim, reset } = ANSI;
export const registerImport = (program: Command) => {
const importCmd = program
.command('import')
.description('Import a runtime, memory, or starter toolkit into this project.');
// Existing YAML flow: agentcore import --source <path>
importCmd
.option('--source <path>', 'Path to the .bedrock_agentcore.yaml configuration file')
.option('--target <target>', 'Deployment target name (only needed if project has multiple targets)')
.option('-y, --yes', 'Auto-confirm prompts')
.action(async (cliOptions: { source?: string; target?: string; yes?: boolean }) => {
if (!cliOptions.source) {
// No --source and no subcommand — launch interactive TUI.
// requireProject() first so users who haven't cd'd to a project get the
// more actionable error before the TTY check (consistent with `view`).
const { requireProject, requireTTY } = await import('../../tui/guards');
requireProject();
requireTTY();
const { render } = await import('ink');
const React = await import('react');
const { ImportFlow } = await import('../../tui/screens/import');
const inkRef: { current?: { clear: () => void; unmount: () => void } } = {};
const exitTui = () => {
inkRef.current?.clear();
inkRef.current?.unmount();
};
const navigateTo = async (command: string) => {
exitTui();
if (command === 'deploy') {
const { DeployScreen } = await import('../../tui/screens/deploy/DeployScreen');
const deployInstance = render(
React.createElement(DeployScreen, {
isInteractive: false,
onExit: () => {
deployInstance.unmount();
process.exit(0);
},
})
);
} else if (command === 'status') {
const { StatusScreen } = await import('../../tui/screens/status/StatusScreen');
const statusInstance = render(
React.createElement(StatusScreen, {
isInteractive: false,
onExit: () => {
statusInstance.unmount();
process.exit(0);
},
})
);
}
};
inkRef.current = render(
React.createElement(ImportFlow, {
onBack: exitTui,
onNavigate: (command: string) => void navigateTo(command),
})
);
return;
}
const warnings: string[] = [];
const result = await withCommandRunTelemetry('import', {}, async () => {
if (!fs.existsSync(cliOptions.source!)) {
return { success: false as const, error: new ValidationError(`Source file not found: ${cliOptions.source}`) };
}
const importResult = await handleImport({
source: cliOptions.source!,
target: cliOptions.target,
yes: cliOptions.yes,
onProgress: (message: string) => {
// Collect warnings for end-of-output display
if (message.startsWith('Warning')) {
warnings.push(message);
return;
}
// Skipped items shown dimmed
if (message.startsWith('Skipping')) {
console.log(`${dim}[skip]${reset} ${message}`);
return;
}
// Normal progress steps shown as [done]
console.log(`${green}[done]${reset} ${message}`);
},
});
return importResult;
});
if (result.success) {
// Summary
console.log('');
console.log(`${green}Import complete!${reset}`);
console.log('');
console.log(`${dim}Imported:${reset}`);
console.log(` Stack: ${result.stackName}`);
if (result.importedAgents && result.importedAgents.length > 0) {
for (const agent of result.importedAgents) {
console.log(` Agent: ${agent}`);
}
}
if (result.importedMemories && result.importedMemories.length > 0) {
for (const mem of result.importedMemories) {
console.log(` Memory: ${mem}`);
}
}
// Show collected warnings
if (warnings.length > 0) {
console.log('');
for (const w of warnings) {
console.log(`${yellow}[warn]${reset} ${w}`);
}
}
// Next steps
console.log('');
console.log('To continue:');
console.log('');
console.log(` ${cyan}agentcore deploy${reset} ${dim}Deploy the imported stack${reset}`);
console.log(` ${cyan}agentcore status${reset} ${dim}Verify resource status${reset}`);
console.log(` ${cyan}agentcore invoke${reset} ${dim}Test your agent${reset}`);
console.log('');
if (result.logPath) {
console.log(`Log: ${result.logPath}`);
}
} else {
console.error(`\n${red}[error]${reset} Import failed: ${result.error.message}`);
if (result.logPath) {
console.error(`Log: ${result.logPath}`);
}
process.exit(1);
}
});
// Register subcommands for importing individual resource types from AWS
registerImportRuntime(importCmd);
registerImportMemory(importCmd);
registerImportEvaluator(importCmd);
registerImportOnlineEval(importCmd);
registerImportGateway(importCmd);
};