improv: navigation
This commit is contained in:
parent
02e61b7013
commit
d808c70086
3 changed files with 33 additions and 79 deletions
|
|
@ -11,15 +11,12 @@ import { listUserOrganizations } from "../auth/workos.js";
|
|||
import { env } from "../env.js";
|
||||
import { isValidAnthropicApiKey, getApiKeyValidationError } from "../util/apiKeyValidation.js";
|
||||
import { updateAnthropicModelInYaml } from "../util/yamlConfigUpdater.js";
|
||||
import { useNavigation } from "./context/NavigationContext.js";
|
||||
|
||||
const CONFIG_PATH = path.join(os.homedir(), ".continue", "config.yaml");
|
||||
|
||||
interface FreeTrialTransitionUIProps {
|
||||
onComplete: () => void;
|
||||
onSwitchToLocalConfig?: () => void;
|
||||
onFullReload?: () => void;
|
||||
onShowConfigSelector?: () => void;
|
||||
onShowOrgSelector?: () => void;
|
||||
onReload: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,12 +38,9 @@ async function createOrUpdateConfig(apiKey: string): Promise<void> {
|
|||
}
|
||||
|
||||
const FreeTrialTransitionUI: React.FC<FreeTrialTransitionUIProps> = ({
|
||||
onComplete,
|
||||
onSwitchToLocalConfig,
|
||||
onFullReload,
|
||||
onShowConfigSelector,
|
||||
onShowOrgSelector,
|
||||
onReload,
|
||||
}) => {
|
||||
const { navigateTo, closeCurrentScreen } = useNavigation();
|
||||
const [currentStep, setCurrentStep] = useState<
|
||||
"choice" | "enterApiKey" | "processing" | "success" | "error"
|
||||
>("choice");
|
||||
|
|
@ -102,11 +96,10 @@ const FreeTrialTransitionUI: React.FC<FreeTrialTransitionUIProps> = ({
|
|||
}
|
||||
} else if (currentStep === "success" || currentStep === "error") {
|
||||
if (key.return) {
|
||||
closeCurrentScreen();
|
||||
// If user went through models setup, do a full reload to register their purchase
|
||||
if (wasModelsSetup && onFullReload) {
|
||||
onFullReload();
|
||||
} else {
|
||||
onComplete();
|
||||
if (wasModelsSetup) {
|
||||
onReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -137,18 +130,10 @@ const FreeTrialTransitionUI: React.FC<FreeTrialTransitionUIProps> = ({
|
|||
setWasModelsSetup(false); // This is not models setup
|
||||
} else if (selectedOption === 3) {
|
||||
// Option 3: Switch to different configuration
|
||||
if (onShowConfigSelector) {
|
||||
onShowConfigSelector();
|
||||
} else {
|
||||
onComplete();
|
||||
}
|
||||
navigateTo('config');
|
||||
} else if (selectedOption === 4 && hasOrganizations) {
|
||||
// Option 4: Switch to organization
|
||||
if (onShowOrgSelector) {
|
||||
onShowOrgSelector();
|
||||
} else {
|
||||
onComplete();
|
||||
}
|
||||
navigateTo('organization');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -164,11 +149,8 @@ const FreeTrialTransitionUI: React.FC<FreeTrialTransitionUIProps> = ({
|
|||
|
||||
// After a brief delay, switch to local configuration
|
||||
setTimeout(() => {
|
||||
if (onSwitchToLocalConfig) {
|
||||
onSwitchToLocalConfig();
|
||||
} else {
|
||||
onComplete();
|
||||
}
|
||||
closeCurrentScreen();
|
||||
onReload();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
setErrorMessage(
|
||||
|
|
|
|||
|
|
@ -198,12 +198,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
|
||||
const { renderMessage } = useMessageRenderer();
|
||||
|
||||
const {
|
||||
showOrgSelector,
|
||||
handleOrganizationSelect,
|
||||
handleOrganizationCancel,
|
||||
showOrganizationSelector,
|
||||
} = useOrganizationSelector({
|
||||
const { handleOrganizationSelect } = useOrganizationSelector({
|
||||
configPath,
|
||||
onAssistantChange: () => {},
|
||||
onMessage: (message) => {
|
||||
|
|
@ -212,12 +207,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
onChatReset: resetChatHistory,
|
||||
});
|
||||
|
||||
const {
|
||||
showConfigSelector,
|
||||
handleConfigSelect,
|
||||
handleConfigCancel,
|
||||
showConfigSelectorUI,
|
||||
} = useConfigSelector({
|
||||
const { handleConfigSelect } = useConfigSelector({
|
||||
configPath,
|
||||
onMessage: (message) => {
|
||||
setMessages((prev) => [...prev, message]);
|
||||
|
|
@ -225,12 +215,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
onChatReset: resetChatHistory,
|
||||
});
|
||||
|
||||
const {
|
||||
showModelSelector,
|
||||
handleModelSelect,
|
||||
handleModelCancel,
|
||||
showModelSelectorUI,
|
||||
} = useModelSelector({
|
||||
const { handleModelSelect } = useModelSelector({
|
||||
onMessage: (message) => {
|
||||
setMessages((prev) => [...prev, message]);
|
||||
},
|
||||
|
|
@ -287,7 +272,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
)}
|
||||
|
||||
{/* Login prompt - shows above input when active */}
|
||||
{loginPrompt && (
|
||||
{isScreenActive('login') && navState.screenData && (
|
||||
<Box
|
||||
paddingX={1}
|
||||
borderStyle="round"
|
||||
|
|
@ -298,7 +283,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
<Text color="yellow" bold>
|
||||
Login Required
|
||||
</Text>
|
||||
<Text>{loginPrompt.text}</Text>
|
||||
<Text>{navState.screenData.text}</Text>
|
||||
<UserInput
|
||||
onSubmit={handleLoginTokenSubmit}
|
||||
isWaitingForResponse={false}
|
||||
|
|
@ -312,42 +297,36 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
)}
|
||||
|
||||
{/* Organization selector - shows above input when active */}
|
||||
{showOrgSelector && (
|
||||
{isScreenActive('organization') && (
|
||||
<OrganizationSelector
|
||||
onSelect={handleOrganizationSelect}
|
||||
onCancel={handleOrganizationCancel}
|
||||
onCancel={closeCurrentScreen}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Config selector - shows above input when active */}
|
||||
{showConfigSelector && (
|
||||
{isScreenActive('config') && (
|
||||
<ConfigSelector
|
||||
onSelect={handleConfigSelect}
|
||||
onCancel={handleConfigCancel}
|
||||
onCancel={closeCurrentScreen}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Model selector - shows above input when active */}
|
||||
{showModelSelector && (
|
||||
{isScreenActive('model') && (
|
||||
<ModelSelector
|
||||
onSelect={handleModelSelect}
|
||||
onCancel={handleModelCancel}
|
||||
onCancel={closeCurrentScreen}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Free trial transition UI - replaces input when active */}
|
||||
{isShowingFreeTrialTransition && (
|
||||
<FreeTrialTransitionUI
|
||||
onComplete={handleFreeTrialTransitionComplete}
|
||||
onSwitchToLocalConfig={handleFreeTrialSwitchToLocal}
|
||||
onFullReload={handleFreeTrialFullReload}
|
||||
onShowConfigSelector={handleFreeTrialShowConfigSelector}
|
||||
onShowOrgSelector={handleFreeTrialShowOrgSelector}
|
||||
/>
|
||||
{isScreenActive('free-trial') && (
|
||||
<FreeTrialTransitionUI onReload={handleReload} />
|
||||
)}
|
||||
|
||||
{/* Input area - only show when not showing free trial transition */}
|
||||
{!isShowingFreeTrialTransition && (
|
||||
{/* Input area - only show when showing chat screen */}
|
||||
{isScreenActive('chat') && (
|
||||
<>
|
||||
{/* Show permission selector when there's an active permission request */}
|
||||
{activePermissionRequest ? (
|
||||
|
|
@ -396,7 +375,13 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
<FreeTrialStatus
|
||||
apiClient={services.apiClient?.apiClient || undefined}
|
||||
model={services.model.model}
|
||||
onTransitionStateChange={setIsShowingFreeTrialTransition}
|
||||
onTransitionStateChange={(shouldShow) => {
|
||||
if (shouldShow && navState.currentScreen === 'chat') {
|
||||
navigateTo('free-trial');
|
||||
} else if (!shouldShow && navState.currentScreen === 'free-trial') {
|
||||
closeCurrentScreen();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
|
|
@ -32,13 +32,11 @@ export function useOrganizationSelector({
|
|||
onMessage,
|
||||
onChatReset,
|
||||
}: UseOrganizationSelectorProps) {
|
||||
const [showOrgSelector, setShowOrgSelector] = useState(false);
|
||||
|
||||
const handleOrganizationSelect = async (
|
||||
organizationId: string | null,
|
||||
organizationName: string
|
||||
) => {
|
||||
setShowOrgSelector(false);
|
||||
|
||||
// Update auth config
|
||||
const authConfig = loadAuthConfig();
|
||||
|
|
@ -101,18 +99,7 @@ export function useOrganizationSelector({
|
|||
}
|
||||
};
|
||||
|
||||
const handleOrganizationCancel = () => {
|
||||
setShowOrgSelector(false);
|
||||
};
|
||||
|
||||
const showOrganizationSelector = () => {
|
||||
setShowOrgSelector(true);
|
||||
};
|
||||
|
||||
return {
|
||||
showOrgSelector,
|
||||
handleOrganizationSelect,
|
||||
handleOrganizationCancel,
|
||||
showOrganizationSelector,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue