refactor: unwrap ExperimentalHttpApiServer namespace + self-reexport (#22979)

This commit is contained in:
Kit Langton
2026-04-17 01:01:24 +00:00
committed by GitHub
parent 54046e0b98
commit 5022895e2b
@@ -25,29 +25,28 @@ const Headers = Schema.Struct({
"x-opencode-directory": Schema.optional(Schema.String),
})
export namespace ExperimentalHttpApiServer {
function decode(input: string) {
function decode(input: string) {
try {
return decodeURIComponent(input)
} catch {
return input
}
}
}
class Unauthorized extends Schema.TaggedErrorClass<Unauthorized>()(
class Unauthorized extends Schema.TaggedErrorClass<Unauthorized>()(
"Unauthorized",
{ message: Schema.String },
{ httpApiStatus: 401 },
) {}
) {}
class Authorization extends HttpApiMiddleware.Service<Authorization>()("@opencode/ExperimentalHttpApiAuthorization", {
class Authorization extends HttpApiMiddleware.Service<Authorization>()("@opencode/ExperimentalHttpApiAuthorization", {
error: Unauthorized,
security: {
basic: HttpApiSecurity.basic,
},
}) {}
}) {}
const normalize = HttpRouter.middleware()(
const normalize = HttpRouter.middleware()(
Effect.gen(function* () {
return (effect) =>
Effect.gen(function* () {
@@ -63,9 +62,9 @@ export namespace ExperimentalHttpApiServer {
return yield* effect.pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, next))
})
}),
).layer
).layer
const auth = Layer.succeed(
const auth = Layer.succeed(
Authorization,
Authorization.of({
basic: (effect, { credential }) =>
@@ -82,9 +81,9 @@ export namespace ExperimentalHttpApiServer {
return yield* effect
}),
}),
)
)
const instance = HttpRouter.middleware()(
const instance = HttpRouter.middleware()(
Effect.gen(function* () {
return (effect) =>
Effect.gen(function* () {
@@ -104,27 +103,28 @@ export namespace ExperimentalHttpApiServer {
return yield* next.pipe(Effect.provideService(InstanceRef, ctx))
})
}),
).layer
).layer
const QuestionSecured = QuestionApi.middleware(Authorization)
const PermissionSecured = PermissionApi.middleware(Authorization)
const ProviderSecured = ProviderApi.middleware(Authorization)
const QuestionSecured = QuestionApi.middleware(Authorization)
const PermissionSecured = PermissionApi.middleware(Authorization)
const ProviderSecured = ProviderApi.middleware(Authorization)
export const routes = Layer.mergeAll(
export const routes = Layer.mergeAll(
HttpApiBuilder.layer(QuestionSecured).pipe(Layer.provide(questionHandlers)),
HttpApiBuilder.layer(PermissionSecured).pipe(Layer.provide(permissionHandlers)),
HttpApiBuilder.layer(ProviderSecured).pipe(Layer.provide(providerHandlers)),
).pipe(
).pipe(
Layer.provide(auth),
Layer.provide(normalize),
Layer.provide(instance),
Layer.provide(HttpServer.layerServices),
Layer.provideMerge(Observability.layer),
)
)
export const webHandler = lazy(() =>
export const webHandler = lazy(() =>
HttpRouter.toWebHandler(routes, {
memoMap,
}),
)
}
)
export * as ExperimentalHttpApiServer from "./server"