Files
Bingxi Zhao (Frank) 4c1e000d85 release: v1.7.3
Prepare v1.7.3 notes for reading and book editing, expanded provider and
agent connections, learning records, model streams, and desktop upgrades.

Sync README prose and 11 translations, archive older release notes, and
update the package version. Resolve release lint/type blockers with explicit
parser and capability contracts, compatible Book call forwarding, accurate
auth task types, and quoted SQLite schema identifiers. Cover positional Book
calls and quoted legacy columns; align KB seed tests with visible retrieval
failure reporting. Keep HTTP fixtures independent of host proxies and translate
new Portuguese UI copy.

Release notes: assets/releases/ver1-7-3.md
2026-11-16 02:17:36 +08:00

89 lines
3.0 KiB
Python

"""Structural contract every document-parsing engine implements.
Parsing is deliberately kept OFF the ``RAGPipeline`` protocol
(``services/rag/pipelines/base.py``): it is an upstream, shared, *optional*
stage. An engine turns bytes/path into a :class:`~deeptutor.services.parsing.types.ParsedDocument`
and declares its availability + model readiness so the UI can gate local model
downloads (default: no silent multi-GB pull).
"""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Callable, Optional, Protocol, runtime_checkable
from .signature import ParserSignature
@dataclass(frozen=True)
class ReadinessReport:
"""Whether an engine can run a parse right now."""
ready: bool
# Machine code: "ready" | "models_missing" | "cli_missing" | "not_configured"
reason: str = "ready"
# User-facing guidance shown when not ready (which escape hatch to take).
message: str = ""
@runtime_checkable
class Parser(Protocol):
"""A document-parsing engine: ``source_path`` in → ``ParsedDocument`` out.
Availability is probed by the factory and by upload/fallback selection before
invoking an engine.
"""
name: str
# True when the engine downloads/needs local model weights (MinerU local,
# Docling). text-only, markitdown, and cloud backends are False.
needs_local_models: bool
@classmethod
def is_available(cls) -> bool:
"""Whether this engine's required runtime is installed or configured."""
...
def resolve_config(self) -> Any:
"""Load this engine's effective config slice from runtime settings."""
...
def supported_formats(self) -> frozenset[str]:
"""Lower-case file suffixes (including the dot) this engine can parse.
Compound suffixes such as ``.dclg.xml`` and ``.tar.gz`` are allowed.
An empty set means the engine performs its own content-based/runtime
detection (for example a remote Tika server with custom parsers).
"""
...
def signature(self, config: Any) -> ParserSignature:
"""Stable identity of ``(engine, version, output-affecting config)``."""
...
def is_ready(self, config: Any) -> ReadinessReport:
"""Whether a parse can run now (models present / cloud configured)."""
...
def parse(
self,
source_path: Path,
workdir: Path,
*,
config: Any,
on_output: Optional[Callable[[str], None]] = None,
) -> None:
"""Write canonical artifacts for ``source_path`` into ``workdir``.
Engines emit ``<stem>.md`` (always) and may add
``<stem>_content_list.json`` and an ``images/`` dir. The caller
(``ParseService``) assembles the :class:`ParsedDocument` from the
workdir via :func:`deeptutor.services.parsing.cache.load_ir` and writes
the cache manifest. Raises :class:`ParserError` on failure.
"""
...
__all__ = ["Parser", "ReadinessReport"]