mirror of
https://github.com/anomalyco/opencode.git
synced 2026-06-01 19:05:38 +00:00
refactor(tui): simplify console state plumbing
This commit is contained in:
@@ -4,15 +4,9 @@ import { useSDK } from "@tui/context/sdk"
|
|||||||
import { useDialog } from "@tui/ui/dialog"
|
import { useDialog } from "@tui/ui/dialog"
|
||||||
import { useToast } from "@tui/ui/toast"
|
import { useToast } from "@tui/ui/toast"
|
||||||
import { useTheme } from "@tui/context/theme"
|
import { useTheme } from "@tui/context/theme"
|
||||||
|
import type { ExperimentalConsoleListOrgsResponse } from "@opencode-ai/sdk/v2"
|
||||||
|
|
||||||
type OrgOption = {
|
type OrgOption = ExperimentalConsoleListOrgsResponse["orgs"][number]
|
||||||
accountID: string
|
|
||||||
accountEmail: string
|
|
||||||
accountUrl: string
|
|
||||||
orgID: string
|
|
||||||
orgName: string
|
|
||||||
active: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
const accountHost = (url: string) => {
|
const accountHost = (url: string) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ export function DialogModel(props: { providerID?: string }) {
|
|||||||
const showSections = showExtra() && needle.length === 0
|
const showSections = showExtra() && needle.length === 0
|
||||||
const favorites = connected() ? local.model.favorite() : []
|
const favorites = connected() ? local.model.favorite() : []
|
||||||
const recents = local.model.recent()
|
const recents = local.model.recent()
|
||||||
const consoleManagedProviders = new Set(sync.data.console_state.consoleManagedProviders)
|
|
||||||
|
|
||||||
function toOptions(items: typeof favorites, category: string) {
|
function toOptions(items: typeof favorites, category: string) {
|
||||||
if (!showSections) return []
|
if (!showSections) return []
|
||||||
@@ -48,7 +47,11 @@ 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(consoleManagedProviders, provider.id, provider.name),
|
description: consoleManagedProviderLabel(
|
||||||
|
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,
|
||||||
@@ -87,7 +90,7 @@ export function DialogModel(props: { providerID?: string }) {
|
|||||||
? "(Favorite)"
|
? "(Favorite)"
|
||||||
: undefined,
|
: undefined,
|
||||||
category: connected()
|
category: connected()
|
||||||
? consoleManagedProviderLabel(consoleManagedProviders, provider.id, provider.name)
|
? consoleManagedProviderLabel(sync.data.console_state.consoleManagedProviders, provider.id, provider.name)
|
||||||
: undefined,
|
: 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,
|
||||||
|
|||||||
@@ -31,13 +31,11 @@ export function createDialogProviderOptions() {
|
|||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
const options = createMemo(() => {
|
const options = createMemo(() => {
|
||||||
const consoleManagedProviders = new Set(sync.data.console_state.consoleManagedProviders)
|
|
||||||
|
|
||||||
return pipe(
|
return pipe(
|
||||||
sync.data.provider_next.all,
|
sync.data.provider_next.all,
|
||||||
sortBy((x) => PROVIDER_PRIORITY[x.id] ?? 99),
|
sortBy((x) => PROVIDER_PRIORITY[x.id] ?? 99),
|
||||||
map((provider) => {
|
map((provider) => {
|
||||||
const consoleManaged = isConsoleManagedProvider(consoleManagedProviders, provider.id)
|
const consoleManaged = isConsoleManagedProvider(sync.data.console_state.consoleManagedProviders, provider.id)
|
||||||
const connected = sync.data.provider_next.connected.includes(provider.id)
|
const connected = sync.data.provider_next.connected.includes(provider.id)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -377,7 +377,6 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|||||||
const blockingRequests: Promise<unknown>[] = [
|
const blockingRequests: Promise<unknown>[] = [
|
||||||
providersPromise,
|
providersPromise,
|
||||||
providerListPromise,
|
providerListPromise,
|
||||||
consoleStatePromise,
|
|
||||||
agentsPromise,
|
agentsPromise,
|
||||||
configPromise,
|
configPromise,
|
||||||
...(args.continue ? [sessionListPromise] : []),
|
...(args.continue ? [sessionListPromise] : []),
|
||||||
@@ -423,6 +422,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|||||||
// non-blocking
|
// non-blocking
|
||||||
Promise.all([
|
Promise.all([
|
||||||
...(args.continue ? [] : [sessionListPromise.then((sessions) => setStore("session", reconcile(sessions)))]),
|
...(args.continue ? [] : [sessionListPromise.then((sessions) => setStore("session", reconcile(sessions)))]),
|
||||||
|
consoleStatePromise.then((consoleState) => setStore("console_state", reconcile(consoleState))),
|
||||||
sdk.client.command.list().then((x) => setStore("command", reconcile(x.data ?? []))),
|
sdk.client.command.list().then((x) => setStore("command", reconcile(x.data ?? []))),
|
||||||
sdk.client.lsp.status().then((x) => setStore("lsp", reconcile(x.data!))),
|
sdk.client.lsp.status().then((x) => setStore("lsp", reconcile(x.data!))),
|
||||||
sdk.client.mcp.status().then((x) => setStore("mcp", reconcile(x.data!))),
|
sdk.client.mcp.status().then((x) => setStore("mcp", reconcile(x.data!))),
|
||||||
|
|||||||
@@ -1051,8 +1051,7 @@ export namespace Config {
|
|||||||
config: Info
|
config: Info
|
||||||
directories: string[]
|
directories: string[]
|
||||||
deps: Promise<void>[]
|
deps: Promise<void>[]
|
||||||
consoleManagedProviders: string[]
|
consoleState: ConsoleState
|
||||||
activeOrgName?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Interface {
|
export interface Interface {
|
||||||
@@ -1467,8 +1466,10 @@ export namespace Config {
|
|||||||
config: result,
|
config: result,
|
||||||
directories,
|
directories,
|
||||||
deps,
|
deps,
|
||||||
consoleManagedProviders: Array.from(consoleManagedProviders),
|
consoleState: {
|
||||||
activeOrgName,
|
consoleManagedProviders: Array.from(consoleManagedProviders),
|
||||||
|
activeOrgName,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1487,10 +1488,7 @@ export namespace Config {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const getConsoleState = Effect.fn("Config.getConsoleState")(function* () {
|
const getConsoleState = Effect.fn("Config.getConsoleState")(function* () {
|
||||||
return yield* InstanceState.use(state, (s) => ({
|
return yield* InstanceState.use(state, (s) => s.consoleState)
|
||||||
consoleManagedProviders: s.consoleManagedProviders,
|
|
||||||
activeOrgName: s.activeOrgName,
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const waitForDependencies = Effect.fn("Config.waitForDependencies")(function* () {
|
const waitForDependencies = Effect.fn("Config.waitForDependencies")(function* () {
|
||||||
|
|||||||
Reference in New Issue
Block a user