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

@@ -17,6 +17,7 @@ const DEFAULT_OUTPUT_DIR = 'runtime_artifacts/pixelrag_visual_evidence';
const DEFAULT_TIMEOUT_MS = 30000;
const DEFAULT_SETTLE_MS = 500;
const DEFAULT_MAX_TILES = 80;
const FORBIDDEN_CONTEXT_HEADER_TOKENS = ['cookie', 'authorization', 'token', 'secret', 'key'];
const ALLOWED_PLATFORM_HOSTS = {
momo: new Set(['m.momoshop.com.tw', 'www.momoshop.com.tw']),
@@ -184,6 +185,30 @@ function positiveInt(value, fallback) {
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
}
function safePublicBrowserContext(manifest) {
const input = manifest.public_browser_context || {};
const headers = {};
const rawHeaders = input.extra_http_headers || {};
for (const [key, value] of Object.entries(rawHeaders)) {
const cleanKey = String(key || '').trim();
const lowerKey = cleanKey.toLowerCase();
if (!cleanKey || FORBIDDEN_CONTEXT_HEADER_TOKENS.some((token) => lowerKey.includes(token))) {
continue;
}
headers[cleanKey] = String(value || '');
}
return {
context_policy: 'public_empty_browser_context_no_login',
locale: String(input.locale || 'zh-TW'),
timezone_id: String(input.timezone_id || input.timezoneId || 'Asia/Taipei'),
extra_http_headers: headers,
credentialed_session_allowed: false,
storage_state_allowed: false,
raw_cookie_or_session_read_allowed: false,
login_allowed: false,
};
}
function buildTilePlan({ width, height, tileWidth, tileHeight, maxTiles }) {
const tiles = [];
const tilesX = Math.max(1, Math.ceil(width / tileWidth));
@@ -273,6 +298,7 @@ function buildBaseArtifact(manifest, options, errors = []) {
tile_size: { width: tileWidth, height: tileHeight },
tile_plan: tilePlan,
files: [],
public_browser_context: safePublicBrowserContext(manifest),
};
}
@@ -288,8 +314,19 @@ async function capture(manifest, options, artifact) {
launchOptions.executablePath = chromePath;
}
const publicContext = safePublicBrowserContext(manifest);
const contextOptions = {
ignoreHTTPSErrors: true,
viewport,
locale: publicContext.locale,
timezoneId: publicContext.timezone_id,
};
if (Object.keys(publicContext.extra_http_headers).length) {
contextOptions.extraHTTPHeaders = publicContext.extra_http_headers;
}
const browser = await chromium.launch(launchOptions);
const context = await browser.newContext({ ignoreHTTPSErrors: true, viewport });
const context = await browser.newContext(contextOptions);
const page = await context.newPage();
try {
const response = await page.goto(manifest.capture_target.url, {