UnloadPlugin removes one plugin from the active runtime and closes its dynamic library.
(id string)
| 377 | |
| 378 | // UnloadPlugin removes one plugin from the active runtime and closes its dynamic library. |
| 379 | func (h *Host) UnloadPlugin(id string) bool { |
| 380 | if h == nil { |
| 381 | return false |
| 382 | } |
| 383 | id = strings.TrimSpace(id) |
| 384 | if id == "" { |
| 385 | return false |
| 386 | } |
| 387 | |
| 388 | h.applyMu.Lock() |
| 389 | defer h.applyMu.Unlock() |
| 390 | |
| 391 | targets := make([]pluginUnloadTarget, 0) |
| 392 | h.mu.Lock() |
| 393 | lp := h.loaded[id] |
| 394 | if lp != nil { |
| 395 | targets = append(targets, pluginUnloadTarget{id: lp.id, name: lp.name, path: lp.path, version: lp.version, client: lp.client}) |
| 396 | } |
| 397 | for _, retired := range h.retired[id] { |
| 398 | if retired == nil { |
| 399 | continue |
| 400 | } |
| 401 | targets = append(targets, pluginUnloadTarget{id: retired.id, name: retired.name, path: retired.path, version: retired.version, client: retired.client}) |
| 402 | } |
| 403 | if len(targets) == 0 { |
| 404 | h.mu.Unlock() |
| 405 | return false |
| 406 | } |
| 407 | delete(h.loaded, id) |
| 408 | delete(h.retired, id) |
| 409 | delete(h.fused, id) |
| 410 | delete(h.activePluginVersions, id) |
| 411 | delete(h.activePluginPaths, id) |
| 412 | for _, target := range targets { |
| 413 | delete(h.pluginFileVersions, cleanPluginPath(target.path)) |
| 414 | } |
| 415 | records, enabled := h.snapshotWithoutPluginLocked(id) |
| 416 | h.removePluginRuntimeStateLocked(id) |
| 417 | h.snapshot.Store(&Snapshot{enabled: enabled, records: records}) |
| 418 | h.mu.Unlock() |
| 419 | |
| 420 | h.refreshThinkingProviders(records) |
| 421 | h.RegisterFrontendAuthProviders() |
| 422 | for _, target := range targets { |
| 423 | if target.client != nil { |
| 424 | target.client.Shutdown() |
| 425 | } |
| 426 | log.WithFields(pluginLogFields(target.id, target.name, target.version, target.path)).Info("pluginhost: plugin unloaded") |
| 427 | } |
| 428 | return true |
| 429 | } |
| 430 | |
| 431 | // ShutdownAll removes active plugin capabilities and closes all loaded dynamic libraries. |
| 432 | func (h *Host) ShutdownAll() { |
nothing calls this directly
no test coverage detected