fix(gui): skip empty content rendering in Discussion Hub; add token usage to comms history
This commit is contained in:
100
src/gui_2.py
100
src/gui_2.py
@@ -306,17 +306,22 @@ class App:
|
|||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
||||||
|
|
||||||
if len(content) > COMMS_CLAMP_CHARS:
|
if len(content) > COMMS_CLAMP_CHARS:
|
||||||
imgui.begin_child(f"heavy_text_child_{label}_{id_suffix}", imgui.ImVec2(0, 80), True)
|
|
||||||
if is_md:
|
if is_md:
|
||||||
|
imgui.begin_child(f"heavy_text_child_{label}_{id_suffix}", imgui.ImVec2(0, 150), True)
|
||||||
markdown_helper.render(content, context_id=ctx_id)
|
markdown_helper.render(content, context_id=ctx_id)
|
||||||
|
imgui.end_child()
|
||||||
else:
|
else:
|
||||||
markdown_helper.render_code(content, context_id=ctx_id)
|
imgui.input_text_multiline(f"##heavy_text_input_{label}_{id_suffix}", content, imgui.ImVec2(-1, 150), imgui.InputTextFlags_.read_only)
|
||||||
imgui.end_child()
|
|
||||||
else:
|
else:
|
||||||
if is_md:
|
if is_md:
|
||||||
markdown_helper.render(content, context_id=ctx_id)
|
markdown_helper.render(content, context_id=ctx_id)
|
||||||
else:
|
else:
|
||||||
markdown_helper.render_code(content, context_id=ctx_id)
|
if self.ui_word_wrap:
|
||||||
|
imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
|
||||||
|
imgui.text(content)
|
||||||
|
imgui.pop_text_wrap_pos()
|
||||||
|
else:
|
||||||
|
imgui.text(content)
|
||||||
|
|
||||||
if is_nerv: imgui.pop_style_color()
|
if is_nerv: imgui.pop_style_color()
|
||||||
# ---------------------------------------------------------------- gui
|
# ---------------------------------------------------------------- gui
|
||||||
@@ -2282,46 +2287,46 @@ def hello():
|
|||||||
self._render_thinking_trace(thinking_segments, i)
|
self._render_thinking_trace(thinking_segments, i)
|
||||||
if read_mode:
|
if read_mode:
|
||||||
content = entry["content"]
|
content = entry["content"]
|
||||||
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
|
if content.strip():
|
||||||
matches = list(pattern.finditer(content))
|
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
|
||||||
is_nerv = theme.is_nerv_active()
|
matches = list(pattern.finditer(content))
|
||||||
if not matches:
|
is_nerv = theme.is_nerv_active()
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
if not matches:
|
||||||
markdown_helper.render(content, context_id=f'disc_{i}')
|
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
else:
|
|
||||||
imgui.begin_child(f"read_content_{i}", imgui.ImVec2(0, 150), True)
|
|
||||||
if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
|
|
||||||
last_idx = 0
|
|
||||||
for m_idx, match in enumerate(matches):
|
|
||||||
before = content[last_idx:match.start()]
|
|
||||||
if before:
|
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
|
||||||
markdown_helper.render(before, context_id=f'disc_{i}_b_{m_idx}')
|
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
header_text = match.group(0).split("\n")[0].strip()
|
|
||||||
path = match.group(2)
|
|
||||||
code_block = match.group(4)
|
|
||||||
if imgui.collapsing_header(header_text):
|
|
||||||
if imgui.button(f"[Source]##{i}_{match.start()}"):
|
|
||||||
res = mcp_client.read_file(path)
|
|
||||||
if res:
|
|
||||||
self.text_viewer_title = path
|
|
||||||
self.text_viewer_content = res
|
|
||||||
self.show_text_viewer = True
|
|
||||||
if code_block:
|
|
||||||
# Render code block with highlighting
|
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
|
||||||
markdown_helper.render(code_block, context_id=f'disc_{i}_c_{m_idx}')
|
|
||||||
if is_nerv: imgui.pop_style_color()
|
|
||||||
last_idx = match.end()
|
|
||||||
after = content[last_idx:]
|
|
||||||
if after:
|
|
||||||
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
||||||
markdown_helper.render(after, context_id=f'disc_{i}_a')
|
markdown_helper.render(content, context_id=f'disc_{i}')
|
||||||
if is_nerv: imgui.pop_style_color()
|
if is_nerv: imgui.pop_style_color()
|
||||||
if self.ui_word_wrap: imgui.pop_text_wrap_pos()
|
else:
|
||||||
imgui.end_child()
|
imgui.begin_child(f"read_content_{i}", imgui.ImVec2(0, 150), True)
|
||||||
|
if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
|
||||||
|
last_idx = 0
|
||||||
|
for m_idx, match in enumerate(matches):
|
||||||
|
before = content[last_idx:match.start()]
|
||||||
|
if before:
|
||||||
|
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
||||||
|
markdown_helper.render(before, context_id=f'disc_{i}_b_{m_idx}')
|
||||||
|
if is_nerv: imgui.pop_style_color()
|
||||||
|
header_text = match.group(0).split("\n")[0].strip()
|
||||||
|
path = match.group(2)
|
||||||
|
code_block = match.group(4)
|
||||||
|
if imgui.collapsing_header(header_text):
|
||||||
|
if imgui.button(f"[Source]##{i}_{match.start()}"):
|
||||||
|
res = mcp_client.read_file(path)
|
||||||
|
if res:
|
||||||
|
self.text_viewer_title = path
|
||||||
|
self.text_viewer_content = res
|
||||||
|
self.show_text_viewer = True
|
||||||
|
if code_block:
|
||||||
|
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
||||||
|
markdown_helper.render(code_block, context_id=f'disc_{i}_c_{m_idx}')
|
||||||
|
if is_nerv: imgui.pop_style_color()
|
||||||
|
last_idx = match.end()
|
||||||
|
after = content[last_idx:]
|
||||||
|
if after:
|
||||||
|
if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80))
|
||||||
|
markdown_helper.render(after, context_id=f'disc_{i}_a')
|
||||||
|
if is_nerv: imgui.pop_style_color()
|
||||||
|
if self.ui_word_wrap: imgui.pop_text_wrap_pos()
|
||||||
|
imgui.end_child()
|
||||||
else:
|
else:
|
||||||
ch, entry["content"] = imgui.input_text_multiline("##content", entry["content"], imgui.ImVec2(-1, 150))
|
ch, entry["content"] = imgui.input_text_multiline("##content", entry["content"], imgui.ImVec2(-1, 150))
|
||||||
imgui.separator()
|
imgui.separator()
|
||||||
@@ -2914,7 +2919,16 @@ def hello():
|
|||||||
elif kind == "response":
|
elif kind == "response":
|
||||||
r = payload.get("round", 0)
|
r = payload.get("round", 0)
|
||||||
sr = payload.get("stop_reason", "STOP")
|
sr = payload.get("stop_reason", "STOP")
|
||||||
imgui.text_colored(C_LBL, f"round: {r} stop_reason: {sr}")
|
usage = payload.get("usage", {})
|
||||||
|
usage_str = ""
|
||||||
|
if usage:
|
||||||
|
inp = usage.get("input_tokens", 0)
|
||||||
|
out = usage.get("output_tokens", 0)
|
||||||
|
cache = usage.get("cache_read_input_tokens", 0)
|
||||||
|
usage_str = f" in:{inp} out:{out}"
|
||||||
|
if cache:
|
||||||
|
usage_str += f" cache:{cache}"
|
||||||
|
imgui.text_colored(C_LBL, f"round: {r} stop_reason: {sr}{usage_str}")
|
||||||
|
|
||||||
text_content = payload.get("text", "")
|
text_content = payload.get("text", "")
|
||||||
segments, parsed_response = thinking_parser.parse_thinking_trace(text_content)
|
segments, parsed_response = thinking_parser.parse_thinking_trace(text_content)
|
||||||
|
|||||||
Reference in New Issue
Block a user