fix(ui): request configured model list

This commit is contained in:
Peter Steinberger
2026-04-28 05:20:55 +01:00
parent 000d52be37
commit 870d993eb8
15 changed files with 236 additions and 13 deletions

View File

@@ -269,7 +269,7 @@ describe("executeSlashCommand directives", () => {
"**Current model:** `gpt-4.1-mini`\n**Available:** `gpt-4.1-mini`, `gpt-4.1`",
);
expect(request).toHaveBeenNthCalledWith(1, "sessions.list", {});
expect(request).toHaveBeenNthCalledWith(2, "models.list", {});
expect(request).toHaveBeenNthCalledWith(2, "models.list", { view: "configured" });
});
it("mirrors resolved provider-qualified model refs after /model changes", async () => {
@@ -587,7 +587,7 @@ describe("executeSlashCommand directives", () => {
"Current thinking level: low.\nOptions: off, minimal, low, medium, high.",
);
expect(request).toHaveBeenNthCalledWith(1, "sessions.list", {});
expect(request).toHaveBeenNthCalledWith(2, "models.list", {});
expect(request).toHaveBeenNthCalledWith(2, "models.list", { view: "configured" });
});
it("accepts minimal and xhigh thinking levels", async () => {

View File

@@ -725,7 +725,9 @@ async function loadModelCatalog(
opts?: { allowFailure?: boolean },
): Promise<ModelCatalogEntry[]> {
try {
const result = await client.request<{ models: ModelCatalogEntry[] }>("models.list", {});
const result = await client.request<{ models: ModelCatalogEntry[] }>("models.list", {
view: "configured",
});
return result?.models ?? [];
} catch (err) {
if (opts?.allowFailure) {

View File

@@ -3,6 +3,7 @@ import { DEFAULT_CRON_FORM } from "../app-defaults.ts";
import {
addCronJob,
cancelCronEdit,
loadCronModelSuggestions,
loadCronJobsPage,
loadCronRuns,
loadMoreCronRuns,
@@ -58,6 +59,27 @@ function createState(overrides: Partial<CronState> = {}): CronState {
}
describe("cron controller", () => {
it("loads model suggestions from the configured model view", async () => {
const request = vi.fn(async () => ({
models: [
{ id: "z-model", provider: "zai" },
{ id: "a-model", provider: "anthropic" },
{ id: "z-model", provider: "other" },
{ provider: "missing-id" },
],
}));
const state = {
client: { request } as unknown as CronState["client"],
connected: true,
cronModelSuggestions: [],
};
await loadCronModelSuggestions(state);
expect(request).toHaveBeenCalledWith("models.list", { view: "configured" });
expect(state.cronModelSuggestions).toEqual(["a-model", "z-model"]);
});
it("normalizes stale announce mode when session/payload no longer support announce", () => {
const normalized = normalizeCronFormState({
...DEFAULT_CRON_FORM,

View File

@@ -205,7 +205,7 @@ export async function loadCronModelSuggestions(state: CronModelSuggestionsState)
return;
}
try {
const res = await state.client.request("models.list", {});
const res = await state.client.request("models.list", { view: "configured" });
const models = (res as { models?: unknown[] } | null)?.models;
if (!Array.isArray(models)) {
state.cronModelSuggestions = [];

View File

@@ -0,0 +1,20 @@
import { describe, expect, it, vi } from "vitest";
import type { GatewayBrowserClient } from "../gateway.ts";
import { loadModels } from "./models.ts";
describe("loadModels", () => {
it("requests the configured model list view", async () => {
const request = vi.fn(async () => ({
models: [
{ id: "MiniMax-M2.7-highspeed", name: "MiniMax M2.7 Highspeed", provider: "minimax" },
],
}));
const models = await loadModels({ request } as unknown as GatewayBrowserClient);
expect(request).toHaveBeenCalledWith("models.list", { view: "configured" });
expect(models).toEqual([
{ id: "MiniMax-M2.7-highspeed", name: "MiniMax M2.7 Highspeed", provider: "minimax" },
]);
});
});

View File

@@ -10,7 +10,9 @@ import type { ModelCatalogEntry } from "../types.ts";
*/
export async function loadModels(client: GatewayBrowserClient): Promise<ModelCatalogEntry[]> {
try {
const result = await client.request<{ models: ModelCatalogEntry[] }>("models.list", {});
const result = await client.request<{ models: ModelCatalogEntry[] }>("models.list", {
view: "configured",
});
return result?.models ?? [];
} catch {
return [];