fix(sdk): preserve generated event contracts

This commit is contained in:
Dax Raad
2026-05-31 03:18:43 -04:00
parent 1afa9e32c9
commit 25edeaf473
7 changed files with 2496 additions and 2150 deletions
@@ -1,6 +1,6 @@
import { Config } from "@/config/config"
import { EventV2 } from "@opencode-ai/core/event"
import "@/server/event"
import { InstanceDisposed } from "@/server/event"
import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
import { described } from "./metadata"
@@ -10,18 +10,37 @@ const GlobalHealth = Schema.Struct({
version: Schema.String,
})
const SyncEventSchemas = EventV2.registry
.values()
.flatMap((definition) => {
if (!definition.sync) return []
return [
Schema.Struct({
type: Schema.Literal("sync"),
name: Schema.Literal(EventV2.versionedType(definition.type, definition.sync.version)),
id: Schema.String,
seq: Schema.Finite,
aggregateID: Schema.Literal(definition.sync.aggregate),
data: definition.data,
}).annotate({ identifier: `SyncEvent.${definition.type}` }),
]
})
.toArray()
const GlobalEventSchema = Schema.Struct({
directory: Schema.String,
project: Schema.optional(Schema.String),
workspace: Schema.optional(Schema.String),
payload: Schema.Union(
EventV2.registry
payload: Schema.Union([
...EventV2.registry
.values()
.map((definition) =>
Schema.Struct({ id: Schema.String, type: Schema.Literal(definition.type), properties: definition.data }),
)
.toArray(),
),
InstanceDisposed,
...SyncEventSchemas,
]),
}).annotate({ identifier: "GlobalEvent" })
export const GlobalUpgradeInput = Schema.Struct({