"""Notion API 常量定义。 集中管理 Notion API 的版本、请求头、退避参数与类型枚举, 版本升级或参数调整时仅需修改本文件。 """ from __future__ import annotations from typing import Any BASE_URL = "https://api.notion.com/v1" NOTION_VERSION = "2022-06-28" # 当前稳定版本 # Notion 通用请求头(除 Authorization 外,由 executor 注入) _NOTION_HEADERS: dict[str, str] = { "Notion-Version": NOTION_VERSION, "Accept": "application/json", } # 运行时工具执行的 429/5xx 退避:通过 retry_policy 配置 # executor 基于 tenacity 重试,retry_status_codes 非空时按配置重试 _RUNTIME_RETRY_POLICY: dict[str, Any] = { "max_attempts": 3, "retry_delay": 1.0, "retry_backoff": 2.0, "retry_status_codes": [429, 502, 503, 504], "retry_on_timeout": True, "retry_on_connection_error": True, } # discover/preview/create 阶段 429 退避参数 _RETRY_MAX_ATTEMPTS = 5 _RETRY_BASE_DELAY = 1.0 # 数据库属性类型枚举(用于 property_mapper 校验) PROPERTY_TYPES = frozenset( { "title", "rich_text", "number", "select", "multi_select", "status", "date", "people", "files", "checkbox", "url", "email", "phone_number", "formula", "relation", "rollup", "created_time", "created_by", "last_edited_time", "last_edited_by", } ) # 文本类块类型枚举(用于 block_parser) TEXT_BLOCK_TYPES = frozenset( { "paragraph", "heading_1", "heading_2", "heading_3", "bulleted_list_item", "numbered_list_item", "to_do", "toggle", "quote", "callout", } )