feat(ai): add PixelRAG platform probe readiness

This commit is contained in:
ogt
2026-07-10 01:21:39 +08:00
parent 83f6d2e255
commit 199c857353
10 changed files with 1113 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ DEFAULT_OUTPUT_DIR = "runtime_artifacts/pixelrag_visual_evidence"
DEFAULT_TIMEOUT_MS = 30000
DEFAULT_SETTLE_MS = 500
DEFAULT_MAX_TILES = 80
FORBIDDEN_CONTEXT_HEADER_TOKENS = ("cookie", "authorization", "token", "secret", "key")
ALLOWED_PLATFORM_HOSTS = {
"momo": {"m.momoshop.com.tw", "www.momoshop.com.tw"},
"pchome": {"24h.pchome.com.tw", "ecshweb.pchome.com.tw", "ecapi-cdn.pchome.com.tw"},
@@ -123,6 +124,33 @@ def _build_tile_plan(
}
def _safe_public_browser_context(manifest: dict[str, Any]) -> dict[str, Any]:
raw_context = manifest.get("public_browser_context") or {}
raw_headers = raw_context.get("extra_http_headers") or {}
headers: dict[str, str] = {}
if isinstance(raw_headers, dict):
for key, value in raw_headers.items():
clean_key = str(key or "").strip()
lower_key = clean_key.lower()
if not clean_key:
continue
if any(token in lower_key for token in FORBIDDEN_CONTEXT_HEADER_TOKENS):
continue
headers[clean_key] = str(value or "")
return {
"context_policy": "public_empty_browser_context_no_login",
"locale": str(raw_context.get("locale") or "zh-TW"),
"timezone_id": str(
raw_context.get("timezone_id") or raw_context.get("timezoneId") or "Asia/Taipei"
),
"extra_http_headers": headers,
"credentialed_session_allowed": False,
"storage_state_allowed": False,
"raw_cookie_or_session_read_allowed": False,
"login_allowed": False,
}
def _output_paths(manifest: dict[str, Any], output_dir: str) -> dict[str, Path]:
target = manifest.get("capture_target") or {}
manifest_id = manifest.get("manifest_id") or _safe_name(
@@ -187,6 +215,7 @@ def _base_artifact(
max_tiles=_positive_int(args.max_tiles, DEFAULT_MAX_TILES),
),
"files": [],
"public_browser_context": _safe_public_browser_context(manifest),
}
@@ -205,10 +234,19 @@ def _capture(
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=True)
context = browser.new_context(ignore_https_errors=True, viewport={
"width": viewport["width"],
"height": viewport["height"],
})
public_context = _safe_public_browser_context(manifest)
context_kwargs = {
"ignore_https_errors": True,
"viewport": {
"width": viewport["width"],
"height": viewport["height"],
},
"locale": public_context["locale"],
"timezone_id": public_context["timezone_id"],
}
if public_context["extra_http_headers"]:
context_kwargs["extra_http_headers"] = public_context["extra_http_headers"]
context = browser.new_context(**context_kwargs)
page = context.new_page()
try:
response = page.goto(target["url"], wait_until=args.wait_until, timeout=timeout_ms)