feat: Office-Extraktion (docx/xlsx/pptx) fuer files-, mail- und notes-MCP
officeutil.py (analog pdfutil): server-seitige Text-Extraktion, damit das LLM Inhalte als Text bekommt statt Base64-Blob. Verkabelt in files.read_file, mail.read_attachment (und notes.read_resource, bereits ine34711d). Aeltere Binaerformate (.doc/.xls/.ppt) und .rtf bewusst nicht behandelt -- is_office() False -> Fallback auf Rohdaten. requirements-extra: python-pptx. War bereits deployed und lief (FileTypes-Tests 14 passed), lag aber uncommittet im Arbeitsverzeichnis; ohne officeutil.py waere ein frischer Clone seite34711dkaputt gewesen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XhHNJKk3RsHgUsJ27WQSom
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
e34711d0ca
commit
4d198017df
+4
-1
@@ -25,6 +25,7 @@ from starlette.routing import Mount
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
from common import get_current_user, OAUTH_ROUTES, BearerAuthMiddleware
|
||||
from pdfutil import pdf_to_content
|
||||
from officeutil import office_to_content, is_office
|
||||
|
||||
from common import load_config as _lc
|
||||
_cfg = _lc()
|
||||
@@ -343,7 +344,7 @@ def read_attachment(
|
||||
key: Annotated[str, Field(description="Message key from search results")],
|
||||
attachment_index: Annotated[int, Field(description="Attachment number from the read_mail attachment list (1-based)")],
|
||||
) -> list[TextContent | ImageContent | EmbeddedResource]:
|
||||
"""Read an email attachment. Images shown inline, PDFs as extracted text, text directly, other documents as binary. Get the index from read_mail."""
|
||||
"""Read an email attachment. Images shown inline, PDFs and Office documents (docx, xlsx, pptx) as extracted text, text directly, other formats as binary. Get the index from read_mail."""
|
||||
_trim_memory()
|
||||
user = get_current_user()
|
||||
if not user:
|
||||
@@ -369,6 +370,8 @@ def read_attachment(
|
||||
return [TextContent(type="text", text=payload.decode("utf-8", errors="replace")[:100000])]
|
||||
if mime == "application/pdf" or att["filename"].lower().endswith(".pdf"):
|
||||
return pdf_to_content(payload, att["filename"], mime, uri=f"mail://attachment/{att['filename']}")
|
||||
if is_office(mime, att["filename"]):
|
||||
return office_to_content(payload, att["filename"], mime, uri=f"mail://attachment/{att['filename']}")
|
||||
return [EmbeddedResource(type="resource", resource=BlobResourceContents(
|
||||
uri=f"mail://attachment/{att['filename']}",
|
||||
blob=base64.b64encode(payload).decode(), mimeType=mime))]
|
||||
|
||||
Reference in New Issue
Block a user