forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeployStatus.tsx
More file actions
186 lines (165 loc) · 5.29 KB
/
Copy pathDeployStatus.tsx
File metadata and controls
186 lines (165 loc) · 5.29 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
import type { DeployMessage } from '../../cdk/toolkit-lib';
import { GradientText } from './StepProgress';
import { Box, Text } from 'ink';
import React, { useMemo } from 'react';
interface DeployStatusProps {
messages: DeployMessage[];
isComplete: boolean;
hasError: boolean;
}
const PROGRESS_BAR_WIDTH = 20;
// CDK message code for resource events
const CDK_CODE_RESOURCE_EVENT = 'CDK_TOOLKIT_I5502';
/**
* Extract resource progress from messages.
* Progress is pre-extracted at the source (in createSwitchableIoHost).
*/
function extractProgress(messages: DeployMessage[]): { current: number; total: number } | null {
// Search from end to find most recent message with progress
for (let i = messages.length - 1; i >= 0; i--) {
const msg = messages[i];
if (msg?.progress) {
return { current: msg.progress.completed, total: msg.progress.total };
}
}
return null;
}
/**
* Progress bar component.
*/
function ProgressBar({ current, total }: { current: number; total: number }) {
const percent = total > 0 ? current / total : 0;
const filled = Math.round(percent * PROGRESS_BAR_WIDTH);
const empty = PROGRESS_BAR_WIDTH - filled;
return (
<Box>
<Text color="cyan">[</Text>
<Text color="green">{'█'.repeat(filled)}</Text>
<Text color="gray">{'░'.repeat(empty)}</Text>
<Text color="cyan">]</Text>
<Text>
{' '}
{current}/{total}
</Text>
</Box>
);
}
type ResourceStatus =
| 'CREATE_IN_PROGRESS'
| 'CREATE_COMPLETE'
| 'CREATE_FAILED'
| 'UPDATE_IN_PROGRESS'
| 'UPDATE_COMPLETE'
| 'UPDATE_FAILED'
| 'DELETE_IN_PROGRESS'
| 'DELETE_COMPLETE'
| 'DELETE_FAILED';
interface ParsedResource {
resourceType: string;
status: ResourceStatus;
}
/**
* Get color for a resource status.
*/
function getStatusColor(status: ResourceStatus): string | undefined {
if (status.endsWith('_COMPLETE')) return 'green';
if (status.endsWith('_FAILED')) return 'red';
if (status.endsWith('_IN_PROGRESS')) return 'cyan';
return undefined;
}
/**
* Extract resource type and status from a CDK resource event message.
* Only processes I5502 (resource event) messages.
*/
function parseResourceMessage(msg: DeployMessage): ParsedResource | null {
// Only process resource event messages
if (msg.code !== CDK_CODE_RESOURCE_EVENT) {
return null;
}
const text = msg.message;
// Skip CLEANUP messages - they're confusing
if (text.includes('CLEANUP')) {
return null;
}
// Format: "StackName | STATUS | AWS::Service::Resource | LogicalId"
const resourceMatch = /(AWS::\S+)/.exec(text);
const statusMatch =
/(CREATE_IN_PROGRESS|CREATE_COMPLETE|CREATE_FAILED|UPDATE_IN_PROGRESS|UPDATE_COMPLETE|UPDATE_FAILED|DELETE_IN_PROGRESS|DELETE_COMPLETE|DELETE_FAILED)/.exec(
text
);
if (resourceMatch?.[1] && statusMatch) {
const shortType = resourceMatch[1].replace(/^AWS::/, '');
return { resourceType: shortType, status: statusMatch[1] as ResourceStatus };
}
return null;
}
/**
* Render a resource line with color-coded status.
*/
function ResourceLine({ resource }: { resource: ParsedResource }) {
const color = getStatusColor(resource.status);
return (
<Text color={color}>
{resource.resourceType} {resource.status}
</Text>
);
}
/**
* Deploy status component showing deployment progress in a contained box.
* During deployment: shows last N resource events (type + status only)
* After completion: shows success/failure state
*/
export function DeployStatus({ messages, isComplete, hasError }: DeployStatusProps) {
// Parse and filter messages to only meaningful resource updates
const parsedResources = messages
.map(msg => ({ original: msg, parsed: parseResourceMessage(msg) }))
.filter((m): m is { original: DeployMessage; parsed: ParsedResource } => m.parsed !== null)
.slice(-8);
// Extract progress for the bar
const progress = useMemo(() => extractProgress(messages), [messages]);
// When complete, show final status
if (isComplete) {
return (
<Box
flexDirection="column"
borderStyle="round"
borderColor={hasError ? 'red' : 'green'}
paddingX={1}
minWidth={50}
>
<Text bold color={hasError ? 'red' : 'green'}>
{hasError ? '✗ Deploy to AWS Failed' : '✓ Deploy to AWS Complete'}
</Text>
{progress && (
<Box marginTop={1}>
<ProgressBar current={progress.total} total={progress.total} />
</Box>
)}
{hasError && (
<Box flexDirection="column" marginTop={1}>
{parsedResources.slice(-3).map((m, i) => (
<ResourceLine key={`${m.original.code}-${i}`} resource={m.parsed} />
))}
</Box>
)}
</Box>
);
}
return (
<Box flexDirection="column" borderStyle="round" borderColor="gray" paddingX={1} minWidth={50}>
<GradientText text="Deploying to AWS" />
{progress && (
<Box marginTop={1}>
<ProgressBar current={progress.current} total={progress.total} />
</Box>
)}
{parsedResources.length > 0 && (
<Box flexDirection="column" marginTop={1}>
{parsedResources.map((m, i) => (
<ResourceLine key={`${m.original.code}-${i}`} resource={m.parsed} />
))}
</Box>
)}
</Box>
);
}