| 4 | * Determine the current view state based on messages and pending asks |
| 5 | */ |
| 6 | export function getView(messages: TUIMessage[], pendingAsk: PendingAsk | null, isLoading: boolean): View { |
| 7 | // If there's a pending ask requiring text input, show input |
| 8 | if (pendingAsk?.type === "followup") { |
| 9 | return "UserInput" |
| 10 | } |
| 11 | |
| 12 | // If there's any pending ask (approval), don't show thinking |
| 13 | if (pendingAsk) { |
| 14 | return "UserInput" |
| 15 | } |
| 16 | |
| 17 | // Initial state or empty - awaiting user input |
| 18 | if (messages.length === 0) { |
| 19 | return "UserInput" |
| 20 | } |
| 21 | |
| 22 | const lastMessage = messages.at(-1) |
| 23 | if (!lastMessage) { |
| 24 | return "UserInput" |
| 25 | } |
| 26 | |
| 27 | // User just sent a message, waiting for response |
| 28 | if (lastMessage.role === "user") { |
| 29 | return "AgentResponse" |
| 30 | } |
| 31 | |
| 32 | // Assistant replied |
| 33 | if (lastMessage.role === "assistant") { |
| 34 | if (lastMessage.hasPendingToolCalls) { |
| 35 | return "ToolUse" |
| 36 | } |
| 37 | |
| 38 | // If loading, still waiting for more |
| 39 | if (isLoading) { |
| 40 | return "AgentResponse" |
| 41 | } |
| 42 | |
| 43 | return "UserInput" |
| 44 | } |
| 45 | |
| 46 | // Tool result received, waiting for next assistant response |
| 47 | if (lastMessage.role === "tool") { |
| 48 | return "AgentResponse" |
| 49 | } |
| 50 | |
| 51 | return "Default" |
| 52 | } |