|
|
@@ -16,18 +16,12 @@ import type {
|
|
|
CommandInfo,
|
|
|
CommandListInput,
|
|
|
CommandListOutput,
|
|
|
- McpApi,
|
|
|
- PathGetInput,
|
|
|
- PathGetOutput,
|
|
|
- PermissionApi,
|
|
|
ProjectCurrentInput,
|
|
|
ProjectCurrentOutput,
|
|
|
ProjectListOutput,
|
|
|
- QuestionApi,
|
|
|
ReferenceListInput,
|
|
|
ReferenceListOutput,
|
|
|
SessionApi,
|
|
|
- VcsApi,
|
|
|
} from "@opencode-ai/client/promise"
|
|
|
import { showToast } from "@/utils/toast"
|
|
|
import { getFilename } from "@opencode-ai/core/util/path"
|
|
|
@@ -50,6 +44,7 @@ import { NormalizedProviderListResponse } from "@opencode-ai/session-ui/context"
|
|
|
import { ScopedKey, type ServerScope } from "@/utils/server-scope"
|
|
|
import { normalizeSessionInfo } from "@/utils/session"
|
|
|
import type { ServerProtocol } from "@/utils/server-protocol"
|
|
|
+import type { ServerApi } from "@/utils/server"
|
|
|
|
|
|
type GlobalStore = {
|
|
|
ready: boolean
|
|
|
@@ -121,9 +116,10 @@ type ProjectApi = {
|
|
|
readonly current: (input?: ProjectCurrentInput) => Promise<ProjectCurrentOutput>
|
|
|
}
|
|
|
|
|
|
-type PathApi = {
|
|
|
- readonly get: (input?: PathGetInput) => Promise<PathGetOutput>
|
|
|
-}
|
|
|
+type McpApi = ServerApi["mcp"]
|
|
|
+type PermissionApi = ServerApi["permission"]
|
|
|
+type QuestionApi = ServerApi["question"]
|
|
|
+type VcsApi = ServerApi["vcs"]
|
|
|
|
|
|
export const loadProjectsQuery = (scope: ServerScope, api: ProjectApi) =>
|
|
|
queryOptions({
|
|
|
@@ -143,7 +139,7 @@ export const loadProjectsQuery = (scope: ServerScope, api: ProjectApi) =>
|
|
|
|
|
|
export async function bootstrapGlobal(input: {
|
|
|
serverSDK: OpencodeClient
|
|
|
- serverAPI: CatalogApi & { readonly path: PathApi; readonly project: ProjectApi }
|
|
|
+ serverAPI: CatalogApi & { readonly project: ProjectApi }
|
|
|
protocol?: Promise<ServerProtocol>
|
|
|
scope: ServerScope
|
|
|
requestFailedTitle: string
|
|
|
@@ -158,7 +154,7 @@ export async function bootstrapGlobal(input: {
|
|
|
input.queryClient.fetchQuery(
|
|
|
loadProvidersQuery(input.scope, null, input.serverAPI, input.serverSDK, input.protocol),
|
|
|
),
|
|
|
- () => input.queryClient.fetchQuery(loadPathQuery(input.scope, null, input.serverAPI.path)),
|
|
|
+ () => input.queryClient.fetchQuery(loadPathQuery(input.scope, null, input.serverSDK, input.protocol)),
|
|
|
() =>
|
|
|
input.queryClient
|
|
|
.fetchQuery(loadProjectsQuery(input.scope, input.serverAPI.project))
|
|
|
@@ -289,17 +285,26 @@ export const loadCommands = (
|
|
|
agent: command.agent,
|
|
|
model: providerID && id ? { providerID, id } : undefined,
|
|
|
subtask: command.subtask,
|
|
|
- source: command.source === "skill" ? undefined : command.source,
|
|
|
+ // source: command.source === "skill" ? undefined : command.source,
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
return api.list({ location: { directory } }).then((result) => result.data)
|
|
|
})
|
|
|
|
|
|
-export const loadPathQuery = (scope: ServerScope, directory: string | null, api: PathApi) =>
|
|
|
+export const loadPathQuery = (
|
|
|
+ scope: ServerScope,
|
|
|
+ directory: string | null,
|
|
|
+ sdk: OpencodeClient,
|
|
|
+ protocol?: Promise<ServerProtocol>,
|
|
|
+) =>
|
|
|
queryOptions<Path>({
|
|
|
queryKey: [scope, directory, "path"],
|
|
|
- queryFn: () => retry(() => api.get(directory ? { location: { directory } } : undefined)),
|
|
|
+ queryFn: async () => {
|
|
|
+ if ((await protocol) !== "v1")
|
|
|
+ return { state: "", config: "", worktree: "", directory: directory ?? "", home: "" }
|
|
|
+ return retry(() => sdk.path.get({ directory: directory ?? undefined }).then((result) => result.data!))
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
export const loadReferencesQuery = (
|
|
|
@@ -328,7 +333,6 @@ export async function bootstrapDirectory(input: {
|
|
|
readonly agent: AgentListApi
|
|
|
readonly command: CommandListApi
|
|
|
readonly mcp: McpApi
|
|
|
- readonly path: PathApi
|
|
|
readonly permission: PermissionApi
|
|
|
readonly project: ProjectApi
|
|
|
readonly question: QuestionApi
|
|
|
@@ -408,19 +412,20 @@ export async function bootstrapDirectory(input: {
|
|
|
!seededPath &&
|
|
|
(() =>
|
|
|
input.queryClient
|
|
|
- .ensureQueryData(loadPathQuery(input.scope, input.directory, input.api.path))
|
|
|
+ .ensureQueryData(loadPathQuery(input.scope, input.directory, input.sdk, input.protocol))
|
|
|
.then((data) => {
|
|
|
const next = projectID(data.directory ?? input.directory, input.global.project)
|
|
|
if (next) input.setStore("project", next)
|
|
|
})),
|
|
|
() =>
|
|
|
- retry(() =>
|
|
|
- input.api.vcs.get({ location: { directory: input.directory } }).then((result) => {
|
|
|
- const next = { branch: result.data.branch, default_branch: result.data.defaultBranch }
|
|
|
+ retry(async () => {
|
|
|
+ if ((await input.protocol) !== "v1") return
|
|
|
+ return input.sdk.vcs.get().then((result) => {
|
|
|
+ const next = { branch: result.data?.branch, default_branch: result.data?.default_branch }
|
|
|
input.setStore("vcs", next)
|
|
|
if (next) input.vcsCache.setStore("value", next)
|
|
|
- }),
|
|
|
- ),
|
|
|
+ })
|
|
|
+ }),
|
|
|
input.mcp &&
|
|
|
(() =>
|
|
|
loadCommands(input.directory, input.api.command, input.sdk, input.protocol).then((commands) =>
|