@absolutejs/search 0.2.3 → 0.3.0

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.
@@ -0,0 +1,23 @@
1
+ import { type ReadWebpageOptions } from "./index";
2
+ import { fetchPublicWebResource } from "./transport";
3
+ export type MapWebsiteOptions = {
4
+ url: string;
5
+ /** Most page URLs to return. Defaults to 500, at most 5000. */
6
+ maxUrls?: number;
7
+ signal?: AbortSignal;
8
+ fetchResource?: typeof fetchPublicWebResource;
9
+ /** Used only for the home-page fallback when a site has no sitemap. */
10
+ render?: ReadWebpageOptions["render"];
11
+ };
12
+ export type MapWebsiteResult = {
13
+ url: string;
14
+ urls: string[];
15
+ source: "sitemap" | "links";
16
+ sitemaps: string[];
17
+ truncated: boolean;
18
+ };
19
+ /** List a site's pages: from its sitemaps (named in robots.txt, or the
20
+ * conventional /sitemap.xml), else from the links on its home page. Only
21
+ * same-origin URLs are returned, and every fetch goes through the public-web
22
+ * transport. */
23
+ export declare const mapWebsite: (options: MapWebsiteOptions) => Promise<MapWebsiteResult>;
@@ -0,0 +1,11 @@
1
+ import { fetchPublicWebResource } from "./transport";
2
+ import type { WebRenderer } from "./index";
3
+ /** Fresh contexts share a browser, never cookies; all HTTP traffic uses pinned public DNS. */
4
+ export declare const createPlaywrightWebRenderer: (options?: {
5
+ executablePath?: string;
6
+ fetchResource?: typeof fetchPublicWebResource;
7
+ }) => {
8
+ render: WebRenderer;
9
+ ready: () => Promise<void>;
10
+ close: () => Promise<void>;
11
+ };
@@ -0,0 +1,455 @@
1
+ // @bun
2
+ // src/web/playwright.ts
3
+ import { chromium } from "playwright-core";
4
+
5
+ // src/web/transport.ts
6
+ import {
7
+ isPublicNetworkAddress,
8
+ networkAddressBlockReason,
9
+ pinnedPublicRequest
10
+ } from "@absolutejs/egress/transport";
11
+ import { lookup } from "dns/promises";
12
+ import { isIP } from "net";
13
+ import { brotliDecompressSync, gunzipSync, inflateSync } from "zlib";
14
+ var blockReasons = new Set([
15
+ "unsupported_protocol",
16
+ "url_credentials",
17
+ "nonstandard_port",
18
+ "local_hostname",
19
+ "empty_dns",
20
+ "ipv4_this_network",
21
+ "ipv4_private",
22
+ "ipv4_loopback",
23
+ "ipv4_multicast_reserved",
24
+ "ipv4_shared",
25
+ "ipv4_link_local",
26
+ "ipv4_protocol_assignment",
27
+ "ipv4_documentation",
28
+ "ipv4_transition",
29
+ "ipv4_benchmark",
30
+ "invalid_address",
31
+ "ipv6_non_global",
32
+ "ipv6_transition",
33
+ "ipv6_special",
34
+ "ipv6_documentation"
35
+ ]);
36
+ var transportCodes = new Set([
37
+ "ENOTFOUND",
38
+ "EAI_AGAIN",
39
+ "ECONNREFUSED",
40
+ "ECONNRESET",
41
+ "ETIMEDOUT",
42
+ "ENETUNREACH",
43
+ "EHOSTUNREACH",
44
+ "HPE_HEADER_OVERFLOW",
45
+ "ERR_RESPONSE_BODY_TOO_LARGE",
46
+ "ERR_BUFFER_TOO_LARGE",
47
+ "CERT_HAS_EXPIRED",
48
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
49
+ "SELF_SIGNED_CERT_IN_CHAIN",
50
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
51
+ "ERR_TLS_CERT_ALTNAME_INVALID",
52
+ "CERT_NOT_YET_VALID",
53
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
54
+ "Z_DATA_ERROR"
55
+ ]);
56
+ var webReadFailureDetails = (value) => {
57
+ if (!value || typeof value !== "object")
58
+ return;
59
+ const stage = Reflect.get(value, "stage");
60
+ if (!["url", "dns", "request", "decode", "navigation", "render"].includes(stage))
61
+ return;
62
+ const code = Reflect.get(value, "transportCode"), limit = Reflect.get(value, "limitBytes");
63
+ const reason = Reflect.get(value, "blockReason"), hop = Reflect.get(value, "redirectHop");
64
+ return {
65
+ stage,
66
+ ...typeof reason === "string" && blockReasons.has(reason) ? { blockReason: reason } : {},
67
+ ...Number.isInteger(hop) && hop >= 0 && hop <= 5 ? { redirectHop: hop } : {},
68
+ ...typeof code === "string" && transportCodes.has(code) ? { transportCode: code } : {},
69
+ ...Number.isSafeInteger(limit) && limit > 0 ? { limitBytes: limit } : {}
70
+ };
71
+ };
72
+ var webTransportFailure = (error, stage, limitBytes) => {
73
+ if (isWebReadError(error))
74
+ return error;
75
+ let current = error, transportCode;
76
+ for (let depth = 0;depth < 4 && current && typeof current === "object"; depth++) {
77
+ const code = Reflect.get(current, "code");
78
+ if (typeof code === "string" && transportCodes.has(code)) {
79
+ transportCode = code;
80
+ break;
81
+ }
82
+ current = Reflect.get(current, "cause");
83
+ }
84
+ let code = "fetch_failed";
85
+ if (transportCode === "ENOTFOUND")
86
+ code = "dns_not_found";
87
+ else if (transportCode === "EAI_AGAIN")
88
+ code = "dns_unavailable";
89
+ else if (transportCode === "HPE_HEADER_OVERFLOW")
90
+ code = "response_headers_too_large";
91
+ else if (["ERR_RESPONSE_BODY_TOO_LARGE", "ERR_BUFFER_TOO_LARGE"].includes(transportCode ?? ""))
92
+ code = "response_body_too_large";
93
+ else if (transportCode === "ETIMEDOUT" || error instanceof Error && error.name === "TimeoutError")
94
+ code = "timeout";
95
+ else if (error instanceof Error && error.name === "AbortError")
96
+ code = "aborted";
97
+ else if (transportCode?.includes("CERT") || transportCode === "UNABLE_TO_VERIFY_LEAF_SIGNATURE")
98
+ code = "tls_error";
99
+ else if (["ECONNREFUSED", "ECONNRESET", "ENETUNREACH", "EHOSTUNREACH"].includes(transportCode ?? ""))
100
+ code = "connection_failed";
101
+ else if (stage === "decode")
102
+ code = "response_decode_failed";
103
+ return new WebReadError(code, `Website retrieval failed (${code}).`, {
104
+ attempts: [],
105
+ failure: {
106
+ stage,
107
+ ...transportCode ? { transportCode } : {},
108
+ ...(code === "response_headers_too_large" || code === "response_body_too_large") && limitBytes ? { limitBytes } : {}
109
+ }
110
+ });
111
+ };
112
+ var diagnosticUrl = (value) => {
113
+ if (typeof value !== "string")
114
+ return;
115
+ try {
116
+ const url = new URL(value);
117
+ if (!["http:", "https:"].includes(url.protocol))
118
+ return;
119
+ return `${url.origin}${url.pathname}`;
120
+ } catch {
121
+ return;
122
+ }
123
+ };
124
+ var webReadDiagnostics = (value) => ({
125
+ failure: webReadFailureDetails(value.failure),
126
+ url: diagnosticUrl(value.url),
127
+ finalUrl: diagnosticUrl(value.finalUrl),
128
+ method: value.method === "http" || value.method === "browser" ? value.method : undefined,
129
+ attempts: Array.isArray(value.attempts) ? value.attempts.slice(0, 16).flatMap((attempt) => {
130
+ if (!attempt || typeof attempt !== "object" || !["http", "browser"].includes(attempt.method) || typeof attempt.status !== "string" || !/^[a-z_]{1,64}$/u.test(attempt.status))
131
+ return [];
132
+ return [
133
+ {
134
+ method: attempt.method,
135
+ status: attempt.status,
136
+ ...webReadFailureDetails(attempt.failure) ? { failure: webReadFailureDetails(attempt.failure) } : {},
137
+ ...Array.isArray(attempt.resourceFailures) ? {
138
+ resourceFailures: attempt.resourceFailures.slice(0, 8).flatMap((v) => {
139
+ const safe = webReadFailureDetails(v);
140
+ return safe ? [safe] : [];
141
+ })
142
+ } : {},
143
+ ...Number.isInteger(attempt.httpStatus) && attempt.httpStatus >= 100 && attempt.httpStatus <= 599 ? { httpStatus: attempt.httpStatus } : {},
144
+ ...Number.isInteger(attempt.extractedChars) && attempt.extractedChars >= 0 ? { extractedChars: attempt.extractedChars } : {}
145
+ }
146
+ ];
147
+ }) : []
148
+ });
149
+ var WEB_READ_ERROR = Symbol.for("@absolutejs/rag/WebReadError");
150
+
151
+ class WebReadError extends Error {
152
+ code;
153
+ diagnostics;
154
+ [WEB_READ_ERROR] = true;
155
+ constructor(code, message, diagnostics) {
156
+ super(message);
157
+ this.code = code;
158
+ this.diagnostics = diagnostics;
159
+ this.name = "WebReadError";
160
+ }
161
+ }
162
+ var isWebReadError = (error) => error instanceof Error && Reflect.get(error, WEB_READ_ERROR) === true && typeof Reflect.get(error, "code") === "string";
163
+ var isPublicWebAddress = (address) => isPublicNetworkAddress(address);
164
+ var blockedUrl = (reason, stage, redirectHop = 0) => new WebReadError("blocked_url", "Source excluded by public-network policy.", {
165
+ attempts: [],
166
+ failure: { stage, blockReason: reason, redirectHop }
167
+ });
168
+ var validatePublicWebUrl = (raw, redirectHop = 0) => {
169
+ let url;
170
+ try {
171
+ url = new URL(raw);
172
+ } catch {
173
+ throw new WebReadError("invalid_url", "Provide a valid public HTTP or HTTPS URL.");
174
+ }
175
+ if (!["http:", "https:"].includes(url.protocol))
176
+ throw blockedUrl("unsupported_protocol", "url", redirectHop);
177
+ if (url.username || url.password)
178
+ throw blockedUrl("url_credentials", "url", redirectHop);
179
+ if (url.port && !["80", "443"].includes(url.port))
180
+ throw blockedUrl("nonstandard_port", "url", redirectHop);
181
+ const host = url.hostname.replace(/^\[|\]$/gu, "").toLowerCase();
182
+ if (host === "localhost" || /\.(?:localhost|local|internal)$/u.test(host))
183
+ throw blockedUrl("local_hostname", "url", redirectHop);
184
+ if (isIP(host)) {
185
+ const reason = networkAddressBlockReason(host);
186
+ if (reason)
187
+ throw blockedUrl(reason, "url", redirectHop);
188
+ }
189
+ return url;
190
+ };
191
+ var fetchPublicWebResource = async (raw, options = {}) => {
192
+ const signal = options.signal ?? AbortSignal.timeout(15000);
193
+ const maxBytes = options.maxBytes ?? 5000000;
194
+ let url = validatePublicWebUrl(raw);
195
+ const redirects = [];
196
+ let method = options.method ?? "GET";
197
+ let body = options.body;
198
+ for (let hop = 0;hop <= 5; hop++) {
199
+ signal.throwIfAborted();
200
+ const host = url.hostname.replace(/^\[|\]$/gu, "");
201
+ const addresses = await lookup(host, { all: true }).catch((error) => {
202
+ throw webTransportFailure(error, "dns");
203
+ });
204
+ if (!addresses.length)
205
+ throw blockedUrl("empty_dns", "dns", hop);
206
+ for (const { address } of addresses) {
207
+ const reason = networkAddressBlockReason(address);
208
+ if (reason)
209
+ throw blockedUrl(reason, "dns", hop);
210
+ }
211
+ signal.throwIfAborted();
212
+ const selected = addresses.find(({ family }) => family === 4) ?? addresses[0];
213
+ const incoming = await pinnedPublicRequest(new Request(url, {
214
+ method,
215
+ body,
216
+ signal,
217
+ headers: {
218
+ "user-agent": "AbsoluteJSReader/1.0",
219
+ accept: "*/*",
220
+ "accept-encoding": "identity",
221
+ ...options.headers,
222
+ host: url.host
223
+ }
224
+ }), {
225
+ hostname: host,
226
+ address: selected.address,
227
+ maxResponseBytes: maxBytes,
228
+ maxResponseHeaderBytes: options.maxHeaderBytes ?? 65536
229
+ }).catch((error) => {
230
+ const failure = webTransportFailure(error, "request");
231
+ if (failure.diagnostics?.failure) {
232
+ if (failure.code === "response_headers_too_large")
233
+ failure.diagnostics.failure.limitBytes = options.maxHeaderBytes ?? 65536;
234
+ if (failure.code === "response_body_too_large")
235
+ failure.diagnostics.failure.limitBytes = maxBytes;
236
+ }
237
+ throw failure;
238
+ });
239
+ let data = new Uint8Array(await incoming.arrayBuffer());
240
+ const encoding = incoming.headers.get("content-encoding");
241
+ const limits = { maxOutputLength: maxBytes };
242
+ try {
243
+ if (encoding === "gzip")
244
+ data = gunzipSync(data, limits);
245
+ else if (encoding === "br")
246
+ data = brotliDecompressSync(data, limits);
247
+ else if (encoding === "deflate")
248
+ data = inflateSync(data, limits);
249
+ } catch (error) {
250
+ throw webTransportFailure(error, "decode", maxBytes);
251
+ }
252
+ const response = {
253
+ url: url.href,
254
+ status: incoming.status,
255
+ headers: Object.fromEntries([...incoming.headers].filter(([key]) => ![
256
+ "content-encoding",
257
+ "content-length",
258
+ "transfer-encoding",
259
+ "set-cookie"
260
+ ].includes(key))),
261
+ body: data
262
+ };
263
+ if (options.redirect === "manual")
264
+ return response;
265
+ if ([301, 302, 303, 307, 308].includes(response.status) && response.headers.location) {
266
+ const next = validatePublicWebUrl(new URL(response.headers.location, url).href, hop + 1);
267
+ redirects.push({
268
+ from: url.href,
269
+ to: next.href,
270
+ kind: "http",
271
+ status: response.status
272
+ });
273
+ url = next;
274
+ if (response.status === 303 || [301, 302].includes(response.status) && method === "POST") {
275
+ method = "GET";
276
+ body = undefined;
277
+ }
278
+ continue;
279
+ }
280
+ return { ...response, redirects };
281
+ }
282
+ throw new WebReadError("redirect_limit", "The site exceeded the redirect limit.");
283
+ };
284
+
285
+ // src/web/playwright.ts
286
+ var createPlaywrightWebRenderer = (options = {}) => {
287
+ let browser;
288
+ let launching;
289
+ const launch = async () => {
290
+ if (browser?.isConnected())
291
+ return browser;
292
+ launching ??= chromium.launch({
293
+ headless: true,
294
+ executablePath: options.executablePath,
295
+ args: ["--disable-dev-shm-usage"]
296
+ });
297
+ try {
298
+ browser = await launching;
299
+ return browser;
300
+ } finally {
301
+ launching = undefined;
302
+ }
303
+ };
304
+ const renderOnce = async (url, { signal }) => {
305
+ validatePublicWebUrl(url);
306
+ signal.throwIfAborted();
307
+ const instance = await launch();
308
+ const context = await instance.newContext({
309
+ serviceWorkers: "block",
310
+ acceptDownloads: false
311
+ });
312
+ const abort = () => {
313
+ context.close().catch(() => {});
314
+ };
315
+ signal.addEventListener("abort", abort, { once: true });
316
+ const redirects = [];
317
+ let navigationFailure;
318
+ const resourceFailures = [];
319
+ let count = 0, bytes = 0;
320
+ try {
321
+ await context.routeWebSocket("**/*", (socket) => socket.close());
322
+ await context.route("**/*", async (route) => {
323
+ const request = route.request();
324
+ try {
325
+ if (++count > 80 || bytes > 20000000 || ["image", "media", "font"].includes(request.resourceType()))
326
+ return await route.abort();
327
+ const body = request.postData() ?? undefined;
328
+ if (body && body.length > 1e5)
329
+ return await route.abort();
330
+ const original = request.headers();
331
+ const headers = {};
332
+ for (const key of ["accept", "content-type", "origin", "user-agent"])
333
+ if (original[key])
334
+ headers[key] = original[key];
335
+ const response = await (options.fetchResource ?? fetchPublicWebResource)(request.url(), {
336
+ signal,
337
+ maxBytes: 5000000,
338
+ method: request.method(),
339
+ body,
340
+ headers,
341
+ redirect: "manual"
342
+ });
343
+ if (request.isNavigationRequest() && request.frame() === context.pages()[0]?.mainFrame() && [301, 302, 303, 307, 308].includes(response.status) && response.headers.location) {
344
+ redirects.push({
345
+ from: request.url(),
346
+ to: new URL(response.headers.location, request.url()).href,
347
+ kind: "http",
348
+ status: response.status
349
+ });
350
+ }
351
+ bytes += response.body.byteLength;
352
+ await route.fulfill({
353
+ status: response.status,
354
+ headers: response.headers,
355
+ body: Buffer.from(response.body)
356
+ });
357
+ } catch (error) {
358
+ const failure = webTransportFailure(error, "request");
359
+ if (request.isNavigationRequest() && request.frame() === context.pages()[0]?.mainFrame())
360
+ navigationFailure = failure;
361
+ else if (failure.diagnostics?.failure && resourceFailures.length < 8)
362
+ resourceFailures.push(failure.diagnostics.failure);
363
+ await route.abort().catch(() => {});
364
+ }
365
+ });
366
+ const page = await context.newPage();
367
+ let previousUrl = url;
368
+ page.on("framenavigated", (frame) => {
369
+ if (frame !== page.mainFrame() || !/^https?:/u.test(frame.url()))
370
+ return;
371
+ const next = frame.url();
372
+ if (next !== previousUrl && !redirects.some((hop) => hop.to === next))
373
+ redirects.push({ from: previousUrl, to: next, kind: "client" });
374
+ previousUrl = next;
375
+ });
376
+ const response = await page.goto(url, {
377
+ waitUntil: "domcontentloaded",
378
+ timeout: 25000
379
+ }).catch((error) => {
380
+ if (navigationFailure)
381
+ throw navigationFailure;
382
+ if (error instanceof Error && error.name === "TimeoutError")
383
+ throw new WebReadError("renderer_timeout", "Browser navigation timed out", { attempts: [], failure: { stage: "navigation" } });
384
+ throw error;
385
+ });
386
+ const settled = await page.waitForFunction(() => {
387
+ const root = document.querySelector("#root,#app,#__next,app-root,[ng-version]");
388
+ const rootText = root?.textContent?.trim() ?? "";
389
+ return document.body.innerText.trim().length > 100 && (!root || rootText.length > 20 && !/^(loading|please wait)/i.test(rootText));
390
+ }, undefined, { timeout: 8000 }).then(() => true, () => false);
391
+ await page.waitForTimeout(1200);
392
+ for (let step = 0;step < 3; step++) {
393
+ await page.evaluate(() => window.scrollBy(0, window.innerHeight));
394
+ await page.waitForTimeout(350);
395
+ }
396
+ await page.evaluate(() => {
397
+ document.querySelectorAll("details").forEach((element) => {
398
+ element.open = true;
399
+ });
400
+ window.scrollTo(0, 0);
401
+ });
402
+ signal.throwIfAborted();
403
+ const html = await page.content();
404
+ if (html.length > 5000000)
405
+ throw new WebReadError("too_large", "Rendered page exceeded the content limit.");
406
+ return {
407
+ html,
408
+ resourceFailures,
409
+ redirects,
410
+ settled,
411
+ text: await page.locator("body").innerText(),
412
+ url: page.url(),
413
+ status: response?.status() ?? 200
414
+ };
415
+ } finally {
416
+ signal.removeEventListener("abort", abort);
417
+ await context.close().catch(() => {});
418
+ }
419
+ };
420
+ const render = async (url, options) => {
421
+ try {
422
+ return await renderOnce(url, options);
423
+ } catch (error) {
424
+ const safeFailure = (failure) => {
425
+ if (isWebReadError(failure))
426
+ return failure;
427
+ if (options.signal.aborted)
428
+ return webTransportFailure(options.signal.reason, "render");
429
+ const code = failure instanceof Error && /(?:browser|target|page|context).*(?:closed|disconnected|crashed)/iu.test(failure.message) ? "renderer_disconnected" : "renderer_failed";
430
+ return new WebReadError(code, `Browser rendering failed (${code}).`, {
431
+ attempts: [],
432
+ failure: { stage: "render" }
433
+ });
434
+ };
435
+ if (options.signal.aborted || browser?.isConnected())
436
+ throw safeFailure(error);
437
+ return renderOnce(url, options).catch((failure) => {
438
+ throw safeFailure(failure);
439
+ });
440
+ }
441
+ };
442
+ return {
443
+ render,
444
+ ready: async () => {
445
+ await launch();
446
+ },
447
+ close: async () => {
448
+ await browser?.close();
449
+ browser = undefined;
450
+ }
451
+ };
452
+ };
453
+ export {
454
+ createPlaywrightWebRenderer
455
+ };
@@ -0,0 +1,35 @@
1
+ import type { ReadWebpageOptions, WebReadResult } from "./index";
2
+ /** Typed boundary for a host-managed isolated website reader. The service URL is
3
+ * trusted host configuration; public destination validation stays in the reader. */
4
+ export type WebsiteServiceResult = Record<string, unknown> & {
5
+ status: "ok" | "partial" | "error";
6
+ text: string;
7
+ limitations?: string[];
8
+ sources?: {
9
+ url: string;
10
+ title?: string;
11
+ citation?: string;
12
+ }[];
13
+ };
14
+ export declare const parseWebsiteServiceResult: (value: unknown) => WebsiteServiceResult;
15
+ export declare const createWebsiteReaderClient: (options: {
16
+ endpoint: string;
17
+ fetch?: typeof fetch;
18
+ timeoutMs?: number;
19
+ fallbackReserveMs?: number;
20
+ /** Optional host fallback. Omit to preserve process isolation on service failure.
21
+ * A fallback must not run untrusted synchronous parsing on the application event loop. */
22
+ fallback?: (input: {
23
+ url: string;
24
+ maxPages: number;
25
+ mode: "auto" | "browser";
26
+ signal: AbortSignal;
27
+ }) => Promise<WebsiteServiceResult>;
28
+ }) => (input: {
29
+ url: string;
30
+ maxPages?: number;
31
+ mode?: "auto" | "browser";
32
+ signal?: AbortSignal;
33
+ }) => Promise<WebsiteServiceResult>;
34
+ /** Adapt an isolated website reader to the exact single-page research contract. */
35
+ export declare const createWebpageReaderClient: (options: Parameters<typeof createWebsiteReaderClient>[0]) => (input: ReadWebpageOptions) => Promise<WebReadResult>;
@@ -0,0 +1,2 @@
1
+ /** Website research needs the whole page, not the highest-scoring article fragment. */
2
+ export declare const websiteHtmlText: (html: string) => string;
@@ -0,0 +1,63 @@
1
+ import type { WebReadAttempt } from "./index";
2
+ /** Allowlisted diagnostic data; never carries transport messages, headers or content. */
3
+ export type WebReadFailureDetails = {
4
+ stage: "url" | "dns" | "request" | "decode" | "navigation" | "render";
5
+ blockReason?: string;
6
+ redirectHop?: number;
7
+ transportCode?: string;
8
+ limitBytes?: number;
9
+ };
10
+ export declare const webReadFailureDetails: (value: unknown) => WebReadFailureDetails | undefined;
11
+ /** Normalize known transport causes without serializing provider-controlled messages. */
12
+ export declare const webTransportFailure: (error: unknown, stage: WebReadFailureDetails["stage"], limitBytes?: number) => WebReadError;
13
+ /** Diagnostic metadata only: no page bodies, headers, URL credentials, queries or fragments. */
14
+ export type WebReadDiagnostics = {
15
+ url?: string;
16
+ finalUrl?: string;
17
+ method?: "http" | "browser";
18
+ attempts: WebReadAttempt[];
19
+ failure?: WebReadFailureDetails;
20
+ };
21
+ /** Copy only bounded diagnostic fields from an isolated reader response. */
22
+ export declare const webReadDiagnostics: (value: {
23
+ url?: unknown;
24
+ finalUrl?: unknown;
25
+ method?: unknown;
26
+ attempts?: unknown;
27
+ failure?: unknown;
28
+ }) => WebReadDiagnostics;
29
+ declare const WEB_READ_ERROR: unique symbol;
30
+ export declare class WebReadError extends Error {
31
+ code: string;
32
+ diagnostics?: WebReadDiagnostics | undefined;
33
+ readonly [WEB_READ_ERROR] = true;
34
+ constructor(code: string, message: string, diagnostics?: WebReadDiagnostics | undefined);
35
+ }
36
+ export declare const isWebReadError: (error: unknown) => error is WebReadError;
37
+ export declare const isPublicWebAddress: (address: string) => boolean;
38
+ export type WebRedirect = {
39
+ from: string;
40
+ to: string;
41
+ kind: "http" | "client";
42
+ status?: number;
43
+ };
44
+ export type WebFetchResult = {
45
+ redirects?: WebRedirect[];
46
+ url: string;
47
+ status: number;
48
+ headers: Record<string, string>;
49
+ body: Uint8Array;
50
+ };
51
+ export type WebFetchOptions = {
52
+ signal?: AbortSignal;
53
+ redirect?: "follow" | "manual";
54
+ maxBytes?: number;
55
+ maxHeaderBytes?: number;
56
+ method?: string;
57
+ body?: string;
58
+ headers?: Record<string, string>;
59
+ };
60
+ export declare const validatePublicWebUrl: (raw: string, redirectHop?: number) => URL;
61
+ /** Pin the validated DNS answer into the connection, including every redirect. */
62
+ export declare const fetchPublicWebResource: (raw: string, options?: WebFetchOptions) => Promise<WebFetchResult>;
63
+ export {};
@@ -0,0 +1,84 @@
1
+ import { type ReadWebpageOptions, type WebReadResult } from "./index";
2
+ /** Bounded company research: preserve citations and follow relevant same-origin links. */
3
+ export declare const readWebsite: (options: ReadWebpageOptions & {
4
+ maxPages?: number;
5
+ }) => Promise<{
6
+ fullText: undefined;
7
+ status: WebReadResult["status"];
8
+ text: string;
9
+ truncated: boolean;
10
+ pages: {
11
+ status: "ok" | "partial" | "error";
12
+ url: string;
13
+ finalUrl: string;
14
+ title: string | null;
15
+ originalChars?: number;
16
+ method: "http" | "browser";
17
+ truncated: boolean;
18
+ attempts: import("./index").WebReadAttempt[];
19
+ failure?: import("./transport").WebReadFailureDetails;
20
+ error?: {
21
+ code: string;
22
+ message: string;
23
+ };
24
+ fetchedAt: string;
25
+ redirects: import("./transport").WebRedirect[];
26
+ evidence: import("./evidence").WebEvidence;
27
+ limitations: string[];
28
+ }[];
29
+ captionEvidence: {
30
+ url: string;
31
+ text: string;
32
+ error?: string;
33
+ }[];
34
+ coverage: {
35
+ pagesRead: number;
36
+ pageLimit: number;
37
+ remainingRelevantLinks: string[];
38
+ deadlineReached: boolean;
39
+ exhaustive: boolean;
40
+ stopReason: string;
41
+ incompleteReads: {
42
+ url: string;
43
+ status: "ok" | "partial" | "error";
44
+ truncated: boolean;
45
+ error: {
46
+ code: string;
47
+ message: string;
48
+ } | undefined;
49
+ }[];
50
+ };
51
+ citationGuidance: string;
52
+ url: string;
53
+ finalUrl: string;
54
+ title: string | null;
55
+ originalChars?: number;
56
+ method: "http" | "browser";
57
+ attempts: import("./index").WebReadAttempt[];
58
+ failure?: import("./transport").WebReadFailureDetails;
59
+ error?: {
60
+ code: string;
61
+ message: string;
62
+ };
63
+ fetchedAt: string;
64
+ redirects: import("./transport").WebRedirect[];
65
+ evidence: import("./evidence").WebEvidence;
66
+ limitations: string[];
67
+ kind: "website_evidence";
68
+ documents: {
69
+ sourceId: string;
70
+ text: string;
71
+ fullText: string;
72
+ originalChars: number;
73
+ sourceTruncated: boolean;
74
+ truncated: boolean;
75
+ }[];
76
+ sources: {
77
+ id: string;
78
+ title: string;
79
+ url: string;
80
+ citation: string;
81
+ inlineCitation: string;
82
+ }[];
83
+ citationRequirements: string;
84
+ }>;