11// Copyright 2025, Command Line Inc.
22// SPDX-License-Identifier: Apache-2.0
33
4- import { isDev } from "@/store/global" ;
5- import { ImperativePanelGroupHandle , ImperativePanelHandle } from "react-resizable-panels" ;
6- import * as jotai from "jotai" ;
74import { getTabMetaKeyAtom } from "@/app/store/global" ;
5+ import { globalStore } from "@/app/store/jotaiStore" ;
6+ import * as WOS from "@/app/store/wos" ;
87import { RpcApi } from "@/app/store/wshclientapi" ;
98import { TabRpcClient } from "@/app/store/wshrpcutil" ;
10- import * as WOS from "@/app/store/wos" ;
11- import { globalStore } from "@/app/store/jotaiStore" ;
12- import { atoms } from "@/store/global" ;
9+ import { atoms , isDev } from "@/store/global" ;
10+ import * as jotai from "jotai" ;
1311import { debounce } from "lodash-es" ;
12+ import { ImperativePanelGroupHandle , ImperativePanelHandle } from "react-resizable-panels" ;
1413
1514const AIPANEL_DEFAULTWIDTH = 300 ;
1615const AIPANEL_MINWIDTH = 250 ;
@@ -21,17 +20,17 @@ class WorkspaceLayoutModel {
2120 panelGroupRef : ImperativePanelGroupHandle | null ;
2221 inResize : boolean ;
2322 private aiPanelVisible : boolean ;
24- private aiPanelWidth : number ;
23+ private aiPanelWidth : number | null ;
2524 private debouncedPersistWidth : ( width : number ) => void ;
2625 private initialized : boolean = false ;
27-
26+
2827 constructor ( ) {
2928 this . aiPanelRef = null ;
3029 this . panelGroupRef = null ;
3130 this . inResize = false ;
3231 this . aiPanelVisible = isDev ( ) ;
33- this . aiPanelWidth = AIPANEL_DEFAULTWIDTH ;
34-
32+ this . aiPanelWidth = null ;
33+
3534 this . debouncedPersistWidth = debounce ( ( width : number ) => {
3635 try {
3736 RpcApi . SetMetaCommand ( TabRpcClient , {
@@ -43,15 +42,15 @@ class WorkspaceLayoutModel {
4342 }
4443 } , 300 ) ;
4544 }
46-
45+
4746 private initializeFromTabMeta ( ) : void {
4847 if ( this . initialized ) return ;
4948 this . initialized = true ;
50-
49+
5150 try {
5251 const savedVisible = globalStore . get ( this . getPanelOpenAtom ( ) ) ;
5352 const savedWidth = globalStore . get ( this . getPanelWidthAtom ( ) ) ;
54-
53+
5554 if ( savedVisible != null ) {
5655 this . aiPanelVisible = savedVisible ;
5756 }
@@ -62,15 +61,15 @@ class WorkspaceLayoutModel {
6261 console . warn ( "Failed to initialize from tab meta:" , e ) ;
6362 }
6463 }
65-
64+
6665 private getTabId ( ) : string {
6766 return globalStore . get ( atoms . staticTabId ) ;
6867 }
69-
68+
7069 private getPanelOpenAtom ( ) : jotai . Atom < boolean > {
7170 return getTabMetaKeyAtom ( this . getTabId ( ) , "waveai:panelopen" ) ;
7271 }
73-
72+
7473 private getPanelWidthAtom ( ) : jotai . Atom < number > {
7574 return getTabMetaKeyAtom ( this . getTabId ( ) , "waveai:panelwidth" ) ;
7675 }
@@ -133,6 +132,9 @@ class WorkspaceLayoutModel {
133132
134133 getAIPanelWidth ( ) : number {
135134 this . initializeFromTabMeta ( ) ;
135+ if ( this . aiPanelWidth == null ) {
136+ this . aiPanelWidth = Math . max ( AIPANEL_DEFAULTWIDTH , window . innerWidth / 3 ) ;
137+ }
136138 return this . aiPanelWidth ;
137139 }
138140
0 commit comments