Skip to content

Commit 49f6cba

Browse files
fix(server): searching delegate models no longer drops words found inside the provider name (#26502)
Co-authored-by: maria-rcks <[email protected]>
1 parent 8df96fb commit 49f6cba

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ describe("OrchestratorMcpService provider resolution", () => {
13031303
instanceId: codexInstanceId,
13041304
driver: ProviderDriverKind.make("codex"),
13051305
}),
1306+
displayName: "Codex",
13061307
models: [
13071308
model("gpt-6", {
13081309
name: "Sol",
@@ -1330,7 +1331,7 @@ describe("OrchestratorMcpService provider resolution", () => {
13301331
],
13311332
},
13321333
}),
1333-
model("gpt-5", { isLegacy: true }),
1334+
model("gpt-5", { name: "Code Legacy", isLegacy: true }),
13341335
model("gpt-4", { isLegacy: true }),
13351336
model("gpt-3", { name: "GPT-3", isLegacy: true }),
13361337
model("my-alpha", { isCustom: true }),
@@ -1436,6 +1437,18 @@ describe("OrchestratorMcpService provider resolution", () => {
14361437
{ id: codexInstanceId, models: ["gpt-6", "gpt-4", "gpt-3", "my-alpha"], omitted: 1 },
14371438
{ id: opencodeInstanceId, models: [], omitted: 0 },
14381439
]);
1440+
assert.deepEqual(listing(yield* capabilitiesWith(" ")), listing(yield* capabilitiesWith()));
1441+
for (const search of ["code", "codex code", " CODE "]) {
1442+
assert.deepEqual(listing(yield* capabilitiesWith(search))[0], {
1443+
id: codexInstanceId,
1444+
models: ["gpt-5"],
1445+
omitted: 0,
1446+
});
1447+
}
1448+
assert.deepEqual(
1449+
listing(yield* capabilitiesWith("open"))[1],
1450+
listing(yield* capabilitiesWith())[1],
1451+
);
14391452
assert.deepEqual(listing(yield* capabilitiesWith("codex gpt 5"))[0], {
14401453
id: codexInstanceId,
14411454
models: ["gpt-5"],

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,8 @@ const FULL_CATALOG_DRIVERS: ReadonlySet<string> = new Set(["codex", "claudeAgent
287287
const LISTED_MODEL_LIMIT = 8;
288288

289289
/**
290-
* Picks the models orchestrator_capabilities shows for one provider. Hidden models never
291-
* appear. Search words naming the provider are dropped; other words list matches. With no
292-
* words left, lists pinned models (custom, favorite, the caller's own) plus non-legacy
293-
* models, or only the first few in the user's model order for large catalogs.
290+
* Lists visible models, keeping pinned models and limiting large catalogs by default.
291+
* Whole provider words select the provider; partial words filter models when any match.
294292
*/
295293
function listCapabilityModels(input: {
296294
readonly provider: ServerProvider;
@@ -306,10 +304,22 @@ function listCapabilityModels(input: {
306304
.toSorted((a, b) => (rank.get(a.slug) ?? rank.size) - (rank.get(b.slug) ?? rank.size));
307305
const { instanceId, driver, displayName } = input.provider;
308306
const providerText = `${instanceId} ${driver} ${displayName ?? ""}`.toLowerCase();
309-
const modelTerms = input.searchTerms.filter((term) => !providerText.includes(term));
307+
// Whole ids like "codex-work" and their parts both name the provider.
308+
const providerWords = new Set([
309+
...providerText.split(/\s+/),
310+
...providerText.split(/[^\p{L}\p{N}]+/u),
311+
]);
312+
const modelText = (model: ServerProviderModel) =>
313+
`${model.slug} ${model.name} ${model.subProvider ?? ""}`.toLowerCase();
314+
// Part of a provider word ("agent" in "claudeAgent") names the provider unless a model matches it.
315+
const modelTerms = input.searchTerms.filter(
316+
(term) =>
317+
!providerWords.has(term) &&
318+
(!providerText.includes(term) || visible.some((model) => modelText(model).includes(term))),
319+
);
310320
if (modelTerms.length > 0) {
311321
const matches = visible.filter((model) => {
312-
const text = `${model.slug} ${model.name} ${model.subProvider ?? ""}`.toLowerCase();
322+
const text = modelText(model);
313323
return modelTerms.every((term) => text.includes(term));
314324
});
315325
const listed = matches.slice(0, LISTED_MODEL_LIMIT);
@@ -2138,7 +2148,7 @@ const make = Effect.gen(function* () {
21382148
Effect.mapError(() => failure("orchestration_error", "Unable to read server settings.")),
21392149
);
21402150
const inherited = parent?.thread.modelSelection;
2141-
const searchTerms = input.search?.toLowerCase().split(/\s+/) ?? [];
2151+
const searchTerms = input.search?.toLowerCase().split(/\s+/).filter(Boolean) ?? [];
21422152
return {
21432153
parentThreadId: parent?.thread.id ?? null,
21442154
inheritedProviderInstanceId: inherited?.instanceId ?? null,

0 commit comments

Comments
 (0)