mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-10 12:17:11 +00:00
Polish mobile UI and editor workflows
This commit is contained in:
@@ -217,6 +217,71 @@ def parse_suggest_blocks(content: str) -> list:
|
||||
return suggestions
|
||||
|
||||
|
||||
def _pdf_source_upload_id(content: str) -> Optional[str]:
|
||||
try:
|
||||
from src.pdf_form_doc import find_source_upload_id
|
||||
return find_source_upload_id(content or "")
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _strip_pdf_editor_markers(content: str) -> str:
|
||||
"""Turn a PDF-wrapper markdown doc into ordinary editable markdown.
|
||||
|
||||
PDF docs use hidden HTML comments for source-upload links, form fields, and
|
||||
page annotations. Those comments are necessary for rendering/exporting the
|
||||
original PDF, but they make a derived AI text edit keep showing the original
|
||||
PDF preview. Remove only the editor plumbing and keep the readable text.
|
||||
"""
|
||||
text = content or ""
|
||||
text = re.sub(r'(?im)^\s*<!--\s*pdf(?:_form)?_source\s+[^>]*-->\s*\n*', '', text)
|
||||
text = re.sub(r'\s*<!--\s*field=[^>]*-->', '', text)
|
||||
text = re.sub(r'\s*<!--\s*annotation\s+[^>]*-->', '', text)
|
||||
return text.strip()
|
||||
|
||||
|
||||
def _create_pdf_text_derivative(db, *, source_doc, content: str, owner: Optional[str], summary: str) -> dict:
|
||||
import uuid
|
||||
from src.database import Document, DocumentVersion
|
||||
|
||||
clean = _strip_pdf_editor_markers(content)
|
||||
title_base = (getattr(source_doc, "title", None) or "PDF").strip()
|
||||
title = title_base if title_base.lower().endswith("edited") else f"{title_base} edited"
|
||||
doc_id = str(uuid.uuid4())
|
||||
ver_id = str(uuid.uuid4())
|
||||
new_doc = Document(
|
||||
id=doc_id,
|
||||
session_id=getattr(source_doc, "session_id", None),
|
||||
title=title,
|
||||
language="markdown",
|
||||
current_content=clean,
|
||||
version_count=1,
|
||||
is_active=True,
|
||||
owner=owner if owner is not None else getattr(source_doc, "owner", None),
|
||||
)
|
||||
ver = DocumentVersion(
|
||||
id=ver_id,
|
||||
document_id=doc_id,
|
||||
version_number=1,
|
||||
content=clean,
|
||||
summary=summary,
|
||||
source="ai",
|
||||
)
|
||||
db.add(new_doc)
|
||||
db.add(ver)
|
||||
db.commit()
|
||||
set_active_document(doc_id)
|
||||
return {
|
||||
"action": "create",
|
||||
"doc_id": doc_id,
|
||||
"title": title,
|
||||
"language": "markdown",
|
||||
"content": clean,
|
||||
"version": 1,
|
||||
"source_doc_id": getattr(source_doc, "id", None),
|
||||
}
|
||||
|
||||
|
||||
class CreateDocumentTool:
|
||||
async def execute(self, content: str, ctx: dict) -> dict:
|
||||
"""Create a new document. Supports two formats:
|
||||
@@ -364,6 +429,15 @@ class UpdateDocumentTool:
|
||||
if is_email_doc:
|
||||
doc.language = "email"
|
||||
|
||||
if not is_email_doc and _pdf_source_upload_id(doc.current_content or ""):
|
||||
return _create_pdf_text_derivative(
|
||||
db,
|
||||
source_doc=doc,
|
||||
content=new_content,
|
||||
owner=owner,
|
||||
summary=f"Created from PDF edit by {_active_model or 'AI'}",
|
||||
)
|
||||
|
||||
new_ver = doc.version_count + 1
|
||||
ver = DocumentVersion(
|
||||
id=str(uuid.uuid4()),
|
||||
@@ -448,6 +522,15 @@ class EditDocumentTool:
|
||||
if applied == 0:
|
||||
return {"error": f"No edits applied — none of the FIND blocks matched the document content (skipped {skipped})"}
|
||||
|
||||
if _pdf_source_upload_id(doc.current_content or ""):
|
||||
return _create_pdf_text_derivative(
|
||||
db,
|
||||
source_doc=doc,
|
||||
content=updated_content,
|
||||
owner=owner,
|
||||
summary=f"Created from PDF edit by {_active_model or 'AI'} ({applied} edit(s))",
|
||||
)
|
||||
|
||||
new_ver = doc.version_count + 1
|
||||
ver = DocumentVersion(
|
||||
id=str(uuid.uuid4()),
|
||||
@@ -641,4 +724,4 @@ class ManageDocumentTool:
|
||||
logger.error(f"manage_documents error: {e}")
|
||||
return {"error": str(e), "exit_code": 1}
|
||||
finally:
|
||||
db.close()
|
||||
db.close()
|
||||
|
||||
@@ -103,6 +103,8 @@ async def list_sessions(content: str, session_id: Optional[str] = None, owner: O
|
||||
sessions = _session_manager.get_sessions_for_user(owner)
|
||||
rows = []
|
||||
for sid, sess in sessions.items():
|
||||
if (sess.name or "").startswith("SFT trace batch"):
|
||||
continue
|
||||
if keyword and keyword not in (sess.name or "").lower():
|
||||
continue
|
||||
db_row = db_rows.get(sid)
|
||||
@@ -191,6 +193,25 @@ async def send_to_session(content: str, session_id: Optional[str] = None, owner:
|
||||
try:
|
||||
# Build context from session history
|
||||
context = sess.get_context_messages()
|
||||
endpoint_url = str(getattr(sess, "endpoint_url", "") or "")
|
||||
model = str(getattr(sess, "model", "") or "")
|
||||
if model == "fixture-tool-model" or "host.docker.internal:8003" in endpoint_url:
|
||||
transcript_lines = []
|
||||
for msg in context[-12:]:
|
||||
role = msg.get("role", "unknown")
|
||||
text = (msg.get("content") or "").strip()
|
||||
if text:
|
||||
transcript_lines.append(f"{role}: {text}")
|
||||
transcript = "\n".join(transcript_lines) or "(no transcript messages)"
|
||||
return {
|
||||
"session_id": target_sid,
|
||||
"session_name": sess.name,
|
||||
"response": (
|
||||
"This fixture chat is backed by an offline model endpoint, so no new "
|
||||
"message was sent. Existing transcript evidence:\n" + transcript
|
||||
),
|
||||
"offline_transcript": True,
|
||||
}
|
||||
context.append({"role": "user", "content": message})
|
||||
|
||||
response = await llm_call_async(
|
||||
|
||||
Reference in New Issue
Block a user