Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ class ApplicationController {

this._responseSeq = (this._responseSeq || 0) + 1;
const messageId = `img-${Date.now()}-${this._responseSeq}`;
windowManager.broadcastToAllWindows("transcription-llm-response-start", {
this.sendToVoiceResponseWindows("transcription-llm-response-start", {
messageId,
skill: this.activeSkill
});
Expand All @@ -1104,7 +1104,7 @@ class ApplicationController {
sessionHistory.recent,
needsProgrammingLanguage ? this.codingLanguage : null,
(delta) => {
windowManager.broadcastToAllWindows("transcription-llm-response-chunk", {
this.sendToVoiceResponseWindows("transcription-llm-response-chunk", {
messageId,
delta
});
Expand All @@ -1119,7 +1119,7 @@ class ApplicationController {
isImageAnalysis: true
});

this.broadcastTranscriptionLLMResponse(llmResult);
this.sendTranscriptionLLMResponseToVoiceTargets(llmResult);

windowManager.showLLMResponse(llmResult.response, {
skill: this.activeSkill,
Expand Down Expand Up @@ -1158,7 +1158,7 @@ class ApplicationController {

this._responseSeq = (this._responseSeq || 0) + 1;
const messageId = `chat-${Date.now()}-${this._responseSeq}`;
windowManager.broadcastToAllWindows("transcription-llm-response-start", {
this.sendToVoiceResponseWindows("transcription-llm-response-start", {
messageId,
skill: this.activeSkill
});
Expand All @@ -1170,7 +1170,7 @@ class ApplicationController {
sessionHistory.recent,
needsProgrammingLanguage ? this.codingLanguage : null,
(delta) => {
windowManager.broadcastToAllWindows("transcription-llm-response-chunk", {
this.sendToVoiceResponseWindows("transcription-llm-response-chunk", {
messageId,
delta
});
Expand All @@ -1193,7 +1193,7 @@ class ApplicationController {
usedFallback: llmResult.metadata.usedFallback,
});

this.broadcastTranscriptionLLMResponse(llmResult);
this.sendTranscriptionLLMResponseToVoiceTargets(llmResult);

windowManager.showLLMResponse(llmResult.response, {
skill: this.activeSkill,
Expand Down Expand Up @@ -1472,30 +1472,13 @@ class ApplicationController {
}

broadcastTranscriptionLLMResponse(llmResult) {
const broadcastData = {
response: llmResult.response,
metadata: llmResult.metadata,
messageId: llmResult.metadata && llmResult.metadata.messageId,
skill: this.activeSkill,
isTranscriptionResponse: true
};

logger.info("Broadcasting transcription LLM response to all windows", {
responseLength: llmResult.response.length,
skill: this.activeSkill,
responsePreview: llmResult.response.substring(0, 100) + "..."
});

windowManager.broadcastToAllWindows("transcription-llm-response", broadcastData);
this.sendTranscriptionLLMResponseToVoiceTargets(llmResult);
}

sendToChatWindow(channel, data) {
const chatWindow = windowManager.getWindow("chat");
if (!chatWindow || chatWindow.isDestroyed()) {
logger.warn("Chat window unavailable for speech event", { channel });
return;
if (!windowManager.sendToWindow("chat", channel, data)) {
logger.warn("Chat window unavailable for event", { channel });
}
chatWindow.webContents.send(channel, data);
}

getVoiceResponseTarget() {
Expand All @@ -1513,10 +1496,7 @@ class ApplicationController {
this.sendToChatWindow(channel, data);
}
if (target === 'overlay' || target === 'both') {
const responseWindow = windowManager.getWindow("llmResponse");
if (responseWindow && !responseWindow.isDestroyed()) {
responseWindow.webContents.send(channel, data);
}
windowManager.sendToWindow("llmResponse", channel, data);
}
}

Expand Down
32 changes: 23 additions & 9 deletions src/managers/window.manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,15 @@ class WindowManager {
});
}

sendToWindow(type, channel, data) {
const window = this.windows.get(type);
if (window && !window.isDestroyed()) {
window.webContents.send(channel, data);
return true;
}
return false;
}

broadcastToAllWindows(channel, data) {
const windowStates = {};

Expand All @@ -1476,15 +1485,20 @@ class WindowManager {
}
});

logger.info('Broadcast sent to all windows', {
channel,
windowCount: this.windows.size,
windowStates,
dataKeys: data ? Object.keys(data) : [],
// Fixed: Check for 'content' instead of 'response' to match actual data structure
dataPreview: data && data.content ? data.content.substring(0, 50) + '...' :
data && data.response ? data.response.substring(0, 50) + '...' : 'No response'
});
// Log at debug level for high-frequency streaming chunk events to reduce per-chunk log overhead
if (channel.endsWith('-chunk') || channel.includes('chunk')) {
logger.debug('Broadcast sent to all windows', { channel, windowCount: this.windows.size });
} else {
logger.info('Broadcast sent to all windows', {
channel,
windowCount: this.windows.size,
windowStates,
dataKeys: data ? Object.keys(data) : [],
// Fixed: Check for 'content' instead of 'response' to match actual data structure
dataPreview: data && data.content ? data.content.substring(0, 50) + '...' :
data && data.response ? data.response.substring(0, 50) + '...' : 'No response'
});
}
}

getWindow(type) {
Expand Down