@@ -75,7 +75,6 @@ import {
7575 resolveProjectProviderInstanceEnabled ,
7676 RuntimeMode ,
7777} from "@t3tools/contracts" ;
78- import { type EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection" ;
7978import { deriveThreadTitleSeed } from "@t3tools/client-runtime/operations" ;
8079import { wasBootstrapThreadDeleted } from "@t3tools/client-runtime/errors" ;
8180import { readPastedComposerContext } from "./composerInlineTokenPaste" ;
@@ -242,7 +241,6 @@ import {
242241 GitBranchIcon ,
243242 ShieldQuestionIcon ,
244243 TargetIcon ,
245- WifiOffIcon ,
246244} from "lucide-react" ;
247245import { cn } from "~/lib/utils" ;
248246import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar" ;
@@ -318,10 +316,6 @@ import {
318316 terminalContextReference ,
319317} from "../lib/composerContextRecords" ;
320318import { type ReviewCommentContext } from "../reviewCommentContext" ;
321- import { environmentCatalog } from "../connection/catalog" ;
322- import { ConnectionDiagnosisHeadline } from "./settings/ConnectionDiagnosisDetails" ;
323- import { isDesktopLocalConnectionTarget } from "../connection/desktopLocal" ;
324- import { useEnvironmentDisconnectDelay } from "../hooks/useEnvironmentDisconnectDelay" ;
325319import { selectThreadTerminalUiState , useTerminalUiStateStore } from "../terminalUiStateStore" ;
326320import { useKnownTerminalSessions , useThreadRunningTerminalIds } from "../state/terminalSessions" ;
327321import { useEnvironmentQuery } from "../state/query" ;
@@ -447,8 +441,6 @@ import {
447441 deriveCommittedServerUserMessageIds ,
448442 deriveComposerSendState ,
449443 dismissBranchMismatchForSession ,
450- hasEnvironmentReconnectWarningGraceElapsed ,
451- scheduleEnvironmentReconnectWarning ,
452444 isBranchMismatchDismissedForSession ,
453445 shouldShowBranchMismatchBanner ,
454446 shouldShowPlanFollowUpPrompt ,
@@ -493,21 +485,6 @@ import { useOrchestrationCommand } from "../state/use-orchestration-command";
493485import { useAtomQueryRunner } from "../state/use-atom-query-runner" ;
494486import { Button , InlineButton } from "./ui/button" ;
495487import { Tooltip , TooltipPopup , TooltipTrigger } from "./ui/tooltip" ;
496- import { ServerUpdateAction , serverUpdateStageLabel } from "./ServerUpdateAction" ;
497- import { useAutoBalanceUpdateBanner } from "./chat/useAutoBalanceUpdateBanner" ;
498- import { ComposerServerUpdateIcon } from "./chat/ComposerServerUpdateStatus" ;
499- import {
500- buildVersionMismatchDismissalKey ,
501- dismissServerUpdateFailure ,
502- dismissVersionMismatch ,
503- isServerUpdateFailureDismissed ,
504- isVersionMismatchDismissed ,
505- resolveServerConfigVersionMismatch ,
506- resolveServerSelfUpdateCapability ,
507- serverUpdateGuidance ,
508- supportsDesktopAppUpdate ,
509- supportsServerUpdateThreadContinuation ,
510- } from "../versionSkew" ;
511488import { useAssetUrls } from "../assets/assetUrls" ;
512489import {
513490 ATTACHMENT_ONLY_BOOTSTRAP_PROMPT ,
@@ -518,6 +495,10 @@ import { ThreadVisitWatermark } from "./chat/ThreadVisitWatermark";
518495import { ChatTerminalDrawers } from "./chat/ChatTerminalDrawers" ;
519496import { ChatRightPanel } from "./chat/ChatRightPanel" ;
520497import { useTimelineFollow } from "./chat/useTimelineFollow" ;
498+ import {
499+ type EnvironmentUnavailableState ,
500+ useSystemComposerBanners ,
501+ } from "./chat/useSystemComposerBanners" ;
521502import { useDraftHeroLayoutTransition } from "./chat/useDraftHeroLayoutTransition" ;
522503import { useLocalDispatchState } from "./chat/useLocalDispatchState" ;
523504import {
@@ -546,11 +527,6 @@ const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = [];
546527const EMPTY_AUTO_UPDATE_ENVIRONMENTS : ReadonlyArray < EnvironmentPresentation > = [ ] ;
547528
548529const EMPTY_PENDING_FILE_SURFACE_IDS : ReadonlySet < string > = new Set ( ) ;
549- type EnvironmentUnavailableState = {
550- readonly environmentId : EnvironmentId ;
551- readonly label : string ;
552- readonly connection : EnvironmentConnectionPresentation ;
553- } ;
554530
555531const SCRIPT_TERMINAL_COLS = 120 ;
556532const SCRIPT_TERMINAL_ROWS = 30 ;
@@ -656,10 +632,6 @@ export default function ChatView(props: ChatViewProps) {
656632 const { environments } = useEnvironments ( ) ;
657633 const providersByEnvironment = useEnvironmentProviders ( ) ;
658634 const primaryEnvironment = usePrimaryEnvironment ( ) ;
659- const retryEnvironment = useAtomCommand ( environmentCatalog . retryNow , { reportFailure : false } ) ;
660- const setEnvironmentEnabled = useAtomCommand ( environmentCatalog . setEnabled , {
661- reportFailure : false ,
662- } ) ;
663635 const environmentById = new Map (
664636 environments . map ( ( environment ) => [ environment . environmentId , environment ] ) ,
665637 ) ;
@@ -1517,35 +1489,8 @@ export default function ChatView(props: ChatViewProps) {
15171489 } , [ activeProjectRef , activeThreadRef ] ) ;
15181490 const activeEnvironment =
15191491 activeThread == null ? null : ( environmentById . get ( activeThread . environmentId ) ?? null ) ;
1520- const activeEnvironmentConnectionPhase = activeEnvironment ?. connection . phase ?? "available" ;
15211492 const activeEnvironmentUnavailable =
1522- activeEnvironment !== null && activeEnvironmentConnectionPhase !== "connected" ;
1523- const activeReconnectingEnvironmentId =
1524- activeEnvironmentConnectionPhase === "connecting" ||
1525- activeEnvironmentConnectionPhase === "reconnecting"
1526- ? ( activeEnvironment ?. environmentId ?? null )
1527- : null ;
1528- const [ reconnectWarningGraceElapsedEnvironmentId , setReconnectWarningGraceElapsedEnvironmentId ] =
1529- useState < EnvironmentId | null > ( null ) ;
1530- // Each reconnect attempt gets its own grace period, including a later one to
1531- // the same environment.
1532- const [ graceReconnectingEnvironmentId , setGraceReconnectingEnvironmentId ] = useState (
1533- activeReconnectingEnvironmentId ,
1534- ) ;
1535- if ( graceReconnectingEnvironmentId !== activeReconnectingEnvironmentId ) {
1536- setGraceReconnectingEnvironmentId ( activeReconnectingEnvironmentId ) ;
1537- setReconnectWarningGraceElapsedEnvironmentId ( null ) ;
1538- }
1539- const reconnectWarningGraceElapsed = hasEnvironmentReconnectWarningGraceElapsed (
1540- activeReconnectingEnvironmentId ,
1541- reconnectWarningGraceElapsedEnvironmentId ,
1542- ) ;
1543- useEffect ( ( ) => {
1544- if ( activeReconnectingEnvironmentId === null ) return ;
1545- return scheduleEnvironmentReconnectWarning ( ( ) =>
1546- setReconnectWarningGraceElapsedEnvironmentId ( activeReconnectingEnvironmentId ) ,
1547- ) ;
1548- } , [ activeReconnectingEnvironmentId ] ) ;
1493+ activeEnvironment !== null && activeEnvironment . connection . phase !== "connected" ;
15491494 const activeEnvironmentUnavailableLabel = activeEnvironment ?. label ?? null ;
15501495 const activeEnvironmentUnavailableState = ( ( ) => {
15511496 if ( ! activeEnvironmentUnavailable || ! activeEnvironmentUnavailableLabel || ! activeEnvironment ) {
@@ -1558,53 +1503,6 @@ export default function ChatView(props: ChatViewProps) {
15581503 connection : activeEnvironment . connection ,
15591504 } ;
15601505 } ) ( ) as EnvironmentUnavailableState | null ;
1561- const handleReconnectActiveEnvironment = async ( environmentId : EnvironmentId ) => {
1562- const result = await retryEnvironment ( environmentId ) ;
1563- if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
1564- const error = squashAtomCommandFailure ( result ) ;
1565- toastManager . add (
1566- stackedThreadToast ( {
1567- type : "error" ,
1568- title : "Could not reconnect environment" ,
1569- description : error instanceof Error ? error . message : "Failed to reconnect." ,
1570- } ) ,
1571- ) ;
1572- }
1573- } ;
1574- const handleReconnectActiveEnvironmentStable = useStableCallback (
1575- handleReconnectActiveEnvironment ,
1576- ) ;
1577- const disconnectDelayElapsed = useEnvironmentDisconnectDelay (
1578- activeEnvironmentUnavailable ? activeEnvironment . environmentId : null ,
1579- ) ;
1580- const canDisconnectActiveEnvironment =
1581- disconnectDelayElapsed &&
1582- activeEnvironment !== null &&
1583- activeEnvironment . entry . target . _tag !== "PrimaryConnectionTarget" &&
1584- ! isDesktopLocalConnectionTarget ( activeEnvironment . entry . target ) ;
1585- const [ disconnectingEnvironment , setDisconnectingEnvironment ] = useState ( false ) ;
1586- const handleDisconnectActiveEnvironment = async ( environmentId : EnvironmentId ) => {
1587- setDisconnectingEnvironment ( true ) ;
1588- const result = await setEnvironmentEnabled ( { environmentId, enabled : false } ) ;
1589- setDisconnectingEnvironment ( false ) ;
1590- if ( result . _tag === "Failure" ) {
1591- if ( ! isAtomCommandInterrupted ( result ) ) {
1592- const error = squashAtomCommandFailure ( result ) ;
1593- toastManager . add (
1594- stackedThreadToast ( {
1595- type : "error" ,
1596- title : "Could not disconnect server" ,
1597- description : error instanceof Error ? error . message : "Failed to disconnect." ,
1598- } ) ,
1599- ) ;
1600- }
1601- return ;
1602- }
1603- void navigate ( { to : "/" , replace : true } ) ;
1604- } ;
1605- const handleDisconnectActiveEnvironmentStable = useStableCallback (
1606- handleDisconnectActiveEnvironment ,
1607- ) ;
16081506 const { openScratchProject } = useScratchProject ( ) ;
16091507 const activeProjectIsScratch =
16101508 activeProject !== null &&
@@ -1774,176 +1672,16 @@ export default function ChatView(props: ChatViewProps) {
17741672 return environment ? [ environment ] : [ ] ;
17751673 } )
17761674 : EMPTY_AUTO_UPDATE_ENVIRONMENTS ;
1777- const autoBalanceUpdateBanner = useAutoBalanceUpdateBanner ( autoUpdateEnvironments ) ;
1778- const versionMismatch = resolveServerConfigVersionMismatch ( serverConfig ) ;
1779- const versionMismatchDismissKey =
1780- versionMismatch && activeThread
1781- ? buildVersionMismatchDismissalKey ( activeThread . environmentId , versionMismatch )
1782- : null ;
1783- const [ dismissedVersionMismatchKey , setDismissedVersionMismatchKey ] = useState < string | null > (
1784- null ,
1785- ) ;
1786- const versionMismatchDismissed =
1787- versionMismatchDismissKey === dismissedVersionMismatchKey ||
1788- isVersionMismatchDismissed ( versionMismatchDismissKey ) ;
1789- const showVersionMismatchBanner =
1790- versionMismatch !== null && versionMismatchDismissKey !== null && ! versionMismatchDismissed ;
1791- const hasMultipleRegisteredEnvironments = environments . length > 1 ;
1792- const versionMismatchServerLabel =
1793- hasMultipleRegisteredEnvironments && activeThread
1794- ? `${ environmentById . get ( activeThread . environmentId ) ?. label ?? serverConfig ?. environment . label ?? activeThread . environmentId } server`
1795- : "server" ;
1796- const serverUpdateEnvironmentId = activeThread ?. environmentId ?? null ;
1797- const versionMismatchSelfUpdate = resolveServerSelfUpdateCapability ( serverConfig ) ;
1798- const versionMismatchInstallation = serverConfig ?. environment . capabilities . serverInstallation ;
1799- const versionMismatchDesktopAppUpdate = supportsDesktopAppUpdate ( serverConfig ) ;
1800- const versionMismatchThreadContinuation = supportsServerUpdateThreadContinuation ( serverConfig ) ;
1801- const serverUpdateState = useAtomValue (
1802- serverEnvironment . updateStateAtom ( serverUpdateEnvironmentId ) ,
1803- ) ;
1804- const [ dismissedServerUpdateState , setDismissedServerUpdateState ] = useState <
1805- typeof serverUpdateState | null
1806- > ( null ) ;
1807- const serverUpdateFailureDismissed =
1808- serverUpdateState === dismissedServerUpdateState ||
1809- isServerUpdateFailureDismissed ( serverUpdateState ) ;
1810- const systemComposerBannerItems = ( ( ) => {
1811- const items : ComposerBannerStackItem [ ] = [ ] ;
1812- const updateRunning = serverUpdateState . status === "running" ;
1813- const unavailableConnection = activeEnvironmentUnavailableState ?. connection ?? null ;
1814- const disconnectAction =
1815- canDisconnectActiveEnvironment && activeEnvironmentUnavailableState ? (
1816- < Button
1817- size = "xs"
1818- variant = "ghost"
1819- disabled = { disconnectingEnvironment }
1820- title = "Hide this server's threads. Switch it on again in Connections."
1821- onClick = { ( ) =>
1822- void handleDisconnectActiveEnvironmentStable (
1823- activeEnvironmentUnavailableState . environmentId ,
1824- )
1825- }
1826- >
1827- Disconnect server
1828- </ Button >
1829- ) : undefined ;
1830- const environmentReconnecting =
1831- unavailableConnection !== null &&
1832- ( unavailableConnection . phase === "connecting" ||
1833- unavailableConnection . phase === "reconnecting" ) ;
1834- const suppressUnavailableBanner =
1835- environmentReconnecting && ( updateRunning || ! reconnectWarningGraceElapsed ) ;
1836- if ( activeEnvironmentUnavailableState && unavailableConnection && ! suppressUnavailableBanner ) {
1837- items . push ( {
1838- id : `environment-unavailable:${ activeEnvironmentUnavailableState . environmentId } ` ,
1839- variant : unavailableConnection . phase === "error" ? "error" : "warning" ,
1840- icon : < WifiOffIcon /> ,
1841- title : `${ activeEnvironmentUnavailableState . label } is ${ environmentReconnecting ? "reconnecting" : "offline" } ` ,
1842- description : activeEnvironment ? (
1843- < ConnectionDiagnosisHeadline environment = { activeEnvironment } />
1844- ) : undefined ,
1845- actions : (
1846- < >
1847- { ! environmentReconnecting ? (
1848- < Button
1849- size = "xs"
1850- variant = "ghost"
1851- onClick = { ( ) =>
1852- void handleReconnectActiveEnvironmentStable (
1853- activeEnvironmentUnavailableState . environmentId ,
1854- )
1855- }
1856- >
1857- Reconnect
1858- </ Button >
1859- ) : null }
1860- { disconnectAction }
1861- </ >
1862- ) ,
1863- } ) ;
1864- }
1865- if (
1866- ! automaticEnvironment &&
1867- serverUpdateEnvironmentId &&
1868- ( serverUpdateState . status === "idle"
1869- ? showVersionMismatchBanner
1870- : ! serverUpdateFailureDismissed )
1871- ) {
1872- const updateInProgress = serverUpdateState . status === "running" ;
1873- const updateFailed = serverUpdateState . status === "failed" ;
1874- items . push ( {
1875- id : `server-version:${ serverUpdateEnvironmentId } ` ,
1876- variant : updateFailed ? "error" : "default" ,
1877- priority : updateInProgress ? "urgent" : "notice" ,
1878- icon : < ComposerServerUpdateIcon status = { serverUpdateState . status } /> ,
1879- title :
1880- updateInProgress || updateFailed ? (
1881- `${ updateFailed ? "Could not update" : "Updating" } ${ versionMismatchServerLabel } `
1882- ) : versionMismatch ? (
1883- < Tooltip >
1884- < TooltipTrigger
1885- render = {
1886- < button
1887- type = "button"
1888- className = "block max-w-full cursor-help truncate rounded-sm text-left"
1889- >
1890- Server update available
1891- </ button >
1892- }
1893- />
1894- < TooltipPopup side = "top" >
1895- { versionMismatchServerLabel } { versionMismatch . serverVersion } { " " }
1896- < span aria-hidden = "true" > →</ span > { versionMismatch . clientVersion }
1897- </ TooltipPopup >
1898- </ Tooltip >
1899- ) : (
1900- "Server update available"
1901- ) ,
1902- description :
1903- serverUpdateState . status === "failed"
1904- ? serverUpdateState . message
1905- : serverUpdateState . status === "running"
1906- ? serverUpdateStageLabel ( serverUpdateState . stage )
1907- : versionMismatchSelfUpdate !== null &&
1908- ( versionMismatchSelfUpdate !== "desktop-managed" ||
1909- ! versionMismatchDesktopAppUpdate )
1910- ? serverUpdateGuidance ( versionMismatchSelfUpdate )
1911- : undefined ,
1912- actions : updateInProgress ? (
1913- disconnectAction
1914- ) : ! versionMismatch ||
1915- ( versionMismatchSelfUpdate === "desktop-managed" &&
1916- ! versionMismatchDesktopAppUpdate ) ? undefined : (
1917- < ServerUpdateAction
1918- environmentId = { serverUpdateEnvironmentId }
1919- serverLabel = { versionMismatchServerLabel }
1920- selfUpdate = { versionMismatchSelfUpdate }
1921- installation = { versionMismatchInstallation }
1922- desktopAppUpdate = { versionMismatchDesktopAppUpdate }
1923- threadContinuation = { versionMismatchThreadContinuation }
1924- targetVersion = { versionMismatch . clientVersion }
1925- label = { updateFailed ? "Retry" : "Update" }
1926- variant = "ghost"
1927- />
1928- ) ,
1929- ...( updateInProgress || ( ! updateFailed && ! versionMismatchDismissKey )
1930- ? { }
1931- : {
1932- dismissLabel : "Dismiss update notice" ,
1933- onDismiss : ( ) => {
1934- if ( updateFailed ) {
1935- dismissServerUpdateFailure ( serverUpdateState ) ;
1936- setDismissedServerUpdateState ( serverUpdateState ) ;
1937- }
1938- dismissVersionMismatch ( versionMismatchDismissKey ) ;
1939- setDismissedVersionMismatchKey ( versionMismatchDismissKey ) ;
1940- } ,
1941- } ) ,
1942- } ) ;
1943- }
1944- if ( autoBalanceUpdateBanner ) items . push ( autoBalanceUpdateBanner ) ;
1945- return items ;
1946- } ) ( ) as ComposerBannerStackItem [ ] ;
1675+ const systemComposerBannerItems = useSystemComposerBanners ( {
1676+ activeEnvironment,
1677+ activeEnvironmentUnavailable,
1678+ activeEnvironmentUnavailableState,
1679+ activeThreadEnvironmentId : activeThread ?. environmentId ?? null ,
1680+ serverConfig,
1681+ hasMultipleRegisteredEnvironments : environments . length > 1 ,
1682+ automaticEnvironment,
1683+ autoUpdateEnvironments,
1684+ } ) ;
19471685 const providerInstanceEntries = sortProviderInstanceEntries (
19481686 applyProviderInstanceSettings (
19491687 deriveProviderInstanceEntries ( providerStatuses ) ,
0 commit comments