mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 20:01:06 +00:00
fix(coding-agent): handle scoped models after logout (#1194)
This commit is contained in:
parent
fe534b2200
commit
f7c03ef6a2
3 changed files with 37 additions and 15 deletions
|
|
@ -1170,22 +1170,39 @@ export class AgentSession {
|
||||||
return this._cycleAvailableModel(direction);
|
return this._cycleAvailableModel(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _getScopedModelsWithApiKey(): Promise<Array<{ model: Model<any>; thinkingLevel: ThinkingLevel }>> {
|
||||||
|
const apiKeysByProvider = new Map<string, string | undefined>();
|
||||||
|
const result: Array<{ model: Model<any>; thinkingLevel: ThinkingLevel }> = [];
|
||||||
|
|
||||||
|
for (const scoped of this._scopedModels) {
|
||||||
|
const provider = scoped.model.provider;
|
||||||
|
let apiKey: string | undefined;
|
||||||
|
if (apiKeysByProvider.has(provider)) {
|
||||||
|
apiKey = apiKeysByProvider.get(provider);
|
||||||
|
} else {
|
||||||
|
apiKey = await this._modelRegistry.getApiKeyForProvider(provider);
|
||||||
|
apiKeysByProvider.set(provider, apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiKey) {
|
||||||
|
result.push(scoped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private async _cycleScopedModel(direction: "forward" | "backward"): Promise<ModelCycleResult | undefined> {
|
private async _cycleScopedModel(direction: "forward" | "backward"): Promise<ModelCycleResult | undefined> {
|
||||||
if (this._scopedModels.length <= 1) return undefined;
|
const scopedModels = await this._getScopedModelsWithApiKey();
|
||||||
|
if (scopedModels.length <= 1) return undefined;
|
||||||
|
|
||||||
const currentModel = this.model;
|
const currentModel = this.model;
|
||||||
let currentIndex = this._scopedModels.findIndex((sm) => modelsAreEqual(sm.model, currentModel));
|
let currentIndex = scopedModels.findIndex((sm) => modelsAreEqual(sm.model, currentModel));
|
||||||
|
|
||||||
if (currentIndex === -1) currentIndex = 0;
|
if (currentIndex === -1) currentIndex = 0;
|
||||||
const len = this._scopedModels.length;
|
const len = scopedModels.length;
|
||||||
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
|
||||||
const next = this._scopedModels[nextIndex];
|
const next = scopedModels[nextIndex];
|
||||||
|
|
||||||
// Validate API key
|
|
||||||
const apiKey = await this._modelRegistry.getApiKey(next.model);
|
|
||||||
if (!apiKey) {
|
|
||||||
throw new Error(`No API key for ${next.model.provider}/${next.model.id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply model
|
// Apply model
|
||||||
this.agent.setModel(next.model);
|
this.agent.setModel(next.model);
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,10 @@ export class ScopedModelsSelectorComponent extends Container implements Focusabl
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildItems(): ModelItem[] {
|
private buildItems(): ModelItem[] {
|
||||||
return getSortedIds(this.enabledIds, this.allIds).map((id) => ({
|
// Filter out IDs that no longer have a corresponding model (e.g., after logout)
|
||||||
|
return getSortedIds(this.enabledIds, this.allIds)
|
||||||
|
.filter((id) => this.modelsById.has(id))
|
||||||
|
.map((id) => ({
|
||||||
fullId: id,
|
fullId: id,
|
||||||
model: this.modelsById.get(id)!,
|
model: this.modelsById.get(id)!,
|
||||||
enabled: isEnabled(this.enabledIds, id),
|
enabled: isEnabled(this.enabledIds, id),
|
||||||
|
|
|
||||||
|
|
@ -3261,6 +3261,8 @@ export class InteractiveMode {
|
||||||
// All enabled or none enabled = no filter
|
// All enabled or none enabled = no filter
|
||||||
this.session.setScopedModels([]);
|
this.session.setScopedModels([]);
|
||||||
}
|
}
|
||||||
|
await this.updateAvailableProviderCount();
|
||||||
|
this.ui.requestRender();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.showSelector((done) => {
|
this.showSelector((done) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue