fix(coding-agent): refresh model catalogs in picker
This commit is contained in:
@@ -501,10 +501,14 @@ export class ModelRuntime implements Models {
|
||||
}
|
||||
|
||||
async refresh(options: ModelsRefreshOptions = {}): Promise<ModelsRefreshResult> {
|
||||
const refreshOptions = {
|
||||
...options,
|
||||
allowNetwork: options.allowNetwork ?? this.allowModelNetwork,
|
||||
};
|
||||
// Published pi-ai builds before ModelsStore returned void and accepted a provider ID.
|
||||
// The fallback keeps source-mode CLI tests working without rebuilding workspace dependencies.
|
||||
const result = ((await this.models.refresh(options)) as ModelsRefreshResult | undefined) ?? {
|
||||
aborted: options.signal?.aborted ?? false,
|
||||
const result = ((await this.models.refresh(refreshOptions)) as ModelsRefreshResult | undefined) ?? {
|
||||
aborted: refreshOptions.signal?.aborted ?? false,
|
||||
errors: new Map(),
|
||||
};
|
||||
this.updateModelSnapshot();
|
||||
|
||||
@@ -17,7 +17,9 @@ function parseCatalog(providerId: string, value: unknown): Model<Api>[] {
|
||||
? value
|
||||
: typeof value === "object" && value !== null && "models" in value && Array.isArray(value.models)
|
||||
? value.models
|
||||
: undefined;
|
||||
: typeof value === "object" && value !== null
|
||||
? Object.values(value)
|
||||
: undefined;
|
||||
if (!entries) throw new Error(`Invalid model catalog for provider "${providerId}"`);
|
||||
return entries
|
||||
.filter((entry): entry is Model<Api> => typeof entry === "object" && entry !== null && "id" in entry)
|
||||
@@ -44,6 +46,7 @@ export function withRemoteCatalog(provider: Provider, catalogBaseUrl: string = D
|
||||
headers: { accept: "application/json" },
|
||||
signal: context.signal,
|
||||
});
|
||||
if (response.status === 404 || response.status === 501) return;
|
||||
if (!response.ok) {
|
||||
throw new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ export class ModelSelectorComponent extends Container implements Focusable {
|
||||
private onSelectCallback: (model: Model<any>) => void;
|
||||
private onCancelCallback: () => void;
|
||||
private errorMessage?: string;
|
||||
private refreshStatusMessage = "Refreshing model catalogs…";
|
||||
private refreshStatusSuccess = false;
|
||||
private tui: TUI;
|
||||
private scopedModels: ReadonlyArray<ScopedModelItem>;
|
||||
private scope: ModelScope = "all";
|
||||
@@ -167,12 +169,19 @@ export class ModelSelectorComponent extends Container implements Focusable {
|
||||
try {
|
||||
const result = await this.modelRuntime.refresh({ signal: this.refreshAbortController.signal });
|
||||
if (this.closed) return;
|
||||
this.refreshStatusMessage = "";
|
||||
if (result.aborted && timedOut) {
|
||||
this.errorMessage = "Model refresh timed out; showing cached models.";
|
||||
} else if (result.errors.size > 0) {
|
||||
this.errorMessage = `Model refresh failed for: ${[...result.errors.keys()].join(", ")}`;
|
||||
} else if (result.errors.size === 1) {
|
||||
this.errorMessage = `Could not refresh ${result.errors.keys().next().value}; showing cached models.`;
|
||||
} else if (result.errors.size > 1) {
|
||||
this.errorMessage = `Could not refresh ${result.errors.size} model catalogs; showing cached models.`;
|
||||
} else {
|
||||
this.errorMessage = this.modelRuntime.getError();
|
||||
if (!this.errorMessage) {
|
||||
this.refreshStatusMessage = "Model catalogs refreshed.";
|
||||
this.refreshStatusSuccess = true;
|
||||
}
|
||||
}
|
||||
this.loadModelsFromSnapshot();
|
||||
this.filterModels(this.searchInput.getValue());
|
||||
@@ -288,6 +297,12 @@ export class ModelSelectorComponent extends Container implements Focusable {
|
||||
this.listContainer.addChild(new Spacer(1));
|
||||
this.listContainer.addChild(new Text(theme.fg("muted", ` Model Name: ${selected.model.name}`), 0, 0));
|
||||
}
|
||||
if (this.refreshStatusMessage) {
|
||||
this.listContainer.addChild(new Spacer(1));
|
||||
this.listContainer.addChild(
|
||||
new Text(theme.fg(this.refreshStatusSuccess ? "success" : "muted", ` ${this.refreshStatusMessage}`), 0, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
handleInput(keyData: string): void {
|
||||
|
||||
Reference in New Issue
Block a user