mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-25 03:34:22 +01:00
remove secondary codegen
This commit is contained in:
@@ -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>(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" });
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -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" });
|
||||
|
||||
Reference in New Issue
Block a user