1+ import { Automation } from "@/automation/automation"
12import { WorkspaceRef } from "@/effect/instance-ref"
23import { InstanceStore } from "@/project/instance-store"
34import { Effect , Layer } from "effect"
@@ -23,12 +24,18 @@ function decode(input: string): string {
2324function provideInstanceContext < E > (
2425 effect : Effect . Effect < HttpServerResponse . HttpServerResponse , E > ,
2526 store : InstanceStore . Interface ,
27+ automation : Automation . Interface ,
2628) : Effect . Effect < HttpServerResponse . HttpServerResponse , E , WorkspaceRouteContext > {
2729 return Effect . gen ( function * ( ) {
2830 const route = yield * WorkspaceRouteContext
2931 return yield * store . provide (
3032 { directory : decode ( route . directory ) } ,
31- effect . pipe ( Effect . provideService ( WorkspaceRef , route . workspaceID ) ) ,
33+ Effect . gen ( function * ( ) {
34+ yield * automation
35+ . init ( )
36+ . pipe ( Effect . catchCause ( ( cause ) => Effect . logWarning ( "automation init failed" , { cause } ) ) )
37+ return yield * effect
38+ } ) . pipe ( Effect . provideService ( WorkspaceRef , route . workspaceID ) ) ,
3239 )
3340 } )
3441}
@@ -37,13 +44,15 @@ export const instanceContextLayer = Layer.effect(
3744 InstanceContextMiddleware ,
3845 Effect . gen ( function * ( ) {
3946 const store = yield * InstanceStore . Service
40- return InstanceContextMiddleware . of ( ( effect ) => provideInstanceContext ( effect , store ) )
47+ const automation = yield * Automation . Service
48+ return InstanceContextMiddleware . of ( ( effect ) => provideInstanceContext ( effect , store , automation ) )
4149 } ) ,
4250)
4351
4452export const instanceRouterMiddleware = HttpRouter . middleware ( ) (
4553 Effect . gen ( function * ( ) {
4654 const store = yield * InstanceStore . Service
47- return ( effect ) => provideInstanceContext ( effect , store )
55+ const automation = yield * Automation . Service
56+ return ( effect ) => provideInstanceContext ( effect , store , automation )
4857 } ) ,
4958)
0 commit comments