fix(ai): complete wiring on first-time configure; guard Ollama fallback

Three follow-up fixes:

1. RestartAIChat() now performs the full post-start wiring (MCP providers,
   patrol adapter, investigation orchestrator) when the service starts for
   the first time via Restart(). Previously these were only wired via
   StartAIChat(), leaving first-time configure with a partially wired service.

2. The Ollama→OpenAI-compatible fallback in createProviderForModel is now
   guarded by !strings.HasPrefix(modelStr, "ollama:") so explicit
   "ollama:llama3" models are never silently rerouted to a different provider.

3. Windows install script registration check now uses the $Hostname override
   (if set) instead of always looking up $env:COMPUTERNAME, so post-install
   verification works correctly when a custom hostname is specified.
This commit is contained in:
rcourtman 2026-03-13 12:06:08 +00:00
parent 6b317f08d2
commit ae2edbde20
3 changed files with 24 additions and 10 deletions

View file

@ -473,7 +473,7 @@ if (-not $NoService) {
for ($i = 1; $i -le $maxRetries; $i++) {
Start-Sleep -Seconds $retryDelay
$hostname = $env:COMPUTERNAME
$hostname = if ($Hostname) { $Hostname } else { $env:COMPUTERNAME }
$lookupHost = Test-AgentRegistration -PulseUrl $PulseUrl -Hostname $hostname -Token $Token
if ($lookupHost) {

View file

@ -773,10 +773,9 @@ func (s *Service) createProviderForModel(modelStr string) (providers.StreamingPr
case "ollama":
baseURL := s.cfg.OllamaBaseURL
if baseURL == "" {
// Ollama not explicitly configured. If the user has a custom OpenAI-compatible
// base URL set, route there instead — this handles bare model names (e.g.
// "qwen3-omni") typed manually for self-hosted OpenAI-compatible endpoints.
if s.cfg.OpenAIAPIKey != "" && s.cfg.OpenAIBaseURL != "" {
// Only fall back for bare/unrecognized model names (no explicit "ollama:" prefix).
// An explicit "ollama:llama3" must not be silently rerouted to a different provider.
if !strings.HasPrefix(modelStr, "ollama:") && s.cfg.OpenAIAPIKey != "" && s.cfg.OpenAIBaseURL != "" {
return providers.NewOpenAIClient(s.cfg.OpenAIAPIKey, modelName, s.cfg.OpenAIBaseURL, timeout), nil
}
baseURL = "http://localhost:11434"

View file

@ -3447,11 +3447,26 @@ func (r *Router) StopAIChat(ctx context.Context) {
// RestartAIChat restarts the AI chat service with updated configuration
// Call this when AI settings change that affect the service (e.g., model selection)
func (r *Router) RestartAIChat(ctx context.Context) {
if r.aiHandler != nil {
if err := r.aiHandler.Restart(ctx); err != nil {
log.Error().Err(err).Msg("Failed to restart AI chat service")
} else {
log.Info().Msg("AI chat service restarted with new configuration")
if r.aiHandler == nil {
return
}
wasRunning := r.aiHandler.IsRunning(ctx)
if err := r.aiHandler.Restart(ctx); err != nil {
log.Error().Err(err).Msg("Failed to restart AI chat service")
return
}
log.Info().Msg("AI chat service restarted with new configuration")
// If the service just started for the first time (was not running before),
// perform the full post-start wiring that StartAIChat normally handles.
if !wasRunning && r.aiHandler.IsRunning(ctx) {
r.wireAIChatProviders()
r.wireChatServiceToAI()
if r.aiSettingsHandler != nil {
r.aiSettingsHandler.WireOrchestratorAfterChatStart()
}
}
}