@@ -13,7 +13,9 @@ import {
1313 type OrchestrationV2ThreadLaunchWorkspaceStrategy ,
1414 type OrchestrationV2TurnItem ,
1515 OrchestratorMcpFailure ,
16+ type OrchestratorMcpCapabilitiesInput ,
1617 type OrchestratorMcpCapabilitiesResult ,
18+ type OrchestratorMcpModelOption ,
1719 type OrchestratorMcpCreateThreadsInput ,
1820 type OrchestratorMcpCreateThreadsResult ,
1921 type OrchestratorMcpCreatedThread ,
@@ -59,9 +61,11 @@ import {
5961 type ScheduledTask ,
6062 type ScheduledTaskUpsertInput ,
6163 type ServerProvider ,
64+ type ServerProviderModel ,
6265 ThreadId ,
6366 isOrchestrationV2WorkActive ,
6467} from "@t3tools/contracts" ;
68+ import { getProviderOptionCurrentValue } from "@t3tools/shared/model" ;
6569import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError" ;
6670import {
6771 normalizeThreadPullRequestKey ,
@@ -136,6 +140,7 @@ type TerminalTaskStatus = Extract<
136140export interface OrchestratorMcpServiceShape {
137141 readonly capabilities : (
138142 scope : McpInvocationScope ,
143+ input ?: OrchestratorMcpCapabilitiesInput ,
139144 ) => Effect . Effect < OrchestratorMcpCapabilitiesResult , OrchestratorMcpFailure > ;
140145 readonly delegateTask : (
141146 scope : McpInvocationScope ,
@@ -303,6 +308,61 @@ function scheduledTaskSummary(task: ScheduledTask, mayRun: boolean): Orchestrato
303308 } ;
304309}
305310
311+ /**
312+ * Large catalogs (OpenCode, Cursor, Pi) can list hundreds of models, so agents
313+ * get a short list by default and search for the rest. These providers have
314+ * small official catalogs, so all their current models are listed.
315+ */
316+ const FULL_CATALOG_DRIVERS : ReadonlySet < string > = new Set ( [ "codex" , "claudeAgent" , "muse" , "grok" ] ) ;
317+ const LISTED_MODEL_LIMIT = 8 ;
318+
319+ /**
320+ * Picks the models orchestrator_capabilities shows for one provider. Hidden
321+ * models never appear. With search terms, lists matches; otherwise lists pinned
322+ * models (custom, favorite, the caller's own) plus the provider's non-legacy
323+ * models, or only the first few in the user's model order for large catalogs.
324+ */
325+ function listCapabilityModels ( input : {
326+ readonly provider : ServerProvider ;
327+ readonly preferences :
328+ | { readonly hiddenModels : ReadonlyArray < string > ; readonly modelOrder : ReadonlyArray < string > }
329+ | undefined ;
330+ readonly isPinned : ( model : ServerProviderModel ) => boolean ;
331+ readonly searchTerms : ReadonlyArray < string > ;
332+ } ) {
333+ const rank = new Map ( input . preferences ?. modelOrder . map ( ( slug , index ) => [ slug , index ] ) ) ;
334+ const visible = input . provider . models
335+ . filter ( ( model ) => model . isCustom || ! input . preferences ?. hiddenModels . includes ( model . slug ) )
336+ . toSorted ( ( a , b ) => ( rank . get ( a . slug ) ?? rank . size ) - ( rank . get ( b . slug ) ?? rank . size ) ) ;
337+ if ( input . searchTerms . length > 0 ) {
338+ const matches = visible . filter ( ( model ) => {
339+ const text = `${ model . slug } ${ model . name } ${ model . subProvider ?? "" } ` . toLowerCase ( ) ;
340+ return input . searchTerms . every ( ( term ) => text . includes ( term ) ) ;
341+ } ) ;
342+ const listed = matches . slice ( 0 , LISTED_MODEL_LIMIT ) ;
343+ return { listed, omitted : matches . length - listed . length } ;
344+ }
345+ const current = visible . filter ( ( model ) => ! model . isLegacy ) ;
346+ const shown = new Set (
347+ FULL_CATALOG_DRIVERS . has ( input . provider . driver )
348+ ? current
349+ : current . slice ( 0 , LISTED_MODEL_LIMIT ) ,
350+ ) ;
351+ const listed = visible . filter ( ( model ) => input . isPinned ( model ) || shown . has ( model ) ) ;
352+ return { listed, omitted : visible . length - listed . length } ;
353+ }
354+
355+ /** Option ids and allowed values are all a delegating agent needs; labels are UI copy. */
356+ function capabilityModelOption ( descriptor : ProviderOptionDescriptor ) : OrchestratorMcpModelOption {
357+ const defaultValue = getProviderOptionCurrentValue ( descriptor ) ;
358+ return {
359+ id : descriptor . id ,
360+ values :
361+ descriptor . type === "boolean" ? [ false , true ] : descriptor . options . map ( ( choice ) => choice . id ) ,
362+ ...( defaultValue === undefined ? { } : { default : defaultValue } ) ,
363+ } ;
364+ }
365+
306366function providerConstraints (
307367 provider : ServerProvider | undefined ,
308368 supportsOrchestrationV2 : boolean ,
@@ -2011,44 +2071,54 @@ const make = Effect.gen(function* () {
20112071 return { status, secretRef : secretRef . value } ;
20122072 } ) ,
20132073
2014- capabilities : Effect . fn ( "OrchestratorMcpService.capabilities" ) ( function * ( scope ) {
2074+ capabilities : Effect . fn ( "OrchestratorMcpService.capabilities" ) ( function * ( scope , input = { } ) {
20152075 const { parent, limits } = yield * loadCaller ( scope ) ;
20162076 const providers = yield * loadProviders ;
20172077 const orchestrationCapableInstanceIds = yield * loadOrchestrationCapableInstanceIds ( ) ;
2018- const modelPreferences = yield * serverSettings . getSettings . pipe (
2019- Effect . map ( ( settings ) => settings . providerModelPreferences ?? { } ) ,
2078+ const settings = yield * serverSettings . getSettings . pipe (
20202079 Effect . mapError ( ( ) => failure ( "orchestration_error" , "Unable to read server settings." ) ) ,
20212080 ) ;
2081+ const inherited = parent ?. thread . modelSelection ;
2082+ const searchTerms = input . search ?. toLowerCase ( ) . split ( / \s + / ) ?? [ ] ;
20222083 return {
20232084 parentThreadId : parent ?. thread . id ?? null ,
2024- inheritedProviderInstanceId : parent ?. thread . modelSelection . instanceId ?? null ,
2025- inheritedModel : parent ?. thread . modelSelection . model ?? null ,
2026- inheritedOptions : parent ?. thread . modelSelection . options ?? [ ] ,
2085+ inheritedProviderInstanceId : inherited ? .instanceId ?? null ,
2086+ inheritedModel : inherited ? .model ?? null ,
2087+ inheritedOptions : inherited ? .options ?? [ ] ,
20272088 runtimeMode : limits . runtimeMode ,
20282089 interactionMode : limits . interactionMode ,
20292090 providers : providers . map ( ( provider ) => {
20302091 const constraints = providerConstraints (
20312092 provider ,
20322093 orchestrationCapableInstanceIds . has ( provider . instanceId ) ,
20332094 ) ;
2095+ const { listed, omitted } = listCapabilityModels ( {
2096+ provider,
2097+ preferences : settings . providerModelPreferences ?. [ provider . instanceId ] ,
2098+ searchTerms,
2099+ isPinned : ( model ) =>
2100+ model . isCustom ||
2101+ ( inherited ?. instanceId === provider . instanceId && inherited . model === model . slug ) ||
2102+ ( settings . favorites ?? [ ] ) . some (
2103+ ( favorite ) =>
2104+ favorite . provider === provider . instanceId && favorite . model === model . slug ,
2105+ ) ,
2106+ } ) ;
20342107 return {
20352108 providerInstanceId : provider . instanceId ,
20362109 driverKind : provider . driver ,
2037- displayName : provider ?. displayName ?? null ,
2038- models :
2039- provider ?. models
2040- . filter (
2041- ( model ) =>
2042- model . isCustom ||
2043- ! modelPreferences [ provider . instanceId ] ?. hiddenModels . includes ( model . slug ) ,
2044- )
2045- . map ( ( model ) => ( {
2046- id : model . slug ,
2047- label : model . name ?? null ,
2048- ...( model . capabilities ?. optionDescriptors === undefined
2049- ? { }
2050- : { options : model . capabilities . optionDescriptors } ) ,
2051- } ) ) ?? [ ] ,
2110+ displayName : provider . displayName ?? null ,
2111+ models : listed . map ( ( model ) => {
2112+ const options = model . capabilities ?. optionDescriptors ?? [ ] ;
2113+ return {
2114+ id : model . slug ,
2115+ ...( model . name . toLowerCase ( ) === model . slug . toLowerCase ( )
2116+ ? { }
2117+ : { label : model . name } ) ,
2118+ ...( options . length === 0 ? { } : { options : options . map ( capabilityModelOption ) } ) ,
2119+ } ;
2120+ } ) ,
2121+ ...( omitted === 0 ? { } : { omittedModels : omitted } ) ,
20522122 ...( provider . supportedRuntimeModes === undefined ||
20532123 provider . supportedRuntimeModes . length === 0
20542124 ? { }
0 commit comments