mindnet/app/frontend/ui.py

454 lines
18 KiB
Python
Raw Normal View History

2025-12-09 18:44:26 +01:00
import streamlit as st
import requests
import uuid
import os
2025-12-09 23:05:28 +01:00
import json
2025-12-10 16:41:21 +01:00
import re
2025-12-10 16:55:56 +01:00
import yaml
2025-12-10 17:14:51 +01:00
from datetime import datetime
2025-12-09 23:05:28 +01:00
from pathlib import Path
2025-12-09 19:00:39 +01:00
from dotenv import load_dotenv
2025-12-09 18:44:26 +01:00
# --- CONFIGURATION ---
2025-12-09 19:00:39 +01:00
load_dotenv()
2025-12-09 18:44:26 +01:00
API_BASE_URL = os.getenv("MINDNET_API_URL", "http://localhost:8002")
CHAT_ENDPOINT = f"{API_BASE_URL}/chat"
FEEDBACK_ENDPOINT = f"{API_BASE_URL}/feedback"
2025-12-11 07:46:27 +01:00
INGEST_ANALYZE_ENDPOINT = f"{API_BASE_URL}/ingest/analyze"
INGEST_SAVE_ENDPOINT = f"{API_BASE_URL}/ingest/save"
2025-12-09 23:05:28 +01:00
HISTORY_FILE = Path("data/logs/search_history.jsonl")
2025-12-09 18:44:26 +01:00
2025-12-09 23:05:28 +01:00
# Timeout Strategy
2025-12-09 19:00:39 +01:00
timeout_setting = os.getenv("MINDNET_API_TIMEOUT") or os.getenv("MINDNET_LLM_TIMEOUT")
API_TIMEOUT = float(timeout_setting) if timeout_setting else 300.0
2025-12-09 18:44:26 +01:00
# --- PAGE SETUP ---
2025-12-10 17:43:03 +01:00
st.set_page_config(page_title="mindnet v2.3.2", page_icon="🧠", layout="wide")
2025-12-09 18:44:26 +01:00
2025-12-09 23:16:28 +01:00
# --- CSS STYLING ---
2025-12-09 18:44:26 +01:00
st.markdown("""
<style>
2025-12-10 16:55:56 +01:00
.block-container { padding-top: 2rem; max_width: 1000px; margin: auto; }
2025-12-09 23:05:28 +01:00
2025-12-09 18:44:26 +01:00
.intent-badge {
2025-12-09 23:05:28 +01:00
background-color: #e8f0fe; color: #1a73e8;
padding: 4px 10px; border-radius: 12px;
font-size: 0.8rem; font-weight: 600;
border: 1px solid #d2e3fc; display: inline-block; margin-bottom: 0.5rem;
2025-12-09 22:27:56 +01:00
}
2025-12-09 23:05:28 +01:00
2025-12-10 16:55:56 +01:00
.draft-box {
2025-12-10 17:14:51 +01:00
border: 1px solid #d0d7de;
border-radius: 6px;
padding: 16px;
background-color: #f6f8fa;
2025-12-10 16:55:56 +01:00
margin-top: 10px;
2025-12-10 17:14:51 +01:00
margin-bottom: 10px;
2025-12-10 16:55:56 +01:00
}
2025-12-10 17:14:51 +01:00
2025-12-10 16:55:56 +01:00
.preview-box {
border: 1px solid #e0e0e0;
2025-12-10 17:14:51 +01:00
border-radius: 6px;
padding: 24px;
2025-12-10 16:55:56 +01:00
background-color: white;
2025-12-10 17:14:51 +01:00
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
2025-12-10 16:55:56 +01:00
}
2025-12-10 17:43:03 +01:00
2025-12-11 07:46:27 +01:00
.suggestion-card {
border-left: 3px solid #1a73e8;
background-color: #ffffff;
padding: 10px;
margin-bottom: 8px;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
2025-12-10 17:43:03 +01:00
}
2025-12-09 18:44:26 +01:00
</style>
""", unsafe_allow_html=True)
2025-12-09 22:27:56 +01:00
# --- SESSION STATE ---
2025-12-09 23:05:28 +01:00
if "messages" not in st.session_state: st.session_state.messages = []
if "user_id" not in st.session_state: st.session_state.user_id = str(uuid.uuid4())
2025-12-10 17:43:03 +01:00
# --- HELPER FUNCTIONS ---
2025-12-09 23:05:28 +01:00
2025-12-10 18:13:35 +01:00
def normalize_meta_and_body(meta, body):
2025-12-11 07:46:27 +01:00
"""Sanitizer: Stellt sicher, dass nur erlaubte Felder im Frontmatter bleiben."""
2025-12-10 18:13:35 +01:00
ALLOWED_KEYS = {"title", "type", "status", "tags", "id", "created", "updated", "aliases", "lang"}
clean_meta = {}
extra_content = []
if "titel" in meta and "title" not in meta:
meta["title"] = meta.pop("titel")
tag_candidates = ["tags", "emotionale_keywords", "keywords", "schluesselwoerter"]
all_tags = []
for key in tag_candidates:
if key in meta:
val = meta[key]
if isinstance(val, list): all_tags.extend(val)
elif isinstance(val, str): all_tags.extend([t.strip() for t in val.split(",")])
for key, val in meta.items():
if key in ALLOWED_KEYS:
clean_meta[key] = val
elif key in tag_candidates:
2025-12-11 07:46:27 +01:00
pass
2025-12-10 18:13:35 +01:00
else:
if val and isinstance(val, str):
header = key.replace("_", " ").title()
extra_content.append(f"## {header}\n{val}\n")
if all_tags:
clean_meta["tags"] = list(set(all_tags))
if extra_content:
new_section = "\n".join(extra_content)
final_body = f"{new_section}\n{body}"
else:
final_body = body
return clean_meta, final_body
2025-12-10 16:55:56 +01:00
def parse_markdown_draft(full_text):
2025-12-11 07:46:27 +01:00
"""Robustes Parsing + Sanitization."""
2025-12-10 17:35:21 +01:00
clean_text = full_text
2025-12-10 17:14:51 +01:00
2025-12-10 17:35:21 +01:00
pattern_block = r"```(?:markdown|md)?\s*(.*?)\s*```"
match_block = re.search(pattern_block, full_text, re.DOTALL | re.IGNORECASE)
if match_block:
clean_text = match_block.group(1).strip()
2025-12-10 16:55:56 +01:00
2025-12-10 18:13:35 +01:00
parts = re.split(r"^---+\s*$", clean_text, maxsplit=2, flags=re.MULTILINE)
2025-12-10 16:55:56 +01:00
2025-12-10 17:35:21 +01:00
meta = {}
body = clean_text
2025-12-10 18:13:35 +01:00
if len(parts) >= 3:
yaml_str = parts[1]
body_candidate = parts[2]
2025-12-10 16:55:56 +01:00
try:
2025-12-10 17:35:21 +01:00
parsed = yaml.safe_load(yaml_str)
if isinstance(parsed, dict):
meta = parsed
2025-12-10 18:13:35 +01:00
body = body_candidate.strip()
2025-12-10 17:43:03 +01:00
except Exception:
2025-12-10 18:13:35 +01:00
pass
2025-12-10 17:35:21 +01:00
2025-12-10 18:13:35 +01:00
return normalize_meta_and_body(meta, body)
2025-12-10 17:14:51 +01:00
def build_markdown_doc(meta, body):
2025-12-10 18:13:35 +01:00
"""Baut das finale Dokument zusammen."""
2025-12-10 17:14:51 +01:00
if "id" not in meta or meta["id"] == "generated_on_save":
2025-12-10 18:13:35 +01:00
safe_title = re.sub(r'[^a-zA-Z0-9]', '-', meta.get('title', 'note')).lower()[:30]
meta["id"] = f"{datetime.now().strftime('%Y%m%d')}-{safe_title}-{uuid.uuid4().hex[:4]}"
2025-12-10 17:14:51 +01:00
meta["updated"] = datetime.now().strftime("%Y-%m-%d")
2025-12-10 18:13:35 +01:00
ordered_meta = {}
prio_keys = ["id", "type", "title", "status", "tags"]
for k in prio_keys:
if k in meta: ordered_meta[k] = meta.pop(k)
ordered_meta.update(meta)
2025-12-10 17:35:21 +01:00
try:
2025-12-10 18:13:35 +01:00
yaml_str = yaml.dump(ordered_meta, default_flow_style=None, sort_keys=False, allow_unicode=True).strip()
2025-12-10 17:35:21 +01:00
except:
yaml_str = "error: generating_yaml"
2025-12-10 16:55:56 +01:00
return f"---\n{yaml_str}\n---\n\n{body}"
2025-12-10 16:41:21 +01:00
2025-12-09 23:05:28 +01:00
def load_history_from_logs(limit=10):
queries = []
if HISTORY_FILE.exists():
try:
with open(HISTORY_FILE, "r", encoding="utf-8") as f:
lines = f.readlines()
for line in reversed(lines):
try:
entry = json.loads(line)
q = entry.get("query_text")
if q and q not in queries:
queries.append(q)
if len(queries) >= limit: break
except: continue
2025-12-10 17:14:51 +01:00
except: pass
2025-12-09 23:05:28 +01:00
return queries
2025-12-09 18:44:26 +01:00
2025-12-11 07:46:27 +01:00
# --- API CLIENT ---
2025-12-09 18:44:26 +01:00
def send_chat_message(message: str, top_k: int, explain: bool):
try:
2025-12-09 23:05:28 +01:00
response = requests.post(
CHAT_ENDPOINT,
json={"message": message, "top_k": top_k, "explain": explain},
timeout=API_TIMEOUT
)
2025-12-09 18:44:26 +01:00
response.raise_for_status()
return response.json()
except Exception as e:
return {"error": str(e)}
2025-12-11 07:46:27 +01:00
def analyze_draft_text(text: str, n_type: str):
"""Ruft den neuen Intelligence-Service (WP-11) auf."""
try:
response = requests.post(
INGEST_ANALYZE_ENDPOINT,
json={"text": text, "type": n_type},
2025-12-11 11:28:16 +01:00
timeout=15 # Erhöhtes Timeout für Suche
2025-12-11 07:46:27 +01:00
)
response.raise_for_status()
return response.json()
except Exception as e:
return {"error": str(e)}
def save_draft_to_vault(markdown_content: str, filename: str = None):
"""Ruft den neuen Persistence-Service (WP-11) auf."""
try:
response = requests.post(
INGEST_SAVE_ENDPOINT,
json={"markdown_content": markdown_content, "filename": filename},
2025-12-11 11:28:16 +01:00
timeout=60 # Indizierung kann dauern
2025-12-11 07:46:27 +01:00
)
response.raise_for_status()
return response.json()
except Exception as e:
return {"error": str(e)}
2025-12-09 23:05:28 +01:00
def submit_feedback(query_id, node_id, score, comment=None):
2025-12-09 18:44:26 +01:00
try:
2025-12-09 23:05:28 +01:00
requests.post(FEEDBACK_ENDPOINT, json={"query_id": query_id, "node_id": node_id, "score": score, "comment": comment}, timeout=2)
2025-12-10 17:14:51 +01:00
st.toast(f"Feedback ({score}) gesendet!")
2025-12-09 23:05:28 +01:00
except: pass
2025-12-09 18:44:26 +01:00
# --- UI COMPONENTS ---
def render_sidebar():
with st.sidebar:
2025-12-09 23:05:28 +01:00
st.title("🧠 mindnet")
2025-12-11 11:28:16 +01:00
st.caption("v2.3.3 | WP-10b (Intelligence)")
2025-12-10 17:14:51 +01:00
mode = st.radio("Modus", ["💬 Chat", "📝 Manueller Editor"], index=0)
2025-12-09 23:05:28 +01:00
st.divider()
st.subheader("⚙️ Settings")
top_k = st.slider("Quellen (Top-K)", 1, 10, 5)
explain = st.toggle("Explanation Layer", True)
2025-12-09 22:27:56 +01:00
st.divider()
2025-12-09 23:05:28 +01:00
st.subheader("🕒 Verlauf")
2025-12-10 17:14:51 +01:00
for q in load_history_from_logs(8):
if st.button(f"🔎 {q[:25]}...", key=f"hist_{q}", use_container_width=True):
2025-12-09 23:05:28 +01:00
st.session_state.messages.append({"role": "user", "content": q})
st.rerun()
return mode, top_k, explain
2025-12-10 16:55:56 +01:00
def render_draft_editor(msg):
qid = msg.get('query_id', str(uuid.uuid4()))
key_base = f"draft_{qid}"
2025-12-10 18:13:35 +01:00
# 1. Init
2025-12-10 17:14:51 +01:00
if f"{key_base}_init" not in st.session_state:
2025-12-10 16:55:56 +01:00
meta, body = parse_markdown_draft(msg["content"])
2025-12-10 18:13:35 +01:00
2025-12-10 17:14:51 +01:00
st.session_state[f"{key_base}_type"] = meta.get("type", "default")
2025-12-10 18:13:35 +01:00
st.session_state[f"{key_base}_title"] = meta.get("title", "")
2025-12-10 17:14:51 +01:00
tags_raw = meta.get("tags", [])
2025-12-10 17:43:03 +01:00
st.session_state[f"{key_base}_tags"] = ", ".join(tags_raw) if isinstance(tags_raw, list) else str(tags_raw)
2025-12-10 16:55:56 +01:00
st.session_state[f"{key_base}_body"] = body.strip()
2025-12-10 18:13:35 +01:00
st.session_state[f"{key_base}_meta"] = meta
2025-12-11 07:46:27 +01:00
st.session_state[f"{key_base}_suggestions"] = []
2025-12-10 17:14:51 +01:00
st.session_state[f"{key_base}_init"] = True
2025-12-10 16:55:56 +01:00
2025-12-11 07:46:27 +01:00
# 2. UI Layout
2025-12-10 16:55:56 +01:00
st.markdown(f'<div class="draft-box">', unsafe_allow_html=True)
st.markdown("### 📝 Entwurf bearbeiten")
2025-12-10 17:35:21 +01:00
2025-12-10 18:13:35 +01:00
# Metadata
c1, c2 = st.columns([2, 1])
2025-12-10 16:55:56 +01:00
with c1:
2025-12-10 18:13:35 +01:00
new_title = st.text_input("Titel", value=st.session_state.get(f"{key_base}_title", ""), key=f"{key_base}_inp_title")
with c2:
2025-12-10 17:35:21 +01:00
known_types = ["concept", "project", "decision", "experience", "journal", "person", "value", "goal", "principle", "default"]
curr_type = st.session_state.get(f"{key_base}_type", "default")
2025-12-10 17:14:51 +01:00
if curr_type not in known_types: known_types.append(curr_type)
new_type = st.selectbox("Typ", known_types, index=known_types.index(curr_type), key=f"{key_base}_sel_type")
2025-12-10 16:55:56 +01:00
2025-12-10 18:13:35 +01:00
new_tags = st.text_input("Tags (kommagetrennt)", value=st.session_state.get(f"{key_base}_tags", ""), key=f"{key_base}_inp_tags")
2025-12-11 07:46:27 +01:00
# Tabs (Jetzt mit "Intelligence")
tab_edit, tab_intel, tab_view = st.tabs(["✏️ Inhalt", "🧠 Intelligence", "👁️ Vorschau"])
2025-12-10 16:55:56 +01:00
2025-12-11 07:46:27 +01:00
# Live Reassembly für alle Tabs
final_tags_list = [t.strip() for t in new_tags.split(",") if t.strip()]
final_meta = {
"id": "generated_on_save",
"type": new_type,
"title": new_title,
"status": "draft",
"tags": final_tags_list
}
# --- TAB 1: EDITOR ---
2025-12-10 16:55:56 +01:00
with tab_edit:
new_body = st.text_area(
2025-12-10 18:13:35 +01:00
"Body",
2025-12-10 17:35:21 +01:00
value=st.session_state.get(f"{key_base}_body", ""),
2025-12-10 17:14:51 +01:00
height=500,
2025-12-10 16:55:56 +01:00
key=f"{key_base}_txt_body",
2025-12-10 17:35:21 +01:00
label_visibility="collapsed"
2025-12-10 16:55:56 +01:00
)
2025-12-11 07:46:27 +01:00
# --- TAB 2: INTELLIGENCE (WP-11 Features) ---
with tab_intel:
st.info("Klicke auf 'Analysieren', um Verknüpfungen zu finden.")
2025-12-11 11:28:16 +01:00
if st.button("🔍 Analyse starten", key=f"{key_base}_analyze"):
2025-12-11 07:46:27 +01:00
with st.spinner("Analysiere Text und suche Verknüpfungen..."):
2025-12-11 11:28:16 +01:00
current_text = st.session_state[f"{key_base}_body"]
# API Call
analysis = analyze_draft_text(current_text, new_type)
2025-12-11 07:46:27 +01:00
if "error" in analysis:
st.error(f"Fehler: {analysis['error']}")
else:
2025-12-11 11:28:16 +01:00
suggestions = analysis.get("suggestions", [])
st.session_state[f"{key_base}_suggestions"] = suggestions
if not suggestions:
2025-12-11 07:46:27 +01:00
st.warning("Keine offensichtlichen Verknüpfungen gefunden.")
2025-12-11 11:28:16 +01:00
# Anzeige der Vorschläge
2025-12-11 07:46:27 +01:00
suggestions = st.session_state.get(f"{key_base}_suggestions", [])
if suggestions:
st.markdown(f"**{len(suggestions)} Vorschläge gefunden:**")
for idx, sugg in enumerate(suggestions):
with st.container():
st.markdown(f"""
<div class="suggestion-card">
2025-12-11 11:28:16 +01:00
<b>{sugg.get('target_title', 'Unbekannt')}</b> <small>({sugg.get('type', 'semantic')})</small><br>
2025-12-11 07:46:27 +01:00
<i>Grund: {sugg.get('reason', 'N/A')}</i><br>
2025-12-11 11:28:16 +01:00
<code>{sugg.get('suggested_markdown', '')}</code>
2025-12-11 07:46:27 +01:00
</div>
""", unsafe_allow_html=True)
if st.button("➕ Einfügen", key=f"{key_base}_add_{idx}"):
current_body = st.session_state[f"{key_base}_body"]
updated_body = f"{current_body}\n\n{sugg['suggested_markdown']}"
st.session_state[f"{key_base}_body"] = updated_body
2025-12-11 11:28:16 +01:00
st.toast(f"Link zu '{sugg.get('target_title', '?')}' eingefügt!")
2025-12-11 07:46:27 +01:00
st.rerun()
# --- TAB 3: PREVIEW ---
final_doc = build_markdown_doc(final_meta, st.session_state.get(f"{key_base}_body", ""))
2025-12-10 16:55:56 +01:00
with tab_view:
st.markdown('<div class="preview-box">', unsafe_allow_html=True)
2025-12-10 17:35:21 +01:00
st.markdown(final_doc)
2025-12-10 16:55:56 +01:00
st.markdown('</div>', unsafe_allow_html=True)
st.markdown("---")
2025-12-11 07:46:27 +01:00
# Actions (SAVE & EXPORT)
2025-12-10 17:14:51 +01:00
b1, b2 = st.columns([1, 1])
2025-12-10 16:55:56 +01:00
with b1:
2025-12-11 11:28:16 +01:00
# Echter Save Button (Ruft API auf)
2025-12-11 07:46:27 +01:00
if st.button("💾 Speichern & Indizieren", type="primary", key=f"{key_base}_save"):
with st.spinner("Speichere im Vault..."):
# Generiere Filename
safe_title = re.sub(r'[^a-zA-Z0-9]', '-', new_title).lower()[:30]
fname = f"{datetime.now().strftime('%Y%m%d')}-{safe_title}.md"
2025-12-11 11:28:16 +01:00
# Wir holen den aktuellsten Stand aus dem State (inklusive eingefügter Links)
latest_body = st.session_state.get(f"{key_base}_body", "")
latest_doc = build_markdown_doc(final_meta, latest_body)
result = save_draft_to_vault(latest_doc, filename=fname)
2025-12-11 07:46:27 +01:00
if "error" in result:
st.error(f"Fehler beim Speichern: {result['error']}")
else:
st.success(f"Gespeichert: {result.get('file_path')}")
st.balloons()
2025-12-10 16:55:56 +01:00
with b2:
2025-12-10 18:13:35 +01:00
if st.button("📋 Code anzeigen", key=f"{key_base}_btn_copy"):
2025-12-10 16:55:56 +01:00
st.code(final_doc, language="markdown")
2025-12-10 18:13:35 +01:00
2025-12-10 16:55:56 +01:00
st.markdown("</div>", unsafe_allow_html=True)
2025-12-10 18:13:35 +01:00
2025-12-09 23:05:28 +01:00
def render_chat_interface(top_k, explain):
2025-12-10 17:35:21 +01:00
for idx, msg in enumerate(st.session_state.messages):
2025-12-09 23:05:28 +01:00
with st.chat_message(msg["role"]):
if msg["role"] == "assistant":
2025-12-11 07:46:27 +01:00
# Header
2025-12-10 17:35:21 +01:00
intent = msg.get("intent", "UNKNOWN")
src = msg.get("intent_source", "?")
2025-12-10 17:43:03 +01:00
icon = {"EMPATHY":"❤️", "DECISION":"⚖️", "CODING":"💻", "FACT":"📚", "INTERVIEW":"📝"}.get(intent, "🧠")
2025-12-10 17:35:21 +01:00
st.markdown(f'<div class="intent-badge">{icon} Intent: {intent} <span style="opacity:0.6; font-size:0.8em">({src})</span></div>', unsafe_allow_html=True)
2025-12-09 23:16:28 +01:00
2025-12-10 17:43:03 +01:00
with st.expander("🐞 Debug Raw Payload", expanded=False):
st.json(msg)
2025-12-10 18:13:35 +01:00
# Logic
2025-12-10 17:35:21 +01:00
if intent == "INTERVIEW":
2025-12-10 16:55:56 +01:00
render_draft_editor(msg)
2025-12-10 16:41:21 +01:00
else:
st.markdown(msg["content"])
2025-12-09 23:05:28 +01:00
2025-12-10 18:13:35 +01:00
# Sources
2025-12-10 16:41:21 +01:00
if "sources" in msg and msg["sources"]:
2025-12-09 23:05:28 +01:00
for hit in msg["sources"]:
2025-12-10 17:43:03 +01:00
with st.expander(f"📄 {hit.get('note_id', '?')} ({hit.get('total_score', 0):.2f})"):
2025-12-09 23:05:28 +01:00
st.markdown(f"_{hit.get('source', {}).get('text', '')[:300]}..._")
if hit.get('explanation'):
st.caption(f"Grund: {hit['explanation']['reasons'][0]['message']}")
2025-12-10 17:35:21 +01:00
def _cb(qid=msg.get("query_id"), nid=hit.get('node_id')):
2025-12-09 23:05:28 +01:00
val = st.session_state.get(f"fb_src_{qid}_{nid}")
2025-12-10 17:14:51 +01:00
if val is not None: submit_feedback(qid, nid, val+1)
2025-12-10 17:35:21 +01:00
st.feedback("faces", key=f"fb_src_{msg.get('query_id')}_{hit.get('node_id')}", on_change=_cb)
2025-12-09 23:05:28 +01:00
2025-12-10 17:43:03 +01:00
if "query_id" in msg:
qid = msg["query_id"]
st.feedback("stars", key=f"fb_glob_{qid}", on_change=lambda: submit_feedback(qid, "generated_answer", st.session_state[f"fb_glob_{qid}"]+1))
2025-12-09 23:05:28 +01:00
else:
st.markdown(msg["content"])
2025-12-10 17:43:03 +01:00
if prompt := st.chat_input("Frage Mindnet..."):
2025-12-09 23:05:28 +01:00
st.session_state.messages.append({"role": "user", "content": prompt})
st.rerun()
2025-12-10 17:43:03 +01:00
if len(st.session_state.messages) > 0 and st.session_state.messages[-1]["role"] == "user":
2025-12-09 23:05:28 +01:00
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
2025-12-10 17:14:51 +01:00
resp = send_chat_message(st.session_state.messages[-1]["content"], top_k, explain)
2025-12-09 23:05:28 +01:00
if "error" in resp:
st.error(resp["error"])
else:
2025-12-10 17:14:51 +01:00
st.session_state.messages.append({
2025-12-09 23:05:28 +01:00
"role": "assistant",
"content": resp.get("answer"),
"intent": resp.get("intent", "FACT"),
2025-12-10 16:41:21 +01:00
"intent_source": resp.get("intent_source", "Unknown"),
2025-12-09 23:05:28 +01:00
"sources": resp.get("sources", []),
"query_id": resp.get("query_id")
2025-12-10 17:14:51 +01:00
})
2025-12-09 23:05:28 +01:00
st.rerun()
2025-12-10 17:14:51 +01:00
def render_manual_editor():
st.header("📝 Manueller Editor")
c1, c2 = st.columns([1, 2])
n_type = c1.selectbox("Typ", ["concept", "project", "decision", "experience", "value", "goal"])
tags = c2.text_input("Tags")
body = st.text_area("Inhalt", height=400, placeholder="# Titel\n\nText...")
2025-12-11 07:46:27 +01:00
if st.button("Speichern (Via API)"):
2025-12-10 17:14:51 +01:00
meta = {"type": n_type, "status": "draft", "tags": [t.strip() for t in tags.split(",")]}
2025-12-11 07:46:27 +01:00
doc = build_markdown_doc(meta, body)
# Test Call
res = save_draft_to_vault(doc, filename=f"manual-{uuid.uuid4().hex[:6]}.md")
if "error" in res:
st.error(res["error"])
else:
st.success(f"Gespeichert: {res.get('file_path')}")
2025-12-09 23:05:28 +01:00
mode, top_k, explain = render_sidebar()
if mode == "💬 Chat":
render_chat_interface(top_k, explain)
else:
2025-12-10 17:14:51 +01:00
render_manual_editor()