Chat: fix mode-tag breakage — toggleState wasn't in scope at those sites

The previous commit read toggleState.mode before it was declared
(send-time site near line 632) and outside its closure (assistant
finalize site near line 3426). Both threw ReferenceError / TDZ on
first send, which crashed the chat send + render pipeline.

Read fresh via Storage.loadToggleState() at each site, defaulting to
'chat' on any error. Mode-tag rendering otherwise unchanged.
This commit is contained in:
pewdiepie-archdaemon
2026-06-11 22:00:22 +09:00
parent 93ae65f99f
commit fce9942ae0
+12 -3
View File
@@ -630,7 +630,12 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
let _userMsgEl = null;
// Capture which mode the user picked at send time so the message
// header can show "Chat" or "Agent" next to the timestamp.
const _sendMode = (toggleState.mode || 'chat') === 'agent' ? 'agent' : 'chat';
// toggleState is declared later in this function — load fresh here.
let _sendMode = 'chat';
try {
const _ts = Storage.loadToggleState();
if ((_ts.mode || 'chat') === 'agent') _sendMode = 'agent';
} catch (_) {}
if (!skipBubble) {
const _userMeta = { mode: _sendMode };
if (_pendingAttachInfo) _userMeta.attachments = _pendingAttachInfo;
@@ -3429,8 +3434,12 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
const model = meta && meta.model;
const meta_ = metricsData ? Object.assign({ model }, metricsData) : { model };
// Carry the send-time mode through so the assistant header gets
// the same Chat/Agent tag next to its timestamp.
meta_.mode = (toggleState.mode || 'chat') === 'agent' ? 'agent' : 'chat';
// the same Chat/Agent tag next to its timestamp. toggleState
// isn't in scope here — read fresh.
try {
const _ts = Storage.loadToggleState();
meta_.mode = ((_ts.mode || 'chat') === 'agent') ? 'agent' : 'chat';
} catch (_) {}
chatRenderer.addMessage('assistant', roundText, model, meta_);
uiModule.scrollHistory();
return true;