diff options
| author | Dax Raad <[email protected]> | 2025-05-29 11:32:55 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-29 11:32:55 -0400 |
| commit | 6f604bd0f999a5df4ed6a57aef524f0dcf9eb356 (patch) | |
| tree | efb732ba56257a8f02edea604424821c9b687cf3 /js | |
| parent | 42c1cd6a852be5295aedc5c19e1a2aef45a464e3 (diff) | |
| download | opencode-6f604bd0f999a5df4ed6a57aef524f0dcf9eb356.tar.gz opencode-6f604bd0f999a5df4ed6a57aef524f0dcf9eb356.zip | |
remove secondary codegen
Diffstat (limited to 'js')
| -rw-r--r-- | js/src/bus/index.ts | 29 | ||||
| -rw-r--r-- | js/src/index.ts | 4 | ||||
| -rw-r--r-- | js/src/lsp/client.ts | 2 | ||||
| -rw-r--r-- | js/src/server/server.ts | 54 | ||||
| -rw-r--r-- | js/src/session/message.ts | 7 | ||||
| -rw-r--r-- | js/src/session/session.ts | 5 | ||||
| -rw-r--r-- | js/src/storage/storage.ts | 2 |
7 files changed, 62 insertions, 41 deletions
diff --git a/js/src/bus/index.ts b/js/src/bus/index.ts index 15d2b1107..cf5101b67 100644 --- a/js/src/bus/index.ts +++ b/js/src/bus/index.ts @@ -1,4 +1,4 @@ -import { z, type ZodType } from "zod/v4"; +import { z, type ZodType } from "zod"; import { App } from "../app"; import { Log } from "../util/log"; @@ -30,16 +30,23 @@ export namespace Bus { return result; } - export function specs() { - const children = {} as any; - for (const [type, def] of registry.entries()) { - children["event." + def.type] = def.properties; - } - const result = z.toJSONSchema(z.object(children)) as any; - result.definitions = result.properties; - delete result.properties; - delete result.required; - return result; + export function payloads() { + return z.discriminatedUnion( + "type", + registry + .entries() + .map(([type, def]) => + z + .object({ + type: z.literal(type), + properties: def.properties, + }) + .openapi({ + ref: "Event" + "." + def.type, + }), + ) + .toArray() as any, + ); } export function publish<Definition extends EventDefinition>( diff --git a/js/src/index.ts b/js/src/index.ts index 380ea64cd..ddea15e91 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -28,10 +28,6 @@ cli.command("generate", "Generate OpenAPI and event specs").action(async () => { path.join(dir, "openapi.json"), JSON.stringify(specs, null, 2), ); - await Bun.write( - path.join(dir, "event.json"), - JSON.stringify(Bus.specs(), null, 2), - ); }); cli diff --git a/js/src/lsp/client.ts b/js/src/lsp/client.ts index fda77948a..cb8bdad2d 100644 --- a/js/src/lsp/client.ts +++ b/js/src/lsp/client.ts @@ -10,7 +10,7 @@ import { App } from "../app"; import { Log } from "../util/log"; import { LANGUAGE_EXTENSIONS } from "./language"; import { Bus } from "../bus"; -import z from "zod/v4"; +import z from "zod"; export namespace LSPClient { const log = Log.create({ service: "lsp.client" }); diff --git a/js/src/server/server.ts b/js/src/server/server.ts index f56c87283..98b2cf5cb 100644 --- a/js/src/server/server.ts +++ b/js/src/server/server.ts @@ -43,26 +43,46 @@ export namespace Server { }, }), ) - .get("/event", async (c) => { - log.info("event connected"); - return streamSSE(c, async (stream) => { - stream.writeSSE({ - data: JSON.stringify({}), - }); - const unsub = Bus.subscribeAll(async (event) => { - await stream.writeSSE({ - data: JSON.stringify(event), + .get( + "/event", + describeRoute({ + description: "Get events", + responses: { + 200: { + description: "Event stream", + content: { + "application/json": { + schema: resolver( + Bus.payloads().openapi({ + ref: "Event", + }), + ), + }, + }, + }, + }, + }), + async (c) => { + log.info("event connected"); + return streamSSE(c, async (stream) => { + stream.writeSSE({ + data: JSON.stringify({}), }); - }); - await new Promise<void>((resolve) => { - stream.onAbort(() => { - unsub(); - resolve(); - log.info("event disconnected"); + const unsub = Bus.subscribeAll(async (event) => { + await stream.writeSSE({ + data: JSON.stringify(event), + }); + }); + await new Promise<void>((resolve) => { + stream.onAbort(() => { + unsub(); + resolve(); + log.info("event disconnected"); + }); }); }); - }); - }) + }, + ) .post( "/session_create", describeRoute({ diff --git a/js/src/session/message.ts b/js/src/session/message.ts index 91bcd19b4..c944fa640 100644 --- a/js/src/session/message.ts +++ b/js/src/session/message.ts @@ -1,14 +1,13 @@ import z from "zod"; -import { z as zv4 } from "zod/v4"; import { Bus } from "../bus"; export namespace Message { export const Event = { Updated: Bus.event( "message.updated", - zv4.object({ - sessionID: zv4.string(), - messageID: zv4.string(), + z.object({ + sessionID: z.string(), + messageID: z.string(), }), ), }; diff --git a/js/src/session/session.ts b/js/src/session/session.ts index a876976bd..1cf89de19 100644 --- a/js/src/session/session.ts +++ b/js/src/session/session.ts @@ -11,7 +11,6 @@ import { streamText, } from "ai"; import { z } from "zod"; -import { z as zv4 } from "zod/v4"; import * as tools from "../tool"; import { Decimal } from "decimal.js"; @@ -35,8 +34,8 @@ export namespace Session { export const Event = { Updated: Bus.event( "session.updated", - zv4.object({ - sessionID: zv4.string(), + z.object({ + sessionID: z.string(), }), ), }; diff --git a/js/src/storage/storage.ts b/js/src/storage/storage.ts index 3b4c63cb8..85fa26be6 100644 --- a/js/src/storage/storage.ts +++ b/js/src/storage/storage.ts @@ -5,7 +5,7 @@ import { Log } from "../util/log"; import { App } from "../app"; import { AppPath } from "../app/path"; import { Bus } from "../bus"; -import z from "zod/v4"; +import z from "zod"; export namespace Storage { const log = Log.create({ service: "storage" }); |
