fix(models): reload the model catalog on reconnect and broadcast its events

Model pickers without a location, such as the goal auditor and walkthrough model settings, could stay stuck on an empty model list. OpenCode's model and provider catalog events were only delivered to clients subscribed to the originating directory, and the provider catalog was not reloaded on a browser stream reconnect or upstream resync, so a list cached empty while OpenCode was loading or restarting never refreshed.

Route model.updated, provider.updated and integration.updated through the resolved-event broadcast like the command, agent and skill catalogs, and reload the provider catalog on reconnect and resync alongside them.
This commit is contained in:
Chris Scott committed 2026-10-09 11:43:48 -04:00
1 parent 4eec94b74c
commit 9c32ba2038
4 files changed
+5 -2

No files matched your search

+1 -1
View File
@@ -34,7 +34,7 @@ type ReplayEventType = 'permission.asked' | 'form.created' | 'session.status'
const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS } = DEFAULTS.SSE
const MULTILINE_PATTERN = /[\r\n]/
const LOCATION_CATALOG_EVENT_TYPES = new Set(['command.updated', 'agent.updated', 'skill.updated'])
const LOCATION_CATALOG_EVENT_TYPES = new Set(['command.updated', 'agent.updated', 'skill.updated', 'model.updated', 'provider.updated', 'integration.updated'])
function serializeEnvelope(directory: string | null, payloadJson: string): string {
return '{"directory":' + JSON.stringify(directory) + ',"payload":' + payloadJson + '}'
+1 -1
View File
@@ -805,7 +805,7 @@ describe('SSEAggregator location-scoped catalog event broadcast', () => {
sseAggregator.setScheduledSessionsResolver(() => [])
})
it.each(['command.updated', 'agent.updated', 'skill.updated'])(
it.each(['command.updated', 'agent.updated', 'skill.updated', 'model.updated', 'provider.updated', 'integration.updated'])(
'broadcasts a location-scoped %s catalog event to every client without leaking other location-scoped events',
(type) => {
const subscribed = createCapturingClient()
@@ -856,6 +856,7 @@ describe('EventProvider permissions and forms', () => {
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'commands'] })
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'agents'] })
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'skills'] })
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'providers'] })
})
})
@@ -880,6 +881,7 @@ describe('EventProvider permissions and forms', () => {
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'commands'] })
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'agents'] })
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'skills'] })
expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'providers'] })
})
})
+1
View File
@@ -33,6 +33,7 @@ const LOCATION_CATALOG_QUERY_KEYS = [
['opencode', 'commands'],
['opencode', 'agents'],
['opencode', 'skills'],
['opencode', 'providers'],
] as const
type PermissionsBySession = Record<string, PermissionRequest[]>