unbrowse 10.1.4 → 10.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/runtime/cli.js +88 -5
- package/runtime/mcp.js +109 -6
package/package.json
CHANGED
package/runtime/cli.js
CHANGED
|
@@ -64923,7 +64923,7 @@ var init_telemetry = __esm(() => {
|
|
|
64923
64923
|
});
|
|
64924
64924
|
|
|
64925
64925
|
// .tmp-runtime-src/build-info.generated.ts
|
|
64926
|
-
var BUILD_RELEASE_VERSION = "10.1.
|
|
64926
|
+
var BUILD_RELEASE_VERSION = "10.1.6", BUILD_GIT_SHA = "416dbff46262", BUILD_CODE_HASH = "5d9ebf619c61", BUILD_RELEASE_MANIFEST_BASE64 = "eyJzY2hlbWFfdmVyc2lvbiI6MSwicmVsZWFzZV92ZXJzaW9uIjoiMTAuMS42IiwiZ2l0X3NoYSI6IjQxNmRiZmY0NjI2MiIsImNvZGVfaGFzaCI6IjVkOWViZjYxOWM2MSIsInRyYWNlX3ZlcnNpb24iOiI1ZDllYmY2MTljNjFANDE2ZGJmZjQ2MjYyIiwiaXNzdWVkX2F0IjoiMjAyNi0wNi0yM1QxMTozNToyMS4wNDlaIn0", BUILD_RELEASE_MANIFEST_SIGNATURE = "NHM896fAvzCu2ZBwpSbNxj9SNehiX7DkfO6fm221Kmo", BUILD_DEFAULT_BACKEND_URL = "https://beta-api.unbrowse.ai", BUILD_DEFAULT_PROFILE = "";
|
|
64927
64927
|
|
|
64928
64928
|
// .tmp-runtime-src/version.ts
|
|
64929
64929
|
import { createHash as createHash8 } from "crypto";
|
|
@@ -196349,9 +196349,20 @@ function normalizeRouteContext(url) {
|
|
|
196349
196349
|
function buildResolveCacheKey(domain, intent, url) {
|
|
196350
196350
|
return `${domain || "global"}:${intent.trim().toLowerCase()}:${normalizeRouteContext(url)}`;
|
|
196351
196351
|
}
|
|
196352
|
+
function mirrorCapturedRouteToContract(cacheKey2, skill, endpointId, ledgerOverride) {
|
|
196353
|
+
if (!localCachesEnabled() || ISOLATED_SKILL_SNAPSHOT_MODE)
|
|
196354
|
+
return;
|
|
196355
|
+
try {
|
|
196356
|
+
const urlTemplate = skill.endpoints?.find((e) => e.endpoint_id === endpointId)?.url_template ?? skill.endpoints?.[0]?.url_template ?? "";
|
|
196357
|
+
const pointer = `route:${createHash20("sha256").update(`${skill.skill_id}|${endpointId ?? ""}|${urlTemplate}`).digest("hex").slice(0, 32)}`;
|
|
196358
|
+
console.error(`[contract-index] route ${cacheKey2} → /contract ledger (mirror fired)`);
|
|
196359
|
+
mirrorResolutionToChain2(cacheKey2, pointer, ledgerOverride ?? {}).catch(() => {});
|
|
196360
|
+
} catch {}
|
|
196361
|
+
}
|
|
196352
196362
|
function promoteLearnedSkill(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
196353
196363
|
if (!localCachesEnabled())
|
|
196354
196364
|
return;
|
|
196365
|
+
const isFreshCapture = !skillRouteCache.has(cacheKey2);
|
|
196355
196366
|
const localSkillPath = writeSkillSnapshot(cacheKey2, skill);
|
|
196356
196367
|
capturedDomainCache.set(cacheKey2, { skill, endpointId, expires: Date.now() + 5 * 60000 });
|
|
196357
196368
|
skillRouteCache.set(cacheKey2, {
|
|
@@ -196362,6 +196373,8 @@ function promoteLearnedSkill(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
|
196362
196373
|
ts: Date.now()
|
|
196363
196374
|
});
|
|
196364
196375
|
persistRouteCache();
|
|
196376
|
+
if (isFreshCapture)
|
|
196377
|
+
mirrorCapturedRouteToContract(cacheKey2, skill, endpointId);
|
|
196365
196378
|
const domainKey = getDomainReuseKey(contextUrl ?? skill.domain);
|
|
196366
196379
|
if (domainKey) {
|
|
196367
196380
|
domainSkillCache.set(domainKey, {
|
|
@@ -196376,6 +196389,7 @@ function promoteLearnedSkill(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
|
196376
196389
|
function cacheResolvedSkill(cacheKey2, skill, endpointId) {
|
|
196377
196390
|
if (!localCachesEnabled())
|
|
196378
196391
|
return;
|
|
196392
|
+
const isFreshCapture = !skillRouteCache.has(cacheKey2);
|
|
196379
196393
|
const localSkillPath = writeSkillSnapshot(cacheKey2, skill);
|
|
196380
196394
|
skillRouteCache.set(cacheKey2, {
|
|
196381
196395
|
skillId: skill.skill_id,
|
|
@@ -196385,6 +196399,8 @@ function cacheResolvedSkill(cacheKey2, skill, endpointId) {
|
|
|
196385
196399
|
ts: Date.now()
|
|
196386
196400
|
});
|
|
196387
196401
|
persistRouteCache();
|
|
196402
|
+
if (isFreshCapture)
|
|
196403
|
+
mirrorCapturedRouteToContract(cacheKey2, skill, endpointId);
|
|
196388
196404
|
}
|
|
196389
196405
|
function promoteResultSnapshot(cacheKey2, skill, endpointId, result, trace) {
|
|
196390
196406
|
if (!localCachesEnabled())
|
|
@@ -199855,6 +199871,7 @@ async function resolveAndExecute(intent, params = {}, context, projection, optio
|
|
|
199855
199871
|
return null;
|
|
199856
199872
|
};
|
|
199857
199873
|
let directFetchCookieHeader = "";
|
|
199874
|
+
let directFetchCookiesAttached = 0;
|
|
199858
199875
|
try {
|
|
199859
199876
|
const dfHost = new URL(ctxUrl).hostname.replace(/^www\./, "");
|
|
199860
199877
|
const { extractBrowserCookies: extractBrowserCookies2 } = await Promise.resolve().then(() => (init_browser_cookies(), exports_browser_cookies));
|
|
@@ -199865,6 +199882,7 @@ async function resolveAndExecute(intent, params = {}, context, projection, optio
|
|
|
199865
199882
|
return `${c.name}=${v}`;
|
|
199866
199883
|
}).filter((pair) => !pair.endsWith("=")).join("; ");
|
|
199867
199884
|
if (directFetchCookieHeader) {
|
|
199885
|
+
directFetchCookiesAttached = directFetchCookieHeader.split("; ").filter(Boolean).length;
|
|
199868
199886
|
console.log(`[direct-fetch] ${ctxUrl} attaching ${dfCookies.length} browser cookie(s) for ${dfHost} on native fetch`);
|
|
199869
199887
|
}
|
|
199870
199888
|
}
|
|
@@ -199986,7 +200004,8 @@ async function resolveAndExecute(intent, params = {}, context, projection, optio
|
|
|
199986
200004
|
trace: trace2,
|
|
199987
200005
|
source: "direct-fetch",
|
|
199988
200006
|
skill: undefined,
|
|
199989
|
-
timing: t
|
|
200007
|
+
timing: t,
|
|
200008
|
+
...directFetchCookiesAttached > 0 ? { cookies_injected: directFetchCookiesAttached } : {}
|
|
199990
200009
|
};
|
|
199991
200010
|
}
|
|
199992
200011
|
} else if (directRes.status === 403 || directRes.status === 429 || directRes.status === 503) {
|
|
@@ -293992,6 +294011,7 @@ async function handler14(parsed, opts) {
|
|
|
293992
294011
|
const conn = wsEndpoint ? await attach(wsEndpoint) : await spawnChrome({ headless: true, perContextProxy: false, persist: true });
|
|
293993
294012
|
const target = await createTarget(conn, url, {});
|
|
293994
294013
|
let cookiesInjected = 0;
|
|
294014
|
+
let injectedCookies = [];
|
|
293995
294015
|
try {
|
|
293996
294016
|
const { shouldImportBrowserCookies: shouldImportBrowserCookies2 } = await init_auth().then(() => exports_auth);
|
|
293997
294017
|
if (shouldImportBrowserCookies2()) {
|
|
@@ -293999,6 +294019,7 @@ async function handler14(parsed, opts) {
|
|
|
293999
294019
|
const { findBestBrowserSession: findBestBrowserSession3, extractBrowserCookies: extractBrowserCookies3 } = await Promise.resolve().then(() => (init_browser_cookies(), exports_browser_cookies));
|
|
294000
294020
|
const best = findBestBrowserSession3(host);
|
|
294001
294021
|
const cookies = best?.cookies ?? extractBrowserCookies3(host).cookies;
|
|
294022
|
+
injectedCookies = cookies.map((c) => ({ name: c.name, value: c.value }));
|
|
294002
294023
|
if (cookies.length > 0) {
|
|
294003
294024
|
const toCdpSameSite = (s) => {
|
|
294004
294025
|
const v = (s ?? "").toLowerCase();
|
|
@@ -294052,6 +294073,44 @@ async function handler14(parsed, opts) {
|
|
|
294052
294073
|
process.stderr.write(`[page] act go: body read skipped: ${readErr instanceof Error ? readErr.message : String(readErr)}
|
|
294053
294074
|
`);
|
|
294054
294075
|
}
|
|
294076
|
+
const decodesToJsonRecord = (s) => {
|
|
294077
|
+
if (!s)
|
|
294078
|
+
return false;
|
|
294079
|
+
const t = s.trim();
|
|
294080
|
+
if (!(t.startsWith("{") || t.startsWith("[")))
|
|
294081
|
+
return false;
|
|
294082
|
+
try {
|
|
294083
|
+
const v = JSON.parse(t);
|
|
294084
|
+
return v !== null && typeof v === "object";
|
|
294085
|
+
} catch {
|
|
294086
|
+
return false;
|
|
294087
|
+
}
|
|
294088
|
+
};
|
|
294089
|
+
if (!decodesToJsonRecord(pageText) && injectedCookies.length > 0) {
|
|
294090
|
+
try {
|
|
294091
|
+
const cookieHeader = injectedCookies.map((c) => {
|
|
294092
|
+
const v = c.value.startsWith('"') && c.value.endsWith('"') ? c.value.slice(1, -1) : c.value;
|
|
294093
|
+
return `${c.name}=${v}`;
|
|
294094
|
+
}).join("; ");
|
|
294095
|
+
const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
|
|
294096
|
+
const res = await fetch(url, {
|
|
294097
|
+
headers: { Cookie: cookieHeader, "User-Agent": ua, Accept: "application/json" },
|
|
294098
|
+
signal: AbortSignal.timeout(1e4)
|
|
294099
|
+
});
|
|
294100
|
+
const directBody = await res.text();
|
|
294101
|
+
if (decodesToJsonRecord(directBody)) {
|
|
294102
|
+
pageText = directBody.slice(0, 200000);
|
|
294103
|
+
process.stderr.write(`[auth] act go: navigated body unstructured/walled; supplemented page.text from authenticated direct fetch (status ${res.status}, ${directBody.length} bytes)
|
|
294104
|
+
`);
|
|
294105
|
+
} else {
|
|
294106
|
+
process.stderr.write(`[auth] act go: direct-fetch supplement skipped — body not a JSON record (status ${res.status})
|
|
294107
|
+
`);
|
|
294108
|
+
}
|
|
294109
|
+
} catch (directErr) {
|
|
294110
|
+
process.stderr.write(`[auth] act go: direct-fetch supplement failed: ${directErr instanceof Error ? directErr.message : String(directErr)}
|
|
294111
|
+
`);
|
|
294112
|
+
}
|
|
294113
|
+
}
|
|
294055
294114
|
let captcha;
|
|
294056
294115
|
if (parsed.flags.solve === true || process.env.UNBROWSE_AUTO_SOLVE === "1") {
|
|
294057
294116
|
const { clearCaptchaInRender: clearCaptchaInRender2 } = await Promise.resolve().then(() => (init_captcha_render(), exports_captcha_render));
|
|
@@ -304859,6 +304918,30 @@ async function cmdRun(args, flags, verb = "run") {
|
|
|
304859
304918
|
run_plan: runPlan
|
|
304860
304919
|
};
|
|
304861
304920
|
}
|
|
304921
|
+
const isActGoNavigateVariant = (() => {
|
|
304922
|
+
const i = (intent ?? "").trim().toLowerCase();
|
|
304923
|
+
return i === "act go" || i === "go" || i === "act read" || i === "read";
|
|
304924
|
+
})();
|
|
304925
|
+
function mirrorNavigateBodyToPage(result) {
|
|
304926
|
+
if (!isActGoNavigateVariant)
|
|
304927
|
+
return result;
|
|
304928
|
+
if ("page" in result)
|
|
304929
|
+
return result;
|
|
304930
|
+
if (result.source !== "direct-fetch")
|
|
304931
|
+
return result;
|
|
304932
|
+
const body = result.result;
|
|
304933
|
+
if (body === null || typeof body !== "object")
|
|
304934
|
+
return result;
|
|
304935
|
+
let text3;
|
|
304936
|
+
try {
|
|
304937
|
+
text3 = JSON.stringify(body);
|
|
304938
|
+
} catch {
|
|
304939
|
+
return result;
|
|
304940
|
+
}
|
|
304941
|
+
if (!text3)
|
|
304942
|
+
return result;
|
|
304943
|
+
return { ...result, page: { text: text3.slice(0, 200000) } };
|
|
304944
|
+
}
|
|
304862
304945
|
function endpointsDiscovered(result) {
|
|
304863
304946
|
if (typeof result.endpoints_discovered === "number")
|
|
304864
304947
|
return result.endpoints_discovered;
|
|
@@ -304969,11 +305052,11 @@ async function cmdRun(args, flags, verb = "run") {
|
|
|
304969
305052
|
return;
|
|
304970
305053
|
}
|
|
304971
305054
|
if (isResolveSuccessResult(result)) {
|
|
304972
|
-
output(decorate(result), !!flags.pretty);
|
|
305055
|
+
output(decorate(mirrorNavigateBodyToPage(result)), !!flags.pretty);
|
|
304973
305056
|
return;
|
|
304974
305057
|
}
|
|
304975
305058
|
if (!shouldIndexFallback(result)) {
|
|
304976
|
-
output(decorate(result), !!flags.pretty);
|
|
305059
|
+
output(decorate(mirrorNavigateBodyToPage(result)), !!flags.pretty);
|
|
304977
305060
|
return;
|
|
304978
305061
|
}
|
|
304979
305062
|
if (flags["no-index"]) {
|
|
@@ -304999,7 +305082,7 @@ async function cmdRun(args, flags, verb = "run") {
|
|
|
304999
305082
|
if (!captureLooksThin(capture)) {
|
|
305000
305083
|
result = await resolveStep("after_index");
|
|
305001
305084
|
if (isResolveSuccessResult(result)) {
|
|
305002
|
-
output(decorate(result), !!flags.pretty);
|
|
305085
|
+
output(decorate(mirrorNavigateBodyToPage(result)), !!flags.pretty);
|
|
305003
305086
|
return;
|
|
305004
305087
|
}
|
|
305005
305088
|
if (resolveResultError(result) === "auth_required") {
|
package/runtime/mcp.js
CHANGED
|
@@ -101443,7 +101443,7 @@ async function mergedAuthHeaders(key, signer) {
|
|
|
101443
101443
|
var AUTH_DOMAIN = "unbrowse-auth:v1";
|
|
101444
101444
|
|
|
101445
101445
|
// .tmp-runtime-src/build-info.generated.ts
|
|
101446
|
-
var BUILD_RELEASE_VERSION = "10.1.
|
|
101446
|
+
var BUILD_RELEASE_VERSION = "10.1.6", BUILD_GIT_SHA = "416dbff46262", BUILD_CODE_HASH = "5d9ebf619c61", BUILD_RELEASE_MANIFEST_BASE64 = "eyJzY2hlbWFfdmVyc2lvbiI6MSwicmVsZWFzZV92ZXJzaW9uIjoiMTAuMS42IiwiZ2l0X3NoYSI6IjQxNmRiZmY0NjI2MiIsImNvZGVfaGFzaCI6IjVkOWViZjYxOWM2MSIsInRyYWNlX3ZlcnNpb24iOiI1ZDllYmY2MTljNjFANDE2ZGJmZjQ2MjYyIiwiaXNzdWVkX2F0IjoiMjAyNi0wNi0yM1QxMTozNToyMS4wNDlaIn0", BUILD_RELEASE_MANIFEST_SIGNATURE = "NHM896fAvzCu2ZBwpSbNxj9SNehiX7DkfO6fm221Kmo", BUILD_DEFAULT_BACKEND_URL = "https://beta-api.unbrowse.ai", BUILD_DEFAULT_PROFILE = "";
|
|
101447
101447
|
|
|
101448
101448
|
// .tmp-runtime-src/version.ts
|
|
101449
101449
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -193486,9 +193486,20 @@ function normalizeRouteContext(url) {
|
|
|
193486
193486
|
function buildResolveCacheKey(domain, intent, url) {
|
|
193487
193487
|
return `${domain || "global"}:${intent.trim().toLowerCase()}:${normalizeRouteContext(url)}`;
|
|
193488
193488
|
}
|
|
193489
|
+
function mirrorCapturedRouteToContract(cacheKey2, skill, endpointId, ledgerOverride) {
|
|
193490
|
+
if (!localCachesEnabled() || ISOLATED_SKILL_SNAPSHOT_MODE)
|
|
193491
|
+
return;
|
|
193492
|
+
try {
|
|
193493
|
+
const urlTemplate = skill.endpoints?.find((e) => e.endpoint_id === endpointId)?.url_template ?? skill.endpoints?.[0]?.url_template ?? "";
|
|
193494
|
+
const pointer = `route:${createHash15("sha256").update(`${skill.skill_id}|${endpointId ?? ""}|${urlTemplate}`).digest("hex").slice(0, 32)}`;
|
|
193495
|
+
console.error(`[contract-index] route ${cacheKey2} → /contract ledger (mirror fired)`);
|
|
193496
|
+
mirrorResolutionToChain(cacheKey2, pointer, ledgerOverride ?? {}).catch(() => {});
|
|
193497
|
+
} catch {}
|
|
193498
|
+
}
|
|
193489
193499
|
function promoteLearnedSkill(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
193490
193500
|
if (!localCachesEnabled())
|
|
193491
193501
|
return;
|
|
193502
|
+
const isFreshCapture = !skillRouteCache.has(cacheKey2);
|
|
193492
193503
|
const localSkillPath = writeSkillSnapshot(cacheKey2, skill);
|
|
193493
193504
|
capturedDomainCache.set(cacheKey2, { skill, endpointId, expires: Date.now() + 5 * 60000 });
|
|
193494
193505
|
skillRouteCache.set(cacheKey2, {
|
|
@@ -193499,6 +193510,8 @@ function promoteLearnedSkill(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
|
193499
193510
|
ts: Date.now()
|
|
193500
193511
|
});
|
|
193501
193512
|
persistRouteCache();
|
|
193513
|
+
if (isFreshCapture)
|
|
193514
|
+
mirrorCapturedRouteToContract(cacheKey2, skill, endpointId);
|
|
193502
193515
|
const domainKey = getDomainReuseKey(contextUrl ?? skill.domain);
|
|
193503
193516
|
if (domainKey) {
|
|
193504
193517
|
domainSkillCache.set(domainKey, {
|
|
@@ -193513,6 +193526,7 @@ function promoteLearnedSkill(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
|
193513
193526
|
function cacheResolvedSkill(cacheKey2, skill, endpointId) {
|
|
193514
193527
|
if (!localCachesEnabled())
|
|
193515
193528
|
return;
|
|
193529
|
+
const isFreshCapture = !skillRouteCache.has(cacheKey2);
|
|
193516
193530
|
const localSkillPath = writeSkillSnapshot(cacheKey2, skill);
|
|
193517
193531
|
skillRouteCache.set(cacheKey2, {
|
|
193518
193532
|
skillId: skill.skill_id,
|
|
@@ -193522,6 +193536,8 @@ function cacheResolvedSkill(cacheKey2, skill, endpointId) {
|
|
|
193522
193536
|
ts: Date.now()
|
|
193523
193537
|
});
|
|
193524
193538
|
persistRouteCache();
|
|
193539
|
+
if (isFreshCapture)
|
|
193540
|
+
mirrorCapturedRouteToContract(cacheKey2, skill, endpointId);
|
|
193525
193541
|
}
|
|
193526
193542
|
function promoteResultSnapshot(cacheKey2, skill, endpointId, result, trace) {
|
|
193527
193543
|
if (!localCachesEnabled())
|
|
@@ -196992,6 +197008,7 @@ async function resolveAndExecute(intent, params = {}, context, projection, optio
|
|
|
196992
197008
|
return null;
|
|
196993
197009
|
};
|
|
196994
197010
|
let directFetchCookieHeader = "";
|
|
197011
|
+
let directFetchCookiesAttached = 0;
|
|
196995
197012
|
try {
|
|
196996
197013
|
const dfHost = new URL(ctxUrl).hostname.replace(/^www\./, "");
|
|
196997
197014
|
const { extractBrowserCookies: extractBrowserCookies2 } = await Promise.resolve().then(() => (init_browser_cookies(), exports_browser_cookies));
|
|
@@ -197002,6 +197019,7 @@ async function resolveAndExecute(intent, params = {}, context, projection, optio
|
|
|
197002
197019
|
return `${c.name}=${v}`;
|
|
197003
197020
|
}).filter((pair) => !pair.endsWith("=")).join("; ");
|
|
197004
197021
|
if (directFetchCookieHeader) {
|
|
197022
|
+
directFetchCookiesAttached = directFetchCookieHeader.split("; ").filter(Boolean).length;
|
|
197005
197023
|
console.log(`[direct-fetch] ${ctxUrl} attaching ${dfCookies.length} browser cookie(s) for ${dfHost} on native fetch`);
|
|
197006
197024
|
}
|
|
197007
197025
|
}
|
|
@@ -197123,7 +197141,8 @@ async function resolveAndExecute(intent, params = {}, context, projection, optio
|
|
|
197123
197141
|
trace: trace2,
|
|
197124
197142
|
source: "direct-fetch",
|
|
197125
197143
|
skill: undefined,
|
|
197126
|
-
timing: t
|
|
197144
|
+
timing: t,
|
|
197145
|
+
...directFetchCookiesAttached > 0 ? { cookies_injected: directFetchCookiesAttached } : {}
|
|
197127
197146
|
};
|
|
197128
197147
|
}
|
|
197129
197148
|
} else if (directRes.status === 403 || directRes.status === 429 || directRes.status === 503) {
|
|
@@ -286020,6 +286039,7 @@ async function handler14(parsed, opts) {
|
|
|
286020
286039
|
const conn = wsEndpoint ? await attach(wsEndpoint) : await spawnChrome({ headless: true, perContextProxy: false, persist: true });
|
|
286021
286040
|
const target = await createTarget(conn, url, {});
|
|
286022
286041
|
let cookiesInjected = 0;
|
|
286042
|
+
let injectedCookies = [];
|
|
286023
286043
|
try {
|
|
286024
286044
|
const { shouldImportBrowserCookies: shouldImportBrowserCookies2 } = await init_auth().then(() => exports_auth);
|
|
286025
286045
|
if (shouldImportBrowserCookies2()) {
|
|
@@ -286027,6 +286047,7 @@ async function handler14(parsed, opts) {
|
|
|
286027
286047
|
const { findBestBrowserSession: findBestBrowserSession2, extractBrowserCookies: extractBrowserCookies2 } = await Promise.resolve().then(() => (init_browser_cookies(), exports_browser_cookies));
|
|
286028
286048
|
const best = findBestBrowserSession2(host);
|
|
286029
286049
|
const cookies = best?.cookies ?? extractBrowserCookies2(host).cookies;
|
|
286050
|
+
injectedCookies = cookies.map((c) => ({ name: c.name, value: c.value }));
|
|
286030
286051
|
if (cookies.length > 0) {
|
|
286031
286052
|
const toCdpSameSite = (s) => {
|
|
286032
286053
|
const v = (s ?? "").toLowerCase();
|
|
@@ -286080,6 +286101,44 @@ async function handler14(parsed, opts) {
|
|
|
286080
286101
|
process.stderr.write(`[page] act go: body read skipped: ${readErr instanceof Error ? readErr.message : String(readErr)}
|
|
286081
286102
|
`);
|
|
286082
286103
|
}
|
|
286104
|
+
const decodesToJsonRecord = (s) => {
|
|
286105
|
+
if (!s)
|
|
286106
|
+
return false;
|
|
286107
|
+
const t = s.trim();
|
|
286108
|
+
if (!(t.startsWith("{") || t.startsWith("[")))
|
|
286109
|
+
return false;
|
|
286110
|
+
try {
|
|
286111
|
+
const v = JSON.parse(t);
|
|
286112
|
+
return v !== null && typeof v === "object";
|
|
286113
|
+
} catch {
|
|
286114
|
+
return false;
|
|
286115
|
+
}
|
|
286116
|
+
};
|
|
286117
|
+
if (!decodesToJsonRecord(pageText) && injectedCookies.length > 0) {
|
|
286118
|
+
try {
|
|
286119
|
+
const cookieHeader = injectedCookies.map((c) => {
|
|
286120
|
+
const v = c.value.startsWith('"') && c.value.endsWith('"') ? c.value.slice(1, -1) : c.value;
|
|
286121
|
+
return `${c.name}=${v}`;
|
|
286122
|
+
}).join("; ");
|
|
286123
|
+
const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
|
|
286124
|
+
const res = await fetch(url, {
|
|
286125
|
+
headers: { Cookie: cookieHeader, "User-Agent": ua, Accept: "application/json" },
|
|
286126
|
+
signal: AbortSignal.timeout(1e4)
|
|
286127
|
+
});
|
|
286128
|
+
const directBody = await res.text();
|
|
286129
|
+
if (decodesToJsonRecord(directBody)) {
|
|
286130
|
+
pageText = directBody.slice(0, 200000);
|
|
286131
|
+
process.stderr.write(`[auth] act go: navigated body unstructured/walled; supplemented page.text from authenticated direct fetch (status ${res.status}, ${directBody.length} bytes)
|
|
286132
|
+
`);
|
|
286133
|
+
} else {
|
|
286134
|
+
process.stderr.write(`[auth] act go: direct-fetch supplement skipped — body not a JSON record (status ${res.status})
|
|
286135
|
+
`);
|
|
286136
|
+
}
|
|
286137
|
+
} catch (directErr) {
|
|
286138
|
+
process.stderr.write(`[auth] act go: direct-fetch supplement failed: ${directErr instanceof Error ? directErr.message : String(directErr)}
|
|
286139
|
+
`);
|
|
286140
|
+
}
|
|
286141
|
+
}
|
|
286083
286142
|
let captcha;
|
|
286084
286143
|
if (parsed.flags.solve === true || process.env.UNBROWSE_AUTO_SOLVE === "1") {
|
|
286085
286144
|
const { clearCaptchaInRender: clearCaptchaInRender2 } = await Promise.resolve().then(() => (init_captcha_render(), exports_captcha_render));
|
|
@@ -297050,6 +297109,30 @@ async function cmdRun(args, flags, verb = "run") {
|
|
|
297050
297109
|
run_plan: runPlan
|
|
297051
297110
|
};
|
|
297052
297111
|
}
|
|
297112
|
+
const isActGoNavigateVariant = (() => {
|
|
297113
|
+
const i = (intent ?? "").trim().toLowerCase();
|
|
297114
|
+
return i === "act go" || i === "go" || i === "act read" || i === "read";
|
|
297115
|
+
})();
|
|
297116
|
+
function mirrorNavigateBodyToPage(result) {
|
|
297117
|
+
if (!isActGoNavigateVariant)
|
|
297118
|
+
return result;
|
|
297119
|
+
if ("page" in result)
|
|
297120
|
+
return result;
|
|
297121
|
+
if (result.source !== "direct-fetch")
|
|
297122
|
+
return result;
|
|
297123
|
+
const body = result.result;
|
|
297124
|
+
if (body === null || typeof body !== "object")
|
|
297125
|
+
return result;
|
|
297126
|
+
let text3;
|
|
297127
|
+
try {
|
|
297128
|
+
text3 = JSON.stringify(body);
|
|
297129
|
+
} catch {
|
|
297130
|
+
return result;
|
|
297131
|
+
}
|
|
297132
|
+
if (!text3)
|
|
297133
|
+
return result;
|
|
297134
|
+
return { ...result, page: { text: text3.slice(0, 200000) } };
|
|
297135
|
+
}
|
|
297053
297136
|
function endpointsDiscovered(result) {
|
|
297054
297137
|
if (typeof result.endpoints_discovered === "number")
|
|
297055
297138
|
return result.endpoints_discovered;
|
|
@@ -297160,11 +297243,11 @@ async function cmdRun(args, flags, verb = "run") {
|
|
|
297160
297243
|
return;
|
|
297161
297244
|
}
|
|
297162
297245
|
if (isResolveSuccessResult(result)) {
|
|
297163
|
-
output(decorate(result), !!flags.pretty);
|
|
297246
|
+
output(decorate(mirrorNavigateBodyToPage(result)), !!flags.pretty);
|
|
297164
297247
|
return;
|
|
297165
297248
|
}
|
|
297166
297249
|
if (!shouldIndexFallback(result)) {
|
|
297167
|
-
output(decorate(result), !!flags.pretty);
|
|
297250
|
+
output(decorate(mirrorNavigateBodyToPage(result)), !!flags.pretty);
|
|
297168
297251
|
return;
|
|
297169
297252
|
}
|
|
297170
297253
|
if (flags["no-index"]) {
|
|
@@ -297190,7 +297273,7 @@ async function cmdRun(args, flags, verb = "run") {
|
|
|
297190
297273
|
if (!captureLooksThin(capture)) {
|
|
297191
297274
|
result = await resolveStep("after_index");
|
|
297192
297275
|
if (isResolveSuccessResult(result)) {
|
|
297193
|
-
output(decorate(result), !!flags.pretty);
|
|
297276
|
+
output(decorate(mirrorNavigateBodyToPage(result)), !!flags.pretty);
|
|
297194
297277
|
return;
|
|
297195
297278
|
}
|
|
297196
297279
|
if (resolveResultError(result) === "auth_required") {
|
|
@@ -300184,6 +300267,7 @@ __export(exports_orchestrator, {
|
|
|
300184
300267
|
pickWalkTarget: () => pickWalkTarget2,
|
|
300185
300268
|
pickPreferredSkillSnapshot: () => pickPreferredSkillSnapshot2,
|
|
300186
300269
|
persistDomainCache: () => persistDomainCache2,
|
|
300270
|
+
mirrorCapturedRouteToContract: () => mirrorCapturedRouteToContract2,
|
|
300187
300271
|
marketplaceSkillMatchesContext: () => marketplaceSkillMatchesContext2,
|
|
300188
300272
|
looksLikeSingleItemRoute: () => looksLikeSingleItemRoute,
|
|
300189
300273
|
isRouteCacheEntryStale: () => isRouteCacheEntryStale2,
|
|
@@ -300768,9 +300852,20 @@ function normalizeRouteContext2(url) {
|
|
|
300768
300852
|
function buildResolveCacheKey2(domain, intent, url) {
|
|
300769
300853
|
return `${domain || "global"}:${intent.trim().toLowerCase()}:${normalizeRouteContext2(url)}`;
|
|
300770
300854
|
}
|
|
300855
|
+
function mirrorCapturedRouteToContract2(cacheKey2, skill, endpointId, ledgerOverride) {
|
|
300856
|
+
if (!localCachesEnabled2() || ISOLATED_SKILL_SNAPSHOT_MODE2)
|
|
300857
|
+
return;
|
|
300858
|
+
try {
|
|
300859
|
+
const urlTemplate = skill.endpoints?.find((e) => e.endpoint_id === endpointId)?.url_template ?? skill.endpoints?.[0]?.url_template ?? "";
|
|
300860
|
+
const pointer = `route:${createHash51("sha256").update(`${skill.skill_id}|${endpointId ?? ""}|${urlTemplate}`).digest("hex").slice(0, 32)}`;
|
|
300861
|
+
console.error(`[contract-index] route ${cacheKey2} → /contract ledger (mirror fired)`);
|
|
300862
|
+
mirrorResolutionToChain(cacheKey2, pointer, ledgerOverride ?? {}).catch(() => {});
|
|
300863
|
+
} catch {}
|
|
300864
|
+
}
|
|
300771
300865
|
function promoteLearnedSkill2(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
300772
300866
|
if (!localCachesEnabled2())
|
|
300773
300867
|
return;
|
|
300868
|
+
const isFreshCapture = !skillRouteCache2.has(cacheKey2);
|
|
300774
300869
|
const localSkillPath = writeSkillSnapshot2(cacheKey2, skill);
|
|
300775
300870
|
capturedDomainCache2.set(cacheKey2, { skill, endpointId, expires: Date.now() + 5 * 60000 });
|
|
300776
300871
|
skillRouteCache2.set(cacheKey2, {
|
|
@@ -300781,6 +300876,8 @@ function promoteLearnedSkill2(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
|
300781
300876
|
ts: Date.now()
|
|
300782
300877
|
});
|
|
300783
300878
|
persistRouteCache2();
|
|
300879
|
+
if (isFreshCapture)
|
|
300880
|
+
mirrorCapturedRouteToContract2(cacheKey2, skill, endpointId);
|
|
300784
300881
|
const domainKey = getDomainReuseKey2(contextUrl ?? skill.domain);
|
|
300785
300882
|
if (domainKey) {
|
|
300786
300883
|
domainSkillCache2.set(domainKey, {
|
|
@@ -300795,6 +300892,7 @@ function promoteLearnedSkill2(scope, cacheKey2, skill, endpointId, contextUrl) {
|
|
|
300795
300892
|
function cacheResolvedSkill2(cacheKey2, skill, endpointId) {
|
|
300796
300893
|
if (!localCachesEnabled2())
|
|
300797
300894
|
return;
|
|
300895
|
+
const isFreshCapture = !skillRouteCache2.has(cacheKey2);
|
|
300798
300896
|
const localSkillPath = writeSkillSnapshot2(cacheKey2, skill);
|
|
300799
300897
|
skillRouteCache2.set(cacheKey2, {
|
|
300800
300898
|
skillId: skill.skill_id,
|
|
@@ -300804,6 +300902,8 @@ function cacheResolvedSkill2(cacheKey2, skill, endpointId) {
|
|
|
300804
300902
|
ts: Date.now()
|
|
300805
300903
|
});
|
|
300806
300904
|
persistRouteCache2();
|
|
300905
|
+
if (isFreshCapture)
|
|
300906
|
+
mirrorCapturedRouteToContract2(cacheKey2, skill, endpointId);
|
|
300807
300907
|
}
|
|
300808
300908
|
function promoteResultSnapshot2(cacheKey2, skill, endpointId, result, trace) {
|
|
300809
300909
|
if (!localCachesEnabled2())
|
|
@@ -304279,6 +304379,7 @@ async function resolveAndExecute2(intent, params = {}, context, projection, opti
|
|
|
304279
304379
|
return null;
|
|
304280
304380
|
};
|
|
304281
304381
|
let directFetchCookieHeader = "";
|
|
304382
|
+
let directFetchCookiesAttached = 0;
|
|
304282
304383
|
try {
|
|
304283
304384
|
const dfHost = new URL(ctxUrl).hostname.replace(/^www\./, "");
|
|
304284
304385
|
const { extractBrowserCookies: extractBrowserCookies3 } = await Promise.resolve().then(() => (init_browser_cookies(), exports_browser_cookies));
|
|
@@ -304289,6 +304390,7 @@ async function resolveAndExecute2(intent, params = {}, context, projection, opti
|
|
|
304289
304390
|
return `${c.name}=${v}`;
|
|
304290
304391
|
}).filter((pair) => !pair.endsWith("=")).join("; ");
|
|
304291
304392
|
if (directFetchCookieHeader) {
|
|
304393
|
+
directFetchCookiesAttached = directFetchCookieHeader.split("; ").filter(Boolean).length;
|
|
304292
304394
|
console.log(`[direct-fetch] ${ctxUrl} attaching ${dfCookies.length} browser cookie(s) for ${dfHost} on native fetch`);
|
|
304293
304395
|
}
|
|
304294
304396
|
}
|
|
@@ -304410,7 +304512,8 @@ async function resolveAndExecute2(intent, params = {}, context, projection, opti
|
|
|
304410
304512
|
trace: trace2,
|
|
304411
304513
|
source: "direct-fetch",
|
|
304412
304514
|
skill: undefined,
|
|
304413
|
-
timing: t
|
|
304515
|
+
timing: t,
|
|
304516
|
+
...directFetchCookiesAttached > 0 ? { cookies_injected: directFetchCookiesAttached } : {}
|
|
304414
304517
|
};
|
|
304415
304518
|
}
|
|
304416
304519
|
} else if (directRes.status === 403 || directRes.status === 429 || directRes.status === 503) {
|