| 1 | import { Box, Text } from "ink"; |
| 2 | import React from "react"; |
| 3 | |
| 4 | import { listSessions } from "../../session.js"; |
| 5 | import { ConfigSelector } from "../ConfigSelector.js"; |
| 6 | import type { NavigationScreen } from "../context/NavigationContext.js"; |
| 7 | import { FreeTrialTransitionUI } from "../FreeTrialTransitionUI.js"; |
| 8 | import { MCPSelector } from "../MCPSelector.js"; |
| 9 | import { ModelSelector } from "../ModelSelector.js"; |
| 10 | import { SessionSelector } from "../SessionSelector.js"; |
| 11 | import type { ConfigOption, ModelOption } from "../types/selectorTypes.js"; |
| 12 | import { UserInput } from "../UserInput.js"; |
| 13 | |
| 14 | import { ToolPermissionSelector } from "./ToolPermissionSelector.js"; |
| 15 | |
| 16 | interface ScreenContentProps { |
| 17 | isScreenActive: (screen: NavigationScreen) => boolean; |
| 18 | navState: any; |
| 19 | services: any; |
| 20 | handleLoginTokenSubmit: (token: string) => void; |
| 21 | handleConfigSelect: (config: ConfigOption) => Promise<void>; |
| 22 | handleModelSelect: (model: ModelOption) => Promise<void>; |
| 23 | handleSessionSelect: (sessionId: string) => Promise<void>; |
| 24 | handleReload: () => Promise<void>; |
| 25 | closeCurrentScreen: () => void; |
| 26 | activePermissionRequest: any; |
| 27 | handleToolPermissionResponse: ( |
| 28 | requestId: string, |
| 29 | approved: boolean, |
| 30 | createPolicy?: boolean, |
| 31 | stopStream?: boolean, |
| 32 | ) => void; |
| 33 | handleUserMessage: (message: string, imageMap?: Map<string, Buffer>) => void; |
| 34 | isWaitingForResponse: boolean; |
| 35 | isCompacting: boolean; |
| 36 | inputMode: boolean; |
| 37 | handleInterrupt: () => void; |
| 38 | handleFileAttached: (filePath: string, content: string) => void; |
| 39 | isInputDisabled: boolean; |
| 40 | wasInterrupted?: boolean; |
| 41 | isRemoteMode: boolean; |
| 42 | onImageInClipboardChange?: (hasImage: boolean) => void; |
| 43 | } |
| 44 | |
| 45 | export const ScreenContent: React.FC<ScreenContentProps> = ({ |
| 46 | isScreenActive, |
| 47 | navState, |
| 48 | services, |
| 49 | handleLoginTokenSubmit, |
| 50 | handleConfigSelect, |
| 51 | handleModelSelect, |
| 52 | handleSessionSelect, |
| 53 | handleReload, |
| 54 | closeCurrentScreen, |
| 55 | activePermissionRequest, |
| 56 | handleToolPermissionResponse, |
| 57 | handleUserMessage, |
| 58 | isWaitingForResponse, |
| 59 | isCompacting, |
| 60 | inputMode, |
| 61 | handleInterrupt, |
| 62 | handleFileAttached, |
| 63 | isInputDisabled, |
| 64 | wasInterrupted = false, |
| 65 | isRemoteMode, |
| 66 | onImageInClipboardChange, |
| 67 | }) => { |
| 68 | // Login prompt |
| 69 | if (isScreenActive("login") && navState.screenData) { |
| 70 | return ( |
| 71 | <Box |
| 72 | paddingX={1} |
| 73 | borderStyle="round" |
| 74 | borderColor="yellow" |
| 75 | flexDirection="column" |
| 76 | gap={1} |
| 77 | > |
| 78 | <Text color="yellow" bold> |
| 79 | Login Required |
| 80 | </Text> |
| 81 | <Text>{navState.screenData.text}</Text> |
| 82 | <UserInput |
| 83 | onSubmit={handleLoginTokenSubmit} |
| 84 | isWaitingForResponse={false} |
| 85 | inputMode={true} |
| 86 | assistant={services.config?.config || undefined} |
| 87 | disabled={false} |
| 88 | placeholder="Enter your token..." |
| 89 | hideNormalUI={true} |
| 90 | /> |
| 91 | </Box> |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | // Config selector |
| 96 | if (isScreenActive("config")) { |
| 97 | return ( |
| 98 | <ConfigSelector |
| 99 | onSelect={handleConfigSelect} |
| 100 | onCancel={closeCurrentScreen} |
| 101 | /> |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | if (isScreenActive("mcp")) { |
| 106 | return <MCPSelector onCancel={closeCurrentScreen} />; |
| 107 | } |
| 108 | |
| 109 | // Model selector |
| 110 | if (isScreenActive("model")) { |
| 111 | return ( |
| 112 | <ModelSelector |
| 113 | onSelect={handleModelSelect} |
| 114 | onCancel={closeCurrentScreen} |
| 115 | /> |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | // Session selector |
| 120 | if (isScreenActive("session")) { |
| 121 | const sessions = listSessions(20); |
| 122 | return ( |
| 123 | <SessionSelector |
| 124 | sessions={sessions} |
| 125 | onSelect={handleSessionSelect} |
| 126 | onExit={closeCurrentScreen} |
| 127 | /> |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | // Free trial transition UI |
| 132 | if (isScreenActive("free-trial")) { |
| 133 | return <FreeTrialTransitionUI onReload={handleReload} />; |
| 134 | } |
| 135 | |
| 136 | // Chat screen with input area |
| 137 | if (isScreenActive("chat")) { |
| 138 | if (activePermissionRequest) { |
| 139 | return ( |
| 140 | <ToolPermissionSelector |
| 141 | toolName={activePermissionRequest.toolName} |
| 142 | toolArgs={activePermissionRequest.toolArgs} |
| 143 | requestId={activePermissionRequest.requestId} |
| 144 | toolCallPreview={activePermissionRequest.toolCallPreview} |
| 145 | hasDynamicEvaluation={activePermissionRequest.hasDynamicEvaluation} |
| 146 | onResponse={handleToolPermissionResponse} |
| 147 | /> |
| 148 | ); |
| 149 | } |
| 150 | return ( |
| 151 | <UserInput |
| 152 | onSubmit={handleUserMessage} |
| 153 | isWaitingForResponse={isWaitingForResponse} |
| 154 | isCompacting={isCompacting} |
| 155 | inputMode={inputMode} |
| 156 | onInterrupt={handleInterrupt} |
| 157 | assistant={services.config?.config || undefined} |
| 158 | wasInterrupted={wasInterrupted} |
| 159 | onFileAttached={handleFileAttached} |
| 160 | disabled={isInputDisabled} |
| 161 | isRemoteMode={isRemoteMode} |
| 162 | onImageInClipboardChange={onImageInClipboardChange} |
| 163 | /> |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | return null; |
| 168 | }; |