job.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { LayerNode } from "@opencode-ai/core/effect/layer-node"
  2. import { BackgroundJob as CoreBackgroundJob } from "@opencode-ai/core/background-job"
  3. import { InstanceState } from "@/effect/instance-state"
  4. import { Effect, Layer } from "effect"
  5. export {
  6. Service,
  7. type ExtendInput,
  8. type Info,
  9. type Interface,
  10. type StartInput,
  11. type Status,
  12. type WaitInput,
  13. type WaitResult,
  14. } from "@opencode-ai/core/background-job"
  15. /** Keeps the legacy service instance-scoped while sharing the core registry engine. */
  16. export const layer = Layer.effect(
  17. CoreBackgroundJob.Service,
  18. Effect.gen(function* () {
  19. const state = yield* InstanceState.make(() => CoreBackgroundJob.make)
  20. return CoreBackgroundJob.Service.of({
  21. list: () => InstanceState.useEffect(state, (jobs) => jobs.list()),
  22. get: (id) => InstanceState.useEffect(state, (jobs) => jobs.get(id)),
  23. start: (input) => InstanceState.useEffect(state, (jobs) => jobs.start(input)),
  24. extend: (input) => InstanceState.useEffect(state, (jobs) => jobs.extend(input)),
  25. wait: (input) => InstanceState.useEffect(state, (jobs) => jobs.wait(input)),
  26. waitForPromotion: (id) => InstanceState.useEffect(state, (jobs) => jobs.waitForPromotion(id)),
  27. promote: (id) => InstanceState.useEffect(state, (jobs) => jobs.promote(id)),
  28. cancel: (id) => InstanceState.useEffect(state, (jobs) => jobs.cancel(id)),
  29. })
  30. }),
  31. )
  32. export const defaultLayer = layer
  33. export const node = LayerNode.make({ service: CoreBackgroundJob.Service, layer, deps: [] })
  34. export * as BackgroundJob from "./job"