* Hydrates MCP session defaults and reports whether a background simulator refresh was scheduled.
( defaults: Partial<SessionDefaults> | undefined, profiles: Record<string, Partial<SessionDefaults>> | undefined, activeProfile: string | undefined, )
| 47 | * Hydrates MCP session defaults and reports whether a background simulator refresh was scheduled. |
| 48 | */ |
| 49 | function hydrateSessionDefaultsForMcp( |
| 50 | defaults: Partial<SessionDefaults> | undefined, |
| 51 | profiles: Record<string, Partial<SessionDefaults>> | undefined, |
| 52 | activeProfile: string | undefined, |
| 53 | ): MCPSessionHydrationResult { |
| 54 | const hydratedDefaults = { ...(defaults ?? {}) }; |
| 55 | const hydratedProfiles = profiles ?? {}; |
| 56 | const hasHydratedDefaults = Object.keys(hydratedDefaults).length > 0; |
| 57 | const hydratedProfileEntries = Object.entries(hydratedProfiles); |
| 58 | if (!hasHydratedDefaults && hydratedProfileEntries.length === 0) { |
| 59 | return { hydrated: false, refreshScheduled: false }; |
| 60 | } |
| 61 | |
| 62 | if (hasHydratedDefaults) { |
| 63 | sessionStore.setDefaultsForProfile(null, hydratedDefaults); |
| 64 | } |
| 65 | for (const [profileName, profileDefaults] of hydratedProfileEntries) { |
| 66 | const trimmedName = profileName.trim(); |
| 67 | if (!trimmedName) continue; |
| 68 | sessionStore.setDefaultsForProfile(trimmedName, profileDefaults); |
| 69 | } |
| 70 | const normalizedActiveProfile = activeProfile?.trim(); |
| 71 | if (normalizedActiveProfile) { |
| 72 | sessionStore.setActiveProfile(normalizedActiveProfile); |
| 73 | } |
| 74 | |
| 75 | const activeDefaults = sessionStore.getAll(); |
| 76 | const revision = sessionStore.getRevision(); |
| 77 | const refreshScheduled = scheduleSimulatorDefaultsRefresh({ |
| 78 | expectedRevision: revision, |
| 79 | reason: 'startup-hydration', |
| 80 | profile: sessionStore.getActiveProfile(), |
| 81 | persist: false, |
| 82 | simulatorId: activeDefaults.simulatorId, |
| 83 | simulatorName: activeDefaults.simulatorName, |
| 84 | recomputePlatform: true, |
| 85 | }); |
| 86 | |
| 87 | return { hydrated: true, refreshScheduled }; |
| 88 | } |
| 89 | |
| 90 | function logHydrationResult(hydration: MCPSessionHydrationResult): void { |
| 91 | if (!hydration.hydrated) { |
no test coverage detected