@@ -62,8 +62,8 @@ func (c *ACP) Models() (map[string]string, error) {
6262 return c .models , nil
6363 }
6464
65- // Attempt to query supported models via ACP. The protocol exposes this via the
66- // (unstable) SessionModelState returned from `session/new`.
65+ // Attempt to query supported models via ACP. The protocol exposes these as a
66+ // "model"-category session config option returned from `session/new`.
6767 models , err := c .fetchModelsViaACP ()
6868 if err == nil && len (models ) > 0 {
6969 c .models = models
@@ -128,15 +128,16 @@ func (c *ACP) fetchModelsViaACP() (map[string]string, error) {
128128 }
129129
130130 models := make (map [string ]string )
131- if sess .Models == nil {
131+ sel := modelConfigOption (sess .ConfigOptions )
132+ if sel == nil {
132133 return models , nil
133134 }
134- for _ , mi := range sess . Models . AvailableModels {
135- id := strings .TrimSpace (string (mi . ModelId ))
135+ for _ , opt := range selectOptionValues ( sel ) {
136+ id := strings .TrimSpace (string (opt . Value ))
136137 if id == "" {
137138 continue
138139 }
139- key := strings .TrimSpace (mi .Name )
140+ key := strings .TrimSpace (opt .Name )
140141 if key == "" {
141142 key = id
142143 }
@@ -149,6 +150,38 @@ func (c *ACP) fetchModelsViaACP() (map[string]string, error) {
149150 return models , nil
150151}
151152
153+ // modelConfigOption returns the model-selection config option the agent
154+ // advertised in its session configuration, or nil if none is exposed. The ACP
155+ // protocol surfaces model choices as a "select" session config option tagged
156+ // with the "model" category.
157+ func modelConfigOption (opts []acp.SessionConfigOption ) * acp.SessionConfigOptionSelect {
158+ for i := range opts {
159+ sel := opts [i ].Select
160+ if sel == nil || sel .Category == nil {
161+ continue
162+ }
163+ if * sel .Category == acp .SessionConfigOptionCategoryModel {
164+ return sel
165+ }
166+ }
167+ return nil
168+ }
169+
170+ // selectOptionValues flattens a select config option's grouped and ungrouped
171+ // values into a single slice.
172+ func selectOptionValues (sel * acp.SessionConfigOptionSelect ) []acp.SessionConfigSelectOption {
173+ var out []acp.SessionConfigSelectOption
174+ if sel .Options .Ungrouped != nil {
175+ out = append (out , (* sel .Options .Ungrouped )... )
176+ }
177+ if sel .Options .Grouped != nil {
178+ for _ , group := range * sel .Options .Grouped {
179+ out = append (out , group .Options ... )
180+ }
181+ }
182+ return out
183+ }
184+
152185func (c * ACP ) SetModel (model string ) error {
153186 model = strings .TrimSpace (model )
154187 if model == "" {
@@ -503,15 +536,21 @@ func (c *ACP) Chat() (string, error) {
503536 return "" , stderrCapture .wrap (fmt .Errorf ("acp: newSession failed: %w" , err ))
504537 }
505538
506- // Best-effort: attempt to set model if the agent supports it (UNSTABLE ACP API).
539+ // Best-effort: attempt to set the model if the agent advertises a model
540+ // configuration option (ACP session config option, category "model").
507541 if m := strings .TrimSpace (c .conf .Model ); m != "" && m != "default" {
508- setModelReq := acp.UnstableSetSessionModelRequest {
509- SessionId : sess .SessionId ,
510- ModelId : acp .UnstableModelId (m ),
511- }
512- if _ , setErr := clientConn .conn .UnstableSetSessionModel (ctx , setModelReq ); setErr != nil {
513- if c .conf .Verbose {
514- log .Debugf ("acp: UnstableSetSessionModel failed (ignored): %v" , setErr )
542+ if sel := modelConfigOption (sess .ConfigOptions ); sel != nil {
543+ setModelReq := acp.SetSessionConfigOptionRequest {
544+ ValueId : & acp.SetSessionConfigOptionValueId {
545+ ConfigId : sel .Id ,
546+ SessionId : sess .SessionId ,
547+ Value : acp .SessionConfigValueId (m ),
548+ },
549+ }
550+ if _ , setErr := clientConn .conn .SetSessionConfigOption (ctx , setModelReq ); setErr != nil {
551+ if c .conf .Verbose {
552+ log .Debugf ("acp: SetSessionConfigOption(model) failed (ignored): %v" , setErr )
553+ }
515554 }
516555 }
517556 }
0 commit comments