Merge branch 'master' of https://gitea.ditaajipratama.net/aji/hendrik
This commit is contained in:
commit
d9ee874f51
@ -51,8 +51,7 @@ class HendrikTUI:
|
||||
}
|
||||
|
||||
def new_session(self):
|
||||
name = f"Session {datetime.now().strftime('%Y-%m-%d %H:%M')}"
|
||||
self.current_session = self.session_mgr.create(name, self._model_info())
|
||||
self.current_session = None
|
||||
self.messages = [{"role": "system", "content": self.build_system_prompt(
|
||||
tools_definition=self.tools_def,
|
||||
character=config.AGENT_CHARACTER or None,
|
||||
@ -60,6 +59,9 @@ class HendrikTUI:
|
||||
)}]
|
||||
self.log.clear()
|
||||
self.scroll = 0
|
||||
self.input_buffer = [""]
|
||||
self.input_line = 0
|
||||
self.input_col = 0
|
||||
log(self, "welcome", WELCOME_ART)
|
||||
|
||||
def switch_session(self, doc_id: int):
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
import curses
|
||||
import json
|
||||
import os
|
||||
import textwrap
|
||||
import config
|
||||
|
||||
# -- Color pair IDs (id 1-9, id 0 = default curses) --
|
||||
C_HEADER = 1 # header bar: biru
|
||||
@ -90,21 +88,21 @@ def draw_chat(app, stdscr):
|
||||
rendered.append(segments)
|
||||
|
||||
def _add_blank():
|
||||
rendered.append([(None, "")])
|
||||
rendered.append([(None, "", False)])
|
||||
|
||||
def _wrap_render(text, indent=0, color=C_INPUT):
|
||||
def _wrap_render(text, indent=0, color=C_INPUT, bold=False):
|
||||
available = w - indent - 1 # sisakan 1 kolom margin kanan
|
||||
if available <= 0:
|
||||
_add_row([(color, " " * indent)])
|
||||
_add_row([(color, " " * indent, bold)])
|
||||
return
|
||||
for line in text.split("\n"):
|
||||
if not line:
|
||||
_add_row([(color, " " * indent)])
|
||||
_add_row([(color, " " * indent, bold)])
|
||||
continue
|
||||
start = 0
|
||||
while start < len(line):
|
||||
chunk = line[start:start + available]
|
||||
_add_row([(color, " " * indent + chunk)])
|
||||
_add_row([(color, " " * indent + chunk, bold)])
|
||||
start += available
|
||||
|
||||
for idx, item in enumerate(app.log):
|
||||
@ -130,21 +128,20 @@ def draw_chat(app, stdscr):
|
||||
model_info = item.get("model_info", None)
|
||||
if model_info:
|
||||
p_name, m_name = model_info
|
||||
if p_name:
|
||||
info_line = f" {p_name} - {m_name} "
|
||||
else:
|
||||
info_line = f" {m_name} "
|
||||
else:
|
||||
p_name = config.resolve_provider(app.llm.base_url, app.llm.model)
|
||||
m_name = app.llm.model
|
||||
if p_name:
|
||||
info_line = f" {p_name} - {m_name} "
|
||||
else:
|
||||
info_line = f" {m_name} "
|
||||
_add_row([(C_USER, info_line)])
|
||||
info_line = " Unknown - Model info not found "
|
||||
_add_row([(C_USER, info_line, False)])
|
||||
label = f" You ({item['time']}) "
|
||||
_add_row([(C_USER, label)])
|
||||
_wrap_render(text, indent=1, color=C_INPUT)
|
||||
_wrap_render(text, indent=1, color=C_INPUT, bold=False)
|
||||
elif role == "ai":
|
||||
label = f" Hendrik ({item['time']}) "
|
||||
_add_row([(C_AI, label)])
|
||||
_wrap_render(text, indent=1, color=C_INPUT)
|
||||
_wrap_render(text, indent=1, color=C_INPUT, bold=False)
|
||||
elif role == "system":
|
||||
lines = text.split("\n")
|
||||
_add_row([(C_SYSTEM, lines[0])])
|
||||
@ -218,10 +215,11 @@ def draw_chat(app, stdscr):
|
||||
for i in range(app.scroll, min(app.scroll + chat_h, total)):
|
||||
segments = rendered[i]
|
||||
x = 0
|
||||
for color, text in segments:
|
||||
for color, text, *bold_flag in segments:
|
||||
if not text:
|
||||
continue
|
||||
attr = curses.color_pair(color) | curses.A_BOLD if color else curses.A_NORMAL
|
||||
is_bold = bold_flag[0] if bold_flag else True
|
||||
attr = curses.color_pair(color) | (curses.A_BOLD if is_bold else 0) if color else curses.A_NORMAL
|
||||
remaining = w - x
|
||||
if remaining <= 0:
|
||||
break
|
||||
|
||||
Loading…
Reference in New Issue
Block a user