Просмотр исходного кода

fix(tui): simplify console org display (#21339)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Kit Langton 1 неделя назад
Родитель
Сommit
ae614d919f

+ 3 - 10
packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

@@ -8,7 +8,6 @@ import { createDialogProviderOptions, DialogProvider } from "./dialog-provider"
 import { DialogVariant } from "./dialog-variant"
 import { useKeybind } from "../context/keybind"
 import * as fuzzysort from "fuzzysort"
-import { consoleManagedProviderLabel } from "@tui/util/provider-origin"
 
 export function useConnected() {
   const sync = useSync()
@@ -47,11 +46,7 @@ export function DialogModel(props: { providerID?: string }) {
             key: item,
             value: { providerID: provider.id, modelID: model.id },
             title: model.name ?? item.modelID,
-            description: consoleManagedProviderLabel(
-              sync.data.console_state.consoleManagedProviders,
-              provider.id,
-              provider.name,
-            ),
+            description: provider.name,
             category,
             disabled: provider.id === "opencode" && model.id.includes("-nano"),
             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)
               ? "(Favorite)"
               : undefined,
-            category: connected()
-              ? consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, provider.id, provider.name)
-              : undefined,
+            category: connected() ? provider.name : undefined,
             disabled: provider.id === "opencode" && model.includes("-nano"),
             footer: info.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
             onSelect() {
@@ -142,7 +135,7 @@ export function DialogModel(props: { providerID?: string }) {
   const title = createMemo(() => {
     const value = provider()
     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) {

+ 2 - 6
packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx

@@ -13,7 +13,7 @@ import { DialogModel } from "./dialog-model"
 import { useKeyboard } from "@opentui/solid"
 import { Clipboard } from "@tui/util/clipboard"
 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> = {
   opencode: 0,
@@ -49,11 +49,7 @@ export function createDialogProviderOptions() {
           }[provider.id],
           footer: consoleManaged ? sync.data.console_state.activeOrgName : undefined,
           category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
-          gutter: consoleManaged ? (
-            <text fg={theme.textMuted}>{CONSOLE_MANAGED_ICON}</text>
-          ) : connected ? (
-            <text fg={theme.success}>✓</text>
-          ) : undefined,
+          gutter: connected ? <text fg={theme.success}>✓</text> : undefined,
           async onSelect() {
             if (consoleManaged) return
 

+ 3 - 22
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

@@ -36,7 +36,6 @@ import { useToast } from "../../ui/toast"
 import { useKV } from "../../context/kv"
 import { useTextareaKeybindings } from "../textarea-keybindings"
 import { DialogSkill } from "../dialog-skill"
-import { CONSOLE_MANAGED_ICON, consoleManagedProviderLabel } from "@tui/util/provider-origin"
 
 export type PromptProps = {
   sessionID?: string
@@ -96,15 +95,8 @@ export function Prompt(props: PromptProps) {
   const list = createMemo(() => props.placeholders?.normal ?? [])
   const shell = createMemo(() => props.placeholders?.shell ?? [])
   const [auto, setAuto] = createSignal<AutocompleteRef>()
-  const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
-  const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
-  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()))
+  const currentProviderLabel = createMemo(() => local.model.parsed().provider)
+  const hasRightContent = createMemo(() => Boolean(props.right))
 
   function promptModelWarning() {
     toast.show({
@@ -1120,17 +1112,6 @@ export function Prompt(props: PromptProps) {
               <Show when={hasRightContent()}>
                 <box flexDirection="row" gap={1} alignItems="center">
                   {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>
               </Show>
             </box>
@@ -1162,7 +1143,7 @@ export function Prompt(props: PromptProps) {
             }
           />
         </box>
-        <box flexDirection="row" justifyContent="space-between">
+        <box width="100%" flexDirection="row" justifyContent="space-between">
           <Show when={status().type !== "idle"} fallback={props.hint ?? <text />}>
             <box
               flexDirection="row"

+ 0 - 13
packages/opencode/src/cli/cmd/tui/util/provider-origin.ts

@@ -1,5 +1,3 @@
-export const CONSOLE_MANAGED_ICON = "⌂"
-
 const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
   Array.isArray(consoleManagedProviders)
     ? consoleManagedProviders.includes(providerID)
@@ -7,14 +5,3 @@ const contains = (consoleManagedProviders: string[] | ReadonlySet<string>, provi
 
 export const isConsoleManagedProvider = (consoleManagedProviders: string[] | ReadonlySet<string>, providerID: string) =>
   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)}`

+ 31 - 0
packages/opencode/test/tool/registry.test.ts

@@ -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(
           path.join(toolsDir, "cowsay.ts"),
           [

+ 1 - 2
packages/opencode/test/tool/webfetch.test.ts

@@ -147,8 +147,7 @@ describe("tool.webfetch", () => {
       )
 
       expect(ids).toHaveLength(1)
-      expect(cleared).toHaveLength(1)
-      expect(cleared[0]).toBe(ids[0])
+      expect(cleared).toContain(ids[0])
     })
   })
 })