fix(ui): make OpenRouter setup models searchable (#22034)

## Thinking Path

> - Paperclip helps people manage AI agents for work.
> - Agent setup lets people select a provider and a model.
> - OpenRouter has a large model catalog and accepts custom model IDs.
> - The setup page used a native select for OpenCode and Pi.
> - The shared model picker already supports search and manual entry.
> - This pull request uses that picker for multi-provider and routed
models.
> - People can find a model or enter a model ID in the same control.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Model selection in the new agent setup page.

**Current behavior**

OpenCode and Pi use a native model select. Users must scroll through the
catalog. Custom models require a separate select option and input field.

**Proposed behavior**

Use the shared searchable model picker for multi-provider harnesses and
routed connections. Users can filter models or choose `Use manual model`
after they type a custom ID.

**Reason and benefit**

OpenRouter catalogs can contain many models. Search helps users find a
model. Manual entry supports models that are absent from the catalog or
entered while the catalog is unavailable.

**Breaking changes**

None. The existing model ID resolver and save path remain in use.

Related work: #15422 set the qualified runner defaults. This change
addresses the model control on the resulting setup page. A search of
related PRs found no duplicate fix.

## What Changed

- Enable the existing searchable picker for multi-provider and routed
models.
- Add seven setup tests with the real model picker. Cover filtered
selection, saved IDs, custom IDs during catalog errors, the OpenCode
routing prefix, single-provider routing, and a linear work limit for 600
models.

## Verification

- The five regression cases fail before the fix because the searchable
model control is absent.
- Final focused Vitest run: 145 tests pass across setup, model picker,
and connection model suites.
- UI typecheck passes after building the required shared and plugin SDK
packages.
- The 600-model search test and the routed Claude setup test pass.
- The broader selected run passed 576 test files and failed two CLI
permission tests under this workspace's `077` umask. The isolated CLI
suites pass all 24 tests with `umask 022`. Review edits also invalidated
that broad run, so it is not a final-revision pass.
- Greptile gives 5/5 with no actionable findings on commit
`1686422063d426b1a35b0c0c0c9a1340153c9679`. All review threads are
resolved. All applicable CI checks pass on that commit. Paperclip review
also gives 5/5 with no actionable findings. [CI
run](https://github.com/paperclipai/paperclip/actions/runs/44137699265).
- Chromium checks pass for desktop search, selection, custom entry,
OpenRouter ID normalization, and mobile search without horizontal
overflow. Five screenshots were captured at desktop and mobile sizes.
They include the populated dropdown with an empty search field. These
checks use production components with API fixtures. They do not make
provider calls.

## Risks

Low risk. The change selects an existing shared control. Model
resolution, connection selection, validation, and saved configuration
use their existing paths. Multi-provider and routed model lists now use
search during setup.

## Model Used

OpenAI GPT-6 Codex. The agent used reasoning, repository tools, and code
execution. The runtime did not expose a more specific model version.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-11-17 12:20:16 -06:00
1 parent f4cb69205e
commit d10e250d55
3 files changed
+125 -3

No files matched your search

@@ -1200,7 +1200,7 @@ function Setup({
<div className="grid items-start gap-5 sm:grid-cols-2">
{showModel && !usingKimiApi && (
<ModelDropdown
presentation={brandType === "codex_local" ? "searchable" : "native"}
presentation={brandType === "codex_local" || multiProvider || connectionModels ? "searchable" : "native"}
models={connectionModels?.models ?? models.data ?? []}
loadingModels={connectionModels?.isLoading ?? models.isLoading}
onRefreshModels={connectionModels?.refreshModels ?? (accountCatalogAvailable ? async () => { await models.refetch(); } : undefined)}
+122
View File
@@ -0,0 +1,122 @@
// @vitest-environment jsdom
import { act } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { api, click, container, managedApi, render, settle } from "./NewAgent.test-support";
import { ModelDropdown } from "@/components/AgentConfigForm";
import * as modelUtils from "@/lib/model-utils";
beforeEach(async () => {
const actual = await vi.importActual<typeof import("@/components/AgentConfigForm")>("@/components/AgentConfigForm");
vi.mocked(ModelDropdown).mockImplementation(actual.ModelDropdown);
});
async function searchModels(query: string) {
const trigger = container.querySelector<HTMLButtonElement>('button[aria-label="Model"]');
expect(trigger).toBeTruthy();
await act(async () => trigger!.click());
await settle();
const input = document.querySelector<HTMLInputElement>('input[placeholder="Search models... (type to create)"]');
expect(input).toBeTruthy();
await act(async () => {
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, query);
input!.dispatchEvent(new Event("input", { bubbles: true }));
});
}
async function selectModel(label: string) {
const option = [...document.querySelectorAll<HTMLButtonElement>('[role="option"]')]
.find(node => node.textContent?.includes(label) || node.querySelector("[title]")?.getAttribute("title") === label);
expect(option).toBeTruthy();
await act(async () => option!.click());
await settle();
}
describe("New agent OpenRouter model selection", () => {
it.each(["opencode_local", "pi_local"])("searches the %s catalog and saves the selected model ID", async adapter => {
api.adapterModels.mockResolvedValue([
{ id: "openrouter/anthropic/claude-sonnet-4.6", label: "Claude Sonnet" },
{ id: "openrouter/z-ai/glm-5", label: "GLM 5" },
]);
await render(adapter);
await searchModels("glm-5");
expect(document.querySelector('[role="option"] [title="openrouter/anthropic/claude-sonnet-4.6"]')).toBeNull();
await selectModel("openrouter/z-ai/glm-5");
expect(document.querySelector('[role="listbox"]')).toBeNull();
await click("Finish setup");
expect(api.hire).toHaveBeenCalledWith("company-1", expect.objectContaining({
adapterConfig: expect.objectContaining({ model: "openrouter/z-ai/glm-5" }),
}));
});
it.each(["opencode_local", "pi_local"])("accepts a custom model for %s when the catalog is unavailable", async adapter => {
api.adapterModels.mockRejectedValue(new Error("Catalog unavailable"));
await render(adapter);
const model = "openrouter/company/custom-model";
await searchModels(` ${model} `);
await selectModel("Use manual model");
expect(container.querySelector('button[aria-label="Model"]')?.textContent).toContain(model);
await click("Finish setup");
expect(api.hire).toHaveBeenCalledWith("company-1", expect.objectContaining({
adapterConfig: expect.objectContaining({ model }),
}));
});
it("normalizes a custom OpenRouter model ID for the OpenCode connection", async () => {
await render("opencode_local");
await searchModels("company/new-model");
await selectModel("Use manual model");
await click("Finish setup");
expect(api.hire).toHaveBeenCalledWith("company-1", expect.objectContaining({
adapterConfig: expect.objectContaining({ model: "openrouter/company/new-model" }),
}));
});
it("searches routed OpenRouter models for a single-provider harness", async () => {
const model = "anthropic/claude-sonnet-4.6";
managedApi.list.mockResolvedValue({ currentUserId: "user-1", canManageConnections: true, connections: [{
id: "00000000-0000-4000-8000-000000000021", grantId: "00000000-0000-4000-8000-000000000022",
companyId: "company-1", provider: "openrouter", method: "api_key", name: "Company OpenRouter",
ownership: "shared", isDefault: false, status: "connected",
routing: { kind: "openrouter", protocol: "messages", auth: "bearer", models: [{ id: model, label: "Routed Claude Sonnet" }] },
}] } as any);
await render("claude_local");
await click("AdvancedCustom Gateway");
const connection = container.querySelector('[role="combobox"][aria-label="Connection"]')!;
await act(async () => connection.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true })));
await settle();
await selectModel("Company OpenRouter");
await click("Use connection");
await searchModels("Routed Claude");
await selectModel(model);
await click("Finish setup");
expect(api.hire).toHaveBeenCalledWith("company-1", expect.objectContaining({
adapterConfig: expect.objectContaining({ model }),
runtimeConfig: expect.objectContaining({ aiConnection: expect.objectContaining({ provider: "openrouter" }) }),
}));
});
it("bounds search work for a large OpenRouter catalog", async () => {
const size = 600;
api.adapterModels.mockResolvedValue(Array.from({ length: size }, (_, index) => ({
id: `openrouter/company/model-${index}`,
label: `Company model ${index}`,
})));
const extractProviderId = modelUtils.extractProviderId;
let calls = 0;
const providerSpy = vi.spyOn(modelUtils, "extractProviderId").mockImplementation(id => {
if (++calls > size * 4) throw new Error("Model search exceeded its linear work limit");
return extractProviderId(id);
});
try {
await render("opencode_local");
await searchModels("model-599");
expect(calls).toBeGreaterThanOrEqual(size);
expect(calls).toBeLessThanOrEqual(size * 4);
expect(document.querySelectorAll('[role="option"] [title]')).toHaveLength(1);
await selectModel("openrouter/company/model-599");
expect(container.querySelector('button[aria-label="Model"]')?.textContent).toContain("Company model 599");
} finally {
providerSpy.mockRestore();
}
});
});
+2 -2
View File
@@ -67,7 +67,7 @@ vi.mock("@/lib/router", () => ({
useSearchParams: () => [state.params],
}));
vi.mock("@/components/AgentConfigForm", () => ({
ModelDropdown: ({
ModelDropdown: vi.fn(({
value,
onChange,
}: {
@@ -79,7 +79,7 @@ vi.mock("@/components/AgentConfigForm", () => ({
value={value}
onChange={(e) => onChange(e.target.value)}
/>
),
)),
AdapterLoginPanel: ({ onConnected }: { onConnected: (id: string) => void }) => (
<button onClick={() => onConnected("login-session")}>
Complete subscription login