@@ -42,7 +42,24 @@ export class HarnessBridge extends EventEmitter {
|
||||
|
||||
async ask(text) {
|
||||
if (!this.session) await this.start();
|
||||
return this.session.prompt(text);
|
||||
// Some QVAC runs deliver the final assistant text through the stream but
|
||||
// omit it from the final envelope after a tool call. Keep the current
|
||||
// post-tool stream as a fallback so the daemon can still speak the reply.
|
||||
let streamed = '';
|
||||
const onChunk = (payload) => { streamed += String(payload?.text || payload?.delta || ''); };
|
||||
const onToolCall = () => { streamed = ''; };
|
||||
const chunkSubscription = this.session.on('agent_message_chunk', onChunk);
|
||||
const toolSubscription = this.session.on('tool_call', onToolCall);
|
||||
const offChunk = typeof chunkSubscription === 'function' ? chunkSubscription : () => this.session.off?.('agent_message_chunk', onChunk);
|
||||
const offToolCall = typeof toolSubscription === 'function' ? toolSubscription : () => this.session.off?.('tool_call', onToolCall);
|
||||
try {
|
||||
const reply = await this.session.prompt(text);
|
||||
if (reply && !reply.text && streamed.trim()) return { ...reply, text: streamed };
|
||||
return reply;
|
||||
} finally {
|
||||
offChunk?.();
|
||||
offToolCall?.();
|
||||
}
|
||||
}
|
||||
|
||||
cancel() { this.session?.cancel(); }
|
||||
|
||||
Reference in New Issue
Block a user