Schließe die Connector-Kapselung ab, damit Paperless, IMAP und weitere Quellen über dieselbe Anbindung laufen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
75a3949f7c
commit
d6b70d8f92
75 files changed
+9477
-414
No files matched your search
@@ -0,0 +1,98 @@
|
||||
"""Declared source and editor capabilities.
|
||||
|
||||
A common contract does not invent abilities the adapter does not have.
|
||||
Search filters that are false stay unavailable until a later delivery.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
PAPERLESS_CAPABILITIES = {
|
||||
"kind": "paperless",
|
||||
"navigate": False,
|
||||
"read_original": True,
|
||||
"read_preview": True,
|
||||
"read_attachment": False,
|
||||
"edit_content": False,
|
||||
"edit_metadata": False,
|
||||
"search": {
|
||||
"query": True,
|
||||
"title": False,
|
||||
"correspondent": False,
|
||||
"document_type": False,
|
||||
"tags": False,
|
||||
"document_range": False,
|
||||
"sort": False,
|
||||
"continuation": False,
|
||||
},
|
||||
}
|
||||
|
||||
IMAP_CAPABILITIES = {
|
||||
"kind": "imap",
|
||||
"navigate": True,
|
||||
"read_original": True,
|
||||
"read_preview": True,
|
||||
"read_attachment": True,
|
||||
"edit_content": False,
|
||||
"edit_metadata": False,
|
||||
"search": {
|
||||
"query": True,
|
||||
"title": False,
|
||||
"correspondent": False,
|
||||
"document_type": False,
|
||||
"tags": False,
|
||||
"document_range": False,
|
||||
"sort": False,
|
||||
"continuation": True,
|
||||
},
|
||||
}
|
||||
|
||||
CAPABILITIES = {
|
||||
"paperless": PAPERLESS_CAPABILITIES,
|
||||
"imap": IMAP_CAPABILITIES,
|
||||
}
|
||||
|
||||
EDITORS = {
|
||||
"note": True,
|
||||
"markdown_file": False,
|
||||
}
|
||||
|
||||
UNSUPPORTED_SEARCH = (
|
||||
"title",
|
||||
"correspondent",
|
||||
"document_type",
|
||||
"tag",
|
||||
"document_from",
|
||||
"document_to",
|
||||
"sort",
|
||||
"cursor",
|
||||
)
|
||||
|
||||
|
||||
def capability_payload() -> dict:
|
||||
from app.sourceregistry import registered_sources
|
||||
|
||||
return {
|
||||
"sources": [module.capabilities for module in registered_sources()],
|
||||
"editors": EDITORS,
|
||||
"protection_profiles": {
|
||||
"legacy-plaintext": "cleartext",
|
||||
"managed-encrypted": "locked",
|
||||
"client-encrypted": "locked",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def unsupported_filters(values: dict[str, str]) -> list[str]:
|
||||
return [name for name in UNSUPPORTED_SEARCH if str(values.get(name) or "").strip()]
|
||||
|
||||
|
||||
def with_capabilities(kind: str, connector_id: str, payload: dict) -> dict:
|
||||
from app.sourceregistry import require_source
|
||||
|
||||
body = dict(payload)
|
||||
spec = require_source(kind).capabilities
|
||||
body["connector_id"] = connector_id
|
||||
body["capabilities"] = spec
|
||||
body["unsupported"] = [name for name, enabled in spec["search"].items() if not enabled]
|
||||
body["continuation"] = body.get("next_before") if spec["search"].get("continuation") else None
|
||||
return body
|
||||
Reference in new issue
Block a user