MCPcopy Create free account
hub / github.com/diillson/chatcli / refreshGatewayModel

Method refreshGatewayModel

cli/gateway_runtime_model.go:92–118  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

90// answers with the operator's current model. A GetClient failure keeps the
91// current model rather than dropping the daemon.
92func (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}

Callers 2

runGatewayMethod · 0.95
gatewayAgentFuncMethod · 0.95

Calls 6

readRuntimeModelStateFunction · 0.85
WarnMethod · 0.80
GetClientMethod · 0.65
ErrorMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected