@@ -8,6 +8,7 @@ import { DefaultChatTransport } from 'ai';
88import { useCoreStore } from '@/stores/core' ;
99import { useAgentTransitions } from './useAgentTransitions' ;
1010import { useWindowSize } from '@vueuse/core' ;
11+ import { remToPx , pxToRem } from '../utils' ;
1112
1213type AgentMode = {
1314 name : string ;
@@ -19,9 +20,9 @@ const PLACEHOLDER_DELETING_DELAY_MS = 35;
1920const PLACEHOLDER_HOLD_DELAY_MS = 3000 ;
2021
2122export const useAgentStore = defineStore ( 'agent' , ( ) => {
22- const DEFAULT_CHAT_WIDTH = 600 ;
23- const MAX_WIDTH = 800 ;
24- const MIN_WIDTH = 382 ; //w-96
23+ const DEFAULT_CHAT_WIDTH = 30 ;
24+ const MAX_WIDTH = 60 ;
25+ const MIN_WIDTH = 25
2526 const agentTransitions = useAgentTransitions ( ) ;
2627
2728 const activeSessionId = ref < string | null > ( null ) ;
@@ -71,6 +72,9 @@ export const useAgentStore = defineStore('agent', () => {
7172 } )
7273 watch ( chatWidth , ( newVal : number ) => {
7374 setLocalStorageItem ( 'chatWidth' , newVal . toString ( ) ) ;
75+ if ( ! isFullScreen . value ) {
76+ setLocalStorageItem ( 'chatWidthBeforeFullScreen' , newVal . toString ( ) ) ;
77+ }
7478 } )
7579 watch ( activeSessionId , ( newVal : string | null ) => {
7680 if ( newVal ) {
@@ -90,14 +94,14 @@ export const useAgentStore = defineStore('agent', () => {
9094 onMounted ( ( ) => {
9195 const chatWidthBeforeFullScreen = parseInt ( getLocalStorageItem ( 'chatWidthBeforeFullScreen' ) || '0' , 10 ) ;
9296 if ( chatWidthBeforeFullScreen ) {
93- chatWidth . value = chatWidthBeforeFullScreen ;
97+ setChatWidth ( remToPx ( chatWidthBeforeFullScreen ) ) ;
9498 } else {
9599 const savedChatWidth = parseInt ( getLocalStorageItem ( 'chatWidth' ) || '0' , 10 ) ;
96100 if ( savedChatWidth ) {
97101 if ( savedChatWidth > MAX_WIDTH || savedChatWidth < MIN_WIDTH ) {
98- chatWidth . value = DEFAULT_CHAT_WIDTH ;
102+ setChatWidth ( remToPx ( DEFAULT_CHAT_WIDTH ) ) ;
99103 } else {
100- chatWidth . value = savedChatWidth ;
104+ setChatWidth ( remToPx ( savedChatWidth ) ) ;
101105 }
102106 }
103107 }
@@ -110,7 +114,7 @@ export const useAgentStore = defineStore('agent', () => {
110114 isChatOpen . value = getLocalStorageItem ( 'isChatOpen' ) === 'true' ;
111115 }
112116 if ( coreStore . isMobile ) {
113- chatWidth . value = window . innerWidth ;
117+ setChatWidth ( window . innerWidth ) ;
114118 }
115119 appRoot . value = document . getElementById ( 'app' ) ;
116120 header . value = document . getElementById ( 'af-header-nav' ) ;
@@ -135,23 +139,24 @@ export const useAgentStore = defineStore('agent', () => {
135139 const isTeleportedBeforeFullScreen = getLocalStorageItem ( 'isTeleportedToBodyBeforeFullScreen' ) === 'true' ;
136140 agentTransitions . setAppRootTransition ( true ) ;
137141 setIsTeleportedToBody ( isTeleportedBeforeFullScreen ) ;
138- setChatWidth ( lastChatWidth , false ) ;
142+ setChatWidth ( remToPx ( lastChatWidth ) , false ) ;
139143 setTimeout ( ( ) => agentTransitions . setAppRootTransition ( false ) , agentTransitions . TRANSITION_DURATION ) ;
140144 }
141145 }
142146
147+ //takes on input width in pixels, converts to rem and sets chat width
143148 function setChatWidth ( width : number , blockTransition = true ) {
144149 if ( blockTransition ) {
145150 agentTransitions . setAppRootTransition ( true ) ;
146151 }
147- chatWidth . value = width ;
152+ chatWidth . value = pxToRem ( width ) ;
148153
149154 }
150155 watch ( [ isTeleportedToBody , isChatOpen , chatWidth ] , ( [ newIsTeleportedToBody , newIsChatOpen , newChatWidth ] : [ boolean , boolean , number ] ) => {
151156 if ( appRoot . value && header . value ) {
152157 if ( newIsTeleportedToBody && newIsChatOpen ) {
153- appRoot . value . style . paddingRight = `${ chatWidth . value } px` ;
154- header . value . style . paddingRight = `${ chatWidth . value } px` ;
158+ appRoot . value . style . paddingRight = `${ remToPx ( chatWidth . value ) } px` ;
159+ header . value . style . paddingRight = `${ remToPx ( chatWidth . value ) } px` ;
155160 } else {
156161 appRoot . value . style . paddingRight = '' ;
157162 header . value . style . paddingRight = '' ;
@@ -572,5 +577,6 @@ export const useAgentStore = defineStore('agent', () => {
572577 DEFAULT_CHAT_WIDTH ,
573578 MAX_WIDTH ,
574579 MIN_WIDTH ,
580+ getLocalStorageItem
575581 }
576582} )
0 commit comments