2776813df3
The Sep 2026 decomposition (PR #102117) makes internal import paths a non-API: names now live in the focused modules that define them. This commit is the ONLY thing keeping the old paths alive, so external plugins have time to update. It is deliberately a single, unsquashed commit: git revert <this sha> removes every shim, stub and manifest at once on the announced date. Nothing in-tree may depend on these pointers: scripts/check_compat_pointers.py (wired into lint.yml) fails CI if it does. What it adds (see COMPAT_MANIFEST.md, compat_manifest.json): - 332 facade modules get one delimited `PLUGIN-COMPAT` block appended at the end of the file - 1,172 moved names resolved lazily via a module `__getattr__` (PEP 562) — never a top-level import, so no import cycles; facades that already had `__getattr__` get a chained one - 592 third-party/stdlib names the old modules used to expose, with their original import statements - 266 public definitions that had been deleted as unused, restored byte-for-byte from the pre-decomposition tree (+40 private helpers and 16 imports pulled in only because a restored definition needs them) - 3 deleted modules recreated as re-export stubs (gateway/startup_watchdog, hermes_cli/observability/ relay_runtime, tools/environments/modal_utils) - private names (`_x`) get no pointer: they were never API (3,792 skipped) Verified: all 335 touched modules import under a fresh HERMES_HOME and every manifest name resolves; the lint reports zero in-tree uses; ruff clean; targeted suites unchanged.
94 lines
3.4 KiB
Python
94 lines
3.4 KiB
Python
"""Feishu Document Tool -- read document content via Feishu/Lark API.
|
|
|
|
Provides ``feishu_doc_read`` for reading document content as plain text.
|
|
Uses the same lazy-import + BaseRequest pattern as feishu_comment.py.
|
|
"""
|
|
|
|
from tools.feishu_lark import ( # noqa: F401 (set_client/get_client are imported by feishu_comment)
|
|
_check_feishu,
|
|
build_request,
|
|
get_client,
|
|
raw_body,
|
|
set_client)
|
|
from tools.registry import registry, tool_error, tool_result
|
|
|
|
_RAW_CONTENT_URI = "/open-apis/docx/v1/documents/:document_id/raw_content"
|
|
|
|
FEISHU_DOC_READ_SCHEMA = {
|
|
"name": "feishu_doc_read",
|
|
"description": (
|
|
"Read the full content of a Feishu/Lark document as plain text. "
|
|
"Useful when you need more context beyond the quoted text in a comment."
|
|
),
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"doc_token": {
|
|
"type": "string",
|
|
"description": "The document token (from the document URL or comment context).",
|
|
},
|
|
},
|
|
"required": ["doc_token"],
|
|
},
|
|
}
|
|
|
|
|
|
def _handle_feishu_doc_read(args: dict, **kwargs) -> str:
|
|
doc_token = args.get("doc_token", "").strip()
|
|
if not doc_token:
|
|
return tool_error("doc_token is required")
|
|
client = get_client()
|
|
if client is None:
|
|
return tool_error("Feishu client not available (not in a Feishu comment context)")
|
|
try:
|
|
request = build_request("GET", _RAW_CONTENT_URI, paths={"document_id": doc_token})
|
|
except ImportError:
|
|
return tool_error("lark_oapi not installed")
|
|
|
|
# Handlers run synchronously in a worker thread (no event loop): call the blocking client.
|
|
response = client.request(request)
|
|
code = getattr(response, "code", None)
|
|
if code != 0:
|
|
return tool_error(f"Failed to read document: code={code} msg={getattr(response, 'msg', 'unknown error')}")
|
|
|
|
body = raw_body(response)
|
|
if body is not None:
|
|
try:
|
|
return tool_result(success=True, content=body.get("data", {}).get("content", ""))
|
|
except AttributeError:
|
|
pass
|
|
data = getattr(response, "data", None) # fallback: the typed response.data
|
|
if data:
|
|
content = data.get("content", "") if isinstance(data, dict) else getattr(data, "content", str(data))
|
|
return tool_result(success=True, content=content)
|
|
return tool_error("No content returned from document API")
|
|
|
|
|
|
registry.register(
|
|
name="feishu_doc_read", toolset="feishu_doc", schema=FEISHU_DOC_READ_SCHEMA, handler=_handle_feishu_doc_read,
|
|
check_fn=_check_feishu, requires_env=[], is_async=False, description="Read Feishu document content",
|
|
emoji="\U0001f4c4")
|
|
|
|
|
|
# ---- BEGIN PLUGIN-COMPAT (revert-scheduled; see COMPAT_MANIFEST.md) ----
|
|
# Names external plugins imported from this module before the Sep 2026 decomposition.
|
|
# Internal code MUST NOT use these (scripts/check_compat_pointers.py fails CI if it does).
|
|
# The whole block is removed by reverting the commit that added it.
|
|
import json # noqa: F401,E402
|
|
import logging # noqa: F401,E402
|
|
import threading # noqa: F401,E402
|
|
|
|
|
|
_PLUGIN_COMPAT_LAZY = {
|
|
'logger': ('tools.approval', 'logger'),
|
|
}
|
|
|
|
|
|
def __getattr__(name): # PEP 562 — lazy so no import cycles
|
|
target = _PLUGIN_COMPAT_LAZY.get(name)
|
|
if target is None:
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
import importlib
|
|
return getattr(importlib.import_module(target[0]), target[1])
|
|
# ---- END PLUGIN-COMPAT ----
|