mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
feat(desktop): pick models from a model dialog with favorites and recent (#55838)
This commit is contained in:
committed by
GitHub
Unverified
parent
fd6c12950a
commit
ac0fa47e99
@@ -277,7 +277,10 @@ story("renders a draft once and supports editing, caret restoration, and failure
|
||||
|
||||
// Closing the model picker restores the controller's saved caret through its editor ref.
|
||||
await component.locator('[data-action="composer-model"]').click()
|
||||
await page.getByRole("menu").getByRole("textbox").press("Escape")
|
||||
await page
|
||||
.getByRole("dialog", { name: "Select model", exact: true })
|
||||
.getByRole("searchbox", { name: "Search models", exact: true })
|
||||
.press("Escape")
|
||||
await expect(input).toBeFocused()
|
||||
await input.pressSequentially("!")
|
||||
await expect(input).toHaveText("XY!reserve this draft on failure")
|
||||
|
||||
@@ -100,9 +100,11 @@ test("an existing session's model waits for its agent instead of showing a fallb
|
||||
await agents.promise
|
||||
await route.fallback()
|
||||
})
|
||||
|
||||
const catalog = ["/api/model", "/api/provider", "/api/config"].map((path) =>
|
||||
page.waitForResponse((response) => new URL(response.url()).pathname === path),
|
||||
)
|
||||
|
||||
await page.goto(sessionHref(sessionID))
|
||||
await Promise.all(catalog)
|
||||
await expect(page.locator('[data-component="composer-editor"]')).toBeEditable()
|
||||
@@ -121,6 +123,7 @@ test("names a Console-managed provider without its workspace unless a direct con
|
||||
{ id: "ses_managed_root", model: { id: "alpha", providerID: "opencode" } },
|
||||
{ id: "ses_managed_openai", model: { id: "gpt", providerID: "console-openai" } },
|
||||
]
|
||||
|
||||
const managed = { integrationID: "opencode" }
|
||||
await openSession(page, {
|
||||
name: "ManagedProvider",
|
||||
@@ -498,10 +501,16 @@ test("marks a Console provider with its workspace only when it is also connected
|
||||
},
|
||||
})
|
||||
|
||||
await page.locator('[data-component="composer"] [data-action="composer-model"]').click()
|
||||
const menu = page.getByRole("menu")
|
||||
await expect(menu.getByRole("menuitemradio", { name: "Direct Gemini", exact: true })).toBeVisible()
|
||||
const headings = menu.locator('[data-slot="menu-v2-group-label"]')
|
||||
const trigger = page.locator('[data-component="composer"] [data-action="composer-model"]')
|
||||
await trigger.hover()
|
||||
const details = page.getByRole("tooltip")
|
||||
await expect(details.getByText("Console Model", { exact: true })).toBeVisible()
|
||||
await expect(details.getByText("OpenCode", { exact: true })).toBeVisible()
|
||||
await expect(details.getByText(/Anomaly \//)).toHaveCount(0)
|
||||
await trigger.click()
|
||||
const menu = page.getByRole("dialog", { name: "Select model", exact: true })
|
||||
await expect(menu.getByRole("button", { name: "Direct Gemini", exact: true })).toBeVisible()
|
||||
const headings = menu.locator('[data-slot="model-dialog-group-title"]')
|
||||
await expect(headings).toHaveCount(4)
|
||||
await expect(headings.filter({ hasText: /^GoogleAnomaly$/ })).toHaveCount(1)
|
||||
await expect(headings.filter({ hasText: /^Google$/ })).toHaveCount(1)
|
||||
|
||||
@@ -122,25 +122,148 @@ for (const direction of ["ltr", "rtl"] as const) {
|
||||
})
|
||||
}
|
||||
|
||||
test(`desktop model and variant pickers retain menus in ${direction}`, async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
await openPickerSession(page, direction, true)
|
||||
const composer = page.locator('[data-component="composer"]')
|
||||
const variant = composer.getByRole("button", { name: "Choose model variant", exact: true })
|
||||
test(`desktop model button opens the model dialog in ${direction}`, async ({ page }) => {
|
||||
const { composer, model, variant, dialog } = await openDesktopPicker(page, direction)
|
||||
await variant.click()
|
||||
await page.getByRole("menuitemradio", { name: "high", exact: true }).click()
|
||||
await expect(variant).toHaveText("high")
|
||||
await expect(page.locator('[data-slot="mobile-drawer-content"]')).toHaveCount(0)
|
||||
const model = composer.locator('[data-action="composer-model"]')
|
||||
await expect(model).toHaveAttribute("data-control-type", "popover")
|
||||
await expect(model).toHaveAttribute("data-control-type", "dialog")
|
||||
await model.click()
|
||||
await expect(page.getByPlaceholder("Search models", { exact: true })).toBeFocused()
|
||||
await page.getByRole("menuitemradio", { name: /Mobile Model B/ }).click()
|
||||
await expect(dialog.getByRole("searchbox", { name: "Search models", exact: true })).toBeFocused()
|
||||
await expect(page.getByRole("menu")).toHaveCount(0)
|
||||
await dialog.locator('[data-option-key="opencode:mobile-b"]').click()
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(model).toHaveText("OpenCode / Mobile Model B")
|
||||
await expect(page.locator('[data-slot="mobile-drawer-content"]')).toHaveCount(0)
|
||||
await expect(composer.getByRole("textbox", { name: "Prompt", exact: true })).toBeFocused()
|
||||
})
|
||||
|
||||
test(`model dialog flyout applies a model and variant in ${direction}`, async ({ page }) => {
|
||||
const { model, variant, dialog } = await openDesktopPicker(page, direction)
|
||||
const flyout = dialog.locator('[data-slot="model-dialog-flyout"]')
|
||||
await model.click()
|
||||
await dialog.locator('[data-option-key="opencode:mobile-a"]').hover()
|
||||
await expect(flyout.getByRole("menuitemradio", { name: "balanced", exact: true })).toHaveAttribute(
|
||||
"aria-checked",
|
||||
"true",
|
||||
)
|
||||
await dialog.locator('[data-option-key="opencode:mobile-b"]').hover()
|
||||
await expect(flyout.getByText("OpenCode · 1M context", { exact: true })).toBeVisible()
|
||||
await expect(flyout.getByText("Text, Image, PDF, Tools", { exact: true })).toBeVisible()
|
||||
await flyout.getByRole("menuitemradio", { name: "max", exact: true }).click()
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(model).toHaveText("OpenCode / Mobile Model B")
|
||||
await expect(variant).toHaveText("max")
|
||||
})
|
||||
|
||||
test(`model dialog arrow keys stage a variant in ${direction}`, async ({ page }) => {
|
||||
const { composer, model, variant, dialog } = await openDesktopPicker(page, direction)
|
||||
const search = dialog.getByRole("searchbox", { name: "Search models", exact: true })
|
||||
const rowA = dialog.locator('[data-option-key="opencode:mobile-a"]')
|
||||
const next = direction === "rtl" ? "ArrowLeft" : "ArrowRight"
|
||||
await model.click()
|
||||
await expect(search).toBeFocused()
|
||||
await search.press(next)
|
||||
await expect(rowA).toContainText("high")
|
||||
await search.press("Escape")
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(variant).toHaveText("balanced")
|
||||
|
||||
await model.click()
|
||||
await search.fill("Mobile Model A")
|
||||
await search.press(next)
|
||||
await expect(search).toHaveValue("Mobile Model A")
|
||||
await expect(rowA).toContainText("balanced")
|
||||
await search.press("ArrowDown")
|
||||
await search.press("ArrowUp")
|
||||
await search.press(next)
|
||||
await expect(rowA).toContainText("high")
|
||||
await search.press("Enter")
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(model).toHaveText("OpenCode / Mobile Model A")
|
||||
await expect(variant).toHaveText("high")
|
||||
await expect(composer.getByRole("textbox", { name: "Prompt", exact: true })).toBeFocused()
|
||||
})
|
||||
|
||||
test(`model shortcut opens the model dialog in ${direction}`, async ({ page }) => {
|
||||
const { composer, model, variant, dialog } = await openDesktopPicker(page, direction)
|
||||
const prompt = composer.getByRole("textbox", { name: "Prompt", exact: true })
|
||||
await prompt.fill("keep me")
|
||||
await prompt.press("ControlOrMeta+Quote")
|
||||
const search = dialog.getByRole("searchbox", { name: "Search models", exact: true })
|
||||
await expect(search).toBeFocused()
|
||||
await search.press(direction === "rtl" ? "ArrowLeft" : "ArrowRight")
|
||||
await expect(dialog.locator('[data-option-key="opencode:mobile-a"]')).toContainText("high")
|
||||
await search.press("Enter")
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(model).toHaveText("OpenCode / Mobile Model A")
|
||||
await expect(variant).toHaveText("high")
|
||||
await expect(prompt).toBeFocused()
|
||||
await expect(prompt).toHaveText("keep me")
|
||||
})
|
||||
}
|
||||
|
||||
test("desktop model button shows the model details", async ({ page }) => {
|
||||
const { model } = await openDesktopPicker(page, "ltr")
|
||||
await model.hover()
|
||||
const details = page.getByRole("tooltip")
|
||||
await expect(details.getByText("Mobile Model A", { exact: true })).toBeVisible()
|
||||
await expect(details.getByText("OpenCode", { exact: true })).toBeVisible()
|
||||
await expect(details.getByText("1,000,000", { exact: true })).toBeVisible()
|
||||
await expect(details.getByText("Input & Output", { exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
test("model dialog shows a summary for models without variants", async ({ page }) => {
|
||||
const { model, dialog } = await openDesktopPicker(page, "ltr")
|
||||
const flyout = dialog.locator('[data-slot="model-dialog-flyout"]')
|
||||
await model.click()
|
||||
await dialog.locator('[data-option-key="opencode:mobile-c"]').hover()
|
||||
await expect(flyout.getByText("OpenCode · 262K context", { exact: true })).toBeVisible()
|
||||
await expect(flyout.getByRole("menuitemradio")).toHaveCount(0)
|
||||
})
|
||||
|
||||
test("model dialog toggles a favorite from the keyboard and leads with favorite and recent models", async ({
|
||||
page,
|
||||
}) => {
|
||||
const { model, dialog } = await openDesktopPicker(page, "ltr")
|
||||
const sections = dialog.locator('[data-slot="model-dialog-group-title"]')
|
||||
const search = dialog.getByRole("searchbox", { name: "Search models", exact: true })
|
||||
await model.click()
|
||||
await expect(sections).toHaveText(["OpenCode"])
|
||||
await search.press("ArrowDown")
|
||||
await search.press("ArrowDown")
|
||||
await search.press("ControlOrMeta+f")
|
||||
await expect(sections).toHaveText(["Favorites", "OpenCode"])
|
||||
await expect(dialog.locator('[data-option-key="favorite:opencode:mobile-c"]')).toBeVisible()
|
||||
await dialog.locator('[data-option-key="opencode:mobile-b"]').click()
|
||||
await expect(model).toHaveText("OpenCode / Mobile Model B")
|
||||
|
||||
await model.click()
|
||||
await expect(sections).toHaveText(["Favorites", "Recent", "OpenCode"])
|
||||
await expect(dialog.locator('[data-option-key="recent:opencode:mobile-b"]')).toHaveAttribute("aria-pressed", "true")
|
||||
await search.fill("Mobile")
|
||||
await expect(sections).toHaveText(["OpenCode"])
|
||||
await search.press("Escape")
|
||||
await expect(dialog).toBeHidden()
|
||||
await model.click()
|
||||
await search.press("ArrowUp")
|
||||
await expect(dialog.locator('[data-option-key="favorite:opencode:mobile-c"]')).toHaveAttribute("data-active", "")
|
||||
await search.press("ControlOrMeta+f")
|
||||
await expect(sections).toHaveText(["Recent", "OpenCode"])
|
||||
await expect(dialog.locator('[data-option-key="opencode:mobile-c"]')).toHaveAttribute("data-active", "")
|
||||
})
|
||||
|
||||
test("model dialog opens Manage models from its search row with Enter", async ({ page }) => {
|
||||
const { model, dialog } = await openDesktopPicker(page, "ltr")
|
||||
await model.click()
|
||||
await expect(dialog.getByRole("searchbox", { name: "Search models", exact: true })).toBeFocused()
|
||||
const manage = dialog.getByRole("button", { name: "Manage models", exact: true })
|
||||
await manage.focus()
|
||||
await manage.press("Enter")
|
||||
await expect(page.getByRole("dialog", { name: "Manage models", exact: true })).toBeVisible()
|
||||
await expect(model).toHaveText("OpenCode / Mobile Model A")
|
||||
})
|
||||
|
||||
test.describe("touch composer pickers", () => {
|
||||
test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true })
|
||||
|
||||
@@ -175,6 +298,19 @@ test.describe("touch composer pickers", () => {
|
||||
})
|
||||
})
|
||||
|
||||
async function openDesktopPicker(page: Page, direction: "ltr" | "rtl") {
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
await openPickerSession(page, direction, true)
|
||||
const composer = page.locator('[data-component="composer"]')
|
||||
|
||||
return {
|
||||
composer,
|
||||
model: composer.locator('[data-action="composer-model"]'),
|
||||
variant: composer.getByRole("button", { name: "Choose model variant", exact: true }),
|
||||
dialog: page.getByRole("dialog", { name: "Select model", exact: true }),
|
||||
}
|
||||
}
|
||||
|
||||
async function openPickerSession(page: Page, direction: "ltr" | "rtl", paid: boolean) {
|
||||
await mockOpenCodeServer(page, {
|
||||
...fixture,
|
||||
@@ -188,14 +324,19 @@ async function openPickerSession(page: Page, direction: "ltr" | "rtl", paid: boo
|
||||
id: "opencode",
|
||||
name: "OpenCode",
|
||||
models: Object.fromEntries(
|
||||
["a", "b"].map((id) => [
|
||||
["a", "b", "c"].map((id) => [
|
||||
`mobile-${id}`,
|
||||
{
|
||||
id: `mobile-${id}`,
|
||||
name: `Mobile Model ${id.toUpperCase()}`,
|
||||
cost: { input: paid ? 1 : 0, output: paid ? 1 : 0 },
|
||||
limit: { context: 200_000 },
|
||||
variants: { balanced: {}, high: {} },
|
||||
limit: { context: id === "c" ? 262_144 : 1_000_000 },
|
||||
capabilities: {
|
||||
tools: id !== "c",
|
||||
input: id === "c" ? ["text"] : ["text", "image", "pdf"],
|
||||
output: ["text"],
|
||||
},
|
||||
variants: id === "c" ? {} : { balanced: {}, high: {}, max: {} },
|
||||
},
|
||||
]),
|
||||
),
|
||||
@@ -212,7 +353,7 @@ async function openPickerSession(page: Page, direction: "ltr" | "rtl", paid: boo
|
||||
localStorage.setItem(
|
||||
"opencode.global.dat:model",
|
||||
JSON.stringify({
|
||||
user: ["a", "b"].map((id) => ({ providerID: "opencode", modelID: `mobile-${id}`, visibility: "show" })),
|
||||
user: ["a", "b", "c"].map((id) => ({ providerID: "opencode", modelID: `mobile-${id}`, visibility: "show" })),
|
||||
recent: [],
|
||||
variant: {},
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Page } from "@playwright/test"
|
||||
import type { OpenCodeEvent, SessionMessageInfo } from "@opencode/client/promise"
|
||||
import { Permission } from "@opencode/schema/permission"
|
||||
import { Model } from "@opencode/schema/model"
|
||||
import { Worktree } from "@opencode/schema/worktree"
|
||||
import { Duration, Effect, Layer, Option, Predicate, Schema } from "effect"
|
||||
import { HttpRouter, HttpServer, HttpServerResponse } from "effect/http"
|
||||
@@ -1429,6 +1430,7 @@ function location(config: MockServerConfig, directory = config.directory) {
|
||||
(root) => root !== undefined && (directory === root || directory.startsWith(`${root}/`)),
|
||||
),
|
||||
)
|
||||
|
||||
const root = listed ? (listed.canonical ?? listed.worktree) : undefined
|
||||
|
||||
if (listed && root) return { directory, project: { id: listed.id, directory: root, canonical: root } }
|
||||
@@ -1475,7 +1477,7 @@ function currentModels(catalog: MockProviderCatalog) {
|
||||
modelID: model.api?.id ?? model.id,
|
||||
providerID: provider.id,
|
||||
name: model.name,
|
||||
capabilities: { tools: true, input: ["text"], output: ["text"] },
|
||||
capabilities: model.capabilities ?? { tools: true, input: ["text"], output: ["text"] },
|
||||
variants: Object.entries(model.variants ?? {}).map(([id, settings]) =>
|
||||
Predicate.isObject(settings) ? { id, settings } : { id },
|
||||
),
|
||||
@@ -1610,6 +1612,7 @@ const decodeModel = Schema.decodeUnknownOption(
|
||||
api: lenient(Schema.Struct({ id: Schema.String })),
|
||||
limit: lenient(Schema.Struct({ context: lenient(Schema.Number), output: lenient(Schema.Number) })),
|
||||
cost: lenient(Schema.Struct({ input: lenient(Schema.Number), output: lenient(Schema.Number) })),
|
||||
capabilities: lenient(Model.Capabilities),
|
||||
variants: lenient(Schema.Record(Schema.String, Schema.Unknown)),
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -82,6 +82,7 @@ function ComposerStory(props: {
|
||||
key: () => ({ providerID: modelOption().provider.id, modelID: modelOption().id }),
|
||||
current: () => modelOption(),
|
||||
recent: () => [modelOption()],
|
||||
favorite: { list: () => [], toggle() {} },
|
||||
list: () => [modelOption()],
|
||||
cycle() {},
|
||||
set() {},
|
||||
|
||||
@@ -4,9 +4,12 @@ import { Button } from "@opencode/ui/button"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import { Keybind } from "@opencode/ui/keybind"
|
||||
import { consoleModelGroup } from "@/providers/models/provider-group"
|
||||
import { consoleProviderName } from "@/providers/catalog/console"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
import { ComposerEditor } from "./editor/editor"
|
||||
import { ModelSelectorPopover } from "@/providers/models/select-dialog"
|
||||
import { DialogSelectModel, ModelSelectorDrawer } from "@/providers/models/select-dialog"
|
||||
import { ModelDetails } from "@/providers/models/details"
|
||||
import { DialogSelectModelUnpaid } from "@/providers/models/unpaid"
|
||||
import { formatKeybind, useCommand } from "@/shell/commands/command"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
@@ -79,6 +82,16 @@ function ComposerModelControl(props: {
|
||||
}) {
|
||||
const shouldAnimate = createMemo<boolean>((previous) => previous ?? props.loading)
|
||||
const mobile = createMediaQuery("(max-width: 767px)")
|
||||
const dialog = useDialog()
|
||||
const managed = createMemo(() => consoleModelGroup(props.model.list()))
|
||||
|
||||
const providerName = (provider: { id: string; name: string }) => {
|
||||
const group = managed()
|
||||
|
||||
return group?.providers.some((item) => item.id === provider.id)
|
||||
? consoleProviderName(group, provider.name)
|
||||
: provider.name
|
||||
}
|
||||
|
||||
const content = () => (
|
||||
<>
|
||||
@@ -103,17 +116,33 @@ function ComposerModelControl(props: {
|
||||
<Show when={!props.loading}>
|
||||
<Tooltip
|
||||
inactive={mobile()}
|
||||
contentClass={props.model.current() ? "!p-0 rounded-md" : undefined}
|
||||
placement="top"
|
||||
gutter={4}
|
||||
value={
|
||||
<>
|
||||
{props.title}
|
||||
<Keybind keys={props.keybind} variant="neutral" />
|
||||
</>
|
||||
<Show
|
||||
when={props.model.current()}
|
||||
fallback={
|
||||
<>
|
||||
{props.title}
|
||||
<Keybind keys={props.keybind} variant="neutral" />
|
||||
</>
|
||||
}
|
||||
>
|
||||
{(model) => (
|
||||
<div class="flex w-[188px] max-w-[calc(100vw-24px)] flex-col">
|
||||
<ModelDetails model={model()} provider={providerName(model().provider)} />
|
||||
<div class="flex h-7 min-w-0 items-center gap-2 border-t-[0.5px] border-v2-border-border-base px-2">
|
||||
<span class="min-w-0 flex-1 truncate text-v2-text-text-faint">{props.title}</span>
|
||||
<Keybind keys={props.keybind} variant="neutral" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
}
|
||||
>
|
||||
<Show
|
||||
when={props.paid || mobile()}
|
||||
when={mobile()}
|
||||
fallback={
|
||||
<Button
|
||||
data-action="composer-model"
|
||||
@@ -123,13 +152,16 @@ function ComposerModelControl(props: {
|
||||
class="min-w-0 max-w-[60cqw] justify-start ![font-weight:440]"
|
||||
classList={{ "animate-in fade-in": shouldAnimate() }}
|
||||
style={{ height: "28px" }}
|
||||
onClick={props.onUnpaidClick}
|
||||
onClick={() => {
|
||||
if (!props.paid) return props.onUnpaidClick()
|
||||
void dialog.show(() => <DialogSelectModel model={props.model} />, props.onClose)
|
||||
}}
|
||||
>
|
||||
{content()}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<ModelSelectorPopover
|
||||
<ModelSelectorDrawer
|
||||
model={props.model}
|
||||
trigger={(triggerProps) => (
|
||||
<Button
|
||||
@@ -140,7 +172,7 @@ function ComposerModelControl(props: {
|
||||
class="min-w-0 max-w-[60cqw] justify-start ![font-weight:440]"
|
||||
classList={{ "animate-in fade-in": shouldAnimate() }}
|
||||
data-action="composer-model"
|
||||
data-control-type={mobile() ? "drawer" : "popover"}
|
||||
data-control-type="drawer"
|
||||
>
|
||||
{content()}
|
||||
</Button>
|
||||
|
||||
@@ -17,6 +17,7 @@ export function createComposerControls(input: { model?: ModelSelection } = {}) {
|
||||
const sdk = useWorkspaceLocation()
|
||||
const data = useData()
|
||||
const providers = useProviders(() => sdk().directory)
|
||||
|
||||
const canonical = (provider: { id: string; canonical?: string }) =>
|
||||
provider.canonical ?? provider.id.replace(/^console-/, "")
|
||||
|
||||
@@ -123,6 +124,13 @@ export function createComposerModelSelection(input: {
|
||||
.filter((item): item is NonNullable<typeof item> => !!item),
|
||||
)
|
||||
|
||||
const favoriteModels = createMemo(() =>
|
||||
models.favorite
|
||||
.list()
|
||||
.map(models.find)
|
||||
.filter((item): item is NonNullable<typeof item> => !!item),
|
||||
)
|
||||
|
||||
const selection = {
|
||||
trackSessionCommit: local.model.trackSessionCommit,
|
||||
remembered: () => Object.fromEntries(Object.entries(remembered).map(([name, model]) => [name, { model }])),
|
||||
@@ -130,6 +138,7 @@ export function createComposerModelSelection(input: {
|
||||
key,
|
||||
current,
|
||||
recent: recentModels,
|
||||
favorite: { list: favoriteModels, toggle: models.favorite.toggle },
|
||||
list: models.list,
|
||||
cycle(direction: 1 | -1) {
|
||||
const items = recentModels()
|
||||
@@ -163,9 +172,8 @@ export function createComposerModelSelection(input: {
|
||||
visible: models.visible,
|
||||
setVisibility: models.setVisibility,
|
||||
variant: {
|
||||
configured() {
|
||||
configured(model = current()) {
|
||||
const item = input.agent()
|
||||
const model = current()
|
||||
|
||||
if (!item || !model) return
|
||||
const global = configuredModel()
|
||||
@@ -186,13 +194,14 @@ export function createComposerModelSelection(input: {
|
||||
|
||||
return model && valid(model) ? model.variant : undefined
|
||||
},
|
||||
current() {
|
||||
const model = current()
|
||||
current(item?: ModelKey) {
|
||||
const model = item ? models.find(item) : current()
|
||||
const same = !item || (current()?.provider.id === item.providerID && current()?.id === item.modelID)
|
||||
|
||||
return resolveModelVariant({
|
||||
variants: this.list(),
|
||||
selected: this.selected(),
|
||||
configured: this.configured(),
|
||||
variants: Object.keys(model?.variants ?? {}),
|
||||
selected: same ? this.selected() : undefined,
|
||||
configured: this.configured(model),
|
||||
preferred: model ? models.variant.get({ providerID: model.provider.id, modelID: model.id }) : undefined,
|
||||
})
|
||||
},
|
||||
|
||||
@@ -25,6 +25,7 @@ const selection = {
|
||||
key: () => ({ providerID: "provider-1", modelID: "model-1" }),
|
||||
current: () => selectedModel,
|
||||
recent: () => [selectedModel],
|
||||
favorite: { list: () => [], toggle() {} },
|
||||
list: () => [selectedModel],
|
||||
cycle() {},
|
||||
set() {},
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { For, Show } from "solid-js"
|
||||
import { Icon } from "@opencode/ui/icon"
|
||||
import type { IconName } from "@opencode/ui/icons/catalog"
|
||||
import { useLanguage } from "@/runtime/i18n/language"
|
||||
import type { ModelSelection } from "./selection"
|
||||
import { ProviderModelIcon } from "./provider-group"
|
||||
|
||||
type ModelInfo = NonNullable<ReturnType<ModelSelection["current"]>>
|
||||
|
||||
type Input = keyof ModelInfo["capabilities"]["input"]
|
||||
|
||||
const inputs: Input[] = ["text", "image", "pdf", "audio", "video"]
|
||||
|
||||
const inputIcons: Record<Input, IconName> = {
|
||||
text: "outline-text",
|
||||
image: "outline-photo",
|
||||
pdf: "file-document",
|
||||
audio: "outline-audio",
|
||||
video: "outline-video",
|
||||
}
|
||||
|
||||
export function ModelDetails(props: { model: ModelInfo; provider: string; compact?: boolean; standalone?: boolean }) {
|
||||
const language = useLanguage()
|
||||
const input = () => inputs.filter((type) => props.model.capabilities.input[type])
|
||||
|
||||
const modalities = () =>
|
||||
inputs.filter((type) => props.model.capabilities.input[type] || props.model.capabilities.output[type])
|
||||
|
||||
const label = (type: Input) => language.t(`model.details.input.${type}`)
|
||||
|
||||
const summary = () =>
|
||||
new Intl.ListFormat(language.intl(), { style: "short", type: "unit" }).format([
|
||||
...input().map(label),
|
||||
...(props.model.capabilities.toolcall ? [language.t("model.details.tools")] : []),
|
||||
])
|
||||
|
||||
return (
|
||||
<Show
|
||||
when={props.compact}
|
||||
fallback={
|
||||
<div class="w-[188px] max-w-[calc(100vw-24px)] font-[440] text-v2-text-text-muted">
|
||||
<div class="border-b-[0.5px] border-v2-border-border-base py-0.5">
|
||||
<div class="flex h-6 min-w-0 items-center gap-1.5 px-2">
|
||||
<ProviderModelIcon provider={props.model.provider} class="!size-3.5 shrink-0" />
|
||||
<bdi class="min-w-0 truncate font-[530]">{props.model.name}</bdi>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1.5 py-1">
|
||||
<dl>
|
||||
<div class="flex h-6 min-w-0 items-center gap-2 px-2">
|
||||
<dt class="min-w-0 flex-1 truncate font-[530] text-v2-text-text-faint">
|
||||
{language.t("model.tooltip.provider")}
|
||||
</dt>
|
||||
<dd class="min-w-0 truncate text-end">
|
||||
<bdi>{props.provider}</bdi>
|
||||
</dd>
|
||||
</div>
|
||||
<div class="flex h-6 min-w-0 items-center gap-2 px-2">
|
||||
<dt class="min-w-0 flex-1 truncate font-[530] text-v2-text-text-faint">
|
||||
{language.t("model.tooltip.context.label")}
|
||||
</dt>
|
||||
<dd class="shrink-0">{props.model.limit.context.toLocaleString(language.intl())}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<div class="mx-2 border-t-[0.5px] border-v2-border-border-base" />
|
||||
<dl>
|
||||
<For each={modalities()}>
|
||||
{(type) => (
|
||||
<div class="flex h-6 min-w-0 items-center gap-1.5 px-2">
|
||||
<Icon name={inputIcons[type]} size="small" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<dt class="min-w-0 flex-1 truncate font-[530] text-v2-text-text-faint">{label(type)}</dt>
|
||||
<dd class="shrink-0">
|
||||
{props.model.capabilities.input[type] && props.model.capabilities.output[type]
|
||||
? language.t("model.details.inputOutput")
|
||||
: props.model.capabilities.input[type]
|
||||
? language.t("model.details.input")
|
||||
: language.t("model.details.output")}
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
<Show when={props.model.capabilities.reasoning}>
|
||||
<div class="flex h-6 min-w-0 items-center gap-1.5 px-2">
|
||||
<Icon name="outline-brain" size="small" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<dt class="min-w-0 flex-1 truncate font-[530] text-v2-text-text-faint">
|
||||
{language.t("model.tooltip.reasoning")}
|
||||
</dt>
|
||||
<dd class="flex shrink-0">
|
||||
<Icon
|
||||
name="check"
|
||||
class="text-v2-icon-icon-muted"
|
||||
aria-label={language.t("model.details.supported")}
|
||||
aria-hidden={false}
|
||||
/>
|
||||
</dd>
|
||||
</div>
|
||||
</Show>
|
||||
<Show when={props.model.capabilities.toolcall}>
|
||||
<div class="flex h-6 min-w-0 items-center gap-1.5 px-2">
|
||||
<Icon name="outline-console" size="small" class="shrink-0 text-v2-icon-icon-muted" />
|
||||
<dt class="min-w-0 flex-1 truncate font-[530] text-v2-text-text-faint">
|
||||
{language.t("model.details.tools")}
|
||||
</dt>
|
||||
<dd class="flex shrink-0">
|
||||
<Icon
|
||||
name="check"
|
||||
class="text-v2-icon-icon-muted"
|
||||
aria-label={language.t("model.details.supported")}
|
||||
aria-hidden={false}
|
||||
/>
|
||||
</dd>
|
||||
</div>
|
||||
</Show>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div
|
||||
class="px-3 py-2 text-[12px] font-[440] leading-5 text-v2-text-text-muted"
|
||||
classList={{ "border-t border-v2-border-border-muted": !props.standalone }}
|
||||
>
|
||||
<bdi class="block">
|
||||
{language.t("model.details.summary", {
|
||||
provider: props.provider,
|
||||
context: new Intl.NumberFormat(language.intl(), {
|
||||
notation: "compact",
|
||||
maximumFractionDigits: 0,
|
||||
roundingMode: "trunc",
|
||||
}).format(props.model.limit.context),
|
||||
})}
|
||||
</bdi>
|
||||
<Show when={summary()}>{(value) => <div>{value()}</div>}</Show>
|
||||
</div>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
@@ -40,7 +40,8 @@ const createModelsController = (directory: Accessor<string | undefined>) => {
|
||||
() =>
|
||||
new Map(
|
||||
available().map(
|
||||
(model) => [modelKey({ providerID: model.provider.id, modelID: model.id }), Date.parse(model.release_date)] as const,
|
||||
(model) =>
|
||||
[modelKey({ providerID: model.provider.id, modelID: model.id }), Date.parse(model.release_date)] as const,
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -130,6 +131,19 @@ const createModelsController = (directory: Accessor<string | undefined>) => {
|
||||
setStore("recent", uniq)
|
||||
}
|
||||
|
||||
// Newest favorite first, as in the TUI.
|
||||
const toggleFavorite = (model: ModelKey) => {
|
||||
const key = modelKey(model)
|
||||
const rest = store.favorite.filter((item) => modelKey(item) !== key)
|
||||
|
||||
setStore(
|
||||
"favorite",
|
||||
rest.length === store.favorite.length
|
||||
? [{ providerID: model.providerID, modelID: model.modelID }, ...rest]
|
||||
: rest,
|
||||
)
|
||||
}
|
||||
|
||||
const variantKey = (model: ModelKey) => `${model.providerID}/${model.modelID}`
|
||||
const getVariant = (model: ModelKey) => store.variant?.[variantKey(model)]
|
||||
|
||||
@@ -155,6 +169,10 @@ const createModelsController = (directory: Accessor<string | undefined>) => {
|
||||
list: models.recent,
|
||||
push,
|
||||
},
|
||||
favorite: {
|
||||
list: models.favorite,
|
||||
toggle: toggleFavorite,
|
||||
},
|
||||
variant: {
|
||||
get: getVariant,
|
||||
set: setVariant,
|
||||
|
||||
@@ -36,3 +36,132 @@
|
||||
padding-inline: 0;
|
||||
}
|
||||
}
|
||||
|
||||
[data-component="dialog-v2"]:has(.model-dialog) [data-slot="dialog-container"] {
|
||||
width: min(calc(100vw - 24px), 480px);
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.model-dialog {
|
||||
[data-slot="model-dialog-search"] {
|
||||
flex-shrink: 0;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-search-box"] {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
height: 32px;
|
||||
padding-inline: 12px 4px;
|
||||
border-radius: 6px;
|
||||
background: color-mix(in srgb, var(--v2-background-bg-layer-02) 60%, transparent);
|
||||
color: var(--v2-icon-icon-muted);
|
||||
|
||||
&:hover,
|
||||
&:focus-within {
|
||||
background: var(--v2-background-bg-layer-02);
|
||||
}
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
background: transparent;
|
||||
color: var(--v2-text-text-base);
|
||||
font-size: 14px;
|
||||
font-weight: 440;
|
||||
letter-spacing: -0.04px;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: var(--v2-text-text-faint);
|
||||
}
|
||||
|
||||
input::-webkit-search-cancel-button {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-results"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 0 6px 6px;
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-group"] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-group-title"] {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 28px;
|
||||
padding: 0 12px;
|
||||
color: var(--v2-text-text-faint);
|
||||
font-size: 13px;
|
||||
font-weight: 530;
|
||||
line-height: var(--line-height-compact);
|
||||
letter-spacing: -0.25px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-row"] {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 28px;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 0 12px;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: var(--v2-text-text-base);
|
||||
font-size: 13px;
|
||||
font-weight: 440;
|
||||
line-height: var(--line-height-base);
|
||||
letter-spacing: -0.04px;
|
||||
text-align: start;
|
||||
cursor: default;
|
||||
scroll-margin: 6px 0;
|
||||
|
||||
&[data-active] {
|
||||
background: var(--v2-overlay-simple-overlay-hover);
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-variant"] {
|
||||
color: var(--v2-text-text-muted);
|
||||
}
|
||||
|
||||
[data-slot="model-dialog-hints"] {
|
||||
display: flex;
|
||||
height: 32px;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 0 12px;
|
||||
border-top: 0.5px solid var(--v2-border-border-base);
|
||||
color: var(--v2-text-text-faint);
|
||||
font-size: 11px;
|
||||
|
||||
> span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[data-color-scheme="dark"] .model-dialog [data-slot="model-dialog-row"][data-active] {
|
||||
background: var(--v2-alpha-light-10);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Button } from "@opencode/ui/button"
|
||||
import { createSignal } from "solid-js"
|
||||
import { useDialog } from "@opencode/ui/context/dialog"
|
||||
import { onMount } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import type { ModelSelection } from "./selection"
|
||||
import { ModelSelectorPopoverView } from "./select-dialog"
|
||||
import { DialogSelectModel } from "./select-dialog"
|
||||
|
||||
const chatgpt = {
|
||||
id: "gpt-5.6-sol",
|
||||
@@ -47,27 +49,52 @@ const models = [
|
||||
},
|
||||
]
|
||||
|
||||
function SelectorStory(props: { plan: boolean }) {
|
||||
const [current, setCurrent] = createSignal(models[0].id)
|
||||
function SelectorStory(props: { favorite?: boolean }) {
|
||||
const dialog = useDialog()
|
||||
|
||||
const [store, setStore] = createStore<{ current: string; favorite: string[]; variant?: string }>({
|
||||
current: models[0].id,
|
||||
favorite: props.favorite ? [models[1].id] : [],
|
||||
})
|
||||
|
||||
const find = (id: string) => models.find((model) => model.id === id)
|
||||
|
||||
const selection = {
|
||||
ready: Object.assign(() => true, { promise: undefined }),
|
||||
key: () => ({ providerID: "openai", modelID: store.current }),
|
||||
current: () => find(store.current),
|
||||
recent: () => [find(store.current)].filter((model) => !!model),
|
||||
favorite: {
|
||||
list: () => store.favorite.flatMap((id) => find(id) ?? []),
|
||||
toggle: (key: { modelID: string }) =>
|
||||
setStore("favorite", (ids) =>
|
||||
ids.includes(key.modelID) ? ids.filter((id) => id !== key.modelID) : [key.modelID, ...ids],
|
||||
),
|
||||
},
|
||||
list: () => models,
|
||||
cycle() {},
|
||||
set: (key: { modelID: string } | undefined) => key && setStore("current", key.modelID),
|
||||
visible: () => true,
|
||||
setVisibility() {},
|
||||
variant: {
|
||||
configured: () => undefined,
|
||||
selected: () => store.variant,
|
||||
current: () => store.variant,
|
||||
list: () => [],
|
||||
set: (variant: string | undefined) => setStore("variant", variant),
|
||||
cycle() {},
|
||||
},
|
||||
} satisfies ModelSelection
|
||||
|
||||
const open = () => dialog.show(() => <DialogSelectModel model={selection} />)
|
||||
|
||||
onMount(open)
|
||||
|
||||
return (
|
||||
<div class="flex min-h-[280px] items-end justify-center">
|
||||
<ModelSelectorPopoverView
|
||||
trigger={(trigger) => (
|
||||
<Button {...trigger} variant="ghost-muted">
|
||||
{models.find((model) => model.id === current())?.name}
|
||||
</Button>
|
||||
)}
|
||||
all={() => models}
|
||||
models={(search) => models.filter((model) => model.name.toLowerCase().includes(search.toLowerCase()))}
|
||||
groups={(items) => [{ category: "openai", items }]}
|
||||
current={`openai:${current()}`}
|
||||
chatgptPlan={props.plan}
|
||||
select={(item) => setCurrent(item.id)}
|
||||
onManage={() => undefined}
|
||||
onConnect={() => undefined}
|
||||
onClose={() => undefined}
|
||||
/>
|
||||
<Button variant="ghost-muted" onClick={open}>
|
||||
{find(store.current)?.name}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -77,6 +104,6 @@ export default {
|
||||
id: "app-dialog-model-selector",
|
||||
}
|
||||
|
||||
export const ChatGPTPlan = { render: () => <SelectorStory plan /> }
|
||||
export const Dialog = { render: () => <SelectorStory /> }
|
||||
|
||||
export const ApiKey = { render: () => <SelectorStory plan={false} /> }
|
||||
export const Favorites = { render: () => <SelectorStory favorite /> }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -290,9 +290,8 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
||||
return models.find(item)
|
||||
})
|
||||
|
||||
const configured = () => {
|
||||
const configured = (model = current()) => {
|
||||
const item = agent.current()
|
||||
const model = current()
|
||||
|
||||
if (!item || !model) return
|
||||
const global = configuredModel()
|
||||
@@ -350,6 +349,15 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
||||
}
|
||||
|
||||
const recent = createMemo(() => models.recent.list().filter(validModel).map(models.find).filter(Boolean))
|
||||
|
||||
const favorite = createMemo(() =>
|
||||
models.favorite
|
||||
.list()
|
||||
.filter(validModel)
|
||||
.map(models.find)
|
||||
.filter((item): item is NonNullable<typeof item> => !!item),
|
||||
)
|
||||
|
||||
const pending = new Map<string, State>()
|
||||
|
||||
const sameSelection = (a: State, b: State) =>
|
||||
@@ -393,6 +401,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
||||
key,
|
||||
current,
|
||||
recent,
|
||||
favorite: { list: favorite, toggle: models.favorite.toggle },
|
||||
list: models.list,
|
||||
trackSessionCommit(sessionID: string, selection: { agent: string; model: ModelKey; variant?: string }) {
|
||||
pending.set(sessionID, selection)
|
||||
@@ -446,13 +455,14 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
||||
variant: {
|
||||
configured,
|
||||
selected,
|
||||
current() {
|
||||
const model = current()
|
||||
current(item?: ModelKey) {
|
||||
const model = item ? models.find(item) : current()
|
||||
const same = !item || (current()?.provider.id === item.providerID && current()?.id === item.modelID)
|
||||
|
||||
return resolveModelVariant({
|
||||
variants: this.list(),
|
||||
selected: this.selected(),
|
||||
configured: this.configured(),
|
||||
variants: Object.keys(model?.variants ?? {}),
|
||||
selected: same ? this.selected() : undefined,
|
||||
configured: configured(model),
|
||||
preferred: model ? models.variant.get({ providerID: model.provider.id, modelID: model.id }) : undefined,
|
||||
})
|
||||
},
|
||||
|
||||
@@ -123,6 +123,12 @@ export const dict = {
|
||||
"dialog.model.manage.description": "Customize which models appear in the model selector.",
|
||||
"dialog.model.chatgptPlan": "Using ChatGPT plan",
|
||||
"dialog.model.chatgptManageUsage": "Manage usage",
|
||||
"dialog.model.favorites": "Favorites",
|
||||
"dialog.model.recent": "Recent",
|
||||
"dialog.model.hint.navigate": "Navigate",
|
||||
"dialog.model.hint.variant": "Variant",
|
||||
"dialog.model.hint.select": "Select",
|
||||
"dialog.model.hint.favorite": "Favorite",
|
||||
|
||||
"dialog.model.unpaid.freeModels.title": "Free models provided by OpenCode",
|
||||
"dialog.model.unpaid.addMore.title": "Add more models from popular providers",
|
||||
@@ -248,6 +254,17 @@ export const dict = {
|
||||
"model.tooltip.reasoning.allowed": "Allows reasoning",
|
||||
"model.tooltip.reasoning.none": "No reasoning",
|
||||
"model.tooltip.context": "Context limit {{limit}}",
|
||||
"model.details.input.text": "Text",
|
||||
"model.details.input.image": "Image",
|
||||
"model.details.input.audio": "Audio",
|
||||
"model.details.input.video": "Video",
|
||||
"model.details.input.pdf": "PDF",
|
||||
"model.details.input": "Input",
|
||||
"model.details.output": "Output",
|
||||
"model.details.inputOutput": "Input & Output",
|
||||
"model.details.tools": "Tools",
|
||||
"model.details.supported": "Supported",
|
||||
"model.details.summary": "{{provider}} · {{context}} context",
|
||||
|
||||
"common.search.placeholder": "Search",
|
||||
"common.goBack": "Navigate back",
|
||||
|
||||
@@ -78,9 +78,17 @@ describe("server persistence schema", () => {
|
||||
|
||||
describe("model persistence schema", () => {
|
||||
test("defaults missing state and keeps valid entries beside malformed entries", () => {
|
||||
const decode = Schema.decodeUnknownSync(Persistence.withInitial(ModelState, { user: [], recent: [], variant: {} }))
|
||||
expect(decode({})).toEqual({ user: [], recent: [], variant: {} })
|
||||
expect(decode({ user: null, recent: 1, variant: [] })).toEqual({ user: [], recent: [], variant: {} })
|
||||
const decode = Schema.decodeUnknownSync(
|
||||
Persistence.withInitial(ModelState, { user: [], recent: [], favorite: [], variant: {} }),
|
||||
)
|
||||
|
||||
expect(decode({})).toEqual({ user: [], recent: [], favorite: [], variant: {} })
|
||||
expect(decode({ user: null, recent: 1, favorite: "x", variant: [] })).toEqual({
|
||||
user: [],
|
||||
recent: [],
|
||||
favorite: [],
|
||||
variant: {},
|
||||
})
|
||||
|
||||
const state = decode({
|
||||
user: [
|
||||
@@ -90,6 +98,7 @@ describe("model persistence schema", () => {
|
||||
{ providerID: "provider", modelID: "hidden", visibility: "hide" },
|
||||
],
|
||||
recent: [false, { providerID: "provider", modelID: "model" }, { providerID: "missing-model" }],
|
||||
favorite: [{ providerID: "provider", modelID: "model" }, { modelID: "missing-provider" }],
|
||||
variant: { model: "high" },
|
||||
})
|
||||
|
||||
@@ -99,6 +108,7 @@ describe("model persistence schema", () => {
|
||||
{ providerID: "provider", modelID: "hidden", visibility: "hide" },
|
||||
],
|
||||
recent: [{ providerID: "provider", modelID: "model" }],
|
||||
favorite: [{ providerID: "provider", modelID: "model" }],
|
||||
variant: { model: "high" },
|
||||
})
|
||||
expect(Schema.encodeSync(ModelState)(state)).toEqual(state)
|
||||
|
||||
@@ -57,6 +57,7 @@ export const ModelState = Persistence.struct({
|
||||
}),
|
||||
),
|
||||
recent: Persistence.array(Persistence.struct({ providerID: Schema.String, modelID: Schema.String })),
|
||||
favorite: Persistence.array(Persistence.struct({ providerID: Schema.String, modelID: Schema.String })),
|
||||
variant: Schema.Record(
|
||||
Schema.String,
|
||||
Schema.mutableKey(
|
||||
|
||||
@@ -118,6 +118,7 @@ function createGlobalModels() {
|
||||
const [store, setStore, _, ready] = persisted(Persist.global("model"), ModelState, {
|
||||
user: [],
|
||||
recent: [],
|
||||
favorite: [],
|
||||
variant: {},
|
||||
})
|
||||
|
||||
@@ -138,6 +139,11 @@ function createGlobalModels() {
|
||||
|
||||
return store.recent
|
||||
},
|
||||
favorite: () => {
|
||||
loaded()
|
||||
|
||||
return store.favorite
|
||||
},
|
||||
// Marks models visible in the picker regardless of the "latest per family" default.
|
||||
show(models: ReadonlyArray<{ providerID: string; modelID: string }>) {
|
||||
const seen = new Map(store.user.map((item, index) => [`${item.providerID}:${item.modelID}`, index]))
|
||||
@@ -265,7 +271,7 @@ function createServerController(
|
||||
|
||||
return list().find((project) => project.id === location.project.id)
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
.catch((error) => {
|
||||
showToast({
|
||||
variant: "error",
|
||||
title: language.t("common.requestFailed"),
|
||||
|
||||
@@ -63,6 +63,7 @@ const modelSelection = {
|
||||
key: () => ({ providerID: storyComposerModel.provider.id, modelID: storyComposerModel.id }),
|
||||
current: () => storyComposerModel,
|
||||
recent: () => [storyComposerModel],
|
||||
favorite: { list: () => [], toggle() {} },
|
||||
list: () => [storyComposerModel],
|
||||
cycle() {},
|
||||
set() {},
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
/** Coordinates focus restoration and actions that must run after menu content unmounts. */
|
||||
export function createMenuDismissController(content: () => HTMLElement | undefined) {
|
||||
let restoreTrigger = true
|
||||
let pending: (() => void) | undefined
|
||||
|
||||
const run = () => {
|
||||
const callback = pending
|
||||
pending = undefined
|
||||
callback?.()
|
||||
}
|
||||
|
||||
return {
|
||||
/** Allows the menu primitive to restore focus to its trigger when closing. */
|
||||
@@ -13,18 +20,31 @@ export function createMenuDismissController(content: () => HTMLElement | undefin
|
||||
},
|
||||
/** Applies the current restoration policy during the menu primitive's close-focus event. */
|
||||
onCloseAutoFocus(event: Event) {
|
||||
if (!restoreTrigger) event.preventDefault()
|
||||
if (restoreTrigger) return
|
||||
event.preventDefault()
|
||||
const focused = document.activeElement
|
||||
// Kobalte's dropdown focuses its trigger after this handler anyway, so undo that before the next paint.
|
||||
queueMicrotask(() => {
|
||||
const trigger = document.activeElement
|
||||
|
||||
if (trigger !== focused && trigger instanceof HTMLElement) trigger.blur()
|
||||
run()
|
||||
})
|
||||
},
|
||||
/** Runs an action after the menu unmounts and its focus-close work has settled. */
|
||||
afterClose(callback: () => void) {
|
||||
pending = callback
|
||||
|
||||
const complete = () => {
|
||||
if (!pending) return
|
||||
|
||||
if (content()?.isConnected) {
|
||||
requestAnimationFrame(complete)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => requestAnimationFrame(callback))
|
||||
requestAnimationFrame(() => requestAnimationFrame(run))
|
||||
}
|
||||
|
||||
requestAnimationFrame(complete)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { onCleanup } from "solid-js"
|
||||
|
||||
type Point = { x: number; y: number }
|
||||
|
||||
/**
|
||||
* Keeps a flyout open while the pointer heads toward it across neighboring rows. The triangle runs from the
|
||||
* pointer's last position on the owning row to the flyout's near corners. A pointer that rests inside it hands
|
||||
* over to the row underneath after `timeout`, as on macOS.
|
||||
*/
|
||||
export function createSafeTriangle(input: { flyout: () => Element | undefined; timeout?: number }) {
|
||||
let apex: Point | undefined
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
onCleanup(() => clearTimeout(timer))
|
||||
|
||||
const corners = () => {
|
||||
const box = input.flyout()?.getBoundingClientRect()
|
||||
|
||||
if (!box || !apex) return
|
||||
|
||||
const x = box.left > apex.x ? box.left : box.right
|
||||
|
||||
return [apex, { x, y: box.top }, { x, y: box.bottom }]
|
||||
}
|
||||
|
||||
const contains = (point: Point) => {
|
||||
const triangle = corners()
|
||||
|
||||
if (!triangle) return false
|
||||
const side = (a: Point, b: Point) => (point.x - b.x) * (a.y - b.y) - (a.x - b.x) * (point.y - b.y)
|
||||
const signs = [side(triangle[0], triangle[1]), side(triangle[1], triangle[2]), side(triangle[2], triangle[0])]
|
||||
|
||||
return !(signs.some((value) => value < 0) && signs.some((value) => value > 0))
|
||||
}
|
||||
|
||||
return {
|
||||
corners,
|
||||
contains,
|
||||
/** Records the pointer on the row that owns the open flyout. */
|
||||
anchor(point: Point) {
|
||||
clearTimeout(timer)
|
||||
apex = point
|
||||
},
|
||||
/** Returns whether a pointer on another row should leave the flyout alone, scheduling `settle` if it rests. */
|
||||
hold(point: Point, settle: () => void) {
|
||||
clearTimeout(timer)
|
||||
|
||||
if (!contains(point)) return false
|
||||
timer = setTimeout(() => {
|
||||
apex = undefined
|
||||
settle()
|
||||
}, input.timeout ?? 300)
|
||||
|
||||
return true
|
||||
},
|
||||
/** Cancels a pending hand-over, such as when the pointer reaches the flyout. */
|
||||
cancel() {
|
||||
clearTimeout(timer)
|
||||
},
|
||||
reset() {
|
||||
clearTimeout(timer)
|
||||
apex = undefined
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,7 @@ function fixture(input: { session?: Commit; agents?: Agent[]; config?: ConfigMod
|
||||
const [preferences, setPreferences] = createStore({
|
||||
user: [] as Array<ModelKey & { visibility: "show" | "hide" }>,
|
||||
recent: [] as ModelKey[],
|
||||
favorite: [] as ModelKey[],
|
||||
variant: (input.preferred ? { "provider/a": input.preferred } : {}) as Record<string, string>,
|
||||
})
|
||||
|
||||
@@ -143,7 +144,13 @@ function fixture(input: { session?: Commit; agents?: Agent[]; config?: ConfigMod
|
||||
state,
|
||||
set,
|
||||
setPreferences,
|
||||
preferences: { store: preferences, set: setPreferences, ready: () => true, recent: () => preferences.recent },
|
||||
preferences: {
|
||||
store: preferences,
|
||||
set: setPreferences,
|
||||
ready: () => true,
|
||||
recent: () => preferences.recent,
|
||||
favorite: () => preferences.favorite,
|
||||
},
|
||||
data: {
|
||||
session: { get: (id: string) => state.sessions[id] },
|
||||
location: {
|
||||
|
||||
@@ -28,6 +28,17 @@ export function parseKeybind(config: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export function matchKeybind(keybinds: ReturnType<typeof parseKeybind>, event: KeyboardEvent) {
|
||||
return keybinds.some(
|
||||
(keybind) =>
|
||||
keybind.key === event.key.toLowerCase() &&
|
||||
keybind.ctrl === event.ctrlKey &&
|
||||
keybind.meta === event.metaKey &&
|
||||
keybind.shift === event.shiftKey &&
|
||||
keybind.alt === event.altKey,
|
||||
)
|
||||
}
|
||||
|
||||
export function formatKeybind(config: string) {
|
||||
return config === "none" ? "" : config
|
||||
}
|
||||
|
||||
@@ -278,6 +278,34 @@ const icons = {
|
||||
viewBox: "0 0 16 16",
|
||||
body: `<path d="M13.1112 13.5555V14.0555H13.6112V13.5555H13.1112ZM2.889 13.5555H2.389L2.389 14.0555H2.889V13.5555ZM3.38901 5.55546L3.38901 5.05546L2.38901 5.05546L2.38901 5.55546L2.88901 5.55546L3.38901 5.55546ZM14.4446 2.44434H14.9446V1.94434L14.4446 1.94434L14.4446 2.44434ZM14.4446 5.55545L14.4446 6.05545L14.9446 6.05545V5.55545H14.4446ZM1.55566 5.55546L1.05566 5.55545L1.05566 6.05546L1.55566 6.05546L1.55566 5.55546ZM1.5557 2.44436L1.5557 1.94436L1.05571 1.94436L1.0557 2.44435L1.5557 2.44436ZM13.1112 5.55546H12.6112V13.5555H13.1112H13.6112V5.55546H13.1112ZM2.889 13.5555H3.389L3.38901 5.55546L2.88901 5.55546L2.38901 5.55546L2.389 13.5555H2.889ZM14.4446 2.44434H13.9446V5.55545H14.4446H14.9446V2.44434H14.4446ZM1.55566 5.55546L2.05566 5.55547L2.0557 2.44436L1.5557 2.44436L1.0557 2.44435L1.05566 5.55545L1.55566 5.55546ZM6.22234 8.22213V8.72213H9.7779V8.22213V7.72213H6.22234V8.22213ZM13.1112 13.5555V13.0555H2.889V13.5555V14.0555H13.1112V13.5555ZM1.5557 2.44436L1.5557 2.94436L14.4446 2.94434L14.4446 2.44434L14.4446 1.94434L1.5557 1.94436L1.5557 2.44436ZM14.4446 5.55545L14.4446 5.05545L1.55566 5.05546L1.55566 5.55546L1.55566 6.05546L14.4446 6.05545L14.4446 5.55545Z" fill="currentColor"/>`,
|
||||
},
|
||||
"outline-text": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M6.99997 11.5938V2.40625M6.99997 11.5938H9.04164M6.99997 11.5938H4.95831M6.99997 2.40625H2.40622V4.95833M6.99997 2.40625H11.5937V4.95833" stroke="currentColor"/>`,
|
||||
},
|
||||
"outline-photo": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M11.6666 11.6666L8.16663 8.16663L6.99997 9.33332L4.66663 6.99998L2.1583 9.50832M2.04163 2.04165H11.9583V11.9583H2.04163V2.04165ZM9.33332 5.24998C9.33332 5.81377 8.87629 6.27081 8.31244 6.27081C7.74866 6.27081 7.29163 5.81377 7.29163 5.24998C7.29163 4.68619 7.74866 4.22915 8.31244 4.22915C8.87629 4.22915 9.33332 4.68619 9.33332 5.24998Z" stroke="currentColor" stroke-linecap="square"/>`,
|
||||
},
|
||||
"file-document": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M7.58331 2.33333V5.25H10.5M2.91664 1.75H7.58331L11.0833 5.25V12.25H2.91664V1.75Z" stroke="currentColor" stroke-linecap="square"/>`,
|
||||
},
|
||||
"outline-audio": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M2.29546 5.62775V8.37207M5.4318 1.96875V12.0312M8.56815 4.40801V9.59173M11.7045 5.62775V8.37207" stroke="currentColor" stroke-linecap="square"/>`,
|
||||
},
|
||||
"outline-video": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M10.7412 7L3.99997 11.333V2.66602L10.7412 7Z" stroke="currentColor"/>`,
|
||||
},
|
||||
"outline-brain": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M6.99997 3.5C6.99997 2.53322 7.7832 1.75 8.74997 1.75C9.71675 1.75 10.5 2.53322 10.5 3.5C10.5 3.57233 10.4875 3.64156 10.479 3.71156C11.4706 3.80022 12.25 4.62389 12.25 5.63889C12.25 6.43222 11.7732 7.11278 11.0919 7.41456C11.55 7.68522 11.8611 8.17911 11.8611 8.75C11.8611 9.54956 11.2552 10.2006 10.479 10.2884C10.4875 10.3584 10.5 10.4277 10.5 10.5C10.5 11.4668 9.71675 12.25 8.74997 12.25C7.7832 12.25 6.99997 11.4668 6.99997 10.5M6.99997 3.5C6.99997 2.53322 6.21675 1.75 5.24997 1.75C4.2832 1.75 3.49997 2.53322 3.49997 3.5C3.49997 3.57233 3.51241 3.64156 3.52097 3.71156C2.5293 3.80022 1.74997 4.62389 1.74997 5.63889C1.74997 6.43222 2.22675 7.11278 2.90808 7.41456C2.44997 7.68522 2.13886 8.17911 2.13886 8.75C2.13886 9.54956 2.74474 10.2006 3.52097 10.2884C3.51241 10.3584 3.49997 10.4277 3.49997 10.5C3.49997 11.4668 4.2832 12.25 5.24997 12.25C6.21675 12.25 6.99997 11.4668 6.99997 10.5M6.99997 3.5V10.5M4.27773 7.58334H3.6944C3.41362 7.58334 3.14607 7.52345 2.90496 7.4169M11.095 7.4169C10.8539 7.52345 10.5863 7.58334 10.3055 7.58334H9.7222" stroke="currentColor" stroke-linecap="square"/>`,
|
||||
},
|
||||
"outline-console": {
|
||||
viewBox: "0 0 14 14",
|
||||
body: `<path d="M2.13889 11.0833L6.22222 7L2.13889 2.91667M7.38888 11.0834H11.8611" stroke="currentColor"/>`,
|
||||
},
|
||||
}
|
||||
|
||||
/** Icon names derived from the shared artwork, with no UI or runtime dependencies. */
|
||||
|
||||
Reference in New Issue
Block a user