"""Vault 写入后钩子 — FTS 增量索引。"""

from __future__ import annotations

from typing import Any

from niannian.vault.search import VaultSearchService


def on_vault_document_written(store, *, entry: dict[str, Any], body: str) -> None:
    config = getattr(store, "_config", None) or {}
    svc = VaultSearchService(store, config=config if isinstance(config, dict) else {})
    svc.index_document(
        vault_id=str(entry.get("vault_id") or ""),
        rel_path=str(entry.get("rel_path") or ""),
        namespace=str(entry.get("namespace") or "user"),
        title=str(entry.get("title") or ""),
        body=body,
    )
