@@ -46,12 +46,16 @@ type pipelinePath struct {
4646}
4747
4848type pipelineStep struct {
49- ID string `json:"id"`
50- Kind string `json:"kind"`
51- Provider string `json:"provider,omitempty"`
52- Region string `json:"region,omitempty"`
53- Model string `json:"model,omitempty"`
54- AccountID string `json:"account_id,omitempty"`
49+ ID string `json:"id"`
50+ Kind string `json:"kind"`
51+ Provider string `json:"provider,omitempty"`
52+ Region string `json:"region,omitempty"`
53+ Model string `json:"model,omitempty"`
54+ AccountID string `json:"account_id,omitempty"`
55+ // AccountIDs is the console's checked-account list. Parsing expands it
56+ // into one member seat per account so a saved document and a live compile
57+ // agree. The canonical document keeps AccountID only.
58+ AccountIDs []string `json:"account_ids,omitempty"`
5559 Weight int `json:"weight,omitempty"`
5660 AggregationID string `json:"aggregation_id,omitempty"`
5761 Classifier * pipelineClassifier `json:"classifier,omitempty"`
@@ -155,9 +159,113 @@ func parsePipeline(document string) (pipelineDoc, error) {
155159 if len (doc .Steps ) == 0 {
156160 return pipelineDoc {}, fmt .Errorf ("aggregation document has no steps" )
157161 }
162+ doc .Steps = normalizePipelineSteps (doc .Steps )
158163 return doc , nil
159164}
160165
166+ // normalizePipelineSteps makes the stored document and the live compiler
167+ // agree on provider, region, and model spelling, and turns a multi-account
168+ // member into one seat per checked account. A hand-written document can
169+ // otherwise carry "Qoder" or "qoder/glm" and compile to a seat no account
170+ // can serve, or keep only the first checked account and widen the rest of
171+ // the route to the whole provider.
172+ func normalizePipelineSteps (steps []pipelineStep ) []pipelineStep {
173+ steps = expandMemberAccounts (steps )
174+ for i := range steps {
175+ step := & steps [i ]
176+ switch step .Kind {
177+ case "member" :
178+ rawProvider := strings .ToLower (strings .TrimSpace (step .Provider ))
179+ if rawProvider != "" {
180+ step .Provider = NormalizeProviderFamily (rawProvider )
181+ }
182+ step .Region = strings .ToLower (strings .TrimSpace (step .Region ))
183+ if strings .TrimSpace (step .Model ) != "" {
184+ step .Model = normalizeAggregationModel (rawProvider , step .Region , step .Model )
185+ }
186+ step .AccountID = strings .TrimSpace (step .AccountID )
187+ case "group" :
188+ step .AggregationID = strings .ToLower (strings .TrimSpace (step .AggregationID ))
189+ case "branch" :
190+ if step .Classifier != nil {
191+ rawProvider := strings .ToLower (strings .TrimSpace (step .Classifier .Provider ))
192+ if rawProvider != "" {
193+ step .Classifier .Provider = NormalizeProviderFamily (rawProvider )
194+ }
195+ step .Classifier .Region = strings .ToLower (strings .TrimSpace (step .Classifier .Region ))
196+ if strings .TrimSpace (step .Classifier .Model ) != "" {
197+ step .Classifier .Model = normalizeAggregationModel (rawProvider , step .Classifier .Region , step .Classifier .Model )
198+ }
199+ }
200+ for j := range step .Paths {
201+ step .Paths [j ].Steps = normalizePipelineSteps (step .Paths [j ].Steps )
202+ }
203+ step .Fallback = normalizePipelineSteps (step .Fallback )
204+ }
205+ }
206+ return steps
207+ }
208+
209+ // expandMemberAccounts splits a member that pins several accounts into one
210+ // step per account, in check order. A single account, or none, stays one step.
211+ func expandMemberAccounts (steps []pipelineStep ) []pipelineStep {
212+ out := make ([]pipelineStep , 0 , len (steps ))
213+ for _ , step := range steps {
214+ if step .Kind != "member" {
215+ out = append (out , step )
216+ continue
217+ }
218+ ids := selectedAccountIDs (step )
219+ step .AccountIDs = nil
220+ if len (ids ) <= 1 {
221+ if len (ids ) == 1 {
222+ step .AccountID = ids [0 ]
223+ } else {
224+ step .AccountID = ""
225+ }
226+ out = append (out , step )
227+ continue
228+ }
229+ base := strings .TrimSpace (step .ID )
230+ if base == "" {
231+ base = "member"
232+ }
233+ for index , id := range ids {
234+ clone := step
235+ clone .AccountIDs = nil
236+ clone .AccountID = id
237+ clone .ID = fmt .Sprintf ("%s-acct%d" , base , index + 1 )
238+ out = append (out , clone )
239+ }
240+ }
241+ return out
242+ }
243+
244+ // selectedAccountIDs prefers the checked-account list. Duplicates collapse
245+ // in place. An empty list falls back to the single account id.
246+ func selectedAccountIDs (step pipelineStep ) []string {
247+ seen := make (map [string ]struct {}, len (step .AccountIDs )+ 1 )
248+ ids := make ([]string , 0 , len (step .AccountIDs ))
249+ add := func (raw string ) {
250+ id := strings .TrimSpace (raw )
251+ if id == "" {
252+ return
253+ }
254+ if _ , ok := seen [id ]; ok {
255+ return
256+ }
257+ seen [id ] = struct {}{}
258+ ids = append (ids , id )
259+ }
260+ for _ , id := range step .AccountIDs {
261+ add (id )
262+ }
263+ if len (ids ) == 0 {
264+ add (step .AccountID )
265+ }
266+ return ids
267+ }
268+
161269func collectSteps (self string , steps []pipelineStep , depth int , stack map [string ]bool , catalog map [string ]Aggregation , seq * int ) ([]AggregationMember , error ) {
162270 var out []AggregationMember
163271 for _ , step := range steps {
@@ -357,13 +465,16 @@ func openGroup(self string, step pipelineStep, depth int, stack map[string]bool,
357465}
358466
359467func leafMember (step pipelineStep , seq * int ) (AggregationMember , error ) {
360- if strings .TrimSpace (step .Provider ) == "" || strings .TrimSpace (step .Model ) == "" {
468+ rawProvider := strings .ToLower (strings .TrimSpace (step .Provider ))
469+ model := strings .TrimSpace (step .Model )
470+ if rawProvider == "" || model == "" {
361471 return AggregationMember {}, fmt .Errorf ("member step %s needs a provider and a model" , step .ID )
362472 }
473+ region := strings .ToLower (strings .TrimSpace (step .Region ))
363474 member := AggregationMember {
364- Provider : step . Provider ,
365- Region : step . Region ,
366- Model : step . Model ,
475+ Provider : NormalizeProviderFamily ( rawProvider ) ,
476+ Region : region ,
477+ Model : normalizeAggregationModel ( rawProvider , region , model ) ,
367478 AccountID : strings .TrimSpace (step .AccountID ),
368479 Priority : * seq ,
369480 Weight : weightOf (step .Weight ),
@@ -383,20 +494,25 @@ func validateClassifier(c *pipelineClassifier, catalog map[string]Aggregation) e
383494 if c == nil {
384495 return nil
385496 }
386- provider := strings .ToLower (strings .TrimSpace (c .Provider ))
497+ rawProvider := strings .ToLower (strings .TrimSpace (c .Provider ))
387498 model := strings .TrimSpace (c .Model )
388- if provider == "" || model == "" {
499+ if rawProvider == "" || model == "" {
389500 return fmt .Errorf ("classifier needs a provider and a model" )
390501 }
391- if provider == AggregationProvider {
502+ provider := NormalizeProviderFamily (rawProvider )
503+ if provider == AggregationProvider || rawProvider == AggregationProvider {
504+ return fmt .Errorf ("classifier must be a concrete model" )
505+ }
506+ if _ , ok := catalog [rawProvider ]; ok {
392507 return fmt .Errorf ("classifier must be a concrete model" )
393508 }
394509 if _ , ok := catalog [provider ]; ok {
395510 return fmt .Errorf ("classifier must be a concrete model" )
396511 }
512+ region := strings .ToLower (strings .TrimSpace (c .Region ))
397513 c .Provider = provider
398- c .Model = model
399- c .Region = strings . ToLower ( strings . TrimSpace ( c . Region ))
514+ c .Model = normalizeAggregationModel ( rawProvider , region , model )
515+ c .Region = region
400516 return nil
401517}
402518
@@ -455,7 +571,7 @@ func filterMembers(members []AggregationMember, allowed map[string]bool) []Aggre
455571 }
456572 out := make ([]AggregationMember , 0 , len (members ))
457573 for _ , member := range members {
458- if allowed [ strings . ToLower (member .Provider )] {
574+ if memberProviderAllowed (member .Provider , allowed ) {
459575 out = append (out , member )
460576 }
461577 }
@@ -470,7 +586,7 @@ func filterSeats(seats []RouteSeat, allowed map[string]bool) []RouteSeat {
470586 for _ , seat := range seats {
471587 switch seat .Kind {
472588 case "member" :
473- if allowed [ strings . ToLower (seat .Member .Provider )] {
589+ if memberProviderAllowed (seat .Member .Provider , allowed ) {
474590 out = append (out , seat )
475591 }
476592 case "group" :
@@ -484,6 +600,17 @@ func filterSeats(seats []RouteSeat, allowed map[string]bool) []RouteSeat {
484600 return out
485601}
486602
603+ // memberProviderAllowed accepts both a stored provider family and its raw
604+ // spelling. An empty provider never inherits NormalizeProviderFamily's qoder
605+ // default: an unnamed member must not become an allowed qoder route.
606+ func memberProviderAllowed (provider string , allowed map [string ]bool ) bool {
607+ raw := strings .ToLower (strings .TrimSpace (provider ))
608+ if raw == "" {
609+ return false
610+ }
611+ return allowed [raw ] || allowed [NormalizeProviderFamily (raw )]
612+ }
613+
487614func hasGroup (seats []RouteSeat ) bool {
488615 for _ , seat := range seats {
489616 if seat .Kind == "group" || hasGroup (seat .GroupSeats ) {
0 commit comments