Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions webview-ui/src/components/settings/ApiOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,22 @@ const ApiOptions = ({
return true
})

return providersWithModels.map(({ value, label }) => ({
const options = providersWithModels.map(({ value, label }) => ({
value,
label,
}))
}, [organizationAllowList, apiConfiguration.apiProvider])

// Pin "roo" to the top if not on welcome screen
if (!fromWelcomeView) {
const rooIndex = options.findIndex((opt) => opt.value === "roo")
if (rooIndex > 0) {
const [rooOption] = options.splice(rooIndex, 1)
options.unshift(rooOption)
}
}

return options
}, [organizationAllowList, apiConfiguration.apiProvider, fromWelcomeView])

return (
<div className="flex flex-col gap-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,5 +611,67 @@ describe("ApiOptions", () => {

expect(screen.queryByTestId("roo-balance-display")).not.toBeInTheDocument()
})

it("pins roo provider to the top when not on welcome screen", () => {
// Mock useExtensionState to ensure no filtering
const useExtensionStateMock = vi.spyOn(ExtensionStateContext, "useExtensionState")
useExtensionStateMock.mockReturnValue({
cloudIsAuthenticated: false,
organizationAllowList: { providers: {} },
} as any)

renderApiOptions({
apiConfiguration: {},
fromWelcomeView: false,
})

const providerSelectContainer = screen.getByTestId("provider-select")
const providerSelect = providerSelectContainer.querySelector("select") as HTMLSelectElement
const options = Array.from(providerSelect.querySelectorAll("option"))

// Filter out the placeholder option (empty value)
const providerOptions = options.filter((opt) => opt.value !== "")

// Find the roo option
const rooOption = providerOptions.find((opt) => opt.value === "roo")

// If roo is available, verify it's pinned to the top
if (rooOption) {
expect(providerOptions[0].value).toBe("roo")
}

useExtensionStateMock.mockRestore()
})

it("does not pin roo provider to the top on welcome screen", () => {
// Mock useExtensionState to ensure no filtering
const useExtensionStateMock = vi.spyOn(ExtensionStateContext, "useExtensionState")
useExtensionStateMock.mockReturnValue({
cloudIsAuthenticated: false,
organizationAllowList: { providers: {} },
} as any)

renderApiOptions({
apiConfiguration: {},
fromWelcomeView: true,
})

const providerSelectContainer = screen.getByTestId("provider-select")
const providerSelect = providerSelectContainer.querySelector("select") as HTMLSelectElement
const options = Array.from(providerSelect.querySelectorAll("option"))

// Filter out the placeholder option (empty value)
const providerOptions = options.filter((opt) => opt.value !== "")

// Check that roo is in the list
const rooOption = providerOptions.find((opt) => opt.value === "roo")

if (rooOption) {
// If roo exists, verify it's NOT at the top (should be in alphabetical order)
expect(providerOptions[0].value).not.toBe("roo")
}

useExtensionStateMock.mockRestore()
})
})
})
Loading