environment.ts 833 B

12345678910111213141516171819202122
  1. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  2. import { Environment } from "@opencode-ai/core/environment"
  3. import { Location } from "@opencode-ai/core/location"
  4. import { Effect, Layer } from "effect"
  5. export type EnvironmentFilesTransform = (files: Environment.Files) => Partial<Environment.Files>
  6. export function transformEnvironmentFiles(
  7. location: Layer.Layer<Location.Service>,
  8. transform: EnvironmentFilesTransform = () => ({}),
  9. ) {
  10. return Layer.effect(
  11. Environment.Service,
  12. Effect.gen(function* () {
  13. const current = yield* Environment.Service
  14. return Environment.Service.of({
  15. ...current,
  16. files: { ...current.files, ...transform(current.files) },
  17. })
  18. }),
  19. ).pipe(Layer.provide(AppNodeBuilder.build(Environment.node, [[Location.node, location]])))
  20. }