8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
// Opencode publish boundary for core events. Attach routed instance location
|
|
// so direct EventV2 consumers can isolate directory/workspace streams.
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { InstanceRef, WorkspaceRef } from "@/effect/instance-ref"
|
|
import { GlobalBus } from "@/bus/global"
|
|
import { EventV2 } from "@opencode-ai/core/event"
|
|
import { Location } from "@opencode-ai/core/location"
|
|
import { Project } from "@opencode-ai/core/project"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { Context, Effect, Layer } from "effect"
|
|
|
|
export class Service extends Context.Service<Service, EventV2.Interface>()("@opencode/EventV2Bridge") {}
|
|
|
|
const layer = Layer.effect(
|
|
Service,
|
|
Effect.gen(function* () {
|
|
const events = yield* EventV2.Service
|
|
|
|
const publish: EventV2.Interface["publish"] = (definition, data, options) =>
|
|
Effect.gen(function* () {
|
|
if (options?.location) return yield* events.publish(definition, data, options)
|
|
const ctx = yield* InstanceRef
|
|
if (!ctx) return yield* events.publish(definition, data, options)
|
|
const workspaceID = yield* WorkspaceRef
|
|
return yield* events.publish(definition, data, {
|
|
...options,
|
|
location: new Location.Info({
|
|
directory: AbsolutePath.make(ctx.directory),
|
|
...(workspaceID ? { workspaceID } : {}),
|
|
project: { id: Project.ID.make(ctx.project.id), directory: AbsolutePath.make(ctx.worktree) },
|
|
}),
|
|
})
|
|
})
|
|
|
|
const unsubscribe = yield* events.listen((event) =>
|
|
Effect.gen(function* () {
|
|
const ctx = yield* InstanceRef
|
|
const workspaceID = (yield* WorkspaceRef) ?? event.location?.workspaceID
|
|
GlobalBus.emit("event", {
|
|
directory: event.location?.directory ?? ctx?.directory,
|
|
project: ctx?.project.id,
|
|
workspace: workspaceID,
|
|
payload: { id: event.id, type: event.type, properties: event.data },
|
|
})
|
|
if (event.durable === undefined) return
|
|
GlobalBus.emit("event", {
|
|
directory: event.location?.directory ?? ctx?.directory,
|
|
project: ctx?.project.id,
|
|
workspace: workspaceID,
|
|
payload: {
|
|
type: "sync",
|
|
syncEvent: {
|
|
id: event.id,
|
|
type: EventV2.versionedType(event.type, event.durable.version),
|
|
seq: event.durable.seq,
|
|
aggregateID: event.durable.aggregateID,
|
|
data: event.data,
|
|
},
|
|
},
|
|
})
|
|
}),
|
|
)
|
|
yield* Effect.addFinalizer(() => unsubscribe)
|
|
|
|
return Service.of({ ...events, publish })
|
|
}),
|
|
)
|
|
|
|
export const node = LayerNode.make({ service: Service, layer: layer, deps: [EventV2.node] })
|
|
|
|
export * as EventV2Bridge from "./event-v2-bridge"
|