fix: track in-flight requests by id; handle llama-swap upsert/remove events
llama-swap emits inflight events with operation 'upsert' (a single request, re-emitted as elapsed_ms updates) and id-only 'remove' events. The decoder ignored 'upsert' and dropped every id-only remove, so the tracker only ever reflected the connect-time snapshot and the count got stuck (e.g. at '1'). The tracker now keys in-flight state by request id (snapshot/add replace by id; remove deletes by id), and the decoder normalizes 'upsert' to 'add' and extracts the id from bare removes.
This commit is contained in:
@@ -9,6 +9,13 @@ export function decodeEvent(msg: SseMessage): FeedEvent | null {
|
||||
const inner = JSON.parse(outer.data) as Record<string, unknown>;
|
||||
|
||||
if (outer.type === "inflight") {
|
||||
const operation = inner.operation as string;
|
||||
if (operation === "remove") {
|
||||
const id = typeof inner.id === "string" ? inner.id : undefined;
|
||||
if (id) return { type: "inflight", operation: "remove", id };
|
||||
return null;
|
||||
}
|
||||
if (operation !== "snapshot" && operation !== "upsert" && operation !== "add") return null;
|
||||
const requests: InflightRequest[] = Array.isArray(inner.requests)
|
||||
? (inner.requests as InflightRequest[])
|
||||
: Array.isArray(inner.request)
|
||||
@@ -18,7 +25,7 @@ export function decodeEvent(msg: SseMessage): FeedEvent | null {
|
||||
: [];
|
||||
return {
|
||||
type: "inflight",
|
||||
operation: inner.operation as "snapshot" | "add" | "remove",
|
||||
operation: operation === "snapshot" ? "snapshot" : "add",
|
||||
requests,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user