fix: throw error when input streams are used without v2 realtime streams

Instead of silently hanging, on() and once() now throw immediately with
a clear error message telling the developer to enable v2RealtimeStreams.

https://claude.ai/code/session_01SJHJts7r2yAxmoKLLz8vpc
This commit is contained in:
Claude
2026-02-22 08:27:15 +00:00
committed by Eric Allam
parent eb2f0a2c4a
commit cefa7ccc58
+13 -1
View File
@@ -41,6 +41,8 @@ export class StandardInputStreamManager implements InputStreamManager {
}
on(streamId: string, handler: InputStreamHandler): { off: () => void } {
this.#requireV2Streams();
let handlerSet = this.handlers.get(streamId);
if (!handlerSet) {
handlerSet = new Set();
@@ -71,6 +73,8 @@ export class StandardInputStreamManager implements InputStreamManager {
}
once(streamId: string, options?: InputStreamOnceOptions): Promise<unknown> {
this.#requireV2Streams();
// Lazily connect the tail on first listener registration
this.#ensureTailConnected();
@@ -170,8 +174,16 @@ export class StandardInputStreamManager implements InputStreamManager {
this.buffer.clear();
}
#requireV2Streams(): void {
if (this.currentRunId && this.streamsVersion !== "v2") {
throw new Error(
"Input streams require v2 realtime streams. Enable them with: { future: { v2RealtimeStreams: true } }"
);
}
}
#ensureTailConnected(): void {
if (!this.tailAbortController && this.currentRunId && this.streamsVersion === "v2") {
if (!this.tailAbortController && this.currentRunId) {
this.connectTail(this.currentRunId);
}
}