@@ -27,8 +27,7 @@ import { Progress } from "@/components/ui/progress";
2727import { toast } from "@/components/ui/sonner" ;
2828import { t } from "@/i18n" ;
2929import { cn } from "@/lib/utils" ;
30- import { resolveExtensionIconSrc } from "@/react-app/design-system/extension-icon-src" ;
31- import { useOrgFeature , useOrgFeatureState } from "@/react-app/domains/cloud/use-org-feature" ;
30+ import { useOrgFeatureState } from "@/react-app/domains/cloud/use-org-feature" ;
3231import { resolveOpenworkConnection } from "./openwork-connection" ;
3332
3433/**
@@ -215,8 +214,8 @@ export async function confirmEngineMigration() {
215214 try {
216215 const status = await consent . client . migrateOpencodeHistory ( { allowActiveSessions : consent . runningTasks > 0 } ) ;
217216 useEngineMigrationStore . setState ( { consent : null } ) ;
218- // Only the flag-gated invitation uses upgrade mode. Manual migrations and
219- // reload discovery retain their dialog and explicit engine-switch decision.
217+ // Upgrade mode comes from a switch to v2 that first needs chats copied. Manual
218+ // migrations and reload discovery retain their dialog and explicit engine-switch decision.
220219 presentMigration ( consent . client , status , consent . mode === "upgrade" ? "banner" : "dialog" , consent . mode === "upgrade" ) ;
221220 } catch ( cause ) {
222221 const running = refusedForRunningTasks ( cause ) ;
@@ -715,36 +714,8 @@ function useRunningMigrationDiscovery(enabled: boolean) {
715714 } , [ enabled ] ) ;
716715}
717716
718- const UPGRADE_SNOOZE_KEY = "openwork.engineUpgrade.snoozedUntil" ;
719- const UPGRADE_SNOOZE_MS = 3 * 24 * 60 * 60_000 ;
720-
721- function readUpgradeSnooze ( ) : number {
722- try {
723- const value = Number ( window . localStorage . getItem ( UPGRADE_SNOOZE_KEY ) ) ;
724- return Number . isFinite ( value ) ? value : 0 ;
725- } catch {
726- return 0 ;
727- }
728- }
729-
730- function snoozeUpgrade ( now = Date . now ( ) ) {
731- try { window . localStorage . setItem ( UPGRADE_SNOOZE_KEY , String ( now + UPGRADE_SNOOZE_MS ) ) ; } catch { /* best effort */ }
732- }
733-
734- /** Offer the upgrade only to people still chatting on v1 who have v1 chats to bring along. */
735- export function shouldOfferEngineUpgrade (
736- status : Pick < EngineV2PreviewStatus , "enabled" | "chatRouting" | "v1HistoryAvailable" | "migration" > ,
737- options : { now : number ; snoozedUntil : number } ,
738- ) : boolean {
739- return selectedChatEngine ( status ) === "v1"
740- && status . v1HistoryAvailable === true
741- && status . migration ?. state !== "running"
742- && options . snoozedUntil <= options . now ;
743- }
744-
745717type EngineUpgradeFeatures = {
746718 ready : boolean ;
747- offer : boolean ;
748719 upgrade : boolean ;
749720} ;
750721
@@ -812,68 +783,6 @@ function useDesktopEngineForcePolicy(features: EngineUpgradeFeatures) {
812783 } , [ ready , upgrade ] ) ;
813784}
814785
815- type UpgradeCandidate = { client : EngineMigrationClient ; status : EngineV2PreviewStatus } ;
816-
817- /** Discovers engine status through startup, and again whenever the engine changes. */
818- function useEngineUpgradeCandidate ( enabled : boolean ) : UpgradeCandidate | null {
819- const [ candidate , setCandidate ] = useState < UpgradeCandidate | null > ( null ) ;
820- useEffect ( ( ) => {
821- if ( ! enabled ) {
822- setCandidate ( null ) ;
823- return ;
824- }
825- let cancelled = false ;
826- let timer : number | undefined ;
827- const load = async ( remaining : number ) => {
828- try {
829- const connection = await resolveOpenworkConnection ( ) ;
830- if ( cancelled ) return ;
831- if ( ! connection . normalizedBaseUrl || ! connection . resolvedToken ) throw new Error ( "Local host is not ready" ) ;
832- const client = createOpenworkServerClient ( {
833- baseUrl : connection . normalizedBaseUrl ,
834- token : connection . resolvedToken ,
835- hostToken : connection . resolvedHostToken ,
836- } ) ;
837- const status = await client . getEngineV2PreviewStatus ( ) ;
838- if ( ! cancelled ) setCandidate ( { client, status } ) ;
839- return ;
840- } catch {
841- // The organization can resolve before the local host starts. Keep the
842- // optional offer discoverable without asking the person to reload.
843- }
844- if ( ! cancelled && remaining > 1 ) timer = window . setTimeout ( ( ) => void load ( remaining - 1 ) , DISCOVERY_RETRY_MS ) ;
845- } ;
846- const reload = ( ) => { window . clearTimeout ( timer ) ; void load ( DISCOVERY_ATTEMPTS ) ; } ;
847- reload ( ) ;
848- window . addEventListener ( "openwork-engine-changed" , reload ) ;
849- return ( ) => { cancelled = true ; window . clearTimeout ( timer ) ; window . removeEventListener ( "openwork-engine-changed" , reload ) ; } ;
850- } , [ enabled ] ) ;
851- return candidate ;
852- }
853-
854- function EngineUpgradeNotice ( props : { candidate : UpgradeCandidate ; onLater : ( ) => void } ) {
855- return (
856- < MigrationFloatingRegion >
857- < div
858- role = "status"
859- data-testid = "engine-upgrade-notice"
860- className = "pointer-events-auto flex max-w-xl items-center gap-3 rounded-2xl bg-popover px-4 py-3 text-popover-foreground shadow-[var(--dls-card-shadow)] ring-1 ring-foreground/5"
861- >
862- < img src = { resolveExtensionIconSrc ( "/openwork-mark.svg" ) } alt = "" className = "size-4 shrink-0 opacity-80 dark:invert" />
863- < p className = "min-w-0 flex-1 text-sm" > { t ( "engine_migration.upgrade_notice" ) } </ p >
864- < div className = "flex shrink-0 items-center gap-2" >
865- < Button type = "button" size = "xs" variant = "ghost" onClick = { props . onLater } >
866- { t ( "engine_migration.upgrade_later" ) }
867- </ Button >
868- < Button type = "button" size = "xs" onClick = { ( ) => requestEngineMigration ( props . candidate . client , "upgrade" ) } >
869- { t ( "engine_migration.upgrade" ) }
870- </ Button >
871- </ div >
872- </ div >
873- </ MigrationFloatingRegion >
874- ) ;
875- }
876-
877786export function EngineMigrationOverlay ( props : { discoverRunningMigration ?: boolean } ) {
878787 const desktop = isDesktopRuntime ( ) ;
879788 const consent = useEngineMigrationStore ( ( state ) => state . consent ) ;
@@ -883,26 +792,14 @@ export function EngineMigrationOverlay(props: { discoverRunningMigration?: boole
883792 const forceUpgrade = useOrgFeatureState ( "engineV2ForceUpgrade" , { desktopOnly : true } ) ;
884793 const features = {
885794 ready : forceUpgrade . resolved ,
886- offer : useOrgFeature ( "engineV2Upgrade" , { desktopOnly : true } ) ,
887795 upgrade : forceUpgrade . enabled ,
888796 } ;
889797 useDesktopEngineForcePolicy ( features ) ;
890798 useRunningMigrationDiscovery ( desktop && props . discoverRunningMigration !== false ) ;
891- const candidate = useEngineUpgradeCandidate ( features . offer && ! features . upgrade ) ;
892- const [ snoozedUntil , setSnoozedUntil ] = useState ( readUpgradeSnooze ) ;
893799 // Local-engine consent and progress never apply to the web runtime, even if the store is populated.
894800 if ( ! desktop ) return null ;
895- const offerUpgrade = features . offer && ! features . upgrade
896- && candidate !== null && ! consent && ! progress && ! switchPrompt
897- && shouldOfferEngineUpgrade ( candidate . status , { now : Date . now ( ) , snoozedUntil } ) ;
898801 return (
899802 < >
900- { offerUpgrade ? (
901- < EngineUpgradeNotice
902- candidate = { candidate }
903- onLater = { ( ) => { snoozeUpgrade ( ) ; setSnoozedUntil ( readUpgradeSnooze ( ) ) ; } }
904- />
905- ) : null }
906803 { consent && ! ( consent . mode === "upgrade" && features . upgrade )
907804 ? < MigrationConsentDialog consent = { consent } /> : null }
908805 { progress ?. view === "dialog" ? < MigrationProgressDialog progress = { progress } /> : null }
0 commit comments