@@ -11,6 +11,7 @@ import { evaluatePolicyProfile, type PolicyCandidateEvidence, type PolicyRequest
1111import { candidateCapabilityEvidence } from "../../routing/capability" ;
1212import { policyCandidateHealthEvidence } from "../../routing/health" ;
1313import { quotaEvidenceForCandidate } from "../../routing/quota" ;
14+ import { costEvidenceForCandidate } from "../../routing/cost" ;
1415import { providerCodexAccountMode } from "../../providers/registry" ;
1516import { getEffectiveActiveCodexAccountId } from "../../codex/routing" ;
1617import { getAccountSet } from "../../oauth/store" ;
@@ -19,6 +20,7 @@ import { isPlainRecord } from "./shared";
1920import { readManagementJsonBody , rethrowManagementBodyTooLarge } from "./body" ;
2021import { jsonResponse } from "../auth-cors" ;
2122import type { ManagementContext } from "./context" ;
23+ import type { OcxConfig } from "../../types" ;
2224
2325function profileDto ( config : Parameters < typeof getRoutingProfile > [ 0 ] , id : string ) : Record < string , unknown > | null {
2426 const profile = getRoutingProfile ( config , id ) ;
@@ -86,6 +88,49 @@ function parseCandidateEvidence(raw: unknown): PolicyCandidateEvidence[] | null
8688 return out ;
8789}
8890
91+ function assembleCandidateEvidence (
92+ config : OcxConfig ,
93+ profile : NonNullable < ReturnType < typeof getRoutingProfile > > ,
94+ ) : PolicyCandidateEvidence [ ] {
95+ // Match execution: fill the same candidate evidence the router would
96+ // assemble, so dry-run/evaluate reports the same eligibility as real routing
97+ // instead of treating every capability as unknown. Cost is always present so
98+ // evaluate mode can surface the profile limit even without a usage estimate.
99+ return profile . candidates . map ( candidate => ( {
100+ provider : candidate . provider ,
101+ model : candidate . model ,
102+ capability : candidateCapabilityEvidence ( config , candidate . provider , candidate . model ) ,
103+ health : policyCandidateHealthEvidence ( config , candidate ) ,
104+ quota : quotaEvidenceForCandidate ( {
105+ provider : candidate . provider ,
106+ model : candidate . model ,
107+ ...( candidate . provider === OPENAI_CODEX_PROVIDER_ID
108+ && providerCodexAccountMode (
109+ OPENAI_CODEX_PROVIDER_ID ,
110+ config . providers [ OPENAI_CODEX_PROVIDER_ID ] ,
111+ ) === "pool"
112+ ? ( ( ) => {
113+ const codexAccountId = getEffectiveActiveCodexAccountId ( config ) ;
114+ return {
115+ codexAccountId,
116+ codexAccountPlan : codexAccountId
117+ ? config . codexAccounts ?. find ( account => account . id === codexAccountId ) ?. plan
118+ : undefined ,
119+ } ;
120+ } ) ( )
121+ : { } ) ,
122+ accountRef : candidate . provider === "anthropic"
123+ ? getAccountSet ( "anthropic" ) ?. activeAccountId
124+ : undefined ,
125+ } ) ,
126+ cost : costEvidenceForCandidate ( {
127+ provider : candidate . provider ,
128+ model : candidate . model ,
129+ limitUsd : profile . limits . maxEstimatedCostUsd ,
130+ } ) ,
131+ } ) ) ;
132+ }
133+
89134export async function handleRoutingProfileRoutes ( ctx : ManagementContext ) : Promise < Response | null > {
90135 const { req, url, config } = ctx ;
91136
@@ -119,37 +164,7 @@ export async function handleRoutingProfileRoutes(ctx: ManagementContext): Promis
119164 return jsonResponse ( { error : { code : "invalid_evidence" , message : "evidence must be an object" } } , 400 , req , config ) ;
120165 }
121166 const candidateEvidence = body . candidates === undefined
122- // Match execution: fill the same candidate evidence the router would
123- // assemble, so dry-run reports the same eligibility as real routing
124- // instead of treating every capability as unknown.
125- ? resolvedProfile . candidates . map ( candidate => ( {
126- provider : candidate . provider ,
127- model : candidate . model ,
128- capability : candidateCapabilityEvidence ( config , candidate . provider , candidate . model ) ,
129- health : policyCandidateHealthEvidence ( config , candidate ) ,
130- quota : quotaEvidenceForCandidate ( {
131- provider : candidate . provider ,
132- model : candidate . model ,
133- ...( candidate . provider === OPENAI_CODEX_PROVIDER_ID
134- && providerCodexAccountMode (
135- OPENAI_CODEX_PROVIDER_ID ,
136- config . providers [ OPENAI_CODEX_PROVIDER_ID ] ,
137- ) === "pool"
138- ? ( ( ) => {
139- const codexAccountId = getEffectiveActiveCodexAccountId ( config ) ;
140- return {
141- codexAccountId,
142- codexAccountPlan : codexAccountId
143- ? config . codexAccounts ?. find ( account => account . id === codexAccountId ) ?. plan
144- : undefined ,
145- } ;
146- } ) ( )
147- : { } ) ,
148- accountRef : candidate . provider === "anthropic"
149- ? getAccountSet ( "anthropic" ) ?. activeAccountId
150- : undefined ,
151- } ) ,
152- } ) )
167+ ? assembleCandidateEvidence ( config , resolvedProfile )
153168 : parseCandidateEvidence ( body . candidates ) ;
154169 if ( candidateEvidence === null ) {
155170 return jsonResponse ( { error : { code : "invalid_candidates" , message : "candidates must be an array of evidence objects" } } , 400 , req , config ) ;
0 commit comments