handleDisconnectCommand handles the /disconnect command. It closes the remote connection and restores the local LLM client.
(ctx context.Context)
| 217 | // handleDisconnectCommand handles the /disconnect command. |
| 218 | // It closes the remote connection and restores the local LLM client. |
| 219 | func (ch *CommandHandler) handleDisconnectCommand(ctx context.Context) { |
| 220 | if !ch.cli.isRemote { |
| 221 | fmt.Println(colorize(i18n.T("connect.error.not_connected"), ColorYellow)) |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | // Clean up remote resources |
| 226 | if ch.cli.pluginManager != nil { |
| 227 | ch.cli.pluginManager.ClearRemotePlugins() |
| 228 | } |
| 229 | ch.cli.remoteAgents = nil |
| 230 | ch.cli.remoteSkills = nil |
| 231 | |
| 232 | // Close remote connection |
| 233 | if ch.cli.remoteConn != nil { |
| 234 | _ = ch.cli.remoteConn.Close() |
| 235 | } |
| 236 | |
| 237 | // Restore local state |
| 238 | ch.cli.Client = ch.cli.localClient |
| 239 | ch.cli.Provider = ch.cli.localProvider |
| 240 | ch.cli.Model = ch.cli.localModel |
| 241 | ch.cli.remoteConn = nil |
| 242 | ch.cli.isRemote = false |
| 243 | ch.cli.remoteAddress = "" |
| 244 | ch.cli.localClient = nil |
| 245 | ch.cli.localProvider = "" |
| 246 | ch.cli.localModel = "" |
| 247 | ch.cli.refreshModelCache(ctx) |
| 248 | |
| 249 | fmt.Println(colorize(i18n.T("connect.status.disconnected"), ColorGreen)) |
| 250 | if ch.cli.Client != nil { |
| 251 | fmt.Println(colorize(i18n.T("connect.status.back_to_local", ch.cli.Model, ch.cli.Provider), ColorCyan)) |
| 252 | } else { |
| 253 | fmt.Println(colorize(i18n.T("connect.status.back_to_local_no_provider"), ColorYellow)) |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | // resolveLocalAuth reads the local auth store and returns the API key/OAuth token. |
| 258 | func (ch *CommandHandler) resolveLocalAuth(ctx context.Context, provider string) (apiKey string, resolvedProvider string, err error) { |
no test coverage detected