refactor(core): consolidate references (#31539)
This commit is contained in:
@@ -17,7 +17,6 @@ import { ProjectCopyApi } from "./groups/project-copy"
|
||||
import { ProviderApi } from "./groups/provider"
|
||||
import { PtyApi, PtyConnectApi } from "./groups/pty"
|
||||
import { QuestionApi } from "./groups/question"
|
||||
import { ReferenceApi } from "./groups/reference"
|
||||
import { SessionApi } from "./groups/session"
|
||||
import { SyncApi } from "./groups/sync"
|
||||
import { TuiApi } from "./groups/tui"
|
||||
@@ -61,7 +60,6 @@ export const InstanceHttpApi = HttpApi.make("opencode-instance")
|
||||
.addHttpApi(QuestionApi)
|
||||
.addHttpApi(PermissionApi)
|
||||
.addHttpApi(ProviderApi)
|
||||
.addHttpApi(ReferenceApi)
|
||||
.addHttpApi(SessionApi)
|
||||
.addHttpApi(SyncApi)
|
||||
.addHttpApi(TuiApi)
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import { Schema } from "effect"
|
||||
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
||||
import { Authorization } from "../middleware/authorization"
|
||||
import { InstanceContextMiddleware } from "../middleware/instance-context"
|
||||
import { WorkspaceRoutingMiddleware, WorkspaceRoutingQuery } from "../middleware/workspace-routing"
|
||||
import { described } from "./metadata"
|
||||
|
||||
export const ReferenceDescriptor = Schema.Union([
|
||||
Schema.Struct({
|
||||
name: Schema.String,
|
||||
kind: Schema.Literal("local"),
|
||||
path: Schema.String,
|
||||
}),
|
||||
Schema.Struct({
|
||||
name: Schema.String,
|
||||
kind: Schema.Literal("git"),
|
||||
repository: Schema.String,
|
||||
path: Schema.String,
|
||||
branch: Schema.optional(Schema.String),
|
||||
}),
|
||||
Schema.Struct({
|
||||
name: Schema.String,
|
||||
kind: Schema.Literal("invalid"),
|
||||
repository: Schema.optional(Schema.String),
|
||||
message: Schema.String,
|
||||
}),
|
||||
]).annotate({ identifier: "ReferenceDescriptor" })
|
||||
|
||||
export const ReferenceApi = HttpApi.make("reference")
|
||||
.add(
|
||||
HttpApiGroup.make("reference")
|
||||
.add(
|
||||
HttpApiEndpoint.get("list", "/reference", {
|
||||
query: WorkspaceRoutingQuery,
|
||||
success: described(Schema.Array(ReferenceDescriptor), "Resolved configured references"),
|
||||
}).annotateMerge(
|
||||
OpenApi.annotations({
|
||||
identifier: "reference.list",
|
||||
summary: "List configured references",
|
||||
description: "List configured references resolved in the current workspace.",
|
||||
}),
|
||||
),
|
||||
)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
title: "reference",
|
||||
description: "Configured reference routes.",
|
||||
}),
|
||||
)
|
||||
.middleware(InstanceContextMiddleware)
|
||||
.middleware(WorkspaceRoutingMiddleware)
|
||||
.middleware(Authorization),
|
||||
)
|
||||
.annotateMerge(
|
||||
OpenApi.annotations({
|
||||
title: "opencode experimental HttpApi",
|
||||
version: "0.0.1",
|
||||
description: "Experimental HttpApi surface for selected instance routes.",
|
||||
}),
|
||||
)
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Reference } from "@/reference/reference"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiBuilder } from "effect/unstable/httpapi"
|
||||
import { InstanceHttpApi } from "../api"
|
||||
|
||||
export const referenceHandlers = HttpApiBuilder.group(InstanceHttpApi, "reference", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
const reference = yield* Reference.Service
|
||||
|
||||
return handlers.handle("list", () =>
|
||||
reference.list().pipe(
|
||||
Effect.map((references) =>
|
||||
references.map((item) => {
|
||||
if (item.kind !== "git") return item
|
||||
return {
|
||||
name: item.name,
|
||||
kind: item.kind,
|
||||
repository: item.repository,
|
||||
path: item.path,
|
||||
...(item.branch !== undefined ? { branch: item.branch } : {}),
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
}),
|
||||
)
|
||||
@@ -35,7 +35,6 @@ import { ModelsDev } from "@opencode-ai/core/models-dev"
|
||||
import { Provider } from "@/provider/provider"
|
||||
import { PtyTicket } from "@opencode-ai/core/pty/ticket"
|
||||
import { Question } from "@/question"
|
||||
import { Reference } from "@/reference/reference"
|
||||
import { Session } from "@/session/session"
|
||||
import { SessionCompaction } from "@/session/compaction"
|
||||
import { LLM } from "@/session/llm"
|
||||
@@ -86,7 +85,6 @@ import { projectCopyHandlers } from "./handlers/project-copy"
|
||||
import { providerHandlers } from "./handlers/provider"
|
||||
import { ptyConnectHandlers, ptyHandlers } from "./handlers/pty"
|
||||
import { questionHandlers } from "./handlers/question"
|
||||
import { referenceHandlers } from "./handlers/reference"
|
||||
import { sessionHandlers } from "./handlers/session"
|
||||
import { syncHandlers } from "./handlers/sync"
|
||||
import { tuiHandlers } from "./handlers/tui"
|
||||
@@ -149,7 +147,6 @@ const instanceApiRoutes = HttpApiBuilder.layer(InstanceHttpApi).pipe(
|
||||
projectCopyHandlers,
|
||||
ptyHandlers,
|
||||
questionHandlers,
|
||||
referenceHandlers,
|
||||
permissionHandlers,
|
||||
providerHandlers,
|
||||
sessionHandlers,
|
||||
@@ -237,7 +234,6 @@ export function createRoutes(
|
||||
Provider.defaultLayer,
|
||||
PtyTicket.defaultLayer,
|
||||
Question.defaultLayer,
|
||||
Reference.defaultLayer,
|
||||
Ripgrep.defaultLayer,
|
||||
RuntimeFlags.defaultLayer,
|
||||
Session.defaultLayer,
|
||||
|
||||
Reference in New Issue
Block a user