Skip to content

Commit affc1ac

Browse files
authored
Perform case insensitive search for model and agent (#2364)
1 parent 59b58f7 commit affc1ac

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/extension/agents/copilotcli/node/copilotCli.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export class CopilotCLIModels implements ICopilotCLIModels {
115115
}
116116
async resolveModel(modelId: string): Promise<string | undefined> {
117117
const models = await this.getModels();
118-
return models.find(m => m.id === modelId)?.id;
118+
modelId = modelId.trim().toLowerCase();
119+
return models.find(m => m.id.toLowerCase() === modelId)?.id;
119120
}
120121
public async getDefaultModel() {
121122
// First item in the list is always the default model (SDK sends the list ordered based on default preference)
@@ -124,9 +125,9 @@ export class CopilotCLIModels implements ICopilotCLIModels {
124125
return;
125126
}
126127
const defaultModel = models[0];
127-
const preferredModelId = this.extensionContext.globalState.get<string>(COPILOT_CLI_MODEL_MEMENTO_KEY, defaultModel.id);
128+
const preferredModelId = this.extensionContext.globalState.get<string>(COPILOT_CLI_MODEL_MEMENTO_KEY, defaultModel.id)?.trim()?.toLowerCase();
128129

129-
return models.find(m => m.id === preferredModelId)?.id ?? defaultModel.id;
130+
return models.find(m => m.id.toLowerCase() === preferredModelId)?.id ?? defaultModel.id;
130131
}
131132

132133
public async setDefaultModel(modelId: string | undefined): Promise<void> {
@@ -197,17 +198,17 @@ export class CopilotCLIAgents implements ICopilotCLIAgents {
197198
return undefined;
198199
}
199200
const agents = await this.getAgents();
200-
return agents.find(agent => agent.name === agentId)?.name;
201+
return agents.find(agent => agent.name.toLowerCase() === agentId)?.name;
201202
}
202203

203204
async getDefaultAgent(): Promise<string> {
204-
const agentId = this.extensionContext.workspaceState.get<string>(COPILOT_CLI_AGENT_MEMENTO_KEY, COPILOT_CLI_DEFAULT_AGENT_ID);
205+
const agentId = this.extensionContext.workspaceState.get<string>(COPILOT_CLI_AGENT_MEMENTO_KEY, COPILOT_CLI_DEFAULT_AGENT_ID).toLowerCase();
205206
if (agentId === COPILOT_CLI_DEFAULT_AGENT_ID) {
206207
return agentId;
207208
}
208209

209210
const agents = await this.getAgents();
210-
return agents.find(agent => agent.name === agentId)?.name ?? COPILOT_CLI_DEFAULT_AGENT_ID;
211+
return agents.find(agent => agent.name.toLowerCase() === agentId)?.name ?? COPILOT_CLI_DEFAULT_AGENT_ID;
211212
}
212213
async setDefaultAgent(agent: string | undefined): Promise<void> {
213214
await this.extensionContext.workspaceState.update(COPILOT_CLI_AGENT_MEMENTO_KEY, agent);
@@ -217,7 +218,8 @@ export class CopilotCLIAgents implements ICopilotCLIAgents {
217218
}
218219
async resolveAgent(agentId: string): Promise<SweCustomAgent | undefined> {
219220
const customAgents = await this.getAgents();
220-
const agent = customAgents.find(agent => agent.name === agentId);
221+
agentId = agentId.toLowerCase();
222+
const agent = customAgents.find(agent => agent.name.toLowerCase() === agentId);
221223
// Return a clone to allow mutations (to tools, etc).
222224
return agent ? this.cloneAgent(agent) : undefined;
223225
}

0 commit comments

Comments
 (0)