@@ -5,8 +5,8 @@ import { MouseButton, TextAttributes } from "@opentui/core"
55import { RouteProvider , useRoute } from "@tui/context/route"
66import { Switch , Match , createEffect , untrack , ErrorBoundary , createSignal , onMount , batch , Show , on } from "solid-js"
77import { win32DisableProcessedInput , win32FlushInputBuffer , win32InstallCtrlCGuard } from "./win32"
8- import { Installation } from "@/installation"
98import { Flag } from "@/flag/flag"
9+ import semver from "semver"
1010import { DialogProvider , useDialog } from "@tui/ui/dialog"
1111import { DialogProvider as DialogProviderList } from "@tui/component/dialog-provider"
1212import { SDKProvider , useSDK } from "@tui/context/sdk"
@@ -29,6 +29,7 @@ import { PromptHistoryProvider } from "./component/prompt/history"
2929import { FrecencyProvider } from "./component/prompt/frecency"
3030import { PromptStashProvider } from "./component/prompt/stash"
3131import { DialogAlert } from "./ui/dialog-alert"
32+ import { DialogConfirm } from "./ui/dialog-confirm"
3233import { ToastProvider , useToast } from "./ui/toast"
3334import { ExitProvider , useExit } from "./context/exit"
3435import { Session as SessionApi } from "@/session"
@@ -103,6 +104,7 @@ async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
103104}
104105
105106import type { EventSource } from "./context/sdk"
107+ import { Installation } from "@/installation"
106108
107109export function tui ( input : {
108110 url : string
@@ -736,13 +738,49 @@ function App() {
736738 } )
737739 } )
738740
739- sdk . event . on ( Installation . Event . UpdateAvailable . type , ( evt ) => {
741+ sdk . event . on ( "installation.update-available" , async ( evt ) => {
742+ const version = evt . properties . version
743+
744+ const skipped = kv . get ( "skipped_version" )
745+ if ( skipped && ! semver . gt ( version , skipped ) ) return
746+
747+ const confirmed = await DialogConfirm . show (
748+ dialog ,
749+ `Update Available` ,
750+ `A new release v${ version } is available. Would you like to update now?` ,
751+ "skip" ,
752+ )
753+
754+ if ( ! confirmed ) {
755+ kv . set ( "skipped_version" , version )
756+ return
757+ }
758+
740759 toast . show ( {
741760 variant : "info" ,
742- title : "Update Available" ,
743- message : `OpenCode v${ evt . properties . version } is available. Run 'opencode upgrade' to update manually.` ,
744- duration : 10000 ,
761+ message : `Updating to v${ version } ...` ,
762+ duration : 30000 ,
745763 } )
764+
765+ const result = await sdk . client . global . upgrade ( { target : version } )
766+
767+ if ( result . error || ! result . data ?. success ) {
768+ toast . show ( {
769+ variant : "error" ,
770+ title : "Update Failed" ,
771+ message : "Update failed" ,
772+ duration : 10000 ,
773+ } )
774+ return
775+ }
776+
777+ await DialogAlert . show (
778+ dialog ,
779+ "Update Complete" ,
780+ `Successfully updated to OpenCode v${ result . data . version } . Please restart the application.` ,
781+ )
782+
783+ exit ( )
746784 } )
747785
748786 return (
0 commit comments