mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(app): drive the Settings Models provider reveal with an explicit state machine (#61944)
This commit is contained in:
committed by
GitHub
Unverified
parent
833b3e1013
commit
2aa8b9b8d1
@@ -2003,6 +2003,65 @@ test("providers: switching Console accounts keeps the list until the new workspa
|
||||
await expect(connected).not.toHaveAttribute("data-flashed")
|
||||
})
|
||||
|
||||
test("models: a Console provider picked on Providers opens its collapsed group, then the search types normally", async ({
|
||||
page,
|
||||
}) => {
|
||||
const model = (id: string, name: string) => ({ [id]: { id, name, limit: { context: 200_000 } } })
|
||||
|
||||
const { settings } = await open(page, {
|
||||
provider: {
|
||||
all: [
|
||||
{
|
||||
id: "opencode",
|
||||
integrationID: "opencode",
|
||||
name: "Anomaly / OpenCode",
|
||||
models: model("console-model", "Console Model"),
|
||||
},
|
||||
{
|
||||
id: "console-google",
|
||||
canonical: "google",
|
||||
integrationID: "opencode",
|
||||
name: "Anomaly / Google",
|
||||
models: model("managed-gemini", "Managed Gemini"),
|
||||
},
|
||||
],
|
||||
connected: ["opencode", "console-google"],
|
||||
default: {},
|
||||
},
|
||||
integrations: [
|
||||
{
|
||||
id: "opencode",
|
||||
name: "OpenCode Console",
|
||||
methods: [{ id: "device", type: "oauth", label: "OpenCode Console account" }],
|
||||
connections: [{ type: "credential", id: "cred_anomaly", label: "Anomaly", method: "oauth" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const group = settings
|
||||
.locator('[data-component="settings-models-console"]')
|
||||
.getByRole("button", { name: /^OpenCode Console/ })
|
||||
|
||||
await settings.getByRole("tab", { name: "Models", exact: true }).click()
|
||||
await group.click()
|
||||
await expect(group).toHaveAttribute("aria-expanded", "false")
|
||||
|
||||
await settings.getByRole("tab", { name: "Providers", exact: true }).click()
|
||||
const connected = settings.locator('[data-component="connected-providers-section"]')
|
||||
await connected.getByRole("button", { name: "2 providers available", exact: true }).click()
|
||||
await connected.getByRole("button", { name: "Google", exact: true }).click()
|
||||
|
||||
// The nested provider mounts only inside the expanded Console group, so the reveal opens the group first.
|
||||
const google = settings.locator('[data-component="provider-model-group"][data-provider="console-google"]')
|
||||
await expect(group).toHaveAttribute("aria-expanded", "true")
|
||||
await expect(google.locator(".provider-model-group-trigger")).toBeFocused()
|
||||
|
||||
const search = settings.getByRole("searchbox", { name: "Search models", exact: true })
|
||||
await search.pressSequentially("gemini")
|
||||
await expect(search).toHaveValue("gemini")
|
||||
await expect(settings.getByRole("switch", { name: "Managed Gemini", exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test("the add server dialog keeps focus above fullscreen settings", async ({ page }) => {
|
||||
await mockRemoteServer(page, { directory: "/remote/settings-demo" })
|
||||
const { settings } = await open(page)
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import {
|
||||
createModelsRevealState,
|
||||
transitionModelsReveal,
|
||||
type ModelsRevealEvent,
|
||||
type ModelsRevealState,
|
||||
} from "./machine"
|
||||
|
||||
function run(events: readonly ModelsRevealEvent[], state: ModelsRevealState = createModelsRevealState()) {
|
||||
return events.reduce<{ state: ModelsRevealState; effects: unknown[] }>(
|
||||
(current, event) => {
|
||||
const next = transitionModelsReveal(current.state, event)
|
||||
|
||||
return { state: next.state, effects: [...next.effects] }
|
||||
},
|
||||
{ state, effects: [] },
|
||||
)
|
||||
}
|
||||
|
||||
const target = (provider: string | undefined, active = true): ModelsRevealEvent => ({
|
||||
type: "target.synced",
|
||||
active,
|
||||
provider,
|
||||
hasFilter: false,
|
||||
})
|
||||
|
||||
const catalog = (input: Partial<Extract<ModelsRevealEvent, { type: "catalog.synced" }>>): ModelsRevealEvent => ({
|
||||
type: "catalog.synced",
|
||||
hasFilter: false,
|
||||
inCatalog: true,
|
||||
inConsoleGroup: false,
|
||||
sectionReady: false,
|
||||
...input,
|
||||
})
|
||||
|
||||
describe("settings models reveal", () => {
|
||||
test("a provider nested in a collapsed Console group expands the group before its section exists", () => {
|
||||
const waiting = run([target("console-google")])
|
||||
expect(waiting.effects).toEqual([{ type: "timeout.start", attempt: 1, timeoutMs: 5_000 }])
|
||||
|
||||
const expanded = run([catalog({ inConsoleGroup: true })], waiting.state)
|
||||
expect(expanded.effects).toEqual([{ type: "section.expand", provider: "console-google", expandConsole: true }])
|
||||
|
||||
const scrolling = run([{ type: "section.ready", provider: "console-google" }], expanded.state)
|
||||
expect(scrolling.state).toEqual({ status: "scrolling", attempt: 1, provider: "console-google" })
|
||||
expect(scrolling.effects).toEqual([
|
||||
{ type: "timeout.cancel" },
|
||||
{ type: "frame.scroll", attempt: 1, provider: "console-google" },
|
||||
])
|
||||
|
||||
expect(run([{ type: "frame.completed", attempt: 1 }], scrolling.state)).toEqual({
|
||||
state: { status: "idle", attempt: 1 },
|
||||
effects: [{ type: "target.consume" }],
|
||||
})
|
||||
})
|
||||
|
||||
test("a provider without models never clears typing and gives up after the timeout", () => {
|
||||
const waiting = run([target("console-empty"), catalog({ inCatalog: false })])
|
||||
expect(waiting.state.status).toBe("waiting")
|
||||
|
||||
const typed = run([{ type: "filter.typed" }], waiting.state)
|
||||
expect(typed.state).toEqual({ status: "idle", attempt: 1 })
|
||||
expect(typed.effects).toEqual([{ type: "timeout.cancel" }, { type: "target.consume" }])
|
||||
// Later catalog changes with a typed filter do nothing.
|
||||
expect(transitionModelsReveal(typed.state, catalog({ hasFilter: true })).state).toBe(typed.state)
|
||||
|
||||
expect(run([{ type: "reveal.timed-out", attempt: 1 }], waiting.state)).toEqual({
|
||||
state: { status: "idle", attempt: 1 },
|
||||
effects: [{ type: "target.consume" }],
|
||||
})
|
||||
})
|
||||
|
||||
test("leaving the Models tab mid-reveal drops the target, so a later visit does not jump", () => {
|
||||
const left = run([target("anthropic"), target("anthropic", false)])
|
||||
expect(left.state).toEqual({ status: "idle", attempt: 1 })
|
||||
expect(left.effects).toEqual([{ type: "timeout.cancel" }, { type: "target.consume" }])
|
||||
|
||||
// A target set while the Providers tab still shows waits for the Models tab.
|
||||
const idle = createModelsRevealState()
|
||||
expect(transitionModelsReveal(idle, target("anthropic", false)).state).toBe(idle)
|
||||
})
|
||||
|
||||
test("a search typed before the reveal is cleared once, when it starts", () => {
|
||||
expect(run([{ type: "target.synced", active: true, provider: "anthropic", hasFilter: true }]).effects).toEqual([
|
||||
{ type: "filter.clear" },
|
||||
{ type: "timeout.start", attempt: 1, timeoutMs: 5_000 },
|
||||
])
|
||||
})
|
||||
|
||||
test("a listed section scrolls on the next frame, expanding the provider itself first", () => {
|
||||
expect(run([target("anthropic"), catalog({ sectionReady: true })]).effects).toEqual([
|
||||
{ type: "section.expand", provider: "anthropic", expandConsole: false },
|
||||
{ type: "timeout.cancel" },
|
||||
{ type: "frame.scroll", attempt: 1, provider: "anthropic" },
|
||||
])
|
||||
})
|
||||
|
||||
test("extra syncs while scrolling are ignored, and disposal cancels the frame and rejects its late completion", () => {
|
||||
const scrolling = run([target("anthropic"), catalog({ sectionReady: true })])
|
||||
|
||||
for (const event of [
|
||||
catalog({ sectionReady: true }),
|
||||
{ type: "section.ready", provider: "anthropic" },
|
||||
target("anthropic"),
|
||||
] as const)
|
||||
expect(transitionModelsReveal(scrolling.state, event).state).toBe(scrolling.state)
|
||||
|
||||
const disposed = run([{ type: "disposed" }], scrolling.state)
|
||||
expect(disposed.effects).toEqual([{ type: "frame.cancel" }, { type: "target.consume" }])
|
||||
expect(transitionModelsReveal(disposed.state, { type: "frame.completed", attempt: 1 }).state).toBe(disposed.state)
|
||||
})
|
||||
|
||||
test("another provider starts a new attempt, so the previous attempt's timeout and frame are stale", () => {
|
||||
const first = run([target("anthropic")])
|
||||
const second = run([target("openai")], first.state)
|
||||
expect(second.state).toEqual({ status: "waiting", attempt: 2, provider: "openai", expanded: false })
|
||||
expect(second.effects).toEqual([
|
||||
{ type: "timeout.cancel" },
|
||||
{ type: "timeout.start", attempt: 2, timeoutMs: 5_000 },
|
||||
])
|
||||
expect(transitionModelsReveal(second.state, { type: "reveal.timed-out", attempt: 1 }).state).toBe(second.state)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,161 @@
|
||||
/** How long a reveal waits for its provider to appear, e.g. while the catalog loads; a missing one gives up. */
|
||||
export const MODELS_REVEAL_TIMEOUT_MS = 5_000
|
||||
|
||||
/**
|
||||
* Revealing the provider picked on the Providers page: `waiting` for its section to be listed and mounted (expanding
|
||||
* the path to it once), then `scrolling` to it on the next frame. Every exit consumes the target.
|
||||
*/
|
||||
export type ModelsRevealState =
|
||||
| { readonly status: "idle"; readonly attempt: number }
|
||||
| { readonly status: "waiting"; readonly attempt: number; readonly provider: string; readonly expanded: boolean }
|
||||
| { readonly status: "scrolling"; readonly attempt: number; readonly provider: string }
|
||||
|
||||
export type ModelsRevealEvent =
|
||||
| {
|
||||
readonly type: "target.synced"
|
||||
readonly active: boolean
|
||||
readonly provider: string | undefined
|
||||
readonly hasFilter: boolean
|
||||
}
|
||||
| {
|
||||
readonly type: "catalog.synced"
|
||||
readonly hasFilter: boolean
|
||||
readonly inCatalog: boolean
|
||||
readonly inConsoleGroup: boolean
|
||||
readonly sectionReady: boolean
|
||||
}
|
||||
| { readonly type: "section.ready"; readonly provider: string }
|
||||
| { readonly type: "frame.completed"; readonly attempt: number }
|
||||
| { readonly type: "filter.typed" }
|
||||
| { readonly type: "reveal.timed-out"; readonly attempt: number }
|
||||
| { readonly type: "disposed" }
|
||||
|
||||
export type ModelsRevealEffect =
|
||||
| { readonly type: "filter.clear" }
|
||||
| { readonly type: "section.expand"; readonly provider: string; readonly expandConsole: boolean }
|
||||
| { readonly type: "frame.scroll"; readonly attempt: number; readonly provider: string }
|
||||
| { readonly type: "frame.cancel" }
|
||||
| { readonly type: "timeout.start"; readonly attempt: number; readonly timeoutMs: number }
|
||||
| { readonly type: "timeout.cancel" }
|
||||
| { readonly type: "target.consume" }
|
||||
|
||||
export type ModelsRevealTransition = {
|
||||
readonly state: ModelsRevealState
|
||||
readonly effects: readonly ModelsRevealEffect[]
|
||||
}
|
||||
|
||||
type Revealing = Exclude<ModelsRevealState, { readonly status: "idle" }>
|
||||
|
||||
const NO_EFFECTS: readonly ModelsRevealEffect[] = Object.freeze([])
|
||||
|
||||
const CONSUME: ModelsRevealEffect = Object.freeze({ type: "target.consume" })
|
||||
|
||||
export function createModelsRevealState(): ModelsRevealState {
|
||||
return { status: "idle", attempt: 0 }
|
||||
}
|
||||
|
||||
export function transitionModelsReveal(state: ModelsRevealState, event: ModelsRevealEvent): ModelsRevealTransition {
|
||||
if (event.type === "target.synced") return synced(state, event)
|
||||
|
||||
if (state.status === "idle") return unchanged(state)
|
||||
|
||||
if (event.type === "catalog.synced") {
|
||||
// The filter is cleared when the reveal starts; a missing provider waits for the catalog until the timeout.
|
||||
if (state.status !== "waiting" || event.hasFilter || !event.inCatalog) return unchanged(state)
|
||||
|
||||
const expand: ModelsRevealEffect = {
|
||||
type: "section.expand",
|
||||
provider: state.provider,
|
||||
expandConsole: event.inConsoleGroup,
|
||||
}
|
||||
|
||||
if (event.sectionReady) return scroll(state, state.expanded ? [] : [expand])
|
||||
|
||||
// A provider nested in a collapsed OpenCode Console group mounts only once the group expands.
|
||||
if (state.expanded) return unchanged(state)
|
||||
|
||||
return { state: { ...state, expanded: true }, effects: [expand] }
|
||||
}
|
||||
|
||||
if (event.type === "section.ready") {
|
||||
if (state.status !== "waiting" || !state.expanded || event.provider !== state.provider) return unchanged(state)
|
||||
|
||||
return scroll(state, [])
|
||||
}
|
||||
|
||||
if (event.type === "frame.completed") {
|
||||
if (state.status !== "scrolling" || event.attempt !== state.attempt) return unchanged(state)
|
||||
|
||||
return { state: idle(state), effects: [CONSUME] }
|
||||
}
|
||||
|
||||
if (event.type === "reveal.timed-out") {
|
||||
if (state.status !== "waiting" || event.attempt !== state.attempt) return unchanged(state)
|
||||
|
||||
return { state: idle(state), effects: [CONSUME] }
|
||||
}
|
||||
|
||||
// Typing a search, or leaving with `disposed`, ends the reveal so it never fights the user.
|
||||
return { state: idle(state), effects: [...cancel(state), CONSUME] }
|
||||
}
|
||||
|
||||
/** The provider a reveal is still looking for, which the catalog sync checks. */
|
||||
export function revealingModelProvider(state: ModelsRevealState) {
|
||||
return state.status === "idle" ? undefined : state.provider
|
||||
}
|
||||
|
||||
function synced(
|
||||
state: ModelsRevealState,
|
||||
event: Extract<ModelsRevealEvent, { readonly type: "target.synced" }>,
|
||||
): ModelsRevealTransition {
|
||||
if (!event.provider) {
|
||||
if (state.status === "idle") return unchanged(state)
|
||||
|
||||
return { state: idle(state), effects: cancel(state) }
|
||||
}
|
||||
|
||||
if (!event.active) {
|
||||
// A target set while another tab still shows waits for the Models tab; leaving it mid-reveal drops the target.
|
||||
if (state.status === "idle") return unchanged(state)
|
||||
|
||||
return { state: idle(state), effects: [...cancel(state), CONSUME] }
|
||||
}
|
||||
|
||||
if (state.status !== "idle" && state.provider === event.provider) return unchanged(state)
|
||||
const attempt = state.attempt + 1
|
||||
|
||||
return {
|
||||
state: { status: "waiting", attempt, provider: event.provider, expanded: false },
|
||||
effects: [
|
||||
...(state.status === "idle" ? [] : cancel(state)),
|
||||
...(event.hasFilter ? [{ type: "filter.clear" as const }] : []),
|
||||
{ type: "timeout.start", attempt, timeoutMs: MODELS_REVEAL_TIMEOUT_MS },
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function scroll(
|
||||
state: Extract<ModelsRevealState, { readonly status: "waiting" }>,
|
||||
effects: readonly ModelsRevealEffect[],
|
||||
): ModelsRevealTransition {
|
||||
return {
|
||||
state: { status: "scrolling", attempt: state.attempt, provider: state.provider },
|
||||
effects: [
|
||||
...effects,
|
||||
{ type: "timeout.cancel" },
|
||||
{ type: "frame.scroll", attempt: state.attempt, provider: state.provider },
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function cancel(state: Revealing): readonly ModelsRevealEffect[] {
|
||||
return state.status === "waiting" ? [{ type: "timeout.cancel" }] : [{ type: "frame.cancel" }]
|
||||
}
|
||||
|
||||
function idle(state: ModelsRevealState): ModelsRevealState {
|
||||
return { status: "idle", attempt: state.attempt }
|
||||
}
|
||||
|
||||
function unchanged(state: ModelsRevealState): ModelsRevealTransition {
|
||||
return { state, effects: NO_EFFECTS }
|
||||
}
|
||||
@@ -1,6 +1,16 @@
|
||||
import { useFilteredList } from "@opencode/ui/hooks"
|
||||
import { Switch } from "@opencode/ui/switch"
|
||||
import { type Component, createEffect, createMemo, For, type JSX, Show } from "solid-js"
|
||||
import {
|
||||
type Component,
|
||||
createEffect,
|
||||
createMemo,
|
||||
createSignal,
|
||||
For,
|
||||
type JSX,
|
||||
onCleanup,
|
||||
Show,
|
||||
untrack,
|
||||
} from "solid-js"
|
||||
|
||||
import { Schema } from "effect"
|
||||
import { Persistence } from "@/runtime/persistence/schema"
|
||||
@@ -15,6 +25,12 @@ import { CONSOLE_GROUP_KEY, consoleModelGroup, ProviderModelSections } from "@/p
|
||||
import { SettingsSearchEmpty } from "@/settings/search-empty"
|
||||
import { SettingsSearchField } from "@/settings/search-field"
|
||||
import { settingsScroller } from "@/settings/scroller"
|
||||
import {
|
||||
createModelsRevealState,
|
||||
revealingModelProvider,
|
||||
transitionModelsReveal,
|
||||
type ModelsRevealEvent,
|
||||
} from "./machine"
|
||||
|
||||
import "@/settings/settings.css"
|
||||
|
||||
@@ -26,8 +42,10 @@ export const ModelProvidersSchema = Schema.Struct({
|
||||
|
||||
export const SettingsModels: Component<{
|
||||
active?: boolean
|
||||
/** A provider to reveal, picked on the Providers page. */
|
||||
provider?: string
|
||||
onReveal?: () => void
|
||||
/** The reveal of `provider` ended: it was shown, gave up, or the user moved on. */
|
||||
onConsumeTarget?: () => void
|
||||
headerAction?: JSX.Element
|
||||
}> = (props) => {
|
||||
const language = useLanguage()
|
||||
@@ -103,43 +121,84 @@ export const SettingsModels: Component<{
|
||||
)
|
||||
}
|
||||
|
||||
createEffect(() => {
|
||||
if (!props.active || !props.provider) return
|
||||
const provider = props.provider
|
||||
const [reveal, setReveal] = createSignal(createModelsRevealState())
|
||||
let revealTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let revealFrame: number | undefined
|
||||
|
||||
if (list.filter()) {
|
||||
list.clear()
|
||||
const dispatch = (event: ModelsRevealEvent): void =>
|
||||
untrack(() => {
|
||||
const result = transitionModelsReveal(reveal(), event)
|
||||
setReveal(result.state)
|
||||
result.effects.forEach((effect) => {
|
||||
if (effect.type === "filter.clear") return list.clear()
|
||||
|
||||
return
|
||||
}
|
||||
// Expand only the path to the target so the saved layout of other providers is kept.
|
||||
if (effect.type === "section.expand") {
|
||||
if (effect.expandConsole) setStore("collapsed", CONSOLE_GROUP_KEY, false)
|
||||
setStore("collapsed", effect.provider, false)
|
||||
|
||||
if (!list.grouped.latest.some((group) => group.category === provider)) return
|
||||
const section = sections.get(provider)
|
||||
return
|
||||
}
|
||||
|
||||
if (!section?.isConnected) return
|
||||
if (effect.type === "timeout.start") {
|
||||
revealTimer = setTimeout(
|
||||
() => dispatch({ type: "reveal.timed-out", attempt: effect.attempt }),
|
||||
effect.timeoutMs,
|
||||
)
|
||||
|
||||
// Expand only the path to the target so the saved layout of other providers is kept.
|
||||
if (managed()?.providers.some((item) => item.id === provider)) setStore("collapsed", CONSOLE_GROUP_KEY, false)
|
||||
setStore("collapsed", provider, false)
|
||||
requestAnimationFrame(() => {
|
||||
const panel = section.closest<HTMLElement>(".settings-panel")
|
||||
const header = panel?.querySelector<HTMLElement>(".settings-tab-header")
|
||||
return
|
||||
}
|
||||
|
||||
if (panel && header) {
|
||||
settingsScroller(panel).scrollBy({
|
||||
top: section.getBoundingClientRect().top - header.getBoundingClientRect().bottom - 24,
|
||||
if (effect.type === "timeout.cancel") {
|
||||
clearTimeout(revealTimer)
|
||||
revealTimer = undefined
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (effect.type === "frame.cancel") {
|
||||
if (revealFrame !== undefined) cancelAnimationFrame(revealFrame)
|
||||
revealFrame = undefined
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (effect.type === "target.consume") return props.onConsumeTarget?.()
|
||||
|
||||
revealFrame = requestAnimationFrame(() => {
|
||||
revealFrame = undefined
|
||||
scrollToSection(sections.get(effect.provider))
|
||||
dispatch({ type: "frame.completed", attempt: effect.attempt })
|
||||
})
|
||||
} else {
|
||||
section.scrollIntoView({ block: "start" })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
section
|
||||
.querySelector<HTMLElement>(".provider-model-group-trigger, .settings-models-group-trigger")
|
||||
?.focus({ preventScroll: true })
|
||||
props.onReveal?.()
|
||||
createEffect(() =>
|
||||
dispatch({
|
||||
type: "target.synced",
|
||||
active: !!props.active,
|
||||
provider: props.provider,
|
||||
hasFilter: untrack(() => !!list.filter()),
|
||||
}),
|
||||
)
|
||||
|
||||
// Checks the catalog only while a reveal looks for its provider.
|
||||
createEffect(() => {
|
||||
const provider = revealingModelProvider(reveal())
|
||||
|
||||
if (!provider) return
|
||||
|
||||
dispatch({
|
||||
type: "catalog.synced",
|
||||
hasFilter: !!list.filter(),
|
||||
inCatalog: list.grouped.latest.some((group) => group.category === provider),
|
||||
inConsoleGroup: !!managed()?.providers.some((item) => item.id === provider),
|
||||
sectionReady: !!sections.get(provider)?.isConnected,
|
||||
})
|
||||
})
|
||||
|
||||
onCleanup(() => dispatch({ type: "disposed" }))
|
||||
|
||||
return (
|
||||
<>
|
||||
<div class="settings-tab-header settings-tab-header--stacked">
|
||||
@@ -153,7 +212,10 @@ export const SettingsModels: Component<{
|
||||
<SettingsSearchField
|
||||
value={list.filter()}
|
||||
active={props.active ?? true}
|
||||
onInput={list.onInput}
|
||||
onInput={(value) => {
|
||||
dispatch({ type: "filter.typed" })
|
||||
list.onInput(value)
|
||||
}}
|
||||
placeholder={language.t("dialog.model.search.placeholder")}
|
||||
/>
|
||||
</div>
|
||||
@@ -188,7 +250,13 @@ export const SettingsModels: Component<{
|
||||
disabled={searching()}
|
||||
onExpandedChange={(key, value) => setStore("collapsed", key, !value)}
|
||||
onSetVisibility={setProviderVisibility}
|
||||
ref={(providerID, element) => sections.set(providerID, element)}
|
||||
ref={(providerID, element) => {
|
||||
sections.set(providerID, element)
|
||||
// A ref runs before the section joins the document.
|
||||
queueMicrotask(() => {
|
||||
if (element.isConnected) dispatch({ type: "section.ready", provider: providerID })
|
||||
})
|
||||
}}
|
||||
rows={(items) => <ModelRows items={items} />}
|
||||
/>
|
||||
</Show>
|
||||
@@ -197,3 +265,21 @@ export const SettingsModels: Component<{
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function scrollToSection(section: HTMLElement | undefined) {
|
||||
if (!section?.isConnected) return
|
||||
const panel = section.closest<HTMLElement>(".settings-panel")
|
||||
const header = panel?.querySelector<HTMLElement>(".settings-tab-header")
|
||||
|
||||
if (panel && header) {
|
||||
settingsScroller(panel).scrollBy({
|
||||
top: section.getBoundingClientRect().top - header.getBoundingClientRect().bottom - 24,
|
||||
})
|
||||
} else {
|
||||
section.scrollIntoView({ block: "start" })
|
||||
}
|
||||
|
||||
section
|
||||
.querySelector<HTMLElement>(".provider-model-group-trigger, .settings-models-group-trigger")
|
||||
?.focus({ preventScroll: true })
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ function RootSettings() {
|
||||
active={surface.view().tab === "models"}
|
||||
provider={state.modelProvider}
|
||||
headerAction={<SettingsServerSwitcher />}
|
||||
onReveal={() => setState("modelProvider", undefined)}
|
||||
onConsumeTarget={() => setState("modelProvider", undefined)}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
<Tabs.Content value="extensions" class="settings-panel">
|
||||
|
||||
Reference in New Issue
Block a user