remove secondary codegen

This commit is contained in:
Dax Raad
2025-05-29 11:32:55 -04:00
parent 42c1cd6a85
commit 6f604bd0f9
14 changed files with 512 additions and 246 deletions

View File

@@ -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>(

View File

@@ -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

View File

@@ -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" });

View File

@@ -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({}),
});
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");
});
});
});
await new Promise<void>((resolve) => {
stream.onAbort(() => {
unsub();
resolve();
log.info("event disconnected");
});
});
});
})
},
)
.post(
"/session_create",
describeRoute({

View File

@@ -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(),
}),
),
};

View File

@@ -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(),
}),
),
};

View File

@@ -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" });