Files
wehub-resource-sync bcbd1bdb22
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:44 +08:00

96 lines
3.0 KiB
Python

from collections.abc import AsyncIterator
from typing import Any
PATH_TREE_ID = "__path_tree__"
PAGE_CHUNK_BATCH_SIZE = 100
async def fetch_path_tree(accessor) -> str:
collection = await accessor.get_collection()
result = await collection.get(ids=[PATH_TREE_ID])
documents = result.get("documents") or []
if not documents:
raise FileNotFoundError(PATH_TREE_ID)
value = documents[0]
if value is None:
raise FileNotFoundError(PATH_TREE_ID)
if isinstance(value, str):
return value
return str(value)
async def fetch_page_chunks(accessor, slug: str) -> str:
chunks = await page_chunks(accessor, slug)
return "\n".join(chunk["document"] for chunk in chunks)
async def iter_page_chunks(accessor, slug: str) -> AsyncIterator[str]:
chunks = await page_chunks(accessor, slug)
for chunk in chunks:
yield chunk["document"]
async def page_chunks(accessor, slug: str) -> list[dict[str, Any]]:
collection = await accessor.get_collection()
chunks: list[dict[str, Any]] = []
offset = 0
while True:
result = await collection.get(
where={accessor.config.slug_field: slug},
include=["documents", "metadatas"],
limit=PAGE_CHUNK_BATCH_SIZE,
offset=offset,
)
documents = result.get("documents") or []
metadatas = result.get("metadatas") or [{} for _ in documents]
for document, metadata in zip(documents, metadatas, strict=True):
chunks.append({
"document": "" if document is None else str(document),
"metadata": metadata if isinstance(metadata, dict) else {},
})
if len(documents) < PAGE_CHUNK_BATCH_SIZE:
break
offset += PAGE_CHUNK_BATCH_SIZE
return sorted(chunks,
key=lambda item: chunk_index(
item["metadata"], accessor.config.chunk_index_field))
async def query_contains(
accessor,
pattern: str,
candidate_slugs: list[str],
*,
regex: bool = False,
) -> list[str]:
if not candidate_slugs:
return []
collection = await accessor.get_collection()
result = await collection.get(
where={accessor.config.slug_field: {
"$in": candidate_slugs
}},
where_document={"$regex" if regex else "$contains": pattern},
include=["metadatas"],
)
matched: set[str] = set()
for metadata in result.get("metadatas") or []:
if isinstance(metadata, dict):
slug = metadata.get(accessor.config.slug_field)
if slug is not None:
matched.add(str(slug))
return sorted(matched)
def chunk_index(metadata: dict[str, Any], field: str) -> int:
value = metadata.get(field, 0)
if isinstance(value, bool):
return 0
if isinstance(value, int):
return value
if isinstance(value, float):
return int(value)
if isinstance(value, str) and value.isdigit():
return int(value)
return 0