Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

Merge branch 'dev' into feat/desktop-loading-times-improvements

Diego Zacariasc92e95ad5f26
diff --cc desktop-app/src/appService.ts
index fe58e00c5,19d3d64e3..f3c2539c6
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@@ -271,11 -284,7 +289,12 @@@ export class AppService
private accessCatalog: AccessCatalog | null = null
private teamDirectoryCache: TeamDirectoryResult | null = null
private teamContextQueue: Promise<void> = Promise.resolve()
+ private restoreSavedSessionInFlight: Promise<SessionState> | null = null
+ private savedSessionRestoreAttemptedEnvKey: string | null = null
+ private savedSessionRestoreAttemptedAtMs = 0
+ private logoutInProgress = false
+ private sessionGeneration = 0
+ private sandboxUiLifecycleQueue: Promise<void> = Promise.resolve()
private workflowApprovalTeamById = new Map<string, string>()
private workflowTeamByKey = new Map<string, string>()
private readonly prewarmAttemptAtByHostRef = new Map<string, number>()
@@@ -533,79 -538,15 +562,80 @@@
)
}
- async initialize(): Promise<SessionState> {
+ private clearAuthenticatedSessionState(): void {
+ this.sessionGeneration += 1
+ this.stopAllStreams()
+ this.sessionToken = null
+ this.me = null
++ this.profileUiBaseUrlCache = null
+ this.accessCatalog = null
+ this.teamDirectoryCache = null
+ this.workflowApprovalTeamById.clear()
+ this.workflowTeamByKey.clear()
+ this.rpcTokenManager.clear()
+ unbindChatStore()
+ }
+
+ private async restoreSavedSession(options: { runLaunchMaintenance?: boolean } = {}) {
+ if (this.restoreSavedSessionInFlight) {
+ return await this.restoreSavedSessionInFlight
+ }
+ const restore = this.restoreSavedSessionOnce(options)
+ this.restoreSavedSessionInFlight = restore
+ try {
+ return await restore
+ } finally {
+ // No newer restore can start while this promise is installed, so the
+ // single-flight slot can be cleared unconditionally after it settles.
+ this.restoreSavedSessionInFlight = null
+ }
+ }
+
+ private async restoreSavedSessionOnce(options: { runLaunchMaintenance?: boolean } = {}) {
+ if (this.logoutInProgress) return { authenticated: false, me: null }
+ const restoreGeneration = this.sessionGeneration
hydrateDesktopRuntimeConfig()
- this.sessionToken = await this.tokenStore.getSessionToken(getActiveEnvKey())
- if (!this.sessionToken) {
+ const envKey = getActiveEnvKey()
+ const legacyEnvKeys = getActiveLegacyEnvKeys()
+ this.savedSessionRestoreAttemptedEnvKey = envKey
+ this.savedSessionRestoreAttemptedAtMs = Date.now()
+ let token: string | null
+ try {
+ token = await this.tokenStore.getSessionToken(envKey, { legacyEnvKeys })
+ } catch (error) {
+ console.warn('[AppService] Failed to read the saved session token:', error)
+ if (this.sessionGeneration === restoreGeneration) {
+ this.clearAuthenticatedSessionState()
+ }
return { authenticated: false, me: null }
}
+ if (this.logoutInProgress) return { authenticated: false, me: null }
+ if (!token) {
+ if (this.sessionGeneration === restoreGeneration) {
+ this.clearAuthenticatedSessionState()
+ }
+ return { authenticated: false, me: null }
+ }
+
+ if (this.sessionGeneration !== restoreGeneration) {
+ return { authenticated: Boolean(this.sessionToken && this.me), me: this.me }
+ }
+ this.sessionToken = token
try {
- this.me = await this.authClient.getMe(this.sessionToken)
- await bindChatStoreForUser(this.me.id, getActiveEnvKey())
+ const restoredMe = await this.authClient.getMe(token)
+ if (this.sessionGeneration !== restoreGeneration || this.sessionToken !== token) {
+ return { authenticated: Boolean(this.sessionToken && this.me), me: this.me }
+ }
+ await bindChatStoreForUser(restoredMe.id, envKey, { legacyEnvKeys })
+ if (this.sessionGeneration !== restoreGeneration || this.sessionToken !== token) {
+ if (this.me) {
+ await this.bindCurrentChatStore(this.me.id)
+ } else {
+ unbindChatStore()
+ }
+ return { authenticated: Boolean(this.sessionToken && this.me), me: this.me }
+ }
+ this.me = restoredMe
this.accessCatalog = null
this.teamDirectoryCache = null
this.workflowApprovalTeamById.clear()
diff --cc desktop-app/src/config.ts
index 46f5224da,8c3e0e13a..78fc5385e
--- a/desktop-app/src/config.ts
+++ b/desktop-app/src/config.ts
@@@ -168,8 -175,12 +180,12 @@@ function deriveProfileUiBaseUrl(externa
return 'http://127.0.0.1:3001'
}
+ function hasExplicitProfileUiBaseUrl(): boolean {
+ return Boolean(process.env.PROFILE_UI_BASE_URL?.trim())
+ }
+
function runtimeConfigDirectoryPath(): string {
- const explicit = process.env.CLERUM_DESKTOP_CONFIG_PATH?.trim()
+ const explicit = explicitRuntimeConfigPath()
if (explicit) return path.dirname(explicit)
if (app?.isReady()) {
diff --cc desktop-app/src/renderer.d.ts
index 49a5bf60c,319e24fb2..6d54a7a29
--- a/desktop-app/src/renderer.d.ts
+++ b/desktop-app/src/renderer.d.ts
@@@ -22,13 -23,13 +22,16 @@@ import
PendingWorkflowApproval,
PrewarmHostResult,
ProfileSettingsOpenOptions,
+ ReplaceChatMessagesOptions,
RpcAllowedServersResult,
+ SandboxUiApp,
+ SandboxUiDeepLinkEnvelope,
+ SessionLifecycleState,
+ SessionMessagesQuery,
+ SessionMessagesResult,
SessionState,
- SessionTokensLite,
+ SessionsListQuery,
+ SessionsListResult,
SetHostModelResult,
TaskProgressStreamEvent,
TeamDirectoryResult,
diff --cc desktop-app/src/rpcProxyClient.ts
index f76eae2ab,2a3af6878..73772ebcd
--- a/desktop-app/src/rpcProxyClient.ts
+++ b/desktop-app/src/rpcProxyClient.ts
@@@ -10,15 -9,12 +10,16 @@@ import
HostModelsResult,
HostRuntimeHealth,
HostRuntimeStatus,
+ MessageToolStep,
PendingApprovalLite,
RpcAllowedServersResult,
+ SandboxUiApp,
SessionLifecycleState,
+ SessionMessagesQuery,
SessionMessagesResult,
SessionTokensLite,
+ SessionsListQuery,
+ SessionsListResult,
SetHostModelResult,
} from './types.js'