refactor(schema): extract public event definitions (#33579)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Schema } from "effect"
|
||||
import { HttpApi } from "effect/unstable/httpapi"
|
||||
import { EventV2 } from "@opencode-ai/core/event"
|
||||
import { EventManifest } from "@/event-manifest"
|
||||
import { Credential } from "@opencode-ai/core/credential"
|
||||
import { Integration } from "@opencode-ai/core/integration"
|
||||
import { SkillV2 } from "@opencode-ai/core/skill"
|
||||
@@ -24,15 +25,13 @@ import { SessionApi } from "./groups/session"
|
||||
import { SyncApi } from "./groups/sync"
|
||||
import { TuiApi } from "./groups/tui"
|
||||
import { WorkspaceApi } from "./groups/workspace"
|
||||
import { Api } from "@opencode-ai/server/api"
|
||||
// GlobalEventSchema snapshots the registry after event-producing groups register their variants.
|
||||
import { makeApi } from "@opencode-ai/server/api"
|
||||
import { GlobalApi } from "./groups/global"
|
||||
import { Authorization } from "./middleware/authorization"
|
||||
import { SchemaErrorMiddleware } from "./middleware/schema-error"
|
||||
|
||||
const EventSchema = Schema.Union([
|
||||
...EventV2.registry
|
||||
.values()
|
||||
...EventManifest.Latest.values()
|
||||
.map((definition) =>
|
||||
Schema.Struct({
|
||||
id: EventV2.ID,
|
||||
@@ -44,6 +43,8 @@ const EventSchema = Schema.Union([
|
||||
InstanceDisposed,
|
||||
]).annotate({ identifier: "Event" })
|
||||
|
||||
export const ServerApi = makeApi(EventManifest.Latest.values().toArray())
|
||||
|
||||
export const RootHttpApi = HttpApi.make("opencode-root")
|
||||
.addHttpApi(ControlApi)
|
||||
.addHttpApi(ControlPlaneApi)
|
||||
@@ -73,7 +74,7 @@ export const OpenCodeHttpApi = HttpApi.make("opencode")
|
||||
.addHttpApi(RootHttpApi)
|
||||
.addHttpApi(EventApi)
|
||||
.addHttpApi(InstanceHttpApi)
|
||||
.addHttpApi(Api)
|
||||
.addHttpApi(ServerApi)
|
||||
.addHttpApi(PtyConnectApi)
|
||||
.annotate(HttpApi.AdditionalSchemas, [
|
||||
EventSchema,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Config } from "@/config/config"
|
||||
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
||||
import { EventV2 } from "@opencode-ai/core/event"
|
||||
import { EventManifest } from "@/event-manifest"
|
||||
import { InstanceDisposed } from "@/server/event"
|
||||
import "@opencode-ai/core/account"
|
||||
import "@/server/event"
|
||||
@@ -13,8 +13,7 @@ const GlobalHealth = Schema.Struct({
|
||||
version: Schema.String,
|
||||
})
|
||||
|
||||
const SyncEventSchemas = EventV2.registry
|
||||
.values()
|
||||
const SyncEventSchemas = EventManifest.Latest.values()
|
||||
.flatMap((definition) => {
|
||||
if (!definition.durable) return []
|
||||
return [
|
||||
@@ -38,8 +37,7 @@ const GlobalEventSchema = Schema.Struct({
|
||||
project: Schema.optional(Schema.String),
|
||||
workspace: Schema.optional(Schema.String),
|
||||
payload: Schema.Union([
|
||||
...EventV2.registry
|
||||
.values()
|
||||
...EventManifest.Latest.values()
|
||||
.map((definition) =>
|
||||
Schema.Struct({ id: EventV2.ID, type: Schema.Literal(definition.type), properties: definition.data }),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user