fix(tui): simplify console org display (#21339)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>dev
parent
65cde7f494
commit
ae614d919f
|
|
@ -8,7 +8,6 @@ import { createDialogProviderOptions, DialogProvider } from "./dialog-provider"
|
||||||
import { DialogVariant } from "./dialog-variant"
|
import { DialogVariant } from "./dialog-variant"
|
||||||
import { useKeybind } from "../context/keybind"
|
import { useKeybind } from "../context/keybind"
|
||||||
import * as fuzzysort from "fuzzysort"
|
import * as fuzzysort from "fuzzysort"
|
||||||
import { consoleManagedProviderLabel } from "@tui/util/provider-origin"
|
|
||||||
|
|
||||||
export function useConnected() {
|
export function useConnected() {
|
||||||
const sync = useSync()
|
const sync = useSync()
|
||||||
|
|
@ -47,11 +46,7 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
key: item,
|
key: item,
|
||||||
value: { providerID: provider.id, modelID: model.id },
|
value: { providerID: provider.id, modelID: model.id },
|
||||||
title: model.name ?? item.modelID,
|
title: model.name ?? item.modelID,
|
||||||
description: consoleManagedProviderLabel(
|
description: provider.name,
|
||||||
sync.data.console_state.consoleManagedProviders,
|
|
||||||
provider.id,
|
|
||||||
provider.name,
|
|
||||||
),
|
|
||||||
category,
|
category,
|
||||||
disabled: provider.id === "opencode" && model.id.includes("-nano"),
|
disabled: provider.id === "opencode" && model.id.includes("-nano"),
|
||||||
footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
||||||
|
|
@ -89,9 +84,7 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
description: favorites.some((item) => item.providerID === provider.id && item.modelID === model)
|
description: favorites.some((item) => item.providerID === provider.id && item.modelID === model)
|
||||||
? "(Favorite)"
|
? "(Favorite)"
|
||||||
: undefined,
|
: undefined,
|
||||||
category: connected()
|
category: connected() ? provider.name : undefined,
|
||||||
? consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, provider.id, provider.name)
|
|
||||||
: undefined,
|
|
||||||
disabled: provider.id === "opencode" && model.includes("-nano"),
|
disabled: provider.id === "opencode" && model.includes("-nano"),
|
||||||
footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
|
||||||
onSelect() {
|
onSelect() {
|
||||||
|
|
@ -142,7 +135,7 @@ export function DialogModel(props: { providerID?: string }) {
|
||||||
const title = createMemo(() => {
|
const title = createMemo(() => {
|
||||||
const value = provider()
|
const value = provider()
|
||||||
if (!value) return "Select model"
|
if (!value) return "Select model"
|
||||||
return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, value.id, value.name)
|
return value.name
|
||||||
})
|
})
|
||||||
|
|
||||||
function onSelect(providerID: string, modelID: string) {
|
function onSelect(providerID: string, modelID: string) {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { DialogModel } from "./dialog-model"
|
||||||
import { useKeyboard } from "@opentui/solid"
|
import { useKeyboard } from "@opentui/solid"
|
||||||
import { Clipboard } from "@tui/util/clipboard"
|
import { Clipboard } from "@tui/util/clipboard"
|
||||||
import { useToast } from "../ui/toast"
|
import { useToast } from "../ui/toast"
|
||||||
import { CONSOLE_MANAGED_ICON, isConsoleManagedProvider } from "@tui/util/provider-origin"
|
import { isConsoleManagedProvider } from "@tui/util/provider-origin"
|
||||||
|
|
||||||
const PROVIDER_PRIORITY: Record<string, number> = {
|
const PROVIDER_PRIORITY: Record<string, number> = {
|
||||||
opencode: 0,
|
opencode: 0,
|
||||||
|
|
@ -49,11 +49,7 @@ export function createDialogProviderOptions() {
|
||||||
}[provider.id],
|
}[provider.id],
|
||||||
footer: consoleManaged ? sync.data.console_state.activeOrgName : undefined,
|
footer: consoleManaged ? sync.data.console_state.activeOrgName : undefined,
|
||||||
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
|
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
|
||||||
gutter: consoleManaged ? (
|
gutter: connected ? <text fg={theme.success}>✓</text> : undefined,
|
||||||
<text fg={theme.textMuted}>{CONSOLE_MANAGED_ICON}</text>
|
|
||||||
) : connected ? (
|
|
||||||
<text fg={theme.success}>✓</text>
|
|
||||||
) : undefined,
|
|
||||||
async onSelect() {
|
async onSelect() {
|
||||||
if (consoleManaged) return
|
if (consoleManaged) return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ import { useToast } from "../../ui/toast"
|
||||||
import { useKV } from "../../context/kv"
|
import { useKV } from "../../context/kv"
|
||||||
import { useTextareaKeybindings } from "../textarea-keybindings"
|
import { useTextareaKeybindings } from "../textarea-keybindings"
|
||||||
import { DialogSkill } from "../dialog-skill"
|
import { DialogSkill } from "../dialog-skill"
|
||||||
import { CONSOLE_MANAGED_ICON, consoleManagedProviderLabel } from "@tui/util/provider-origin"
|
|
||||||
|
|
||||||
export type PromptProps = {
|
export type PromptProps = {
|
||||||
sessionID?: string
|
sessionID?: string
|
||||||
|
|
@ -96,15 +95,8 @@ export function Prompt(props: PromptProps) {
|
||||||
const list = createMemo(() => props.placeholders?.normal ?? [])
|
const list = createMemo(() => props.placeholders?.normal ?? [])
|
||||||
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
||||||
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
||||||
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
|
const currentProviderLabel = createMemo(() => local.model.parsed().provider)
|
||||||
const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
|
const hasRightContent = createMemo(() => Boolean(props.right))
|
||||||
const currentProviderLabel = createMemo(() => {
|
|
||||||
const current = local.model.current()
|
|
||||||
const provider = local.model.parsed().provider
|
|
||||||
if (!current) return provider
|
|
||||||
return consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, current.providerID, provider)
|
|
||||||
})
|
|
||||||
const hasRightContent = createMemo(() => Boolean(props.right || activeOrgName()))
|
|
||||||
|
|
||||||
function promptModelWarning() {
|
function promptModelWarning() {
|
||||||
toast.show({
|
toast.show({
|
||||||
|
|
@ -1120,17 +1112,6 @@ export function Prompt(props: PromptProps) {
|
||||||
<Show when={hasRightContent()}>
|
<Show when={hasRightContent()}>
|
||||||
<box flexDirection="row" gap={1} alignItems="center">
|
<box flexDirection="row" gap={1} alignItems="center">
|
||||||
{props.right}
|
{props.right}
|
||||||
<Show when={activeOrgName()}>
|
|
||||||
<text
|
|
||||||
fg={theme.textMuted}
|
|
||||||
onMouseUp={() => {
|
|
||||||
if (!canSwitchOrgs()) return
|
|
||||||
command.trigger("console.org.switch")
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
|
|
||||||
</text>
|
|
||||||
</Show>
|
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
|
|
@ -1162,7 +1143,7 @@ export function Prompt(props: PromptProps) {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</box>
|
</box>
|
||||||
<box flexDirection="row" justifyContent="space-between">
|
<box width="100%" flexDirection="row" justifyContent="space-between">
|
||||||
<Show when={status().type !== "idle"} fallback={props.hint ?? <text />}>
|
<Show when={status().type !== "idle"} fallback={props.hint ?? <text />}>
|
||||||
<box
|
<box
|
||||||
flexDirection="row"
|
flexDirection="row"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
export const CONSOLE_MANAGED_ICON = "⌂"
|
|
||||||
|
|
||||||
const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
||||||
Array.isArray(consoleManagedProviders)
|
Array.isArray(consoleManagedProviders)
|
||||||
? consoleManagedProviders.includes(providerID)
|
? consoleManagedProviders.includes(providerID)
|
||||||
|
|
@ -7,14 +5,3 @@ const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, provi
|
||||||
|
|
||||||
export const isConsoleManagedProvider = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
export const isConsoleManagedProvider = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
|
||||||
contains(consoleManagedProviders, providerID)
|
contains(consoleManagedProviders, providerID)
|
||||||
|
|
||||||
export const consoleManagedProviderSuffix = (
|
|
||||||
consoleManagedProviders: string[] | ReadonlySet<string>,
|
|
||||||
providerID: string,
|
|
||||||
) => (contains(consoleManagedProviders, providerID) ? ` ${CONSOLE_MANAGED_ICON}` : "")
|
|
||||||
|
|
||||||
export const consoleManagedProviderLabel = (
|
|
||||||
consoleManagedProviders: string[] | ReadonlySet<string>,
|
|
||||||
providerID: string,
|
|
||||||
providerName: string,
|
|
||||||
) => `${providerName}${consoleManagedProviderSuffix(consoleManagedProviders, providerID)}`
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,37 @@ describe("tool.registry", () => {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await Bun.write(
|
||||||
|
path.join(opencodeDir, "package-lock.json"),
|
||||||
|
JSON.stringify({
|
||||||
|
name: "custom-tools",
|
||||||
|
lockfileVersion: 3,
|
||||||
|
packages: {
|
||||||
|
"": {
|
||||||
|
dependencies: {
|
||||||
|
"@opencode-ai/plugin": "^0.0.0",
|
||||||
|
cowsay: "^1.6.0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const cowsayDir = path.join(opencodeDir, "node_modules", "cowsay")
|
||||||
|
await fs.mkdir(cowsayDir, { recursive: true })
|
||||||
|
await Bun.write(
|
||||||
|
path.join(cowsayDir, "package.json"),
|
||||||
|
JSON.stringify({
|
||||||
|
name: "cowsay",
|
||||||
|
type: "module",
|
||||||
|
exports: "./index.js",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
await Bun.write(
|
||||||
|
path.join(cowsayDir, "index.js"),
|
||||||
|
["export function say({ text }) {", " return `moo ${text}`", "}", ""].join("\n"),
|
||||||
|
)
|
||||||
|
|
||||||
await Bun.write(
|
await Bun.write(
|
||||||
path.join(toolsDir, "cowsay.ts"),
|
path.join(toolsDir, "cowsay.ts"),
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,7 @@ describe("tool.webfetch", () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(ids).toHaveLength(1)
|
expect(ids).toHaveLength(1)
|
||||||
expect(cleared).toHaveLength(1)
|
expect(cleared).toContain(ids[0])
|
||||||
expect(cleared[0]).toBe(ids[0])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue