AvailableSessionModels returns the list of models available for the session's current agent. The agent's name and the active model override (if any) are returned alongside the choices so callers don't have to peek into the runtime registry. A session-scoped runtime is required, so the session must h
(ctx context.Context, sessionID string)
| 1245 | // config, a synthetic choice is appended (mirrors App.AvailableModels via |
| 1246 | // the shared runtime.DecorateModelChoices helper). |
| 1247 | func (sm *SessionManager) AvailableSessionModels(ctx context.Context, sessionID string) (string, string, []runtime.ModelChoice, error) { |
| 1248 | rs, ok := sm.runtimeSessions.Load(sessionID) |
| 1249 | if !ok { |
| 1250 | return "", "", nil, ErrSessionNotRunning |
| 1251 | } |
| 1252 | |
| 1253 | if !rs.runtime.SupportsModelSwitching() { |
| 1254 | return "", "", nil, ErrModelSwitchingNotSupported |
| 1255 | } |
| 1256 | |
| 1257 | agentName := rs.runtime.CurrentAgentName(ctx) |
| 1258 | |
| 1259 | // Snapshot the override and custom-model history under sm.mux so the |
| 1260 | // read is atomic with respect to SetSessionAgentModel writes. The |
| 1261 | // (potentially slow) runtime.AvailableModels call must NOT happen |
| 1262 | // under sm.mux: it can perform network I/O (provider discovery, |
| 1263 | // models.dev catalog lookup) and would block every other session |
| 1264 | // operation in the manager. |
| 1265 | sm.mux.Lock() |
| 1266 | current := "" |
| 1267 | var customRefs []string |
| 1268 | if rs.session != nil { |
| 1269 | current = rs.session.AgentModelOverrides[agentName] |
| 1270 | if n := len(rs.session.CustomModelsUsed); n > 0 { |
| 1271 | customRefs = make([]string, n) |
| 1272 | copy(customRefs, rs.session.CustomModelsUsed) |
| 1273 | } |
| 1274 | } |
| 1275 | sm.mux.Unlock() |
| 1276 | |
| 1277 | choices := runtime.DecorateModelChoices(rs.runtime.AvailableModels(ctx), current, customRefs) |
| 1278 | return agentName, current, choices, nil |
| 1279 | } |
| 1280 | |
| 1281 | // SetSessionAgentModel applies modelRef as the model override for the |
| 1282 | // current agent of the session and persists it. Pass an empty modelRef |