effect: add RuntimeFlags service (#27181)
This commit is contained in:
27
packages/opencode/src/effect/runtime-flags.ts
Normal file
27
packages/opencode/src/effect/runtime-flags.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Config, ConfigProvider, Context, Effect, Layer } from "effect"
|
||||
import { ConfigService } from "@/effect/config-service"
|
||||
|
||||
export class Service extends ConfigService.Service<Service>()("@opencode/RuntimeFlags", {
|
||||
pure: Config.boolean("OPENCODE_PURE").pipe(Config.withDefault(false)),
|
||||
disableDefaultPlugins: Config.boolean("OPENCODE_DISABLE_DEFAULT_PLUGINS").pipe(Config.withDefault(false)),
|
||||
}) {}
|
||||
|
||||
export type Info = Context.Service.Shape<typeof Service>
|
||||
|
||||
const emptyConfigLayer = Service.defaultLayer.pipe(
|
||||
Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))),
|
||||
Layer.orDie,
|
||||
)
|
||||
|
||||
export const layer = (overrides: Partial<Info> = {}) =>
|
||||
Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const flags = yield* Service
|
||||
return Service.of({ ...flags, ...overrides })
|
||||
}),
|
||||
).pipe(Layer.provide(emptyConfigLayer))
|
||||
|
||||
export const defaultLayer = Service.defaultLayer.pipe(Layer.orDie)
|
||||
|
||||
export * as RuntimeFlags from "./runtime-flags"
|
||||
Reference in New Issue
Block a user