| 22 | } |
| 23 | |
| 24 | func (r *RuleRouter) SelectRoute(ctx context.Context, req types.AIRequest, state types.RuntimeState) (types.RouteDecision, error) { |
| 25 | if err := ctx.Err(); err != nil { |
| 26 | return types.RouteDecision{}, err |
| 27 | } |
| 28 | tenant, _ := r.cfg.TenantByID(req.TenantID) |
| 29 | baseDecision, err := r.selectByRules(tenant, req, state) |
| 30 | if err != nil { |
| 31 | return types.RouteDecision{}, err |
| 32 | } |
| 33 | |
| 34 | optimized := r.optimizeByCost(tenant, req, baseDecision, state) |
| 35 | return optimized, nil |
| 36 | } |
| 37 | |
| 38 | // BackendHealthOK mirrors routing semantics: unknown backends are treated as selectable. |
| 39 | func BackendHealthOK(health map[string]bool, backendName string) bool { |