Skip to content

Commit 555e505

Browse files
committed
fix(js/client): forward chat-response into chatStream() to match Python
A publisher that ignores the stream:true flag (chat_handler returns a plain string or {text}) replies with a single chat-response envelope instead of chat-chunks. zhub/client.py:549-552 unpacks that into {delta:text, done:false} + {done:true} so chat_stream() yields the text and exits cleanly; the JS port routed chat-response only through the pending Map, so a chatStream() caller hung for the full timeoutPerChunkMs (default 60s) on what is the most common publisher shape.
1 parent b73e7c0 commit 555e505

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

js/src/client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,17 @@ export class ZhubConnection {
683683
this.pending.delete(env.request_id);
684684
cb.resolve(env.payload);
685685
}
686+
// A publisher that ignores the stream:true flag (e.g. one whose
687+
// chat_handler returns a plain string or {text}) replies with a
688+
// single chat-response. Forward it to a registered stream consumer
689+
// as text-delta + done so chatStream() doesn't hang waiting for
690+
// chat-chunks that will never arrive — mirrors zhub/client.py.
691+
const onStream = this.streams.get(env.request_id);
692+
if (onStream) {
693+
const text = String((env.payload as { text?: unknown }).text ?? '');
694+
onStream({ delta: text, done: false });
695+
onStream({ done: true });
696+
}
686697
return;
687698
}
688699
case 'chat-chunk': {

0 commit comments

Comments
 (0)