()
| 39 | } |
| 40 | |
| 41 | export function StatusBarConnection() { |
| 42 | const t = useTranslations("Folder.statusBar.connection") |
| 43 | const store = useConnectionStore() |
| 44 | const { tabs, activeTabId } = useTabContext() |
| 45 | const { conversations } = useAppWorkspace() |
| 46 | |
| 47 | // Subscribe to activeKey changes |
| 48 | const subscribeActiveKey = useCallback( |
| 49 | (cb: () => void) => store.subscribeActiveKey(cb), |
| 50 | [store] |
| 51 | ) |
| 52 | const getActiveKey = useCallback(() => store.getActiveKey(), [store]) |
| 53 | const activeKey = useSyncExternalStore( |
| 54 | subscribeActiveKey, |
| 55 | getActiveKey, |
| 56 | getActiveKey |
| 57 | ) |
| 58 | |
| 59 | // Subscribe to the active connection's changes |
| 60 | const subscribeConn = useCallback( |
| 61 | (cb: () => void) => { |
| 62 | if (!activeKey) return () => {} |
| 63 | return store.subscribeKey(activeKey, cb) |
| 64 | }, |
| 65 | [store, activeKey] |
| 66 | ) |
| 67 | const getConnSnapshot = useCallback( |
| 68 | () => (activeKey ? store.getConnection(activeKey) : undefined), |
| 69 | [store, activeKey] |
| 70 | ) |
| 71 | const activeConn = useSyncExternalStore( |
| 72 | subscribeConn, |
| 73 | getConnSnapshot, |
| 74 | getConnSnapshot |
| 75 | ) |
| 76 | |
| 77 | const status = activeConn?.status ?? null |
| 78 | const agentType = activeConn?.agentType ?? null |
| 79 | |
| 80 | const model = useMemo(() => { |
| 81 | const tab = tabs.find((t) => t.id === activeTabId) |
| 82 | if (!tab || tab.kind !== "conversation") return null |
| 83 | const conv = conversations.find( |
| 84 | (c) => c.id === tab.conversationId && c.agent_type === tab.agentType |
| 85 | ) |
| 86 | return conv?.model ?? null |
| 87 | }, [tabs, activeTabId, conversations]) |
| 88 | |
| 89 | if (!agentType || !status || status === "disconnected") { |
| 90 | return ( |
| 91 | <TooltipProvider> |
| 92 | <Tooltip> |
| 93 | <TooltipTrigger asChild> |
| 94 | <div className="flex items-center gap-1.5"> |
| 95 | <Unplug className="h-3.5 w-3.5 text-muted-foreground/50" /> |
| 96 | {model && <span>{model}</span>} |
| 97 | </div> |
| 98 | </TooltipTrigger> |
nothing calls this directly
no test coverage detected