(ctx context.Context, req pluginapi.ModelRouteRequest, skipPluginID string)
| 31 | } |
| 32 | |
| 33 | func (h *Host) RouteModelExcept(ctx context.Context, req pluginapi.ModelRouteRequest, skipPluginID string) (pluginapi.ModelRouteResponse, bool) { |
| 34 | if h == nil { |
| 35 | return pluginapi.ModelRouteResponse{}, false |
| 36 | } |
| 37 | skipPluginID = strings.TrimSpace(skipPluginID) |
| 38 | req.AvailableProviders = h.availableProvidersSnapshot() |
| 39 | for _, record := range h.activeRecords() { |
| 40 | router := record.plugin.Capabilities.ModelRouter |
| 41 | if router == nil || h.isPluginFused(record.id) || record.id == skipPluginID { |
| 42 | continue |
| 43 | } |
| 44 | nextReq := cloneModelRouteRequest(req) |
| 45 | nextReq.Plugin = clonePluginMetadata(record.meta) |
| 46 | nextReq.PluginID = record.id |
| 47 | resp, ok := h.callModelRouter(ctx, record.id, router, nextReq) |
| 48 | if !ok || !resp.Handled { |
| 49 | continue |
| 50 | } |
| 51 | resp, valid := normalizeModelRouteResponse(record.id, resp) |
| 52 | if !valid { |
| 53 | log.WithFields(log.Fields{"plugin_id": record.id, "target_kind": resp.TargetKind, "target": resp.Target}).Warn("pluginhost: model router returned invalid target") |
| 54 | continue |
| 55 | } |
| 56 | switch resp.TargetKind { |
| 57 | case pluginapi.ModelRouteTargetProvider: |
| 58 | if !h.HasBuiltinProvider(resp.Target) { |
| 59 | log.WithFields(log.Fields{"plugin_id": record.id, "target_provider": resp.Target}).Warn("pluginhost: model router returned unavailable provider") |
| 60 | continue |
| 61 | } |
| 62 | return resp, true |
| 63 | case pluginapi.ModelRouteTargetSelf, pluginapi.ModelRouteTargetExecutor: |
| 64 | if !h.executorPluginReady(resp.Target, nextReq) { |
| 65 | log.WithFields(log.Fields{"plugin_id": record.id, "target_plugin_id": resp.Target}).Warn("pluginhost: model router returned unavailable executor plugin") |
| 66 | continue |
| 67 | } |
| 68 | return resp, true |
| 69 | default: |
| 70 | log.WithFields(log.Fields{"plugin_id": record.id, "target_kind": resp.TargetKind}).Warn("pluginhost: model router returned unsupported target kind") |
| 71 | continue |
| 72 | } |
| 73 | } |
| 74 | return pluginapi.ModelRouteResponse{}, false |
| 75 | } |
| 76 | |
| 77 | func (h *Host) callModelRouter(ctx context.Context, pluginID string, router pluginapi.ModelRouter, req pluginapi.ModelRouteRequest) (out pluginapi.ModelRouteResponse, ok bool) { |
| 78 | if h == nil || router == nil || h.isPluginFused(pluginID) { |
no test coverage detected