@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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ This file is generated by `absolute-changelog` from the entries in
6
6
  `changelog/`. Edit an entry, not this file — and add new ones under
7
7
  `changelog/unreleased/`.
8
8
 
9
+ ## 0.3.0 — 2026-12-05
10
+
11
+ ### Added
12
+
13
+ - **extractWebpage reads a page and returns host-model data checked against a TypeBox schema, or schema_mismatch with what was received.**
14
+ - **mapWebsite lists a site's same-origin pages from its sitemaps (robots.txt, sitemap indexes), else its home-page links.**
15
+ - **Web reading moves here from @absolutejs/rag: @absolutejs/search/web gives readWebpage, readWebsite, the public-network transport and page evidence, and @absolutejs/search/web/playwright the optional browser renderer. Non-HTML documents go to a host-supplied readDocument.**
16
+
9
17
  ## 0.2.3 — 2026-10-22
10
18
 
11
19
  ### Changed
package/README.md CHANGED
@@ -17,3 +17,40 @@ Source excerpts are untrusted evidence. Publication and retrieval timestamps do
17
17
  Providers may declare `capabilities` with supported modes, filters and content views. `SearchRequest.filters` carries domain/date/category constraints. `assertSearchCapabilities` and `withSearchCapabilities` reject unsupported constraints before provider work. Brave advertises web/context excerpts and freshness/country/language; unsupported domain/date/category filters are rejected, never silently ignored. Existing providers without metadata remain compatible with existing request fields, but must declare support before accepting the new filters.
18
18
 
19
19
  The manifest exports a guarded `search_web` agent tool and a Brave configuration recipe using `BRAVE_SEARCH_API_KEY`. Bind the configured provider and host enforcer through the existing manifest AI/MCP bridges. Search spending and tenant authorization remain host-controlled. For complete research, extraction, monitoring and framework flows, compose with `@absolutejs/rag/research`.
20
+
21
+ ## Reading the web
22
+
23
+ `@absolutejs/search/web` reads pages safely: every request goes through a
24
+ public-network transport (no private addresses, bounded redirects and sizes),
25
+ and pages that are only a JavaScript shell are re-read in a browser when you
26
+ supply one.
27
+
28
+ ```ts
29
+ import {
30
+ extractWebpage,
31
+ mapWebsite,
32
+ readWebpage,
33
+ readWebsite,
34
+ } from "@absolutejs/search/web";
35
+ import { createPlaywrightWebRenderer } from "@absolutejs/search/web/playwright";
36
+ import { Type } from "@sinclair/typebox";
37
+
38
+ const render = createPlaywrightWebRenderer(); // optional; needs playwright-core
39
+
40
+ const page = await readWebpage({ url: "https://example.com", render });
41
+ const site = await readWebsite({ url: "https://example.com", maxPages: 8 });
42
+ const map = await mapWebsite({ url: "https://example.com" }); // sitemap, else home-page links
43
+ const facts = await extractWebpage({
44
+ url: "https://example.com/about",
45
+ schema: Type.Object({ founded: Type.Number(), headquarters: Type.String() }),
46
+ extract: async ({ text, schema }) => askYourModel(text, schema), // you choose the model
47
+ });
48
+ ```
49
+
50
+ - `readWebpage` reads HTML and plain text itself. For PDFs and other
51
+ documents, pass `readDocument`; `@absolutejs/rag` passes its document
52
+ loader, so its readers handle them out of the box.
53
+ - `extractWebpage` checks the model's answer against the schema and returns
54
+ `schema_mismatch`, with what it received, when it does not fit.
55
+ - `mapWebsite` returns same-origin URLs only, follows sitemap indexes, and
56
+ says when it cut the list short.
package/changelog.json CHANGED
@@ -2,6 +2,24 @@
2
2
  "contract": 1,
3
3
  "name": "@absolutejs/search",
4
4
  "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "kind": "added",
9
+ "summary": "extractWebpage reads a page and returns host-model data checked against a TypeBox schema, or schema_mismatch with what was received."
10
+ },
11
+ {
12
+ "kind": "added",
13
+ "summary": "mapWebsite lists a site's same-origin pages from its sitemaps (robots.txt, sitemap indexes), else its home-page links."
14
+ },
15
+ {
16
+ "kind": "added",
17
+ "summary": "Web reading moves here from @absolutejs/rag: @absolutejs/search/web gives readWebpage, readWebsite, the public-network transport and page evidence, and @absolutejs/search/web/playwright the optional browser renderer. Non-HTML documents go to a host-supplied readDocument."
18
+ }
19
+ ],
20
+ "date": "2026-12-05",
21
+ "version": "0.3.0"
22
+ },
5
23
  {
6
24
  "changes": [
7
25
  {
@@ -0,0 +1,26 @@
1
+ export type WebLink = {
2
+ url: string;
3
+ label: string;
4
+ };
5
+ export type WebImage = {
6
+ url: string | null;
7
+ label: string;
8
+ context: string;
9
+ };
10
+ export type WebMedia = {
11
+ kind: "video" | "audio" | "embed" | "captions";
12
+ url: string;
13
+ label: string;
14
+ };
15
+ export type WebEvidence = {
16
+ links: WebLink[];
17
+ images: WebImage[];
18
+ media: WebMedia[];
19
+ canonicalUrl: string | null;
20
+ };
21
+ /** Preserve semantic evidence that visible body text omits. Labels are not verified customer relationships. */
22
+ export declare const extractWebEvidence: (html: string, url: string) => WebEvidence;
23
+ /** Navigation/footer text alone must not mask an empty or loading app root. */
24
+ export declare const hasIncompleteAppContent: (html: string) => boolean;
25
+ /** Parse attributes once: overlapping HTML regex quantifiers can stall on repeated attributes. */
26
+ export declare const hasEmptyAppRoot: (html: string) => boolean;
@@ -0,0 +1,33 @@
1
+ import type { Static, TSchema } from "@sinclair/typebox";
2
+ import { type ReadWebpageOptions, type WebReadResult } from "./index";
3
+ /** The model call that fills the schema from the page. Search does not pick a
4
+ * model: the host supplies one (for example through @absolutejs/ai). */
5
+ export type WebExtractor = (input: {
6
+ instructions?: string;
7
+ schema: TSchema;
8
+ text: string;
9
+ title: string | null;
10
+ url: string;
11
+ signal: AbortSignal;
12
+ }) => Promise<unknown>;
13
+ export type ExtractWebpageOptions<Schema extends TSchema> = ReadWebpageOptions & {
14
+ schema: Schema;
15
+ extract: WebExtractor;
16
+ instructions?: string;
17
+ };
18
+ export type ExtractWebpageResult<Data> = {
19
+ status: "ok";
20
+ data: Data;
21
+ page: WebReadResult;
22
+ } | {
23
+ status: "error";
24
+ error: {
25
+ code: string;
26
+ message: string;
27
+ };
28
+ page: WebReadResult;
29
+ /** The extractor's answer when it did not match the schema. */
30
+ received?: unknown;
31
+ };
32
+ /** Read a page and return the data a schema asks for, checked against it. */
33
+ export declare const extractWebpage: <Schema extends TSchema>(options: ExtractWebpageOptions<Schema>) => Promise<ExtractWebpageResult<Static<Schema>>>;
@@ -0,0 +1,77 @@
1
+ import { type WebEvidence } from "./evidence";
2
+ import type { WebRedirect } from "./transport";
3
+ export type { WebEvidence, WebLink, WebImage, WebMedia } from "./evidence";
4
+ export type { WebRedirect } from "./transport";
5
+ import { fetchPublicWebResource, type WebReadFailureDetails } from "./transport";
6
+ export { fetchPublicWebResource, validatePublicWebUrl, isPublicWebAddress, webReadDiagnostics, webReadFailureDetails, webTransportFailure, WebReadError, isWebReadError, } from "./transport";
7
+ export type { WebFetchResult, WebFetchOptions, WebReadFailureDetails, WebReadDiagnostics, } from "./transport";
8
+ export type WebReadAttempt = {
9
+ method: "http" | "browser";
10
+ status: string;
11
+ httpStatus?: number;
12
+ extractedChars?: number;
13
+ failure?: WebReadFailureDetails;
14
+ resourceFailures?: WebReadFailureDetails[];
15
+ };
16
+ export type WebReadResult = {
17
+ status: "ok" | "partial" | "error";
18
+ url: string;
19
+ finalUrl: string;
20
+ title: string | null;
21
+ text: string;
22
+ /** Complete extracted source, independent of the model-facing preview budget. */
23
+ fullText?: string;
24
+ originalChars?: number;
25
+ method: "http" | "browser";
26
+ truncated: boolean;
27
+ attempts: WebReadAttempt[];
28
+ failure?: WebReadFailureDetails;
29
+ error?: {
30
+ code: string;
31
+ message: string;
32
+ };
33
+ fetchedAt: string;
34
+ redirects: WebRedirect[];
35
+ evidence: WebEvidence;
36
+ limitations: string[];
37
+ };
38
+ export type WebRenderer = (url: string, options: {
39
+ signal: AbortSignal;
40
+ }) => Promise<{
41
+ html: string;
42
+ text?: string;
43
+ url: string;
44
+ status: number;
45
+ redirects?: WebRedirect[];
46
+ settled?: boolean;
47
+ resourceFailures?: WebReadFailureDetails[];
48
+ }>;
49
+ /** Reads a non-HTML response (a PDF, an Office file) into text. Search reads
50
+ * HTML and plain text itself; anything else needs a host-supplied reader, so
51
+ * the web reader stays free of document-parsing dependencies. */
52
+ export type WebDocumentReader = (input: {
53
+ body: Uint8Array;
54
+ contentType: string;
55
+ url: string;
56
+ }) => Promise<{
57
+ text: string;
58
+ title?: string | null;
59
+ }>;
60
+ export type ReadWebpageOptions = {
61
+ url: string;
62
+ readDocument?: WebDocumentReader;
63
+ render?: WebRenderer;
64
+ signal?: AbortSignal;
65
+ maxChars?: number;
66
+ mode?: "auto" | "browser";
67
+ fetchResource?: typeof fetchPublicWebResource;
68
+ };
69
+ /** Read prepared evidence, escalating thin HTML shells to a host-supplied browser. */
70
+ export declare const readWebpage: (options: ReadWebpageOptions) => Promise<WebReadResult>;
71
+ export { readWebsite } from "./website";
72
+ export { createWebsiteReaderClient, parseWebsiteServiceResult, type WebsiteServiceResult, } from "./remote";
73
+ export { createWebpageReaderClient } from "./remote";
74
+ export { mapWebsite } from "./map";
75
+ export type { MapWebsiteOptions, MapWebsiteResult } from "./map";
76
+ export { extractWebpage } from "./extract";
77
+ export type { ExtractWebpageOptions, ExtractWebpageResult, WebExtractor, } from "./extract";