Refactor event HTTP API route modules (#27441)
This commit is contained in:
@@ -4,7 +4,7 @@ import { BusEvent } from "@/bus/bus-event"
|
|||||||
import { SyncEvent } from "@/sync"
|
import { SyncEvent } from "@/sync"
|
||||||
import { ConfigApi } from "./groups/config"
|
import { ConfigApi } from "./groups/config"
|
||||||
import { ControlApi } from "./groups/control"
|
import { ControlApi } from "./groups/control"
|
||||||
import { EventApi } from "./event"
|
import { EventApi } from "./groups/event"
|
||||||
import { ExperimentalApi } from "./groups/experimental"
|
import { ExperimentalApi } from "./groups/experimental"
|
||||||
import { FileApi } from "./groups/file"
|
import { FileApi } from "./groups/file"
|
||||||
import { GlobalApi } from "./groups/global"
|
import { GlobalApi } from "./groups/global"
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { Schema } from "effect"
|
||||||
|
import { HttpApi, HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
|
||||||
|
import { WorkspaceRoutingQuery } from "../middleware/workspace-routing"
|
||||||
|
|
||||||
|
export const EventPaths = {
|
||||||
|
event: "/event",
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export const EventApi = HttpApi.make("event").add(
|
||||||
|
HttpApiGroup.make("event")
|
||||||
|
.add(
|
||||||
|
HttpApiEndpoint.get("subscribe", EventPaths.event, {
|
||||||
|
query: WorkspaceRoutingQuery,
|
||||||
|
success: Schema.String.pipe(HttpApiSchema.asText({ contentType: "text/event-stream" })),
|
||||||
|
}).annotateMerge(
|
||||||
|
OpenApi.annotations({
|
||||||
|
identifier: "event.subscribe",
|
||||||
|
summary: "Subscribe to events",
|
||||||
|
description: "Get events",
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.annotateMerge(OpenApi.annotations({ title: "event", description: "Instance event stream route." })),
|
||||||
|
)
|
||||||
+3
-24
@@ -1,35 +1,14 @@
|
|||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { Effect, Schema } from "effect"
|
import { Effect } from "effect"
|
||||||
import * as Stream from "effect/Stream"
|
import * as Stream from "effect/Stream"
|
||||||
import { HttpServerResponse } from "effect/unstable/http"
|
import { HttpServerResponse } from "effect/unstable/http"
|
||||||
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
|
import { HttpApiBuilder } from "effect/unstable/httpapi"
|
||||||
import * as Sse from "effect/unstable/encoding/Sse"
|
import * as Sse from "effect/unstable/encoding/Sse"
|
||||||
import { WorkspaceRoutingQuery } from "./middleware/workspace-routing"
|
import { EventApi } from "../groups/event"
|
||||||
|
|
||||||
const log = Log.create({ service: "server" })
|
const log = Log.create({ service: "server" })
|
||||||
|
|
||||||
export const EventPaths = {
|
|
||||||
event: "/event",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export const EventApi = HttpApi.make("event").add(
|
|
||||||
HttpApiGroup.make("event")
|
|
||||||
.add(
|
|
||||||
HttpApiEndpoint.get("subscribe", EventPaths.event, {
|
|
||||||
query: WorkspaceRoutingQuery,
|
|
||||||
success: Schema.String.pipe(HttpApiSchema.asText({ contentType: "text/event-stream" })),
|
|
||||||
}).annotateMerge(
|
|
||||||
OpenApi.annotations({
|
|
||||||
identifier: "event.subscribe",
|
|
||||||
summary: "Subscribe to events",
|
|
||||||
description: "Get events",
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.annotateMerge(OpenApi.annotations({ title: "event", description: "Instance event stream route." })),
|
|
||||||
)
|
|
||||||
|
|
||||||
function eventData(data: unknown): Sse.Event {
|
function eventData(data: unknown): Sse.Event {
|
||||||
return {
|
return {
|
||||||
_tag: "Event",
|
_tag: "Event",
|
||||||
@@ -58,7 +58,8 @@ import { ServerAuth } from "@/server/auth"
|
|||||||
import { InstanceHttpApi, RootHttpApi } from "./api"
|
import { InstanceHttpApi, RootHttpApi } from "./api"
|
||||||
import { PublicApi } from "./public"
|
import { PublicApi } from "./public"
|
||||||
import { authorizationLayer, authorizationRouterMiddleware } from "./middleware/authorization"
|
import { authorizationLayer, authorizationRouterMiddleware } from "./middleware/authorization"
|
||||||
import { EventApi, eventHandlers } from "./event"
|
import { EventApi } from "./groups/event"
|
||||||
|
import { eventHandlers } from "./handlers/event"
|
||||||
import { configHandlers } from "./handlers/config"
|
import { configHandlers } from "./handlers/config"
|
||||||
import { controlHandlers } from "./handlers/control"
|
import { controlHandlers } from "./handlers/control"
|
||||||
import { experimentalHandlers } from "./handlers/experimental"
|
import { experimentalHandlers } from "./handlers/experimental"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"
|
|||||||
import { Bus } from "../../src/bus"
|
import { Bus } from "../../src/bus"
|
||||||
import { Instance } from "../../src/project/instance"
|
import { Instance } from "../../src/project/instance"
|
||||||
import { Server } from "../../src/server/server"
|
import { Server } from "../../src/server/server"
|
||||||
import { EventPaths } from "../../src/server/routes/instance/httpapi/event"
|
import { EventPaths } from "../../src/server/routes/instance/httpapi/groups/event"
|
||||||
import { Event as ServerEvent } from "../../src/server/event"
|
import { Event as ServerEvent } from "../../src/server/event"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test"
|
|||||||
import { ConfigProvider, Layer } from "effect"
|
import { ConfigProvider, Layer } from "effect"
|
||||||
import { HttpRouter } from "effect/unstable/http"
|
import { HttpRouter } from "effect/unstable/http"
|
||||||
import { Instance } from "../../src/project/instance"
|
import { Instance } from "../../src/project/instance"
|
||||||
import { EventPaths } from "../../src/server/routes/instance/httpapi/event"
|
import { EventPaths } from "../../src/server/routes/instance/httpapi/groups/event"
|
||||||
import { PtyPaths } from "../../src/server/routes/instance/httpapi/groups/pty"
|
import { PtyPaths } from "../../src/server/routes/instance/httpapi/groups/pty"
|
||||||
import { ExperimentalHttpApiServer } from "../../src/server/routes/instance/httpapi/server"
|
import { ExperimentalHttpApiServer } from "../../src/server/routes/instance/httpapi/server"
|
||||||
import { PtyID } from "../../src/pty/schema"
|
import { PtyID } from "../../src/pty/schema"
|
||||||
|
|||||||
Reference in New Issue
Block a user