handleConnectCommand handles the /connect [flags] command. It connects to a remote ChatCLI gRPC server and swaps the LLM client.
(ctx context.Context, userInput string)
| 62 | // handleConnectCommand handles the /connect <address> [flags] command. |
| 63 | // It connects to a remote ChatCLI gRPC server and swaps the LLM client. |
| 64 | func (ch *CommandHandler) handleConnectCommand(ctx context.Context, userInput string) { |
| 65 | args := strings.Fields(userInput) |
| 66 | |
| 67 | if len(args) < 2 { |
| 68 | fmt.Println(colorize(i18n.T("connect.usage.main"), ColorYellow)) |
| 69 | fmt.Println(colorize(i18n.T("connect.usage.stackspot"), ColorYellow)) |
| 70 | fmt.Println(colorize(i18n.T("connect.usage.ollama"), ColorYellow)) |
| 71 | fmt.Println(colorize(i18n.T("connect.usage.tls"), ColorYellow)) |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | if ch.cli.isRemote { |
| 76 | fmt.Println(colorize(i18n.T("connect.error.already_connected"), ColorYellow)) |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | // Parse arguments manually (same pattern as /switch) |
| 81 | address := args[1] |
| 82 | parsed := parseConnectArgs(args) |
| 83 | token, provider, model, llmKey, caCert := parsed.token, parsed.provider, parsed.model, parsed.llmKey, parsed.caCert |
| 84 | clientID, clientKey, realm, agentID, ollamaURL := parsed.clientID, parsed.clientKey, parsed.realm, parsed.agentID, parsed.ollamaURL |
| 85 | useLocalAuth, useTLS := parsed.useLocalAuth, parsed.useTLS |
| 86 | |
| 87 | // Resolve local auth if requested |
| 88 | if useLocalAuth && llmKey == "" { |
| 89 | resolvedKey, resolvedProvider, err := ch.resolveLocalAuth(ctx, provider) |
| 90 | if err != nil { |
| 91 | fmt.Println(colorize(i18n.T("connect.error.resolve_local_auth", err), ColorRed)) |
| 92 | return |
| 93 | } |
| 94 | llmKey = resolvedKey |
| 95 | if provider == "" { |
| 96 | provider = resolvedProvider |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Build provider-specific config |
| 101 | providerConfig := make(map[string]string) |
| 102 | if clientID != "" { |
| 103 | providerConfig["client_id"] = clientID |
| 104 | } |
| 105 | if clientKey != "" { |
| 106 | providerConfig["client_key"] = clientKey |
| 107 | } |
| 108 | if realm != "" { |
| 109 | providerConfig["realm"] = realm |
| 110 | } |
| 111 | if agentID != "" { |
| 112 | providerConfig["agent_id"] = agentID |
| 113 | } |
| 114 | if ollamaURL != "" { |
| 115 | providerConfig["base_url"] = ollamaURL |
| 116 | } |
| 117 | |
| 118 | fmt.Println(colorize(i18n.T("connect.status.connecting", address), ColorCyan)) |
| 119 | |
| 120 | // Create remote client |
| 121 | cfg := remote.Config{ |
no test coverage detected