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:
parent
93ae65f99f
commit
fce9942ae0
1 changed files with 12 additions and 3 deletions
|
|
@ -630,7 +630,12 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
|
||||||
let _userMsgEl = null;
|
let _userMsgEl = null;
|
||||||
// Capture which mode the user picked at send time so the message
|
// Capture which mode the user picked at send time so the message
|
||||||
// header can show "Chat" or "Agent" next to the timestamp.
|
// 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) {
|
if (!skipBubble) {
|
||||||
const _userMeta = { mode: _sendMode };
|
const _userMeta = { mode: _sendMode };
|
||||||
if (_pendingAttachInfo) _userMeta.attachments = _pendingAttachInfo;
|
if (_pendingAttachInfo) _userMeta.attachments = _pendingAttachInfo;
|
||||||
|
|
@ -3429,8 +3434,12 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer
|
||||||
const model = meta && meta.model;
|
const model = meta && meta.model;
|
||||||
const meta_ = metricsData ? Object.assign({ model }, metricsData) : { model };
|
const meta_ = metricsData ? Object.assign({ model }, metricsData) : { model };
|
||||||
// Carry the send-time mode through so the assistant header gets
|
// Carry the send-time mode through so the assistant header gets
|
||||||
// the same Chat/Agent tag next to its timestamp.
|
// the same Chat/Agent tag next to its timestamp. toggleState
|
||||||
meta_.mode = (toggleState.mode || 'chat') === 'agent' ? 'agent' : 'chat';
|
// 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_);
|
chatRenderer.addMessage('assistant', roundText, model, meta_);
|
||||||
uiModule.scrollHistory();
|
uiModule.scrollHistory();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue