@@ -41,9 +41,35 @@ const MISSING_LOG_STORAGE_ERROR = 'Log storage not found.'
4141const PROCESS_FINISHED_MESSAGE = ' Process finished.'
4242const PROCESS_NOT_RUNNING_ERROR = ' Process is not running.'
4343const PROCESS_NOT_FOUND_ERROR = ' Process not found.'
44+ const LOG_CACHE_PREFIX = ' terminalLogCache:'
4445let currentTimeTimer: ReturnType <typeof setInterval > | null = null
4546const currentLogKey = ref (' ' )
4647
48+ const getLogCacheKey = (logKey : string ) => ` ${LOG_CACHE_PREFIX }${props .mode }:${logKey } `
49+
50+ const saveLogCache = (logKey : string ) => {
51+ if (! logKey ) return
52+ try {
53+ localStorage .setItem (getLogCacheKey (logKey ), JSON .stringify (logData .value .slice (- 200 )))
54+ } catch {
55+ // ignore cache errors
56+ }
57+ }
58+
59+ const restoreLogCache = (logKey : string ) => {
60+ if (! logKey ) return false
61+ try {
62+ const raw = localStorage .getItem (getLogCacheKey (logKey ))
63+ if (! raw ) return false
64+ const parsed = JSON .parse (raw )
65+ if (! Array .isArray (parsed )) return false
66+ logData .value = parsed
67+ return true
68+ } catch {
69+ return false
70+ }
71+ }
72+
4773const resolveLogKey = async (projectId ? : string ) => {
4874 const id = projectId ?? store .selectedBot ?.project_id
4975 if (! id ) {
@@ -187,6 +213,7 @@ const scrollToBottom = async () => {
187213
188214const appendLocalLog = async (message : string ) => {
189215 logData .value .push ({ message })
216+ saveLogCache (currentLogKey .value )
190217 await scrollToBottom ()
191218}
192219
@@ -230,6 +257,7 @@ const getHistoryLogs = async (projectId?: string) => {
230257 if (data ) {
231258 if (currentLogKey .value !== logId ) return
232259 logData .value = data .detail
260+ saveLogCache (logId )
233261 await scrollToBottom ()
234262 }
235263}
@@ -450,6 +478,7 @@ onMounted(async () => {
450478
451479 if (! store .selectedBot ) return
452480 const logKey = await resolveLogKey (store .selectedBot .project_id )
481+ restoreLogCache (logKey )
453482 await getHistoryLogs (logKey )
454483 if (props .mode === ' shell' && ! store .selectedBot .is_running ) {
455484 await ensureStoppedProjectTerminal (store .selectedBot .project_id )
@@ -472,6 +501,7 @@ watch(
472501
473502 const parsedData: ProcessLog = JSON .parse (rawData .toString ())
474503 logData .value .push (parsedData )
504+ saveLogCache (currentLogKey .value )
475505 if (parsedData .message === PROCESS_FINISHED_MESSAGE ) {
476506 await syncSelectedBotStatus ()
477507 }
0 commit comments