feat: decode activity SSE events and expose tracker total
This commit is contained in:
@@ -8,6 +8,12 @@ export function decodeEvent(msg: SseMessage): FeedEvent | null {
|
||||
if (!outer.data) return null;
|
||||
const inner = JSON.parse(outer.data) as Record<string, unknown>;
|
||||
|
||||
if (outer.type === "activity") {
|
||||
const id = typeof inner.id === "number" ? inner.id : Number.NaN;
|
||||
if (Number.isFinite(id)) return { type: "activity", id };
|
||||
return null;
|
||||
}
|
||||
|
||||
if (outer.type === "inflight") {
|
||||
const operation = inner.operation as string;
|
||||
if (operation === "remove") {
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface ModelState {
|
||||
export type FeedEvent =
|
||||
| { type: "inflight"; operation: "snapshot" | "add"; requests: InflightRequest[] }
|
||||
| { type: "inflight"; operation: "remove"; id: string }
|
||||
| { type: "activity"; id: number }
|
||||
| { type: "modelStatus"; models: ModelState[] };
|
||||
|
||||
export type ModelRuntimeState = "stopped" | "loading" | "ready";
|
||||
@@ -44,6 +45,10 @@ export class InflightTracker {
|
||||
return n;
|
||||
}
|
||||
|
||||
total(): number {
|
||||
return this.requests.size;
|
||||
}
|
||||
|
||||
state(modelId: string): ModelRuntimeState | undefined {
|
||||
return this.states.get(modelId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user