mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-07-18 21:50:55 +00:00
perf(reconnect): pre-index toolCalls and remove unreachable guard (#4811)
This commit is contained in:
committed by
nesquena-hermes
parent
e86ebb6379
commit
f330fa7f44
+10
-3
@@ -2551,6 +2551,15 @@ function attachLiveStream(activeSid, streamId, uploaded=[], options={}){
|
||||
if(!byIdx.has(idx)) byIdx.set(idx,[]);
|
||||
byIdx.get(idx).push(row);
|
||||
};
|
||||
// Pre-index S.toolCalls by assistant_msg_idx for O(m+n) lookup
|
||||
const toolsByIdx=new Map();
|
||||
if(S.toolCalls) for(const tc of S.toolCalls){
|
||||
const ti=typeof tc.toolIdx==='number'? tc.toolIdx : parseInt(tc.assistant_msg_idx,10);
|
||||
if(Number.isFinite(ti)){
|
||||
if(!toolsByIdx.has(ti)) toolsByIdx.set(ti,[]);
|
||||
toolsByIdx.get(ti).push(tc);
|
||||
}
|
||||
}
|
||||
let encounter=0;
|
||||
for(let idx=turnStart+1;idx<lastAsstIndex;idx+=1){
|
||||
const message=messages[idx];
|
||||
@@ -2575,12 +2584,10 @@ function attachLiveStream(activeSid, streamId, uploaded=[], options={}){
|
||||
if(tid) seenToolIds.add(tid);
|
||||
}
|
||||
// Merge S.toolCalls for this index, dedup by tool id
|
||||
const toolCalls=Array.isArray(S.toolCalls)?S.toolCalls:[];
|
||||
for(const tool of toolCalls){
|
||||
for(const tool of (toolsByIdx.get(idx)||[])){
|
||||
if(!tool||typeof tool!=='object') continue;
|
||||
const toolIdx=Number(tool.assistant_msg_idx);
|
||||
if(!Number.isFinite(toolIdx)||toolIdx!==idx) continue;
|
||||
if(toolIdx<=turnStart||toolIdx>=lastAsstIndex) continue;
|
||||
const row=_anchorSceneToolRowFromCall(tool,0,idx);
|
||||
const tid=row.tool_call_id||(row.tool&&row.tool.id);
|
||||
if(tid&&seenToolIds.has(tid)) continue;
|
||||
|
||||
@@ -709,8 +709,9 @@ def test_settled_anchor_scene_persists_the_full_assistant_turn_not_only_tail():
|
||||
assert "messages.slice(turnStart+1,lastAsstIndex+1)" in complete
|
||||
assert "message.reasoning||message._reasoning||message.reasoning_content||message.thinking" in reasoning_text
|
||||
assert "const reasoning=_anchorSceneMessageReasoningText(message);" in rows_by_message
|
||||
assert "const toolCalls=Array.isArray(S.toolCalls)?S.toolCalls:[]" in rows_by_message
|
||||
assert "toolIdx<=turnStart||toolIdx>=lastAsstIndex" in rows_by_message
|
||||
assert "const toolsByIdx=new Map();" in rows_by_message
|
||||
assert "if(S.toolCalls) for(const tc of S.toolCalls){" in rows_by_message
|
||||
assert "for(const tool of (toolsByIdx.get(idx)||[]))" in rows_by_message
|
||||
assert "_anchorSceneToolRowFromCall(tool,0,idx)" in rows_by_message
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user