forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand.tsx
More file actions
78 lines (69 loc) · 2.95 KB
/
Copy pathcommand.tsx
File metadata and controls
78 lines (69 loc) · 2.95 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
import { getErrorMessage } from '../../errors';
import { handlePauseResume } from '../../operations/eval';
import type { OnlineEvalActionOptions } from '../../operations/eval';
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
import { requireProject } from '../../tui/guards';
import type { Command } from '@commander-js/extra-typings';
import { Text, render } from 'ink';
import React from 'react';
function registerOnlineEvalSubcommand(parent: Command, action: 'pause' | 'resume') {
const description =
action === 'pause'
? 'Pause a deployed online eval config. Use --arn to target configs outside the project.'
: 'Resume a paused online eval config. Use --arn to target configs outside the project.';
const pastTense = action === 'pause' ? 'Paused' : 'Resumed';
parent
.command('online-eval')
.description(description)
.argument('[name]', 'Config name from project (not needed with --arn)')
.option('--arn <arn>', 'Online eval config ARN — operate without a project directory')
.option('--region <region>', 'AWS region override (auto-detected from ARN otherwise)')
.option('--json', 'Output as JSON')
.action(async (name: string | undefined, cliOptions: { arn?: string; region?: string; json?: boolean }) => {
if (!cliOptions.arn && !name) {
const error = 'Either a config name or --arn is required';
if (cliOptions.json) {
console.log(JSON.stringify({ success: false, error }));
} else {
render(<Text color="red">{error}</Text>);
}
process.exit(1);
}
if (!cliOptions.arn) {
requireProject();
}
const options: OnlineEvalActionOptions = {
name: name ?? '',
arn: cliOptions.arn,
region: cliOptions.region,
json: cliOptions.json,
};
try {
const result = await handlePauseResume(options, action);
if (cliOptions.json) {
console.log(JSON.stringify(result));
} else if (result.success) {
const displayName = cliOptions.arn ? result.configId : name;
console.log(`${pastTense} online eval config "${displayName}" (status: ${result.executionStatus})`);
} else {
render(<Text color="red">{result.error}</Text>);
}
process.exit(result.success ? 0 : 1);
} catch (error) {
if (cliOptions.json) {
console.log(JSON.stringify({ success: false, error: getErrorMessage(error) }));
} else {
render(<Text color="red">Error: {getErrorMessage(error)}</Text>);
}
process.exit(1);
}
});
}
export const registerPause = (program: Command) => {
const pauseCmd = program.command('pause').description(COMMAND_DESCRIPTIONS.pause);
registerOnlineEvalSubcommand(pauseCmd, 'pause');
};
export const registerResume = (program: Command) => {
const resumeCmd = program.command('resume').description(COMMAND_DESCRIPTIONS.resume);
registerOnlineEvalSubcommand(resumeCmd, 'resume');
};