MCPcopy Create free account
hub / github.com/TanStack/ai / selectProvider

Function selectProvider

testing/panel/tests/helpers.ts:11–63  ·  view source on GitHub ↗
(
  page: Page,
  provider: ProviderId,
  model: string,
)

Source from the content-addressed store, hash-verified

9 * Select a provider/model from the model dropdown on the chat page
10 */
11export async function selectProvider(
12 page: Page,
13 provider: ProviderId,
14 model: string,
15): Promise<void> {
16 // The model selector shows labels like "OpenAI - GPT-4o"
17 // We need to find the option that matches our provider and model
18 const select = page.locator('select').first()
19 await select.waitFor({ state: 'visible' })
20
21 // Get all options and find the one matching our provider/model
22 const options = await select.locator('option').all()
23 let targetIndex = -1
24
25 for (let i = 0; i < options.length; i++) {
26 const text = await options[i].textContent()
27 // Match by provider name in the label (e.g., "OpenAI - GPT-4o")
28 const providerName = getProviderDisplayName(provider)
29 if (text?.includes(providerName) && text?.includes(model)) {
30 targetIndex = i
31 break
32 }
33 // Also match if model contains the text (for models like "gpt-4o-mini")
34 if (text?.includes(providerName)) {
35 // Check if this is the model we want by looking at model substring
36 const modelPart = model.split('/').pop() || model // Handle openrouter models like "openai/gpt-4o"
37 if (text?.toLowerCase().includes(modelPart.toLowerCase())) {
38 targetIndex = i
39 break
40 }
41 }
42 }
43
44 // If we found a match, select it; otherwise try to find by provider only
45 if (targetIndex === -1) {
46 for (let i = 0; i < options.length; i++) {
47 const text = await options[i].textContent()
48 const providerName = getProviderDisplayName(provider)
49 if (text?.includes(providerName)) {
50 targetIndex = i
51 break
52 }
53 }
54 }
55
56 if (targetIndex >= 0) {
57 await select.selectOption({ index: targetIndex })
58 } else {
59 throw new Error(
60 `Could not find model option for provider: ${provider}, model: ${model}`,
61 )
62 }
63}
64
65/**
66 * Get the display name for a provider (as shown in the UI)

Callers 2

tool-flow.spec.tsFile · 0.90

Calls 1

getProviderDisplayNameFunction · 0.85

Tested by

no test coverage detected