-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcommand.tsx
More file actions
299 lines (271 loc) · 10.1 KB
/
command.tsx
File metadata and controls
299 lines (271 loc) · 10.1 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
import { requireProject } from '../../tui/guards';
import { AddFlow } from '../../tui/screens/add/AddFlow';
import { handleAddAgent, handleAddGateway, handleAddIdentity, handleAddMcpTool, handleAddMemory } from './actions';
import type {
AddAgentOptions,
AddGatewayOptions,
AddIdentityOptions,
AddMcpToolOptions,
AddMemoryOptions,
} from './types';
import {
validateAddAgentOptions,
validateAddGatewayOptions,
validateAddIdentityOptions,
validateAddMcpToolOptions,
validateAddMemoryOptions,
} from './validate';
import type { Command } from '@commander-js/extra-typings';
import { render } from 'ink';
import React from 'react';
async function handleAddAgentCLI(options: AddAgentOptions): Promise<void> {
const validation = validateAddAgentOptions(options);
if (!validation.valid) {
if (options.json) {
console.log(JSON.stringify({ success: false, error: validation.error }));
} else {
console.error(validation.error);
}
process.exit(1);
}
const result = await handleAddAgent({
name: options.name!,
type: options.type! ?? 'create',
buildType: (options.build as 'CodeZip' | 'Container') ?? 'CodeZip',
language: options.language!,
framework: options.framework!,
modelProvider: options.modelProvider!,
apiKey: options.apiKey,
memory: options.memory,
codeLocation: options.codeLocation,
entrypoint: options.entrypoint,
});
if (options.json) {
console.log(JSON.stringify(result));
} else if (result.success) {
console.log(`Added agent '${result.agentName}'`);
if (result.agentPath) {
console.log(`Agent code: ${result.agentPath}`);
}
} else {
console.error(result.error);
}
process.exit(result.success ? 0 : 1);
}
// Gateway disabled - rename to _handleAddGatewayCLI until feature is re-enabled
async function _handleAddGatewayCLI(options: AddGatewayOptions): Promise<void> {
const validation = validateAddGatewayOptions(options);
if (!validation.valid) {
if (options.json) {
console.log(JSON.stringify({ success: false, error: validation.error }));
} else {
console.error(validation.error);
}
process.exit(1);
}
const result = await handleAddGateway({
name: options.name!,
description: options.description,
authorizerType: options.authorizerType ?? 'NONE',
discoveryUrl: options.discoveryUrl,
allowedAudience: options.allowedAudience,
allowedClients: options.allowedClients,
agents: options.agents,
});
if (options.json) {
console.log(JSON.stringify(result));
} else if (result.success) {
console.log(`Added gateway '${result.gatewayName}'`);
} else {
console.error(result.error);
}
process.exit(result.success ? 0 : 1);
}
// MCP Tool disabled - prefix with underscore until feature is re-enabled
async function _handleAddMcpToolCLI(options: AddMcpToolOptions): Promise<void> {
const validation = validateAddMcpToolOptions(options);
if (!validation.valid) {
if (options.json) {
console.log(JSON.stringify({ success: false, error: validation.error }));
} else {
console.error(validation.error);
}
process.exit(1);
}
const result = await handleAddMcpTool({
name: options.name!,
description: options.description,
language: options.language! as 'Python' | 'TypeScript',
exposure: options.exposure!,
agents: options.agents,
gateway: options.gateway,
host: options.host,
});
if (options.json) {
console.log(JSON.stringify(result));
} else if (result.success) {
console.log(`Added MCP tool '${result.toolName}'`);
if (result.sourcePath) {
console.log(`Tool code: ${result.sourcePath}`);
}
} else {
console.error(result.error);
}
process.exit(result.success ? 0 : 1);
}
// v2: Memory is a top-level resource (no owner/user)
async function handleAddMemoryCLI(options: AddMemoryOptions): Promise<void> {
const validation = validateAddMemoryOptions(options);
if (!validation.valid) {
if (options.json) {
console.log(JSON.stringify({ success: false, error: validation.error }));
} else {
console.error(validation.error);
}
process.exit(1);
}
const result = await handleAddMemory({
name: options.name!,
strategies: options.strategies,
expiry: options.expiry,
});
if (options.json) {
console.log(JSON.stringify(result));
} else if (result.success) {
console.log(`Added memory '${result.memoryName}'`);
} else {
console.error(result.error);
}
process.exit(result.success ? 0 : 1);
}
// v2: Identity/Credential is a top-level resource (no owner/user)
async function handleAddIdentityCLI(options: AddIdentityOptions): Promise<void> {
const validation = validateAddIdentityOptions(options);
if (!validation.valid) {
if (options.json) {
console.log(JSON.stringify({ success: false, error: validation.error }));
} else {
console.error(validation.error);
}
process.exit(1);
}
const result = await handleAddIdentity({
name: options.name!,
apiKey: options.apiKey!,
});
if (options.json) {
console.log(JSON.stringify(result));
} else if (result.success) {
console.log(`Added credential '${result.credentialName}'`);
} else {
console.error(result.error);
}
process.exit(result.success ? 0 : 1);
}
export function registerAdd(program: Command) {
const addCmd = program
.command('add')
.description(COMMAND_DESCRIPTIONS.add)
// Catch-all argument for invalid subcommands - Commander matches subcommands first
.argument('[subcommand]')
.action((subcommand: string | undefined, _options, cmd) => {
if (subcommand) {
console.error(`error: '${subcommand}' is not a valid subcommand.`);
cmd.outputHelp();
process.exit(1);
}
requireProject();
const { clear, unmount } = render(
<AddFlow
isInteractive={false}
onExit={() => {
clear();
unmount();
}}
/>
);
})
.showHelpAfterError()
.showSuggestionAfterError();
// Subcommand: add agent
addCmd
.command('agent')
.description('Add an agent to the project')
.option('--name <name>', 'Agent name (start with letter, alphanumeric only, max 64 chars) [non-interactive]')
.option('--type <type>', 'Agent type: create or byo [non-interactive]', 'create')
.option('--build <type>', 'Build type: CodeZip or Container (default: CodeZip) [non-interactive]')
.option('--language <lang>', 'Language: Python (create), or Python/TypeScript/Other (BYO) [non-interactive]')
.option(
'--framework <fw>',
'Framework: Strands, LangChain_LangGraph, CrewAI, GoogleADK, OpenAIAgents [non-interactive]'
)
.option('--model-provider <provider>', 'Model provider: Bedrock, Anthropic, OpenAI, Gemini [non-interactive]')
.option('--api-key <key>', 'API key for non-Bedrock providers [non-interactive]')
.option('--memory <mem>', 'Memory: none, shortTerm, longAndShortTerm (create path only) [non-interactive]')
.option('--code-location <path>', 'Path to existing code (BYO path only) [non-interactive]')
.option('--entrypoint <file>', 'Entry file relative to code-location (BYO, default: main.py) [non-interactive]')
.option('--json', 'Output as JSON [non-interactive]')
.action(async options => {
requireProject();
await handleAddAgentCLI(options as AddAgentOptions);
});
// Subcommand: add gateway (disabled - coming soon)
addCmd
.command('gateway', { hidden: true })
.description('Add an MCP gateway to the project')
.option('--name <name>', 'Gateway name')
.option('--description <desc>', 'Gateway description')
.option('--authorizer-type <type>', 'Authorizer type: NONE or CUSTOM_JWT', 'NONE')
.option('--discovery-url <url>', 'OIDC discovery URL (required for CUSTOM_JWT)')
.option('--allowed-audience <values>', 'Comma-separated allowed audience values (required for CUSTOM_JWT)')
.option('--allowed-clients <values>', 'Comma-separated allowed client IDs (required for CUSTOM_JWT)')
.option('--agents <names>', 'Comma-separated agent names to attach gateway to')
.option('--json', 'Output as JSON')
.action(() => {
console.error('AgentCore Gateway integration is coming soon.');
process.exit(1);
});
// Subcommand: add mcp-tool (disabled - coming soon)
addCmd
.command('mcp-tool', { hidden: true })
.description('Add an MCP tool to the project')
.option('--name <name>', 'Tool name')
.option('--description <desc>', 'Tool description')
.option('--language <lang>', 'Language: Python or TypeScript')
.option('--exposure <mode>', 'Exposure mode: mcp-runtime or behind-gateway')
.option('--agents <names>', 'Comma-separated agent names (for mcp-runtime)')
.option('--gateway <name>', 'Gateway name (for behind-gateway)')
.option('--host <host>', 'Compute host: Lambda or AgentCoreRuntime (for behind-gateway)')
.option('--json', 'Output as JSON')
.action(() => {
console.error('MCP Tool integration is coming soon.');
process.exit(1);
});
// Subcommand: add memory (v2: top-level resource)
addCmd
.command('memory')
.description('Add a memory resource to the project')
.option('--name <name>', 'Memory name [non-interactive]')
.option(
'--strategies <types>',
'Comma-separated strategies: SEMANTIC, SUMMARIZATION, USER_PREFERENCE [non-interactive]'
)
.option('--expiry <days>', 'Event expiry duration in days (default: 30) [non-interactive]', parseInt)
.option('--json', 'Output as JSON [non-interactive]')
.action(async options => {
requireProject();
await handleAddMemoryCLI(options as AddMemoryOptions);
});
// Subcommand: add identity (v2: top-level credential resource)
addCmd
.command('identity')
.description('Add a credential to the project')
.option('--name <name>', 'Credential name [non-interactive]')
.option('--api-key <key>', 'The API key value [non-interactive]')
.option('--json', 'Output as JSON [non-interactive]')
.action(async options => {
requireProject();
await handleAddIdentityCLI(options as AddIdentityOptions);
});
}