@@ -57,10 +57,11 @@ export class WaveAIModel {
5757 widgetAccessAtom ! : jotai . Atom < boolean > ;
5858 droppedFiles : jotai . PrimitiveAtom < DroppedFile [ ] > = jotai . atom ( [ ] ) ;
5959 chatId ! : jotai . PrimitiveAtom < string > ;
60- currentAIMode : jotai . PrimitiveAtom < string > = jotai . atom ( "waveai@balanced" ) ;
60+ currentAIMode ! : jotai . PrimitiveAtom < string > ;
6161 aiModeConfigs ! : jotai . Atom < Record < string , AIModeConfigType > > ;
62+ hasPremiumAtom ! : jotai . Atom < boolean > ;
63+ defaultModeAtom ! : jotai . Atom < string > ;
6264 errorMessage : jotai . PrimitiveAtom < string > = jotai . atom ( null ) as jotai . PrimitiveAtom < string > ;
63- modelAtom ! : jotai . Atom < string > ;
6465 containerWidth : jotai . PrimitiveAtom < number > = jotai . atom ( 0 ) ;
6566 codeBlockMaxWidth ! : jotai . Atom < number > ;
6667 inputAtom : jotai . PrimitiveAtom < string > = jotai . atom ( "" ) ;
@@ -77,16 +78,13 @@ export class WaveAIModel {
7778 private constructor ( orefContext : ORef , inBuilder : boolean ) {
7879 this . orefContext = orefContext ;
7980 this . inBuilder = inBuilder ;
80- const defaultMode = globalStore . get ( getSettingsKeyAtom ( "waveai:defaultmode" ) ) ?? "waveai@balanced" ;
81- this . currentAIMode = jotai . atom ( defaultMode ) ;
8281 this . chatId = jotai . atom ( null ) as jotai . PrimitiveAtom < string > ;
83-
84- this . modelAtom = jotai . atom ( ( get ) => {
85- const modelMetaAtom = getOrefMetaKeyAtom ( this . orefContext , "waveai:model" ) ;
86- return get ( modelMetaAtom ) ?? "gpt-5.1" ;
87- } ) ;
8882 this . aiModeConfigs = atoms . waveaiModeConfigAtom ;
8983
84+ this . hasPremiumAtom = jotai . atom ( ( get ) => {
85+ const rateLimitInfo = get ( atoms . waveAIRateLimitInfoAtom ) ;
86+ return ! rateLimitInfo || rateLimitInfo . unknown || rateLimitInfo . preq > 0 ;
87+ } ) ;
9088
9189 this . widgetAccessAtom = jotai . atom ( ( get ) => {
9290 if ( this . inBuilder ) {
@@ -115,6 +113,39 @@ export class WaveAIModel {
115113 }
116114 return get ( WorkspaceLayoutModel . getInstance ( ) . panelVisibleAtom ) ;
117115 } ) ;
116+
117+ this . defaultModeAtom = jotai . atom ( ( get ) => {
118+ const telemetryEnabled = get ( getSettingsKeyAtom ( "telemetry:enabled" ) ) ?? false ;
119+
120+ if ( this . inBuilder ) {
121+ return telemetryEnabled ? "waveai@balanced" : "unknown" ;
122+ }
123+
124+ const aiModeConfigs = get ( this . aiModeConfigs ) ;
125+ const hasPremium = get ( this . hasPremiumAtom ) ;
126+
127+ const waveFallback = hasPremium ? "waveai@balanced" : "waveai@quick" ;
128+ let mode = get ( getSettingsKeyAtom ( "waveai:defaultmode" ) ) ?? waveFallback ;
129+
130+ const modeExists = aiModeConfigs != null && mode in aiModeConfigs ;
131+
132+ if ( ! modeExists ) {
133+ if ( telemetryEnabled ) {
134+ mode = waveFallback ;
135+ } else {
136+ return "unknown" ;
137+ }
138+ }
139+
140+ if ( mode . startsWith ( "waveai@" ) && ! telemetryEnabled ) {
141+ return "unknown" ;
142+ }
143+
144+ return mode ;
145+ } ) ;
146+
147+ const defaultMode = globalStore . get ( this . defaultModeAtom ) ;
148+ this . currentAIMode = jotai . atom ( defaultMode ) ;
118149 }
119150
120151 getPanelVisibleAtom ( ) : jotai . Atom < boolean > {
@@ -350,6 +381,42 @@ export class WaveAIModel {
350381 } ) ;
351382 }
352383
384+ async fixRTInfoMode ( ) : Promise < void > {
385+ const rtInfo = await RpcApi . GetRTInfoCommand ( TabRpcClient , {
386+ oref : this . orefContext ,
387+ } ) ;
388+ const mode = rtInfo ?. [ "waveai:mode" ] ;
389+
390+ if ( mode == null ) {
391+ return ;
392+ }
393+
394+ let shouldClear = false ;
395+
396+ if ( mode . startsWith ( "waveai@" ) ) {
397+ const telemetryEnabled = globalStore . get ( getSettingsKeyAtom ( "telemetry:enabled" ) ) ?? false ;
398+ if ( ! telemetryEnabled ) {
399+ shouldClear = true ;
400+ }
401+ }
402+
403+ if ( ! shouldClear ) {
404+ const aiModeConfigs = globalStore . get ( this . aiModeConfigs ) ;
405+ if ( aiModeConfigs == null || ! ( mode in aiModeConfigs ) ) {
406+ shouldClear = true ;
407+ }
408+ }
409+
410+ if ( shouldClear ) {
411+ const defaultMode = globalStore . get ( this . defaultModeAtom ) ;
412+ globalStore . set ( this . currentAIMode , defaultMode ) ;
413+ RpcApi . SetRTInfoCommand ( TabRpcClient , {
414+ oref : this . orefContext ,
415+ data : { "waveai:mode" : null } ,
416+ } ) ;
417+ }
418+ }
419+
353420 async loadInitialChat ( ) : Promise < WaveUIMessage [ ] > {
354421 const rtInfo = await RpcApi . GetRTInfoCommand ( TabRpcClient , {
355422 oref : this . orefContext ,
0 commit comments