(ctx context.Context, cfg *config.Config, req types.AIRequest, deps Dependencies)
| 112 | } |
| 113 | |
| 114 | func replayCurrent(ctx context.Context, cfg *config.Config, req types.AIRequest, deps Dependencies) (types.AIResponse, error) { |
| 115 | pol, err := deps.Policy.Evaluate(ctx, req) |
| 116 | if err != nil { |
| 117 | return types.AIResponse{}, err |
| 118 | } |
| 119 | if !pol.Allowed { |
| 120 | return types.AIResponse{}, fmt.Errorf("policy rejected: %s", pol.Reason) |
| 121 | } |
| 122 | req = pol.Normalized |
| 123 | if req.RequestType == types.RequestTypeAgent { |
| 124 | return types.AIResponse{}, errors.New("agent execution not implemented") |
| 125 | } |
| 126 | |
| 127 | health := allHealthy(cfg) |
| 128 | primary, err := deps.Router.SelectRoute(ctx, req, types.RuntimeState{ |
| 129 | QueueDepth: 0, |
| 130 | BackendHealth: health, |
| 131 | OverloadDegrade: false, |
| 132 | }) |
| 133 | if err != nil { |
| 134 | return types.AIResponse{}, err |
| 135 | } |
| 136 | |
| 137 | if req.RequestType == types.RequestTypeRAG { |
| 138 | if err := runRAGRetrieve(ctx, cfg, &req, deps.Retrieval, deps.Rerank); err != nil { |
| 139 | return types.AIResponse{}, err |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | fallback := buildFallbackList(cfg, primary.BackendName, health) |
| 144 | execRes, err := deps.Reliability.ExecuteWithFallback(ctx, req, primary, fallback) |
| 145 | if err != nil { |
| 146 | return types.AIResponse{}, err |
| 147 | } |
| 148 | return buildResponse(cfg, req, pol.Reason, primary, execRes, req.RequestID, ""), nil |
| 149 | } |
| 150 | |
| 151 | func allHealthy(cfg *config.Config) map[string]bool { |
| 152 | out := make(map[string]bool, len(cfg.Backends)) |
no test coverage detected