2026-04-16 02:07:42 +00:00
|
|
|
import { ProviderAuth } from "@/provider/auth"
|
|
|
|
|
import { Effect, Layer } from "effect"
|
|
|
|
|
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
|
|
|
|
|
2026-04-16 03:02:48 +00:00
|
|
|
const root = "/provider"
|
2026-04-16 02:07:42 +00:00
|
|
|
|
|
|
|
|
export const ProviderApi = HttpApi.make("provider")
|
|
|
|
|
.add(
|
|
|
|
|
HttpApiGroup.make("provider")
|
|
|
|
|
.add(
|
|
|
|
|
HttpApiEndpoint.get("auth", `${root}/auth`, {
|
|
|
|
|
success: ProviderAuth.Methods,
|
|
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "provider.auth",
|
|
|
|
|
summary: "Get provider auth methods",
|
|
|
|
|
description: "Retrieve available authentication methods for all AI providers.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
title: "provider",
|
|
|
|
|
description: "Experimental HttpApi provider routes.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
title: "opencode experimental HttpApi",
|
|
|
|
|
version: "0.0.1",
|
|
|
|
|
description: "Experimental HttpApi surface for selected instance routes.",
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-16 03:02:48 +00:00
|
|
|
export const providerHandlers = Layer.unwrap(
|
2026-04-16 02:07:42 +00:00
|
|
|
Effect.gen(function* () {
|
|
|
|
|
const svc = yield* ProviderAuth.Service
|
|
|
|
|
|
|
|
|
|
const auth = Effect.fn("ProviderHttpApi.auth")(function* () {
|
|
|
|
|
return yield* svc.methods()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return HttpApiBuilder.group(ProviderApi, "provider", (handlers) => handlers.handle("auth", auth))
|
|
|
|
|
}),
|
|
|
|
|
).pipe(Layer.provide(ProviderAuth.defaultLayer))
|