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:
1 parent
3495281282
commit
192e2e90dc
78 files changed
+1620
-1194
No files matched your search
+2
-2
@@ -8,7 +8,7 @@ LGPL 2.1 license texts.
|
||||
|
||||
Corresponding upstream source:
|
||||
|
||||
- nanobot TUI: the `tui/` directory in the GitHub release tag that contains this archive
|
||||
- nanobot TUI: the `tui/` and `packages/client-events/` directories in the GitHub release tag that contains this archive
|
||||
- Bun 1.3.13 (`bf2e2cecf27e800962b1e7f03d66278f9d5d2e79`):
|
||||
<https://github.com/oven-sh/bun/tree/bun-v1.3.13>
|
||||
- Bun's patched WebKit (`4d5e75ebd84a14edbc7ae264245dcd77fe597c10`):
|
||||
@@ -21,7 +21,7 @@ build instructions. Then unpack
|
||||
`nanobot-tui-source.tar.gz` from the release archive and run the resulting Bun executable:
|
||||
|
||||
```bash
|
||||
cd nanobot-tui-source
|
||||
cd nanobot-tui-source/tui
|
||||
/path/to/modified/bun install --frozen-lockfile
|
||||
/path/to/modified/bun run build -- <target>
|
||||
```
|
||||
|
||||
@@ -43,7 +43,10 @@ def _source_archive(root: Path) -> bytes:
|
||||
path = root / relative
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(path)
|
||||
archive.add(path, arcname=Path("nanobot-tui-source") / relative)
|
||||
archive.add(path, arcname=Path("nanobot-tui-source/tui") / relative)
|
||||
archive.add(root.parent / "packages/client-events",
|
||||
arcname="nanobot-tui-source/packages/client-events")
|
||||
archive.add(root.parent / "LICENSE", arcname="nanobot-tui-source/LICENSE")
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
|
||||
+6
-42
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user