Wire provider streaming request lifecycle

This commit is contained in:
ZacharyZhang-NY committed 2026-05-23 20:20:14 -04:00
1 parent 6805d8a624
commit 08364c2571
18 files changed
+863 -164

No files matched your search

@@ -5,6 +5,7 @@ import { isRecord } from "./provider-http";
export interface ProviderStreamEvent {
type: "message_start" | "text_delta" | "message_stop" | "error";
textDelta: string | null;
providerResponseId: string | null;
rawEventJson: string;
}
@@ -119,7 +120,7 @@ export function cancelUnsupported(providerLabel: string): () => Promise<Provider
}
function streamEvent(type: ProviderStreamEvent["type"], textDelta: string | null, message: ProviderEventStreamMessage): ProviderStreamEvent {
return { type, textDelta, rawEventJson: message.rawData };
return { type, textDelta, providerResponseId: readProviderResponseId(message.data), rawEventJson: message.rawData };
}
function eventType(message: ProviderEventStreamMessage): string | null {
@@ -153,6 +154,13 @@ function readErrorText(data: JsonRecord): string | null {
return null;
}
function readProviderResponseId(data: JsonRecord): string | null {
const direct = stringField(data, "id") ?? stringField(data, "response_id");
if (direct) return direct;
const response = recordField(data, "response");
return response ? stringField(response, "id") : null;
}
function stringField(record: JsonRecord, key: string): string | null {
const value = record[key];
return typeof value === "string" ? value : null;