refactor: declone model picker model ref parsing

This commit is contained in:
Peter Steinberger
2026-03-14 01:23:24 +00:00
parent c0831927b0
commit 91d9573b55
4 changed files with 38 additions and 14 deletions

View File

@@ -60,6 +60,15 @@ describe("Mattermost model picker", () => {
expect(view.buttons[0]?.[0]?.text).toBe("Browse providers");
});
it("trims accidental model spacing in Mattermost current-model text", () => {
const view = renderMattermostModelSummaryView({
ownerUserId: "user-1",
currentModel: " OpenAI/ gpt-5 ",
});
expect(view.text).toContain("Current: openai/gpt-5");
});
it("renders providers and models with Telegram-style navigation", () => {
const providersView = renderMattermostProviderPickerView({
ownerUserId: "user-1",

View File

@@ -36,15 +36,13 @@ export type MattermostModelPickerRenderedView = {
function splitModelRef(modelRef?: string | null): { provider: string; model: string } | null {
const trimmed = modelRef?.trim();
if (!trimmed) {
const match = trimmed?.match(/^([^/]+)\/(.+)$/u);
if (!match) {
return null;
}
const slashIndex = trimmed.indexOf("/");
if (slashIndex <= 0 || slashIndex >= trimmed.length - 1) {
return null;
}
const provider = normalizeProviderId(trimmed.slice(0, slashIndex));
const model = trimmed.slice(slashIndex + 1).trim();
const provider = normalizeProviderId(match[1]);
// Mattermost copy should normalize accidental whitespace around the model.
const model = match[2].trim();
if (!provider || !model) {
return null;
}