fix(web): offer a just-authored preset on the new-session chip

Authoring writes a FILE, not a settings field, so nothing on the wire announces
it — `settings/changed` covers the default moving, never the directory. The
chip therefore kept the roster it read when it first mounted, and a preset
authored to be used was missing from the one screen that starts sessions.

The page that changes the directory now says so, and every surface reading the
same roster re-reads it. The chip subscribes rather than being reached from the
outer scope, because it is registered later, under `conversation`/`sessions`.
This commit is contained in:
Yichen Jiang
2026-08-07 03:29:26 +08:00
parent a7ab8b27c5
commit 9fc1430b79
3 changed files with 79 additions and 4 deletions

View File

@@ -51,7 +51,13 @@ export const inject = ['slots', 'locale', 'connection']
export function apply(ctx: ClientContext): void {
const { api } = ctx.get('connection') as ConnectionHandle
const controller = new AgentPresetSettingsController(api)
const section = new AgentPresetSectionController(api)
// One roster, four surfaces. The chip is registered in a later scope, so it
// subscribes here rather than being reached from this one.
const rosterReaders = new Set<() => void>()
const section = new AgentPresetSectionController(api, () => {
void controller.load()
for (const read of rosterReaders) read()
})
ctx.effect(() => ctx.locale.register('settings.agentPreset', { zh, en }), 'ui-agent-preset: settings row dictionaries')
@@ -119,6 +125,12 @@ export function apply(ctx: ClientContext): void {
if (ns !== undefined && ns !== AGENT_PRESET_SETTINGS_NS) return
void seat.load()
})
// Authoring writes a FILE, not a setting, so nothing on the wire
// announces it — without this the screen that starts the next session
// keeps offering the roster as it stood when the chip first loaded, and
// a preset authored to be used is missing from the one place it is used.
const readRoster = (): void => { void seat.load() }
rosterReaders.add(readRoster)
const chip = scope.slots.register({
name: 'conversation.hero.agentPreset',
locale: 'settings.agentPreset',
@@ -134,6 +146,7 @@ export function apply(ctx: ClientContext): void {
return () => {
stop()
settingsMoved()
rosterReaders.delete(readRoster)
chip()
label()
}

View File

@@ -107,7 +107,17 @@ export class AgentPresetSectionController {
/** Page snapshot the renderer subscribes to. */
readonly store: SnapshotStore<AgentPresetSectionState> = createSnapshotStore(INITIAL)
constructor(private readonly api: Pick<IApiClient, 'agentPresets' | 'settings'>) {}
constructor(
private readonly api: Pick<IApiClient, 'agentPresets' | 'settings'>,
/**
* Called after this page changes the roster DIRECTORY, so the other
* surfaces reading the same roster re-read it. A settings field moving is
* already announced by the host through `settings/changed`; a file written
* or deleted here is not, and the new-session chip has no other way to
* learn a preset it should offer now exists.
*/
private readonly rosterChanged: () => void = () => {},
) {}
private set(patch: Partial<AgentPresetSectionState>): void {
this.store.set({ ...this.store.getSnapshot(), ...patch })
@@ -265,6 +275,7 @@ export class AgentPresetSectionController {
}
this.set({ draft: null })
await this.load()
this.rosterChanged()
} catch (error) {
this.patchDraft({ saving: false, error: messageOf(error) })
}
@@ -303,6 +314,7 @@ export class AgentPresetSectionController {
draft: draft?.id === pendingDelete && !draft.creating ? null : draft,
})
await this.load()
this.rosterChanged()
} catch (error) {
this.set({ deleting: false, pendingDelete: null, error: messageOf(error) })
}