Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions server/comms-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@

import { sectionKey, type BotRecord, type GroupRecord, type Message, type Store } from "./store.ts";

/** Machine-readable delegation lifecycle evidence. The payload is deliberately
* metadata-only: task and routing ids plus bounded enum-like state. Prompts,
* tool output, credentials, and approval-card text never enter the turn log. */
export interface DelegationAuditEvent {
type: "delegation.status";
threadId: string;
taskId: string;
targetBotId: string;
state: "completed" | "queued" | "failed";
reason?: string;
attemptCount: number;
duplicate?: boolean;
}

/** What a peer-exchange helper needs from the outside world:
* the store (for persisted messages + groups) and the SSE broadcasters
* so chat clients see the change without waiting for a refresh. */
export interface CommsBus {
store: Store;
/** SSE broadcast (kind: "message" envelope). */
broadcast: (payload: Record<string, unknown>) => void;
/** Optional bridge into the canonical per-thread event ledger. */
recordDelegation?: (event: DelegationAuditEvent) => void;
/** SSE broadcast (kind: "group" envelope) for a single group. */
}

Expand Down
10 changes: 10 additions & 0 deletions server/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ export type RuntimeEvent = RuntimeEventBase &
// `setup: true` marks a failure the user fixes by installing or
// configuring something, not by retrying — the UI offers setup instead.
| { type: "runtime.error"; message: string; setup?: boolean }
| {
/** Metadata-only lifecycle evidence for a durable async handoff. */
type: "delegation.status";
taskId: string;
targetBotId: string;
state: "completed" | "queued" | "failed";
reason?: string;
attemptCount: number;
duplicate?: boolean;
}
);

export type RuntimeEventListener = (event: RuntimeEvent) => void;
Expand Down
Loading
Loading