qwen-code/packages/cli/src/ui/components/subagents/ActionSelectionStep.tsx

75 lines
2 KiB
TypeScript
Raw Normal View History

2025-09-04 16:34:51 +08:00
/**
* @license
* Copyright 2025 Qwen
* SPDX-License-Identifier: Apache-2.0
*/
2025-09-04 23:29:47 +08:00
import { useState } from 'react';
2025-09-04 16:34:51 +08:00
import { Box } from 'ink';
import { RadioButtonSelect } from '../shared/RadioButtonSelect.js';
2025-09-04 23:29:47 +08:00
import { MANAGEMENT_STEPS } from './types.js';
import { SubagentConfig } from '@qwen-code/qwen-code-core';
2025-09-04 23:29:47 +08:00
interface ActionSelectionStepProps {
selectedAgent: SubagentConfig | null;
2025-09-04 23:29:47 +08:00
onNavigateToStep: (step: string) => void;
onNavigateBack: () => void;
}
2025-09-04 16:34:51 +08:00
export const ActionSelectionStep = ({
selectedAgent,
2025-09-04 23:29:47 +08:00
onNavigateToStep,
onNavigateBack,
}: ActionSelectionStepProps) => {
const [selectedAction, setSelectedAction] = useState<
'view' | 'edit' | 'delete' | null
>(null);
// Filter actions based on whether the agent is built-in
const allActions = [
2025-09-04 16:34:51 +08:00
{ label: 'View Agent', value: 'view' as const },
{ label: 'Edit Agent', value: 'edit' as const },
{ label: 'Delete Agent', value: 'delete' as const },
{ label: 'Back', value: 'back' as const },
];
const actions = selectedAgent?.isBuiltin
? allActions.filter(
(action) => action.value === 'view' || action.value === 'back',
)
: allActions;
2025-09-04 16:34:51 +08:00
const handleActionSelect = (value: 'view' | 'edit' | 'delete' | 'back') => {
if (value === 'back') {
2025-09-04 23:29:47 +08:00
onNavigateBack();
2025-09-04 16:34:51 +08:00
return;
}
2025-09-04 23:29:47 +08:00
setSelectedAction(value);
// Navigate to appropriate step based on action
if (value === 'view') {
onNavigateToStep(MANAGEMENT_STEPS.AGENT_VIEWER);
} else if (value === 'edit') {
onNavigateToStep(MANAGEMENT_STEPS.EDIT_OPTIONS);
} else if (value === 'delete') {
onNavigateToStep(MANAGEMENT_STEPS.DELETE_CONFIRMATION);
}
2025-09-04 16:34:51 +08:00
};
2025-09-04 23:29:47 +08:00
const selectedIndex = selectedAction
? actions.findIndex((action) => action.value === selectedAction)
2025-09-04 16:34:51 +08:00
: 0;
return (
<Box flexDirection="column">
<RadioButtonSelect
items={actions}
initialIndex={selectedIndex}
onSelect={handleActionSelect}
showNumbers={false}
/>
</Box>
);
};