refactor(events): unify scoped runtime notifications across clients (#5670)

* refactor(events): unify scoped runtime notifications across clients

* style(tests): sort auto-compaction event imports

* refactor(events): scope connections and remove retry callback plumbing

* docs: remove runtime notification design write-up

* refactor(bus): route operation events through the message bus

* fix(channels): isolate outbound sends by destination

* style(events): group shared notification imports

* refactor(events): converge runtime and hook delivery on MessageBus

* test(events): migrate fixtures to unified message bus
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-06 02:11:19 +08:00
1 parent 3495281282
commit 192e2e90dc
78 files changed
+1620 -1194

No files matched your search

+6 -42
View File
@@ -1,3 +1,7 @@
import { decodeNotification, isCompactionPhase, isRecoveryState } from "../../packages/client-events/notifications"
import type { ContextCompaction, NotificationEvent, RecoveryState } from "../../packages/client-events/notifications"
export type { ContextCompaction, RecoveryState, RecoveryStatus } from "../../packages/client-events/notifications"
export type ConnectionStatus =
| "starting"
| "connecting"
@@ -76,21 +80,6 @@ export interface RuntimeControls {
canUseFullAccess: boolean
}
export type RecoveryStatus = "resuming" | "awaiting_user" | "recovered" | "failed"
export interface RecoveryState {
status: RecoveryStatus
recovery_id: string
reason?: string
attempts?: number
can_continue?: boolean
}
export interface ContextCompaction {
id: string
phase: "started" | "succeeded" | "failed" | "cancelled"
}
export type InboundEvent =
| { event: "ready"; chat_id: string; client_id: string }
| {
@@ -156,13 +145,7 @@ export type InboundEvent =
turn_id?: string
}
| { event: "goal_state"; chat_id: string; goal_state: Record<string, unknown> }
| ({ event: "recovery_state"; chat_id: string } & RecoveryState)
| {
event: "context_compaction"
chat_id: string
compaction_id: string
phase: ContextCompaction["phase"]
}
| NotificationEvent
| {
event: "session_updated"
chat_id: string
@@ -382,10 +365,6 @@ function optional(value: unknown, type: "boolean" | "number" | "string"): boolea
return value === undefined || typeof value === type
}
function isCompactionPhase(value: unknown): value is ContextCompaction["phase"] {
return value === "started" || value === "succeeded" || value === "failed" || value === "cancelled"
}
function isToolEvent(value: unknown): value is ToolProgressEvent {
if (!isRecord(value)) return false
return optional(value.version, "number")
@@ -456,15 +435,6 @@ function isWorkspaceScope(value: unknown): value is WorkspaceScopePayload {
&& optional(value.restrict_to_workspace, "boolean")
}
function isRecoveryState(value: unknown): value is RecoveryState {
return isRecord(value)
&& ["resuming", "awaiting_user", "recovered", "failed"].includes(String(value.status))
&& typeof value.recovery_id === "string"
&& optional(value.reason, "string")
&& optional(value.attempts, "number")
&& optional(value.can_continue, "boolean")
}
interface WebUIResponseEvent {
event: "webui_response"
request_id: string
@@ -560,13 +530,7 @@ function decodeInboundEvent(value: unknown): InboundEvent | null | undefined {
) return null
if (name === "goal_status" && record.status !== "running" && record.status !== "idle") return null
if (name === "goal_state" && !isRecord(record.goal_state)) return null
if (name === "recovery_state" && !isRecoveryState(record)) return null
if (
name === "context_compaction"
&& (typeof record.compaction_id !== "string"
|| !record.compaction_id
|| !isCompactionPhase(record.phase))
) return null
if (decodeNotification(record) === null) return null
if (
name === "session_updated"
&& (!optional(record.scope, "string")
+2 -1
View File
@@ -1,3 +1,4 @@
import { acceptsCompactionPhase } from "../../packages/client-events/notifications"
import {
BoxRenderable,
CodeRenderable,
@@ -331,7 +332,7 @@ export class Transcript {
compaction(compaction: ContextCompaction, index?: number): boolean {
let entry = this.compactions.get(compaction.id)
// Hydration can replay a terminal state before an already queued start event.
if (entry && (entry.phase !== "started" || entry.phase === compaction.phase)) return false
if (!acceptsCompactionPhase(entry?.phase, compaction.phase)) return false
const added = !entry
if (index === undefined) {
this.noteOutput()