location.ts 806 B

12345678910111213141516171819202122232425262728
  1. import { Context, Effect, Layer } from "effect"
  2. import { Info, Ref, response } from "@opencode-ai/schema/location"
  3. import { Project } from "./project"
  4. export * as Location from "./location"
  5. export { Info, Ref, response }
  6. export interface Interface extends Info {
  7. readonly vcs?: Project.Vcs
  8. }
  9. export class Service extends Context.Service<Service, Interface>()("@opencode/Location") {}
  10. export const layer = (ref: Ref) =>
  11. Layer.effect(
  12. Service,
  13. Effect.gen(function* () {
  14. const project = yield* Project.Service
  15. const resolved = yield* project.resolve(ref.directory)
  16. return Service.of({
  17. directory: ref.directory,
  18. workspaceID: ref.workspaceID,
  19. project: { id: resolved.id, directory: resolved.directory },
  20. vcs: resolved.vcs,
  21. })
  22. }),
  23. )