diff options
| author | Dax Raad <[email protected]> | 2025-05-29 11:17:34 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-29 11:17:34 -0400 |
| commit | 42c1cd6a852be5295aedc5c19e1a2aef45a464e3 (patch) | |
| tree | 4c73d3121590991e487b86b6c0ea445fad5b732d /js/src/session | |
| parent | 33a831d2be1fd7bea60421287f118be0bd968650 (diff) | |
| download | opencode-42c1cd6a852be5295aedc5c19e1a2aef45a464e3.tar.gz opencode-42c1cd6a852be5295aedc5c19e1a2aef45a464e3.zip | |
event
Diffstat (limited to 'js/src/session')
| -rw-r--r-- | js/src/session/message.ts | 11 | ||||
| -rw-r--r-- | js/src/session/session.ts | 25 |
2 files changed, 34 insertions, 2 deletions
diff --git a/js/src/session/message.ts b/js/src/session/message.ts index 75c22ef0b..91bcd19b4 100644 --- a/js/src/session/message.ts +++ b/js/src/session/message.ts @@ -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"), diff --git a/js/src/session/session.ts b/js/src/session/session.ts index abeb29842..a876976bd 100644 --- a/js/src/session/session.ts +++ b/js/src/session/session.ts @@ -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) { |
