Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: preserve local-ui desktop auth runtime
Josué0568c7015e10
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.jsonindex bf7593734..a86de9fcb 100644--- a/desktop-app/package-lock.json+++ b/desktop-app/package-lock.json@@ -1,12 +1,12 @@{"name": "evenfire",- "version": "0.1.320",+ "version": "0.1.321","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "evenfire",- "version": "0.1.320",+ "version": "0.1.321","license": "MPL-2.0","dependencies": {"@tanstack/react-query": "5.100.10",diff --git a/desktop-app/package.json b/desktop-app/package.jsonindex 424fb5ca2..ce2450ae7 100644--- a/desktop-app/package.json+++ b/desktop-app/package.json@@ -1,7 +1,7 @@{"name": "evenfire","productName": "Evenfire",- "version": "0.1.320",+ "version": "0.1.321","private": true,"license": "MPL-2.0","description": "Evenfire desktop client for secure agent and workflow access",diff --git a/desktop-app/scripts/start-branded-app.mjs b/desktop-app/scripts/start-branded-app.mjsindex b1c147957..f24b3edaa 100644--- a/desktop-app/scripts/start-branded-app.mjs+++ b/desktop-app/scripts/start-branded-app.mjs@@ -72,7 +72,7 @@ async function main() {const appProcess = spawn(executable, [], {cwd: projectDirectory,- env: process.env,+ env: { ...process.env, EVENFIRE_DESKTOP_DEV_PACKAGE: '1' },stdio: 'inherit',})diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.tsindex 3a888c8fe..8241d6d35 100644--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts@@ -312,6 +312,61 @@ describe('AppService invitation configuration lookup', () => {expect(clearSessionToken).toHaveBeenCalledWith(resolveEnvKey('https://api.example.com'))})+ it('keeps a saved token when startup session restore is forbidden', async () => {+ const configPath = path.join(+ os.tmpdir(),+ `clerum-desktop-restore-forbidden-${Date.now()}-${Math.random().toString(16).slice(2)}.json`+ )+ await fs.writeFile(+ configPath,+ JSON.stringify({+ externalRestApiBaseUrl: 'https://api.example.com',+ rpcProxyBaseUrl: 'https://rpc.example.com',+ appName: 'Example',+ })+ )+ process.env.CLERUM_DESKTOP_CONFIG_PATH = configPath+ process.env.EXTERNAL_REST_API_BASE_URL = 'https://api.example.com'+ process.env.RPC_PROXY_BASE_URL = 'https://rpc.example.com'+ delete process.env.PROFILE_UI_BASE_URL+ vi.resetModules()++ const [{ AppService }, { ApiError }] = await Promise.all([+ import('../appService.js'),+ import('../httpClient.js'),+ ])+ const clearSessionToken = vi.fn().mockResolvedValue(undefined)+ const service = new AppService() as unknown as {+ authClient: { getMe: ReturnType<typeof vi.fn> }+ tokenStore: {+ getSessionToken: ReturnType<typeof vi.fn>+ clearSessionToken: ReturnType<typeof vi.fn>+ }+ rpcTokenManager: { clear: ReturnType<typeof vi.fn> }+ initialize: () => Promise<unknown>+ }++ service.authClient = {+ getMe: vi.fn().mockRejectedValue(new ApiError('403 Forbidden', 403, '')),+ } as never+ service.tokenStore = {+ getSessionToken: vi.fn().mockResolvedValue('stored-token'),+ clearSessionToken,+ } as never+ service.rpcTokenManager = {+ clear: vi.fn(),+ } as never++ const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)+ try {+ await expect(service.initialize()).resolves.toEqual({ authenticated: false, me: null })++ expect(clearSessionToken).not.toHaveBeenCalled()+ } finally {+ warn.mockRestore()+ }+ })+it('persists a manually saved runtime environment', async () => {const configPath = path.join(os.tmpdir(),diff --git a/desktop-app/src/__tests__/config.runtimeConfig.test.ts b/desktop-app/src/__tests__/config.runtimeConfig.test.tsindex 188399c6f..6bb701167 100644--- a/desktop-app/src/__tests__/config.runtimeConfig.test.ts+++ b/desktop-app/src/__tests__/config.runtimeConfig.test.ts@@ -1,4 +1,4 @@-import { afterEach, describe, expect, it, vi } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import fsp from 'node:fs/promises'import os from 'node:os'import path from 'node:path'@@ -8,8 +8,15 @@ describe('desktop runtime config', () => {const originalExternalRestApiBaseUrl = process.env.EXTERNAL_REST_API_BASE_URLconst originalRpcProxyBaseUrl = process.env.RPC_PROXY_BASE_URLconst originalDesktopAppName = process.env.DESKTOP_APP_NAME+ const originalDesktopDevPackage = process.env.EVENFIRE_DESKTOP_DEV_PACKAGE+ const originalRendererUrl = process.env.EVENFIRE_RENDERER_URLlet tempUserDataDir: string | null = null+ beforeEach(() => {+ vi.doUnmock('electron')+ vi.resetModules()+ })+afterEach(async () => {if (originalConfigPath === undefined) {delete process.env.CLERUM_DESKTOP_CONFIG_PATH@@ -31,6 +38,16 @@ describe('desktop runtime config', () => {} else {process.env.DESKTOP_APP_NAME = originalDesktopAppName}+ if (originalDesktopDevPackage === undefined) {+ delete process.env.EVENFIRE_DESKTOP_DEV_PACKAGE+ } else {+ process.env.EVENFIRE_DESKTOP_DEV_PACKAGE = originalDesktopDevPackage+ }+ if (originalRendererUrl === undefined) {+ delete process.env.EVENFIRE_RENDERER_URL+ } else {+ process.env.EVENFIRE_RENDERER_URL = originalRendererUrl+ }if (tempUserDataDir) {await fsp.rm(tempUserDataDir, { recursive: true, force: true })@@ -85,6 +102,65 @@ describe('desktop runtime config', () => {expect(config.rpcProxyBaseUrl).toBe('http://127.0.0.1:8094')})+ it('selects localhost for the packaged development app used by npm run ui', async () => {+ tempUserDataDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'evenfire-user-data-'))+ const runtimeConfigDir = path.join(tempUserDataDir, 'runtime-configs')+ await fsp.mkdir(runtimeConfigDir, { recursive: true })+ await fsp.writeFile(+ path.join(runtimeConfigDir, 'index.json'),+ JSON.stringify({+ version: 1,+ activeProfileId: 'prod',+ profiles: [+ {+ id: 'prod',+ appName: 'Production',+ fileName: 'runtime-config-prod.json',+ createdAt: '2026-01-01T00:00:00.000Z',+ updatedAt: '2026-01-01T00:00:00.000Z',+ },+ ],+ })+ )+ await fsp.writeFile(+ path.join(runtimeConfigDir, 'runtime-config-prod.json'),+ JSON.stringify({+ externalRestApiBaseUrl: 'https://api.example.com',+ rpcProxyBaseUrl: 'https://rpc.example.com',+ appName: 'Production',+ })+ )+ delete process.env.CLERUM_DESKTOP_CONFIG_PATH+ delete process.env.DESKTOP_APP_NAME+ process.env.EXTERNAL_REST_API_BASE_URL = 'http://127.0.0.1:8091'+ process.env.RPC_PROXY_BASE_URL = 'http://127.0.0.1:8094'+ process.env.EVENFIRE_RENDERER_URL = 'http://127.0.0.1:5173'+ process.env.EVENFIRE_DESKTOP_DEV_PACKAGE = '1'++ vi.doMock('electron', () => ({+ app: {+ getPath: vi.fn((name: string) =>+ name === 'userData' ? tempUserDataDir : path.dirname(tempUserDataDir || os.tmpdir())+ ),+ isPackaged: true,+ isReady: vi.fn(() => true),+ setName: vi.fn(),+ setPath: vi.fn(),+ },+ }))++ const { config, getDesktopRuntimeConfigState } = await import('../config.js')++ expect(config.externalRestApiBaseUrl).toBe('http://127.0.0.1:8091')+ expect(config.rpcProxyBaseUrl).toBe('http://127.0.0.1:8094')++ expect(getDesktopRuntimeConfigState()).toMatchObject({+ configured: true,+ isLocalhost: true,+ activeOptionId: '__localhost__',+ })+ })+it('preserves env-provided localhost runtime ports without selecting the fixed localhost profile', async () => {tempUserDataDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'evenfire-user-data-'))delete process.env.CLERUM_DESKTOP_CONFIG_PATHdiff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex e232ed13d..7e2b867bd 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -329,7 +329,7 @@ export class AppService {}private static isRejectedStoredSessionError(error: unknown): boolean {- return error instanceof ApiError && (error.status === 401 || error.status === 403)+ return error instanceof ApiError && error.status === 401}/**diff --git a/desktop-app/src/config.ts b/desktop-app/src/config.tsindex e749daf3e..cebc1bee2 100644--- a/desktop-app/src/config.ts+++ b/desktop-app/src/config.ts@@ -337,12 +337,17 @@ function loadStoredProfilesSync(): {function configsMatch(a: DesktopRuntimeConfig, b: DesktopRuntimeConfig): boolean {return (- a.externalRestApiBaseUrl === b.externalRestApiBaseUrl &&- a.rpcProxyBaseUrl === b.rpcProxyBaseUrl &&+ runtimeEndpointsMatch(a, b) &&(a.appName?.trim() || DEFAULT_APP_NAME) === (b.appName?.trim() || DEFAULT_APP_NAME))}+function runtimeEndpointsMatch(a: DesktopRuntimeConfig, b: DesktopRuntimeConfig): boolean {+ return (+ a.externalRestApiBaseUrl === b.externalRestApiBaseUrl && a.rpcProxyBaseUrl === b.rpcProxyBaseUrl+ )+}+function isLocalhostUrl(value: string): boolean {try {const parsed = new URL(value)@@ -407,6 +412,7 @@ function resolveActiveProfile(profiles: StoredRuntimeProfile[],activeProfileId: string | null): StoredRuntimeProfile | null {+ if (activeProfileId === LOCALHOST_OPTION_ID) return nullif (activeProfileId) {const direct = profiles.find(profile => profile.id === activeProfileId)if (direct) return direct@@ -475,25 +481,30 @@ const envRuntimeConfig = validateRuntimeConfig({rpcProxyBaseUrl: requiredOrDefault('RPC_PROXY_BASE_URL', LOCALHOST_RPC_PROXY_BASE_URL),appName: requiredOrDefault('DESKTOP_APP_NAME', DEFAULT_APP_NAME),})+const desktopDevPackageRuntimeConfigEnabled =+ process.env.EVENFIRE_DESKTOP_DEV_PACKAGE?.trim() === '1'+const canUseEnvRuntimeConfig = !app?.isPackaged || desktopDevPackageRuntimeConfigEnabledconst envRuntimeConfigured = Boolean(- !app?.isPackaged &&+ canUseEnvRuntimeConfig &&process.env.EXTERNAL_REST_API_BASE_URL?.trim() &&process.env.RPC_PROXY_BASE_URL?.trim())-const envMatchesLocalhostOption = configsMatch(envRuntimeConfig, localhostRuntimeConfig)+const envMatchesLocalhostOption = runtimeEndpointsMatch(envRuntimeConfig, localhostRuntimeConfig)function shouldPreferLocalhostByDefault(): boolean {- return (- !app?.isPackaged &&- Boolean(process.env.EVENFIRE_RENDERER_URL?.trim()) &&- envMatchesLocalhostOption- )+ return canUseEnvRuntimeConfig && envRuntimeConfigured && envMatchesLocalhostOption}const loadedProfilesState = loadStoredProfilesSync()let storedProfiles = loadedProfilesState.profiles-let activeRuntimeOptionId = loadedProfilesState.activeProfileId-const activeStoredProfile = resolveActiveProfile(storedProfiles, activeRuntimeOptionId)+const preferLocalhostRuntimeByDefault = shouldPreferLocalhostByDefault()+let activeRuntimeOptionId = preferLocalhostRuntimeByDefault+ ? LOCALHOST_OPTION_ID+ : loadedProfilesState.activeProfileId+const activeStoredProfile = preferLocalhostRuntimeByDefault+ ? null+ : resolveActiveProfile(storedProfiles, activeRuntimeOptionId)if (+ !preferLocalhostRuntimeByDefault &&!activeStoredProfile &&activeRuntimeOptionId !== LOCALHOST_OPTION_ID &&envRuntimeConfigured &&@@ -549,7 +560,12 @@ export function hydrateDesktopRuntimeConfig(): void {const loaded = loadStoredProfilesSync()storedProfiles = loaded.profiles- activeRuntimeOptionId = loaded.activeProfileId+ const preserveLocalhostRuntime =+ preferLocalhostRuntimeByDefault ||+ (desktopDevPackageRuntimeConfigEnabled &&+ envMatchesLocalhostOption &&+ isLocalhostRuntimeConfig(currentRuntimeConfig()))+ activeRuntimeOptionId = preserveLocalhostRuntime ? LOCALHOST_OPTION_ID : loaded.activeProfileIdconst selectedProfile = resolveActiveProfile(storedProfiles, activeRuntimeOptionId)if (selectedProfile) {