Skip to content

Commit 74a35cb

Browse files
authored
fix: agentcore add component opens component wizard directly (aws#896)
When running `agentcore add memory` (or any other component), the TUI was always showing the generic resource selection screen. This is because AddFlow always started in the 'select' state regardless of which subcommand invoked it. Added an `initialResource` prop to AddFlow that maps directly to the correct wizard state, skipping the selection screen. Each primitive now passes its resource type when rendering AddFlow in TUI fallback mode. Closes aws#857
1 parent b97e337 commit 74a35cb

7 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/cli/primitives/AgentPrimitive.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ export class AgentPrimitive extends BasePrimitive<AddAgentOptions, RemovableReso
340340
const { clear, unmount } = render(
341341
React.createElement(AddFlow, {
342342
isInteractive: false,
343+
initialResource: 'agent',
343344
onExit: () => {
344345
clear();
345346
unmount();

src/cli/primitives/CredentialPrimitive.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ export class CredentialPrimitive extends BasePrimitive<AddCredentialOptions, Rem
347347
const { clear, unmount } = render(
348348
React.createElement(AddFlow, {
349349
isInteractive: false,
350+
initialResource: 'credential',
350351
onExit: () => {
351352
clear();
352353
unmount();

src/cli/primitives/EvaluatorPrimitive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export class EvaluatorPrimitive extends BasePrimitive<AddEvaluatorOptions, Remov
324324
const { clear, unmount } = render(
325325
React.createElement(AddFlow, {
326326
isInteractive: false,
327+
initialResource: 'evaluator',
327328
onExit: () => {
328329
clear();
329330
unmount();

src/cli/primitives/MemoryPrimitive.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export class MemoryPrimitive extends BasePrimitive<AddMemoryOptions, RemovableMe
238238
const { clear, unmount } = render(
239239
React.createElement(AddFlow, {
240240
isInteractive: false,
241+
initialResource: 'memory',
241242
onExit: () => {
242243
clear();
243244
unmount();

src/cli/primitives/OnlineEvalConfigPrimitive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class OnlineEvalConfigPrimitive extends BasePrimitive<AddOnlineEvalConfig
179179
const { clear, unmount } = render(
180180
React.createElement(AddFlow, {
181181
isInteractive: false,
182+
initialResource: 'online-eval',
182183
onExit: () => {
183184
clear();
184185
unmount();

src/cli/primitives/PolicyPrimitive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ export class PolicyPrimitive extends BasePrimitive<AddPolicyOptions, RemovablePo
351351
const { clear, unmount } = render(
352352
React.createElement(AddFlow, {
353353
isInteractive: false,
354+
initialResource: 'policy',
354355
onExit: () => {
355356
clear();
356357
unmount();

src/cli/tui/screens/add/AddFlow.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,37 @@ interface AddFlowProps {
157157
onDev?: () => void;
158158
/** Called when user selects deploy from success screen */
159159
onDeploy?: () => void;
160+
/** Skip the selection screen and go directly to a specific resource wizard */
161+
initialResource?: AddResourceType;
162+
}
163+
164+
function getInitialFlowState(resource?: AddResourceType): FlowState {
165+
switch (resource) {
166+
case 'agent':
167+
return { name: 'agent-wizard' };
168+
case 'gateway':
169+
return { name: 'gateway-wizard' };
170+
case 'gateway-target':
171+
return { name: 'tool-wizard' };
172+
case 'memory':
173+
return { name: 'memory-wizard' };
174+
case 'credential':
175+
return { name: 'identity-wizard' };
176+
case 'evaluator':
177+
return { name: 'evaluator-wizard' };
178+
case 'online-eval':
179+
return { name: 'online-eval-wizard' };
180+
case 'policy':
181+
return { name: 'policy-wizard' };
182+
default:
183+
return { name: 'select' };
184+
}
160185
}
161186

162187
export function AddFlow(props: AddFlowProps) {
163188
const { addAgent, reset: resetAgent } = useAddAgent();
164189
const { agents, refresh: refreshAgents } = useAvailableAgents();
165-
const [flow, setFlow] = useState<FlowState>({ name: 'select' });
190+
const [flow, setFlow] = useState<FlowState>(() => getInitialFlowState(props.initialResource));
166191

167192
// In non-interactive mode, exit after success (but not while loading)
168193
useEffect(() => {

0 commit comments

Comments
 (0)