refreshGatewayModel re-reads the shared runtime-model state and rebuilds the LLM client when the interactive session has switched models since the daemon last looked. The daemon calls it at startup and before every inbound message (under the run lock in gatewayAgentFunc), so a long-lived gateway alw
()
| 90 | // answers with the operator's current model. A GetClient failure keeps the |
| 91 | // current model rather than dropping the daemon. |
| 92 | func (cli *ChatCLI) refreshGatewayModel() { |
| 93 | s, ok := readRuntimeModelState() |
| 94 | if !ok { |
| 95 | return |
| 96 | } |
| 97 | if s.Provider == cli.Provider && s.Model == cli.Model { |
| 98 | return |
| 99 | } |
| 100 | // No manager wired (e.g. a bare ChatCLI before LLM setup, or under unit |
| 101 | // tests) means there is nothing to rebuild the client with — keep the |
| 102 | // current model rather than panicking on a nil dereference. |
| 103 | if cli.manager == nil { |
| 104 | return |
| 105 | } |
| 106 | client, err := cli.manager.GetClient(s.Provider, s.Model) |
| 107 | if err != nil { |
| 108 | cli.logger.Warn("gateway: could not adopt runtime model; keeping current", |
| 109 | zap.String("provider", s.Provider), zap.String("model", s.Model), zap.Error(err)) |
| 110 | return |
| 111 | } |
| 112 | cli.logger.Info("gateway: adopting runtime model from interactive session", |
| 113 | zap.String("from_provider", cli.Provider), zap.String("from_model", cli.Model), |
| 114 | zap.String("to_provider", s.Provider), zap.String("to_model", s.Model)) |
| 115 | cli.Client = client |
| 116 | cli.Provider = s.Provider |
| 117 | cli.Model = s.Model |
| 118 | } |