refactor stapp rerun reset logic and simplify vision SOP

This commit is contained in:
Liang Jiaqing
2026-04-20 21:10:49 +08:00
parent bf4bc5d2ea
commit 5c1dd1270c
2 changed files with 7 additions and 17 deletions

View File

@@ -177,8 +177,7 @@ _embed_html(f'<script>{_js_scroll_fix};{_js_ime_fix}</script>', height=0)
if prompt := st.chat_input("any task?"):
ts = time.strftime("%Y-%m-%d %H:%M:%S")
cmd = (prompt or "").strip()
if cmd == "/new":
st.session_state.messages = [{"role": "assistant", "content": reset_conversation(agent), "time": ts}]
def _reset_and_rerun():
st.session_state.streaming = False
st.session_state.stopping = False
st.session_state.display_queue = None
@@ -187,19 +186,15 @@ if prompt := st.chat_input("any task?"):
st.session_state.current_prompt = ""
st.session_state.last_reply_time = int(time.time())
st.rerun()
if cmd == "/new":
st.session_state.messages = [{"role": "assistant", "content": reset_conversation(agent), "time": ts}]
_reset_and_rerun()
if cmd.startswith("/continue"):
st.session_state.messages = list(st.session_state.messages) + [
{"role": "user", "content": cmd, "time": ts},
{"role": "assistant", "content": handle_frontend_command(agent, cmd), "time": ts},
]
st.session_state.streaming = False
st.session_state.stopping = False
st.session_state.display_queue = None
st.session_state.partial_response = ""
st.session_state.reply_ts = ""
st.session_state.current_prompt = ""
st.session_state.last_reply_time = int(time.time())
st.rerun()
_reset_and_rerun()
st.session_state.messages.append({"role": "user", "content": prompt})
if hasattr(agent, '_pet_req') and not prompt.startswith('/'): agent._pet_req('state=walk')
with st.chat_message("user"): st.markdown(prompt)