@absolutejs/search 0.2.1 → 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 +20 -0
- package/README.md +37 -0
- package/changelog.json +41 -0
- package/dist/brave.js +17 -9
- package/dist/index.js +3 -3
- package/dist/types.d.ts +4 -0
- package/dist/web/evidence.d.ts +26 -0
- package/dist/web/extract.d.ts +33 -0
- package/dist/web/index.d.ts +77 -0
- package/dist/web/index.js +1062 -0
- package/dist/web/map.d.ts +23 -0
- package/dist/web/playwright.d.ts +11 -0
- package/dist/web/playwright.js +455 -0
- package/dist/web/remote.d.ts +35 -0
- package/dist/web/text.d.ts +2 -0
- package/dist/web/transport.d.ts +63 -0
- package/dist/web/website.d.ts +84 -0
- package/package.json +24 -5
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,26 @@ 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
|
+
|
|
17
|
+
## 0.2.3 — 2026-10-22
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **SearchAttempt includes optional errorCode and errorMessage fields for sanitized provider diagnostics.** (`SearchAttempt`)
|
|
22
|
+
|
|
23
|
+
## 0.2.2 — 2026-10-22
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **Preserve sanitized Brave error codes, explanations and request IDs; classify invalid subscription tokens as unavailable rather than generic HTTP 422 errors.**
|
|
28
|
+
|
|
9
29
|
## 0.2.1 — 2026-09-28
|
|
10
30
|
|
|
11
31
|
### Fixed
|
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,47 @@
|
|
|
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
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"changes": [
|
|
25
|
+
{
|
|
26
|
+
"kind": "changed",
|
|
27
|
+
"summary": "SearchAttempt includes optional errorCode and errorMessage fields for sanitized provider diagnostics.",
|
|
28
|
+
"symbols": [
|
|
29
|
+
"SearchAttempt"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"date": "2026-10-22",
|
|
34
|
+
"version": "0.2.3"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"changes": [
|
|
38
|
+
{
|
|
39
|
+
"kind": "fixed",
|
|
40
|
+
"summary": "Preserve sanitized Brave error codes, explanations and request IDs; classify invalid subscription tokens as unavailable rather than generic HTTP 422 errors."
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"date": "2026-10-22",
|
|
44
|
+
"version": "0.2.2"
|
|
45
|
+
},
|
|
5
46
|
{
|
|
6
47
|
"changes": [
|
|
7
48
|
{
|
package/dist/brave.js
CHANGED
|
@@ -194,9 +194,17 @@ var createBraveSearch = (options) => {
|
|
|
194
194
|
if (!response.ok) {
|
|
195
195
|
result.status = response.status === 429 ? "rate_limited" : response.status === 401 || response.status === 403 ? "unavailable" : "error";
|
|
196
196
|
const error = await response.json().catch(() => null);
|
|
197
|
-
if (record(error) && record(error.error)
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
if (record(error) && record(error.error)) {
|
|
198
|
+
const sanitize = (value) => text(value)?.split(options.apiKey).join("[redacted]").replace(/Bearer\s+\S+/giu, "Bearer [redacted]").replace(/[\r\n]+/gu, " ").slice(0, 500);
|
|
199
|
+
attempt.errorCode = sanitize(error.error.code);
|
|
200
|
+
attempt.errorMessage = sanitize(error.error.detail);
|
|
201
|
+
attempt.providerRequestId ??= sanitize(error.error.id);
|
|
202
|
+
if (attempt.errorCode === "QUOTA_LIMITED")
|
|
203
|
+
result.status = "quota_exceeded";
|
|
204
|
+
if (attempt.errorCode === "SUBSCRIPTION_TOKEN_INVALID")
|
|
205
|
+
result.status = "unavailable";
|
|
206
|
+
}
|
|
207
|
+
result.limitations.push(`Brave request failed with HTTP ${response.status}${attempt.errorCode ? ` (${attempt.errorCode})` : ""}${attempt.errorMessage ? `: ${attempt.errorMessage}` : ""}`);
|
|
200
208
|
} else {
|
|
201
209
|
const body = await response.json();
|
|
202
210
|
if (!record(body))
|
|
@@ -214,27 +222,27 @@ var createBraveSearch = (options) => {
|
|
|
214
222
|
invalid++;
|
|
215
223
|
continue;
|
|
216
224
|
}
|
|
217
|
-
const
|
|
225
|
+
const url = publicUrl(row.url);
|
|
218
226
|
const excerpts = mode === "context" ? strings(row.snippets) : [
|
|
219
227
|
text(row.description),
|
|
220
228
|
...strings(row.extra_snippets)
|
|
221
229
|
].filter((item) => Boolean(item));
|
|
222
|
-
if (!
|
|
230
|
+
if (!url || !text(row.title) || mode === "context" && !excerpts.length) {
|
|
223
231
|
invalid++;
|
|
224
232
|
continue;
|
|
225
233
|
}
|
|
226
234
|
const metadata = record(body.sources) && record(body.sources[String(row.url)]) ? body.sources[String(row.url)] : {};
|
|
227
235
|
const age = Array.isArray(metadata.age) ? text(metadata.age[3]) : undefined;
|
|
228
236
|
const publishedAt = text(row.page_age) ?? age;
|
|
229
|
-
const previous = byUrl.get(
|
|
237
|
+
const previous = byUrl.get(url);
|
|
230
238
|
if (previous)
|
|
231
239
|
previous.excerpts = [
|
|
232
240
|
...new Set([...previous.excerpts, ...excerpts])
|
|
233
241
|
];
|
|
234
242
|
else
|
|
235
|
-
byUrl.set(
|
|
236
|
-
id:
|
|
237
|
-
url
|
|
243
|
+
byUrl.set(url, {
|
|
244
|
+
id: url,
|
|
245
|
+
url,
|
|
238
246
|
title: String(row.title),
|
|
239
247
|
excerpts,
|
|
240
248
|
retrievedAt: new Date(now()).toISOString(),
|
package/dist/index.js
CHANGED
|
@@ -91,14 +91,14 @@ var withSearchCache = (provider, options) => {
|
|
|
91
91
|
if (searchCompleted(result)) {
|
|
92
92
|
const ttl = result.status === "empty" ? options.emptyTtlMs ?? 60000 : options.ttlMs ?? 300000;
|
|
93
93
|
if (ttl > 0) {
|
|
94
|
-
const
|
|
94
|
+
const entry = {
|
|
95
95
|
result: structuredClone(result),
|
|
96
96
|
expiresAt: now() + ttl
|
|
97
97
|
};
|
|
98
98
|
while (cache.size >= capacity)
|
|
99
99
|
cache.delete(cache.keys().next().value);
|
|
100
|
-
cache.set(key,
|
|
101
|
-
await options.store?.set(key,
|
|
100
|
+
cache.set(key, entry);
|
|
101
|
+
await options.store?.set(key, entry);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
return result;
|
package/dist/types.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export type SearchAttempt = {
|
|
|
34
34
|
durationMs: number;
|
|
35
35
|
status: SearchStatus;
|
|
36
36
|
httpStatus?: number;
|
|
37
|
+
/** Provider diagnostic code, retained independently of HTTP status. */
|
|
38
|
+
errorCode?: string;
|
|
39
|
+
/** Bounded provider explanation with the configured credential removed. */
|
|
40
|
+
errorMessage?: string;
|
|
37
41
|
retryAfterMs?: number;
|
|
38
42
|
/** A successful HTTP response is billable even if parsing fails. */
|
|
39
43
|
billing: "fulfilled" | "rejected" | "unknown" | "not_sent";
|
|
@@ -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";
|