From b13a2d712a40721ef1799ef03431e9468246e559 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Mon, 22 Jun 2026 08:20:39 -0400 Subject: [PATCH] fix(server): isolate event schema types --- packages/core/src/event.ts | 29 +++++++++-------------------- packages/server/src/groups/event.ts | 14 +++++++++++--- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/core/src/event.ts b/packages/core/src/event.ts index 47f9753b9..32aaeae69 100644 --- a/packages/core/src/event.ts +++ b/packages/core/src/event.ts @@ -19,11 +19,6 @@ export const ID = Schema.String.check(Schema.isStartsWith("evt_")).pipe( ) export type ID = typeof ID.Type -type ServiceFreeSchema = Schema.Top & { - readonly DecodingServices: never - readonly EncodingServices: never -} - export type Definition = { readonly type: Type readonly durable?: { @@ -35,15 +30,6 @@ export type Definition = Schema.Schema.Type -export const Payload = Schema.Struct({ - id: ID, - metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)), - type: Schema.String, - durable: Schema.optional(Schema.Struct({ aggregateID: Schema.String, seq: Schema.Int, version: Schema.Int })), - location: Schema.optional(Location.Ref), - data: Schema.Unknown, -}) - export type Payload = { readonly id: ID readonly type: D["type"] @@ -80,10 +66,10 @@ export function versionedType(type: string, version: number) { return `${type}.${version}` } -export const registry = new Map>() -const durableRegistry = new Map>() +export const registry = new Map() +const durableRegistry = new Map() -export function define>(input: { +export function define(input: { readonly type: Type readonly durable?: { readonly version: number @@ -92,13 +78,16 @@ export function define>>> & Definition> { const Data = Schema.Struct(input.schema) - const Event = Schema.Struct({ - ...Payload.fields, + const Payload = Schema.Struct({ + id: ID, + metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)), type: Schema.Literal(input.type), + durable: Schema.optional(Schema.Struct({ aggregateID: Schema.String, seq: Schema.Number, version: Schema.Number })), + location: Schema.optional(Location.Ref), data: Data, }).annotate({ identifier: input.type }) - const definition = Object.assign(Event, { + const definition = Object.assign(Payload, { type: input.type, ...(input.durable === undefined ? {} : { durable: input.durable }), data: Data, diff --git a/packages/server/src/groups/event.ts b/packages/server/src/groups/event.ts index a7f912547..fffa0250d 100644 --- a/packages/server/src/groups/event.ts +++ b/packages/server/src/groups/event.ts @@ -1,17 +1,25 @@ import { EventV2 } from "@opencode-ai/core/event" +import { Location } from "@opencode-ai/core/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" +const fields = { + id: EventV2.ID, + metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)), + durable: Schema.optional(Schema.Struct({ aggregateID: Schema.String, seq: Schema.Int, version: Schema.Int })), + location: Schema.optional(Location.Ref), +} + const Event = Schema.Union([ ...EventV2.definitions().map((definition) => Schema.Struct({ - ...EventV2.Payload.fields, + ...fields, type: Schema.Literal(definition.type), - data: definition.data, + data: definition.data as Schema.Struct<{}>, }).annotate({ identifier: `V2Event.${definition.type}` }), ), Schema.Struct({ - ...EventV2.Payload.fields, + ...fields, type: Schema.Literal("server.connected"), data: Schema.Struct({}), }).annotate({ identifier: "V2Event.server.connected" }),