diff --git a/packages/client/ui-agent-preset/src/client/section-store.ts b/packages/client/ui-agent-preset/src/client/section-store.ts index 41d7d19235..b713e0ba51 100644 --- a/packages/client/ui-agent-preset/src/client/section-store.ts +++ b/packages/client/ui-agent-preset/src/client/section-store.ts @@ -137,9 +137,7 @@ export class AgentPresetSectionController { * @returns once the snapshot reflects the host. */ async load(): Promise { - const roster = await beginRosterRead( - this.api, () => this.store.getSnapshot().status, (patch) => { this.set(patch) }, - ) + const roster = await beginRosterRead(this.api, this.store) if (roster === undefined) return const { presets, authorable } = roster if (presets.length === 0) { diff --git a/packages/client/ui-agent-preset/src/client/settings-store.ts b/packages/client/ui-agent-preset/src/client/settings-store.ts index c69076afde..6b2cdcc282 100644 --- a/packages/client/ui-agent-preset/src/client/settings-store.ts +++ b/packages/client/ui-agent-preset/src/client/settings-store.ts @@ -115,20 +115,19 @@ export async function readRoster(api: Pick): Promise * further — either another read owns it, or this one already wrote the * failure. What differs between surfaces starts after this. * @param api - the agent-preset wire face. - * @param status - reads the store's current status. - * @param set - patches the store's status and error. + * @param store - the surface's own snapshot store. * @returns the roster, or undefined when the caller should return. */ -export async function beginRosterRead( +export async function beginRosterRead( api: Pick, - status: () => string, - set: (patch: { status?: 'loading' | 'error'; error?: string | null }) => void, + store: SnapshotStore, ): Promise { - if (status() === 'loading') return undefined - set({ status: 'loading', error: null }) + const before = store.getSnapshot() + if (before.status === 'loading') return undefined + store.set({ ...before, status: 'loading', error: null }) const roster = await readRoster(api) if (roster.ok) return roster.value - set({ status: 'error', error: roster.error }) + store.set({ ...store.getSnapshot(), status: 'error', error: roster.error }) return undefined } @@ -196,9 +195,7 @@ export class AgentPresetSettingsController { * @returns once the snapshot reflects the host. */ async load(): Promise { - const roster = await beginRosterRead( - this.api, () => this.store.getSnapshot().status, (patch) => { this.set(patch) }, - ) + const roster = await beginRosterRead(this.api, this.store) if (roster === undefined) return const { presets } = roster const [first] = presets