mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
event
This commit is contained in:
@@ -30,17 +30,6 @@ export namespace Bus {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function payloads() {
|
||||
return registry
|
||||
.entries()
|
||||
.map(([type, def]) =>
|
||||
z.object({
|
||||
type: z.string("hey"),
|
||||
}),
|
||||
)
|
||||
.toArray();
|
||||
}
|
||||
|
||||
export function specs() {
|
||||
const children = {} as any;
|
||||
for (const [type, def] of registry.entries()) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import "zod-openapi/extend";
|
||||
import { App } from "./app";
|
||||
import { Server } from "./server/server";
|
||||
import fs from "fs/promises";
|
||||
@@ -15,13 +16,6 @@ cli.command("", "Start the opencode in interactive mode").action(async () => {
|
||||
await App.provide({ directory: process.cwd() }, async () => {
|
||||
await Share.init();
|
||||
Server.listen();
|
||||
|
||||
Bun.spawnSync({
|
||||
stderr: "inherit",
|
||||
stdout: "inherit",
|
||||
stdin: "inherit",
|
||||
cmd: ["go", "run", "cmd/main.go"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import { streamSSE } from "hono/streaming";
|
||||
import { Session } from "../session/session";
|
||||
import { resolver, validator as zValidator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
import "zod-openapi/extend";
|
||||
import { Config } from "../app/config";
|
||||
import { LLM } from "../llm/llm";
|
||||
import { Message } from "../session/message";
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
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(),
|
||||
}),
|
||||
),
|
||||
};
|
||||
export const ToolCall = z
|
||||
.object({
|
||||
state: z.literal("call"),
|
||||
|
||||
@@ -11,6 +11,7 @@ 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";
|
||||
|
||||
@@ -18,7 +19,8 @@ import PROMPT_ANTHROPIC from "./prompt/anthropic.txt";
|
||||
import PROMPT_TITLE from "./prompt/title.txt";
|
||||
|
||||
import { Share } from "../share/share";
|
||||
import type { Message } from "./message";
|
||||
import { Message } from "./message";
|
||||
import { Bus } from "../bus";
|
||||
|
||||
export namespace Session {
|
||||
const log = Log.create({ service: "session" });
|
||||
@@ -30,6 +32,15 @@ export namespace Session {
|
||||
});
|
||||
export type Info = z.output<typeof Info>;
|
||||
|
||||
export const Event = {
|
||||
Updated: Bus.event(
|
||||
"session.updated",
|
||||
zv4.object({
|
||||
sessionID: zv4.string(),
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
const state = App.state("session", () => {
|
||||
const sessions = new Map<string, Info>();
|
||||
const messages = new Map<string, Message.Info[]>();
|
||||
@@ -49,6 +60,9 @@ export namespace Session {
|
||||
state().sessions.set(result.id, result);
|
||||
await Storage.writeJSON("session/info/" + result.id, result);
|
||||
await share(result.id);
|
||||
Bus.publish(Event.Updated, {
|
||||
sessionID: result.id,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -80,6 +94,9 @@ export namespace Session {
|
||||
editor(session);
|
||||
sessions.set(id, session);
|
||||
await Storage.writeJSON("session/info/" + id, session);
|
||||
Bus.publish(Event.Updated, {
|
||||
sessionID: id,
|
||||
});
|
||||
return session;
|
||||
}
|
||||
|
||||
@@ -126,10 +143,14 @@ export namespace Session {
|
||||
const model = await LLM.findModel(input.providerID, input.modelID);
|
||||
const msgs = await messages(input.sessionID);
|
||||
async function write(msg: Message.Info) {
|
||||
return Storage.writeJSON(
|
||||
await Storage.writeJSON(
|
||||
"session/message/" + input.sessionID + "/" + msg.id,
|
||||
msg,
|
||||
);
|
||||
Bus.publish(Message.Event.Updated, {
|
||||
sessionID: input.sessionID,
|
||||
messageID: msg.id,
|
||||
});
|
||||
}
|
||||
const app = await App.use();
|
||||
if (msgs.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user