mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-22 03:45:23 +00:00
refactor(config): use effectful HttpApi group builder
Build the config providers HttpApi handler with an effectful group callback so the provider service is resolved once at layer construction time and the endpoint handler closes over the resulting service access.
This commit is contained in:
@@ -134,20 +134,27 @@ const Api = HttpApi.make("config")
|
||||
}),
|
||||
)
|
||||
|
||||
const providers = Effect.fn("ConfigHttpApi.providers")(function* () {
|
||||
const svc = yield* Provider.Service
|
||||
const all = mapValues(yield* svc.list(), (item) => item)
|
||||
return Schema.decodeUnknownSync(Providers)(
|
||||
JSON.parse(
|
||||
JSON.stringify({
|
||||
providers: Object.values(all),
|
||||
default: mapValues(all, (item) => Provider.sort(Object.values(item.models))[0].id),
|
||||
}),
|
||||
),
|
||||
)
|
||||
})
|
||||
const ConfigLive = HttpApiBuilder.group(
|
||||
Api,
|
||||
"config",
|
||||
Effect.fn("ConfigHttpApi.handlers")(function* (handlers) {
|
||||
const svc = yield* Provider.Service
|
||||
|
||||
const ConfigLive = HttpApiBuilder.group(Api, "config", (handlers) => handlers.handle("providers", providers))
|
||||
const providers = Effect.fn("ConfigHttpApi.providers")(function* () {
|
||||
const all = mapValues(yield* svc.list(), (item) => item)
|
||||
return Schema.decodeUnknownSync(Providers)(
|
||||
JSON.parse(
|
||||
JSON.stringify({
|
||||
providers: Object.values(all),
|
||||
default: mapValues(all, (item) => Provider.sort(Object.values(item.models))[0].id),
|
||||
}),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
return handlers.handle("providers", providers)
|
||||
}),
|
||||
).pipe(Layer.provide(Provider.defaultLayer))
|
||||
|
||||
const web = lazy(() =>
|
||||
HttpRouter.toWebHandler(
|
||||
|
||||
Reference in New Issue
Block a user