Skip to content

Commit afe1939

Browse files
committed
fix: avoid duplicate icebreaker prompts in desktop mode
1 parent 7421c08 commit afe1939

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

static/icebreaker/new-user-icebreaker.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@
189189
}
190190
}
191191

192+
function shouldRenderIcebreakerOnLocalChatHost() {
193+
try {
194+
var path = String((window.location && window.location.pathname) || '');
195+
if (window.__NEKO_MULTI_WINDOW__ === true && !/^\/chat(?:\/|$)/.test(path)) {
196+
return false;
197+
}
198+
} catch (_) {}
199+
return true;
200+
}
201+
192202
function broadcastIcebreaker(action, payload) {
193203
var message = Object.assign({
194204
action: action,
@@ -288,6 +298,9 @@
288298
};
289299
broadcastIcebreakerAppendMessage(message);
290300
appendLlmContext(role, messageText, meta || {});
301+
if (!shouldRenderIcebreakerOnLocalChatHost()) {
302+
return Promise.resolve(message);
303+
}
291304
return waitForChatHost(30000).then(function (host) {
292305
if (typeof host.openWindow === 'function') {
293306
host.openWindow();
@@ -372,6 +385,9 @@
372385
options: buildPromptOptions(node, localeData)
373386
};
374387
broadcastIcebreakerChoicePrompt(prompt);
388+
if (!shouldRenderIcebreakerOnLocalChatHost()) {
389+
return Promise.resolve(false);
390+
}
375391
return waitForChatHost(30000).then(function (host) {
376392
if (!host || typeof host.setIcebreakerChoicePrompt !== 'function') return false;
377393
host.setIcebreakerChoicePrompt(prompt);
@@ -386,6 +402,7 @@
386402
if (!activeSession || !activeSession.sessionId) return;
387403
var sessionId = activeSession.sessionId;
388404
broadcastIcebreakerClearChoicePrompt(sessionId);
405+
if (!shouldRenderIcebreakerOnLocalChatHost()) return;
389406
waitForChatHost(1200).then(function (host) {
390407
if (host && typeof host.clearIcebreakerChoicePrompt === 'function') {
391408
host.clearIcebreakerChoicePrompt(sessionId);

tests/unit/test_new_user_icebreaker_static_contracts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ def test_icebreaker_uses_broadcast_channel_for_desktop_chat_window():
376376
assert "broadcastIcebreakerAppendMessage" in runtime
377377
assert "broadcastIcebreakerChoicePrompt" in runtime
378378
assert "broadcastIcebreakerClearChoicePrompt" in runtime
379+
assert "shouldRenderIcebreakerOnLocalChatHost" in runtime
380+
assert "window.__NEKO_MULTI_WINDOW__ === true" in runtime
381+
assert "!/^\\/chat(?:\\/|$)/.test(path)" in runtime
382+
assert "if (!shouldRenderIcebreakerOnLocalChatHost())" in runtime
379383
assert "window.appInterpage" in runtime
380384
assert "action: 'icebreaker_append_chat_message'" in runtime
381385
assert "action: 'icebreaker_set_choice_prompt'" in runtime

0 commit comments

Comments
 (0)