0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
231 lines
8.2 KiB
Python
231 lines
8.2 KiB
Python
"""Transform modules for Headroom SDK."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from importlib import import_module
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
# Expose concrete types to static analysis while keeping runtime imports lazy.
|
|
from headroom.transforms.anchor_selector import ( # noqa: F401
|
|
AnchorSelector,
|
|
AnchorStrategy,
|
|
AnchorWeights,
|
|
DataPattern,
|
|
calculate_information_score,
|
|
compute_item_hash,
|
|
)
|
|
from headroom.transforms.base import Transform # noqa: F401
|
|
from headroom.transforms.cache_aligner import CacheAligner # noqa: F401
|
|
from headroom.transforms.code_compressor import ( # noqa: F401
|
|
CodeAwareCompressor,
|
|
CodeCompressionResult,
|
|
CodeCompressorConfig,
|
|
CodeLanguage,
|
|
DocstringMode,
|
|
detect_language,
|
|
is_tree_sitter_available,
|
|
)
|
|
from headroom.transforms.content_detector import ( # noqa: F401
|
|
ContentType,
|
|
DetectionResult,
|
|
detect_content_type,
|
|
)
|
|
from headroom.transforms.content_router import ( # noqa: F401
|
|
CompressionStrategy,
|
|
ContentRouter,
|
|
ContentRouterConfig,
|
|
RouterCompressionResult,
|
|
)
|
|
from headroom.transforms.diff_compressor import ( # noqa: F401
|
|
DiffCompressionResult,
|
|
DiffCompressor,
|
|
DiffCompressorConfig,
|
|
)
|
|
from headroom.transforms.html_extractor import ( # noqa: F401
|
|
HTMLExtractionResult,
|
|
HTMLExtractor,
|
|
HTMLExtractorConfig,
|
|
is_html_content,
|
|
)
|
|
from headroom.transforms.log_compressor import ( # noqa: F401
|
|
LogCompressionResult,
|
|
LogCompressor,
|
|
LogCompressorConfig,
|
|
)
|
|
from headroom.transforms.pipeline import TransformPipeline # noqa: F401
|
|
from headroom.transforms.search_compressor import ( # noqa: F401
|
|
SearchCompressionResult,
|
|
SearchCompressor,
|
|
SearchCompressorConfig,
|
|
)
|
|
from headroom.transforms.smart_crusher import SmartCrusher, SmartCrusherConfig # noqa: F401
|
|
from headroom.transforms.tabular_ingest import ( # noqa: F401
|
|
TabularCompressionResult,
|
|
TabularCompressor,
|
|
TabularCompressorConfig,
|
|
)
|
|
|
|
_HTML_EXTRACTOR_AVAILABLE = importlib.util.find_spec("trafilatura") is not None
|
|
|
|
__all__ = [
|
|
# Base
|
|
"Transform",
|
|
"TransformPipeline",
|
|
# Anchor selection
|
|
"AnchorSelector",
|
|
"AnchorStrategy",
|
|
"AnchorWeights",
|
|
"DataPattern",
|
|
"calculate_information_score",
|
|
"compute_item_hash",
|
|
# JSON compression
|
|
"SmartCrusher",
|
|
"SmartCrusherConfig",
|
|
# Text compression (coding tasks)
|
|
"ContentType",
|
|
"DetectionResult",
|
|
"detect_content_type",
|
|
"SearchCompressor",
|
|
"SearchCompressorConfig",
|
|
"SearchCompressionResult",
|
|
"LogCompressor",
|
|
"LogCompressorConfig",
|
|
"LogCompressionResult",
|
|
"TabularCompressor",
|
|
"TabularCompressorConfig",
|
|
"TabularCompressionResult",
|
|
"DiffCompressor",
|
|
"DiffCompressorConfig",
|
|
"DiffCompressionResult",
|
|
# Code-aware compression (AST-based)
|
|
"CodeAwareCompressor",
|
|
"CodeCompressorConfig",
|
|
"CodeCompressionResult",
|
|
"CodeLanguage",
|
|
"DocstringMode",
|
|
"detect_language",
|
|
"is_tree_sitter_available",
|
|
# Content routing
|
|
"ContentRouter",
|
|
"ContentRouterConfig",
|
|
"RouterCompressionResult",
|
|
"CompressionStrategy",
|
|
# Other transforms
|
|
"CacheAligner",
|
|
# HTML extraction (optional)
|
|
"_HTML_EXTRACTOR_AVAILABLE",
|
|
]
|
|
|
|
# Conditionally add HTML extractor exports
|
|
if _HTML_EXTRACTOR_AVAILABLE:
|
|
__all__.extend(
|
|
[
|
|
"HTMLExtractor",
|
|
"HTMLExtractorConfig",
|
|
"HTMLExtractionResult",
|
|
"is_html_content",
|
|
]
|
|
)
|
|
|
|
_LAZY_EXPORTS: dict[str, tuple[str, str]] = {
|
|
# Base
|
|
"Transform": ("headroom.transforms.base", "Transform"),
|
|
"TransformPipeline": ("headroom.transforms.pipeline", "TransformPipeline"),
|
|
# Anchor selection
|
|
"AnchorSelector": ("headroom.transforms.anchor_selector", "AnchorSelector"),
|
|
"AnchorStrategy": ("headroom.transforms.anchor_selector", "AnchorStrategy"),
|
|
"AnchorWeights": ("headroom.transforms.anchor_selector", "AnchorWeights"),
|
|
"DataPattern": ("headroom.transforms.anchor_selector", "DataPattern"),
|
|
"calculate_information_score": (
|
|
"headroom.transforms.anchor_selector",
|
|
"calculate_information_score",
|
|
),
|
|
"compute_item_hash": ("headroom.transforms.anchor_selector", "compute_item_hash"),
|
|
# JSON compression
|
|
"SmartCrusher": ("headroom.transforms.smart_crusher", "SmartCrusher"),
|
|
"SmartCrusherConfig": ("headroom.transforms.smart_crusher", "SmartCrusherConfig"),
|
|
# Text compression (coding tasks)
|
|
"ContentType": ("headroom.transforms.content_detector", "ContentType"),
|
|
"DetectionResult": ("headroom.transforms.content_detector", "DetectionResult"),
|
|
"detect_content_type": ("headroom.transforms.content_detector", "detect_content_type"),
|
|
"SearchCompressor": ("headroom.transforms.search_compressor", "SearchCompressor"),
|
|
"SearchCompressorConfig": (
|
|
"headroom.transforms.search_compressor",
|
|
"SearchCompressorConfig",
|
|
),
|
|
"SearchCompressionResult": (
|
|
"headroom.transforms.search_compressor",
|
|
"SearchCompressionResult",
|
|
),
|
|
"LogCompressor": ("headroom.transforms.log_compressor", "LogCompressor"),
|
|
"LogCompressorConfig": ("headroom.transforms.log_compressor", "LogCompressorConfig"),
|
|
"LogCompressionResult": ("headroom.transforms.log_compressor", "LogCompressionResult"),
|
|
"TabularCompressor": ("headroom.transforms.tabular_ingest", "TabularCompressor"),
|
|
"TabularCompressorConfig": (
|
|
"headroom.transforms.tabular_ingest",
|
|
"TabularCompressorConfig",
|
|
),
|
|
"TabularCompressionResult": (
|
|
"headroom.transforms.tabular_ingest",
|
|
"TabularCompressionResult",
|
|
),
|
|
"DiffCompressor": ("headroom.transforms.diff_compressor", "DiffCompressor"),
|
|
"DiffCompressorConfig": ("headroom.transforms.diff_compressor", "DiffCompressorConfig"),
|
|
"DiffCompressionResult": (
|
|
"headroom.transforms.diff_compressor",
|
|
"DiffCompressionResult",
|
|
),
|
|
# Code-aware compression (AST-based)
|
|
"CodeAwareCompressor": ("headroom.transforms.code_compressor", "CodeAwareCompressor"),
|
|
"CodeCompressorConfig": ("headroom.transforms.code_compressor", "CodeCompressorConfig"),
|
|
"CodeCompressionResult": (
|
|
"headroom.transforms.code_compressor",
|
|
"CodeCompressionResult",
|
|
),
|
|
"CodeLanguage": ("headroom.transforms.code_compressor", "CodeLanguage"),
|
|
"DocstringMode": ("headroom.transforms.code_compressor", "DocstringMode"),
|
|
"detect_language": ("headroom.transforms.code_compressor", "detect_language"),
|
|
"is_tree_sitter_available": (
|
|
"headroom.transforms.code_compressor",
|
|
"is_tree_sitter_available",
|
|
),
|
|
# Content routing
|
|
"ContentRouter": ("headroom.transforms.content_router", "ContentRouter"),
|
|
"ContentRouterConfig": ("headroom.transforms.content_router", "ContentRouterConfig"),
|
|
"RouterCompressionResult": (
|
|
"headroom.transforms.content_router",
|
|
"RouterCompressionResult",
|
|
),
|
|
"CompressionStrategy": ("headroom.transforms.content_router", "CompressionStrategy"),
|
|
# Other transforms
|
|
"CacheAligner": ("headroom.transforms.cache_aligner", "CacheAligner"),
|
|
# HTML extraction (optional dependency - requires trafilatura)
|
|
"HTMLExtractor": ("headroom.transforms.html_extractor", "HTMLExtractor"),
|
|
"HTMLExtractorConfig": ("headroom.transforms.html_extractor", "HTMLExtractorConfig"),
|
|
"HTMLExtractionResult": ("headroom.transforms.html_extractor", "HTMLExtractionResult"),
|
|
"is_html_content": ("headroom.transforms.html_extractor", "is_html_content"),
|
|
}
|
|
|
|
|
|
def __getattr__(name: str) -> object:
|
|
if name == "__path__":
|
|
raise AttributeError(name)
|
|
if name == "_HTML_EXTRACTOR_AVAILABLE":
|
|
return _HTML_EXTRACTOR_AVAILABLE
|
|
|
|
try:
|
|
module_name, attr_name = _LAZY_EXPORTS[name]
|
|
except KeyError as exc:
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from exc
|
|
|
|
module = import_module(module_name)
|
|
value = getattr(module, attr_name)
|
|
globals()[name] = value
|
|
return value
|
|
|
|
|
|
def __dir__() -> list[str]:
|
|
return sorted(set(globals()) | set(__all__))
|