feat: bridge permission and provider auth routes behind OPENCODE_EXPERIMENTAL_HTTPAPI (#22736)
This commit is contained in:
@@ -3,7 +3,7 @@ import { PermissionID } from "@/permission/schema"
|
||||
import { Effect, Layer, Schema } from "effect"
|
||||
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
||||
|
||||
const root = "/experimental/httpapi/permission"
|
||||
const root = "/permission"
|
||||
|
||||
export const PermissionApi = HttpApi.make("permission")
|
||||
.add(
|
||||
@@ -45,7 +45,7 @@ export const PermissionApi = HttpApi.make("permission")
|
||||
}),
|
||||
)
|
||||
|
||||
export const PermissionLive = Layer.unwrap(
|
||||
export const permissionHandlers = Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
const svc = yield* Permission.Service
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ProviderAuth } from "@/provider/auth"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
||||
|
||||
const root = "/experimental/httpapi/provider"
|
||||
const root = "/provider"
|
||||
|
||||
export const ProviderApi = HttpApi.make("provider")
|
||||
.add(
|
||||
@@ -33,7 +33,7 @@ export const ProviderApi = HttpApi.make("provider")
|
||||
}),
|
||||
)
|
||||
|
||||
export const ProviderLive = Layer.unwrap(
|
||||
export const providerHandlers = Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
const svc = yield* ProviderAuth.Service
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export const QuestionApi = HttpApi.make("question")
|
||||
}),
|
||||
)
|
||||
|
||||
export const QuestionLive = Layer.unwrap(
|
||||
export const questionHandlers = Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
const svc = yield* Question.Service
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import { InstanceBootstrap } from "@/project/bootstrap"
|
||||
import { Instance } from "@/project/instance"
|
||||
import { lazy } from "@/util/lazy"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { PermissionApi, PermissionLive } from "./permission"
|
||||
import { ProviderApi, ProviderLive } from "./provider"
|
||||
import { QuestionApi, QuestionLive } from "./question"
|
||||
import { PermissionApi, permissionHandlers } from "./permission"
|
||||
import { ProviderApi, providerHandlers } from "./provider"
|
||||
import { QuestionApi, questionHandlers } from "./question"
|
||||
|
||||
const Query = Schema.Struct({
|
||||
directory: Schema.optional(Schema.String),
|
||||
@@ -111,13 +111,9 @@ export namespace ExperimentalHttpApiServer {
|
||||
const ProviderSecured = ProviderApi.middleware(Authorization)
|
||||
|
||||
export const routes = Layer.mergeAll(
|
||||
HttpApiBuilder.layer(QuestionSecured).pipe(Layer.provide(QuestionLive)),
|
||||
HttpApiBuilder.layer(PermissionSecured, { openapiPath: "/experimental/httpapi/permission/doc" }).pipe(
|
||||
Layer.provide(PermissionLive),
|
||||
),
|
||||
HttpApiBuilder.layer(ProviderSecured, { openapiPath: "/experimental/httpapi/provider/doc" }).pipe(
|
||||
Layer.provide(ProviderLive),
|
||||
),
|
||||
HttpApiBuilder.layer(QuestionSecured).pipe(Layer.provide(questionHandlers)),
|
||||
HttpApiBuilder.layer(PermissionSecured).pipe(Layer.provide(permissionHandlers)),
|
||||
HttpApiBuilder.layer(ProviderSecured).pipe(Layer.provide(providerHandlers)),
|
||||
).pipe(
|
||||
Layer.provide(auth),
|
||||
Layer.provide(normalize),
|
||||
|
||||
@@ -41,7 +41,12 @@ export const InstanceRoutes = (upgrade: UpgradeWebSocket): Hono => {
|
||||
|
||||
if (Flag.OPENCODE_EXPERIMENTAL_HTTPAPI) {
|
||||
const handler = ExperimentalHttpApiServer.webHandler().handler
|
||||
app.all("/question", (c) => handler(c.req.raw)).all("/question/*", (c) => handler(c.req.raw))
|
||||
app
|
||||
.all("/question", (c) => handler(c.req.raw))
|
||||
.all("/question/*", (c) => handler(c.req.raw))
|
||||
.all("/permission", (c) => handler(c.req.raw))
|
||||
.all("/permission/*", (c) => handler(c.req.raw))
|
||||
.all("/provider/auth", (c) => handler(c.req.raw))
|
||||
}
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user