refactor(tui): remove legacy sdk surfaces
This commit is contained in:
parent
56a7c06a80
commit
2a7e32c416
54 changed files with 278 additions and 2324 deletions
|
|
@ -21,10 +21,10 @@ import type {
|
|||
SessionMessageAssistantText,
|
||||
SessionMessageAssistantTool,
|
||||
SessionInfo,
|
||||
Shell,
|
||||
ShellInfo,
|
||||
SkillInfo,
|
||||
} from "@opencode-ai/sdk/v2"
|
||||
import type { OpenCodeEvent } from "@opencode-ai/client/promise"
|
||||
OpenCodeEvent,
|
||||
} from "@opencode-ai/client"
|
||||
import { createStore, produce, reconcile } from "solid-js/store"
|
||||
import { createSimpleContext } from "./helper"
|
||||
import { useSDK } from "./sdk"
|
||||
|
|
@ -49,7 +49,7 @@ type LocationData = {
|
|||
reference?: ReferenceInfo[]
|
||||
// Currently running shell commands for this location, keyed by shell id. Entries are removed
|
||||
// once the command exits or is deleted, so this only ever holds in-flight shells.
|
||||
shell?: Record<string, Shell>
|
||||
shell?: Record<string, ShellInfo>
|
||||
skill?: SkillInfo[]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
|||
})
|
||||
|
||||
const slots = createMemo(() => {
|
||||
const existing = new Set(sync.data.session.filter((x) => x.parentID === undefined).map((x) => x.id))
|
||||
const existing = new Set(data.session.list().filter((x) => x.parentID === undefined).map((x) => x.id))
|
||||
return sessionStore.pinned.filter((id) => existing.has(id)).slice(0, 9)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { LocationRef } from "@opencode-ai/sdk/v2"
|
||||
import type { LocationRef } from "@opencode-ai/client"
|
||||
import { createContext, useContext, type Accessor, type ParentProps } from "solid-js"
|
||||
|
||||
const context = createContext<Accessor<LocationRef | undefined>>()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
import { batch } from "solid-js"
|
||||
import type { Path, Workspace } from "@opencode-ai/sdk/v2"
|
||||
import { createStore, reconcile } from "solid-js/store"
|
||||
import { createSimpleContext } from "./helper"
|
||||
import { useSDK } from "./sdk"
|
||||
|
||||
type WorkspaceStatus = "connected" | "connecting" | "disconnected" | "error"
|
||||
|
||||
export const { use: useProject, provider: ProjectProvider } = createSimpleContext({
|
||||
name: "Project",
|
||||
init: () => {
|
||||
|
|
@ -17,7 +14,7 @@ export const { use: useProject, provider: ProjectProvider } = createSimpleContex
|
|||
config: "",
|
||||
worktree: "",
|
||||
directory: process.cwd(),
|
||||
} satisfies Path
|
||||
}
|
||||
|
||||
const [store, setStore] = createStore({
|
||||
project: {
|
||||
|
|
@ -30,42 +27,26 @@ export const { use: useProject, provider: ProjectProvider } = createSimpleContex
|
|||
},
|
||||
workspace: {
|
||||
current: undefined as string | undefined,
|
||||
list: [] as Workspace[],
|
||||
status: {} as Record<string, WorkspaceStatus>,
|
||||
},
|
||||
})
|
||||
|
||||
async function sync() {
|
||||
const workspace = store.workspace.current
|
||||
const location = { workspace }
|
||||
const [instancePath, project] = await Promise.all([
|
||||
sdk.client.path.get({ workspace }),
|
||||
sdk.api.project.current({ location }),
|
||||
])
|
||||
const directories = await sdk.api.project.directories({ projectID: project.id, location })
|
||||
const current = await sdk.api.location.get({ location })
|
||||
const directories = await sdk.api.project.directories({ projectID: current.project.id, location })
|
||||
batch(() => {
|
||||
setStore("instance", "path", reconcile(instancePath.data || defaultPath))
|
||||
setStore("project", "id", project.id)
|
||||
setStore("project", "worktree", project.directory)
|
||||
setStore(
|
||||
"instance",
|
||||
"path",
|
||||
reconcile({ ...defaultPath, worktree: current.project.directory, directory: current.directory }),
|
||||
)
|
||||
setStore("project", "id", current.project.id)
|
||||
setStore("project", "worktree", current.project.directory)
|
||||
setStore("project", "mainDir", directories.findLast((item) => item.strategy === undefined)?.directory)
|
||||
})
|
||||
}
|
||||
|
||||
async function syncWorkspace() {
|
||||
const listed = await sdk.client.experimental.workspace.list().catch(() => undefined)
|
||||
if (!listed?.data) return
|
||||
const status = await sdk.client.experimental.workspace.status().catch(() => undefined)
|
||||
const next = Object.fromEntries((status?.data ?? []).map((item) => [item.workspaceID, item.status]))
|
||||
|
||||
batch(() => {
|
||||
setStore("workspace", "list", reconcile(listed.data))
|
||||
setStore("workspace", "status", reconcile(next))
|
||||
if (!listed.data.some((item) => item.id === store.workspace.current)) {
|
||||
setStore("workspace", "current", undefined)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
data: store,
|
||||
project() {
|
||||
|
|
@ -88,19 +69,6 @@ export const { use: useProject, provider: ProjectProvider } = createSimpleContex
|
|||
if (store.workspace.current === workspace) return
|
||||
setStore("workspace", "current", workspace)
|
||||
},
|
||||
list() {
|
||||
return store.workspace.list
|
||||
},
|
||||
get(workspaceID: string) {
|
||||
return store.workspace.list.find((item) => item.id === workspaceID)
|
||||
},
|
||||
status(workspaceID: string) {
|
||||
return store.workspace.status[workspaceID]
|
||||
},
|
||||
statuses() {
|
||||
return store.workspace.status
|
||||
},
|
||||
sync: syncWorkspace,
|
||||
},
|
||||
sync,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import type {
|
|||
Agent,
|
||||
Command,
|
||||
Config,
|
||||
ConsoleState,
|
||||
FormatterStatus,
|
||||
LspStatus,
|
||||
McpResource,
|
||||
|
|
@ -11,8 +10,6 @@ import type {
|
|||
Part,
|
||||
PermissionRequest,
|
||||
Provider,
|
||||
ProviderAuthMethod,
|
||||
ProviderListResponse,
|
||||
QuestionRequest,
|
||||
Session,
|
||||
FileDiffInfo,
|
||||
|
|
@ -22,11 +19,6 @@ import { createStore } from "solid-js/store"
|
|||
import { createSimpleContext } from "./helper"
|
||||
import { useProject } from "./project"
|
||||
|
||||
const emptyConsoleState: ConsoleState = {
|
||||
consoleManagedProviders: [],
|
||||
switchableOrgCount: 0,
|
||||
}
|
||||
|
||||
export const {
|
||||
context: SyncContext,
|
||||
use: useSync,
|
||||
|
|
@ -38,10 +30,6 @@ export const {
|
|||
const [store, setStore] = createStore<{
|
||||
status: "loading" | "partial" | "complete"
|
||||
provider: Provider[]
|
||||
provider_default: Record<string, string>
|
||||
provider_next: ProviderListResponse
|
||||
console_state: ConsoleState
|
||||
provider_auth: Record<string, ProviderAuthMethod[]>
|
||||
agent: Agent[]
|
||||
command: Command[]
|
||||
permission: Record<string, PermissionRequest[]>
|
||||
|
|
@ -59,14 +47,6 @@ export const {
|
|||
}>({
|
||||
status: "complete",
|
||||
provider: [],
|
||||
provider_default: {},
|
||||
provider_next: {
|
||||
all: [],
|
||||
default: {},
|
||||
connected: [],
|
||||
},
|
||||
console_state: emptyConsoleState,
|
||||
provider_auth: {},
|
||||
agent: [],
|
||||
command: [],
|
||||
permission: {},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue