webforai 3.0.0 → 4.0.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.
Files changed (92) hide show
  1. package/README.md +25 -5
  2. package/dist/bin.js +1277 -479
  3. package/dist/cjs/detect-client-shell.js +78 -0
  4. package/dist/cjs/extract-meta-refresh.js +71 -0
  5. package/dist/cjs/extractors/lib/sanitize.js +4 -0
  6. package/dist/cjs/html-to-mdast.js +2 -1
  7. package/dist/cjs/index.js +12 -0
  8. package/dist/cjs/link-replacer.js +19 -13
  9. package/dist/cjs/loaders/cf-puppeteer.js +14 -7
  10. package/dist/cjs/loaders/fetch.js +14 -2
  11. package/dist/cjs/loaders/playwright.js +32 -30
  12. package/dist/cjs/loaders/puppeteer.js +14 -7
  13. package/dist/cjs/md-splitter.js +24 -11
  14. package/dist/cjs/mdast-handlers/custom-code-handler.js +18 -7
  15. package/dist/cjs/mdast-handlers/custom-div-handler.js +12 -33
  16. package/dist/cjs/mdast-handlers/definition-list-handler.js +17 -6
  17. package/dist/cjs/mdast-to-markdown.js +2 -5
  18. package/dist/cjs/normalize/index.js +11 -2
  19. package/dist/cjs/platform/client.js +73 -16
  20. package/dist/cjs/platform/index.js +4 -0
  21. package/dist/cjs/platform/types.js +7 -1
  22. package/dist/detect-client-shell.js +53 -0
  23. package/dist/extract-meta-refresh.js +47 -0
  24. package/dist/extractors/lib/sanitize.js +4 -0
  25. package/dist/html-to-mdast.js +2 -1
  26. package/dist/index.js +14 -0
  27. package/dist/link-replacer.js +19 -13
  28. package/dist/loaders/cf-puppeteer.js +15 -8
  29. package/dist/loaders/fetch.js +14 -2
  30. package/dist/loaders/playwright.js +32 -30
  31. package/dist/loaders/puppeteer.js +15 -8
  32. package/dist/md-splitter.js +24 -11
  33. package/dist/mdast-handlers/custom-code-handler.js +17 -7
  34. package/dist/mdast-handlers/custom-div-handler.js +12 -33
  35. package/dist/mdast-handlers/definition-list-handler.js +17 -6
  36. package/dist/mdast-to-markdown.js +2 -5
  37. package/dist/normalize/index.js +12 -2
  38. package/dist/platform/client.js +73 -16
  39. package/dist/platform/index.js +4 -0
  40. package/dist/platform/types.js +5 -1
  41. package/dist/types/cli/bin.js.map +1 -1
  42. package/dist/types/cli/commands/jobs/files.d.ts +28 -0
  43. package/dist/types/cli/commands/jobs/files.js.map +1 -0
  44. package/dist/types/cli/commands/jobs/llms-txt.d.ts +33 -0
  45. package/dist/types/cli/commands/jobs/llms-txt.js.map +1 -0
  46. package/dist/types/cli/commands/jobs/options.d.ts +58 -0
  47. package/dist/types/cli/commands/jobs/options.js.map +1 -0
  48. package/dist/types/cli/commands/jobs/run.d.ts +44 -0
  49. package/dist/types/cli/commands/jobs/run.js.map +1 -0
  50. package/dist/types/cli/commands/skill/content.js.map +1 -1
  51. package/dist/types/cli/commands/webforai/interactive.d.ts +1 -1
  52. package/dist/types/cli/commands/webforai/interactive.js.map +1 -1
  53. package/dist/types/cli/commands/webforai/options.d.ts +9 -2
  54. package/dist/types/cli/commands/webforai/options.js.map +1 -1
  55. package/dist/types/cli/commands/webforai/run.js.map +1 -1
  56. package/dist/types/cli/utils.d.ts +8 -1
  57. package/dist/types/cli/utils.js.map +1 -1
  58. package/dist/types/detect-client-shell.d.ts +24 -0
  59. package/dist/types/detect-client-shell.js.map +1 -0
  60. package/dist/types/extract-meta-refresh.d.ts +29 -0
  61. package/dist/types/extract-meta-refresh.js.map +1 -0
  62. package/dist/types/extractors/lib/sanitize.js.map +1 -1
  63. package/dist/types/html-to-mdast.js.map +1 -1
  64. package/dist/types/index.d.ts +2 -0
  65. package/dist/types/index.js.map +1 -1
  66. package/dist/types/link-replacer.d.ts +3 -1
  67. package/dist/types/link-replacer.js.map +1 -1
  68. package/dist/types/loaders/cf-puppeteer.js.map +1 -1
  69. package/dist/types/loaders/fetch.d.ts +4 -0
  70. package/dist/types/loaders/fetch.js.map +1 -1
  71. package/dist/types/loaders/playwright.js.map +1 -1
  72. package/dist/types/loaders/puppeteer.js.map +1 -1
  73. package/dist/types/md-splitter.d.ts +1 -1
  74. package/dist/types/md-splitter.js.map +1 -1
  75. package/dist/types/mdast-handlers/custom-code-handler.d.ts +2 -0
  76. package/dist/types/mdast-handlers/custom-code-handler.js.map +1 -1
  77. package/dist/types/mdast-handlers/custom-div-handler.js.map +1 -1
  78. package/dist/types/mdast-handlers/definition-list-handler.d.ts +0 -11
  79. package/dist/types/mdast-handlers/definition-list-handler.js.map +1 -1
  80. package/dist/types/mdast-to-markdown.js.map +1 -1
  81. package/dist/types/normalize/index.js.map +1 -1
  82. package/dist/types/platform/client.d.ts +2 -1
  83. package/dist/types/platform/client.js.map +1 -1
  84. package/dist/types/platform/error.d.ts +5 -3
  85. package/dist/types/platform/error.js.map +1 -1
  86. package/dist/types/platform/fetch.d.ts +2 -0
  87. package/dist/types/platform/fetch.js.map +1 -1
  88. package/dist/types/platform/index.d.ts +1 -1
  89. package/dist/types/platform/index.js.map +1 -1
  90. package/dist/types/platform/types.d.ts +35 -6
  91. package/dist/types/platform/types.js.map +1 -1
  92. package/package.json +16 -5
@@ -3,9 +3,11 @@
3
3
  * `{ error: { code, message } }` envelope.
4
4
  *
5
5
  * `code` values worth branching on: `invalid_request` (400), `invalid_api_key` (401),
6
- * `payment_required` (402), `job_not_found` (404), `rate_limited` (429, `retryAfter` set on
7
- * the demo endpoint), `engine_unavailable` (503). The client never retries on its own; a
8
- * caller that wants backoff should honour `retryAfter` when present.
6
+ * `payment_required` / `spend_cap_reached` (402), `robots_disallowed` (403), `job_not_found`
7
+ * (404), `rate_limited` / `too_many_jobs` (429, `retryAfter` set when the server sends it),
8
+ * `engine_unavailable` / `result_unavailable` / `scheduling_unknown` (503). 401 and 402
9
+ * messages end with a hint naming the deployment's dashboard. The client never retries on its
10
+ * own; a caller that wants backoff should honour `retryAfter` when present.
9
11
  *
10
12
  * Network-level failures (DNS, refused connections) are NOT wrapped — they propagate as the
11
13
  * runtime's own `fetch` errors. `code` is `invalid_response` when the server answered with
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/platform/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAM1C,YAAY,IAAY,EAAE,OAAe,EAAE,MAAc,EAAE,UAAmB;QAC7E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/platform/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAM1C,YAAY,IAAY,EAAE,OAAe,EAAE,MAAc,EAAE,UAAmB;QAC7E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD"}
@@ -14,6 +14,8 @@ export interface FetchRequestInit {
14
14
  method: string;
15
15
  headers?: Record<string, string>;
16
16
  body?: string;
17
+ /** Cancels an in-flight status request when polling stops or times out. */
18
+ signal?: AbortSignal;
17
19
  }
18
20
  /** The subset of a Response the client reads. */
19
21
  export interface FetchResponseLike {
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/platform/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmBH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAkB,EAAa,EAAE;IAC7D,IAAI,MAAM,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC;IACf,CAAC;IACD,MAAM,WAAW,GAAI,UAAoC,CAAC,KAAK,CAAC;IAChE,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;IACrH,CAAC;IACD,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC,CAAC"}
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/platform/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAkB,EAAa,EAAE;IAC7D,IAAI,MAAM,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC;IACf,CAAC;IACD,MAAM,WAAW,GAAI,UAAoC,CAAC,KAAK,CAAC;IAChE,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;IACrH,CAAC;IACD,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
1
  export { DEFAULT_BASE_URL, createPlatformClient, type PlatformClient, type PlatformClientOptions, type WaitForJobOptions, } from "./client";
2
2
  export { PlatformApiError } from "./error";
3
3
  export type { FetchLike, FetchRequestInit, FetchResponseLike } from "./fetch";
4
- export { ENGINES, REGIONS, isStoredPageStub, type BatchOptions, type ConvertOptions, type CrawlOptions, type DemoResult, type DemoScrapeOptions, type Engine, type ExtractorPreset, type JobRef, type JobResultItem, type JobResultsPage, type JobState, type JobStatus, type JobType, type PageError, type PageFailure, type PageResult, type PageSuccess, type Region, type ScrapeOptions, type ScrapeResult, type StoredPageStub, } from "./types";
4
+ export { CRAWL_SITEMAP_MODES, ENGINES, REGIONS, REQUESTED_ENGINES, isStoredPageStub, type BatchOptions, type ConvertOptions, type CrawlOptions, type CrawlSitemapMode, type DemoResult, type DemoScrapeOptions, type Engine, type ExtractorPreset, type JobRef, type JobResultItem, type JobResultsPage, type JobState, type JobStatus, type JobType, type PageError, type PageFailure, type PageResult, type PageSuccess, type Region, type RequestedEngine, type ScrapeOptions, type ScrapeResult, type StoredPageStub, } from "./types";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,OAAO,EACN,gBAAgB,EAChB,oBAAoB,GAIpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EACN,OAAO,EACP,OAAO,EACP,gBAAgB,GAsBhB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,OAAO,EACN,gBAAgB,EAChB,oBAAoB,GAIpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EACN,mBAAmB,EACnB,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,gBAAgB,GAwBhB,MAAM,SAAS,CAAC"}
@@ -8,8 +8,16 @@
8
8
  /** How the platform acquires the page's HTML. */
9
9
  export declare const ENGINES: readonly ["fetch", "browser", "proxy-fetch", "proxy-browser"];
10
10
  export type Engine = (typeof ENGINES)[number];
11
+ /**
12
+ * What a request may ask for: a concrete engine, or `auto` (the server default) — the
13
+ * cheapest engine for the request, escalated to browser rendering when the fetched HTML is
14
+ * a client-rendered shell. Responses report the concrete engine that ran.
15
+ */
16
+ export declare const REQUESTED_ENGINES: readonly ["fetch", "browser", "proxy-fetch", "proxy-browser", "auto"];
17
+ export type RequestedEngine = (typeof REQUESTED_ENGINES)[number];
11
18
  /** Coarse egress location, honoured by the proxy engines only. */
12
- export declare const REGIONS: readonly ["auto", "us", "eu", "uk", "jp", "asia"];
19
+ /** Egress regions the hosted platform can honour (Japan, or no geo-targeting). */
20
+ export declare const REGIONS: readonly ["auto", "jp"];
13
21
  export type Region = (typeof REGIONS)[number];
14
22
  /** Extraction presets understood by the platform (passed through to the webforai library). */
15
23
  export type ExtractorPreset = "auto" | "takumi" | "minimal" | "none";
@@ -21,13 +29,19 @@ export interface ConvertOptions {
21
29
  baseUrl?: string;
22
30
  }
23
31
  interface CommonRequestOptions {
24
- /** Defaults to `fetch` server-side. */
25
- engine?: Engine;
32
+ /** Defaults to `auto` server-side. */
33
+ engine?: RequestedEngine;
26
34
  /** Browser engines only (`browser`, `proxy-browser`); +1 credit. */
27
35
  screenshot?: boolean;
28
36
  /** Re-upload the page's images behind expiring URLs; +1 credit per started 5 images. */
29
37
  rehostImages?: boolean;
30
38
  region?: Region;
39
+ /**
40
+ * Honor the target site's robots.txt rules: each URL is checked before it is fetched, and a
41
+ * disallowed URL fails with `robots_disallowed` (never billed). Defaults to `false` for
42
+ * scrape and batch and to `true` for crawl (pass `false` to turn it off).
43
+ */
44
+ respectRobotsTxt?: boolean;
31
45
  convert?: ConvertOptions;
32
46
  }
33
47
  export interface ScrapeOptions extends CommonRequestOptions {
@@ -37,6 +51,13 @@ export interface BatchOptions extends CommonRequestOptions {
37
51
  /** 1–100 URLs. */
38
52
  urls: string[];
39
53
  }
54
+ /**
55
+ * How a crawl uses the site's sitemaps (robots.txt `Sitemap:` lines, else `/sitemap.xml`):
56
+ * `skip` (default) ignores them; `include` adds their same-origin URLs at depth 1 next to the
57
+ * links found on pages; `only` crawls the seed plus sitemap URLs and follows no page links.
58
+ */
59
+ export declare const CRAWL_SITEMAP_MODES: readonly ["skip", "include", "only"];
60
+ export type CrawlSitemapMode = (typeof CRAWL_SITEMAP_MODES)[number];
40
61
  export interface CrawlOptions extends CommonRequestOptions {
41
62
  url: string;
42
63
  /** 0–5, default 2. */
@@ -48,10 +69,13 @@ export interface CrawlOptions extends CommonRequestOptions {
48
69
  excludePaths?: string[];
49
70
  /** The platform currently only supports same-origin crawls; sending `false` is a 400. */
50
71
  sameOrigin?: true;
72
+ /** Seed the crawl from the site's sitemaps; default `skip`. See {@link CRAWL_SITEMAP_MODES}. */
73
+ sitemap?: CrawlSitemapMode;
51
74
  }
52
75
  export interface ScrapeResult {
53
76
  /** Final URL after redirects. */
54
77
  url: string;
78
+ /** The engine that produced the result — `auto` requests resolve to a concrete one. */
55
79
  engine: Engine;
56
80
  markdown: string;
57
81
  metadata: Record<string, unknown>;
@@ -63,6 +87,8 @@ export interface ScrapeResult {
63
87
  original: string;
64
88
  rehosted: string;
65
89
  }[];
90
+ /** Present when the result is probably degraded (e.g. an unrendered client-side shell). */
91
+ warning?: string;
66
92
  }
67
93
  export interface JobRef {
68
94
  jobId: string;
@@ -92,7 +118,8 @@ export type PageSuccess = ScrapeResult & {
92
118
  export interface PageFailure {
93
119
  status: "error";
94
120
  url: string;
95
- engine: Engine;
121
+ /** As requested — a failed `auto` page never resolved to a concrete engine. */
122
+ engine: RequestedEngine;
96
123
  error: PageError;
97
124
  }
98
125
  /** One page of an async job, after the client resolves any spilled results. */
@@ -105,7 +132,7 @@ export type PageResult = PageSuccess | PageFailure;
105
132
  export interface StoredPageStub {
106
133
  status: "ok";
107
134
  url: string;
108
- engine: Engine;
135
+ engine: RequestedEngine;
109
136
  credits: number;
110
137
  resultUrl: string;
111
138
  }
@@ -124,7 +151,9 @@ export interface DemoScrapeOptions {
124
151
  export interface DemoResult {
125
152
  url: string;
126
153
  region: Region;
127
- /** Truncated to ~8000 characters by the demo endpoint. */
154
+ /** The engine `auto` resolved to. Absent from deployments older than 2026-09-24. */
155
+ engine?: Engine;
156
+ /** Truncated to ~40,000 characters by the demo endpoint (~8000 before 2026-09-24). */
128
157
  markdown: string;
129
158
  truncated: boolean;
130
159
  title?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/platform/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,CAAU,CAAC;AAGrF,kEAAkE;AAClE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAU,CAAC;AAwIzE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAmB,EAA0B,EAAE,CAC/E,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,WAAW,IAAI,IAAI,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/platform/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,CAAU,CAAC;AAGrF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,CAAU,CAAC;AAG/D,kEAAkE;AAClE,kFAAkF;AAClF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,IAAI,CAAU,CAAC;AAwC/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAU,CAAC;AAiHxE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAmB,EAA0B,EAAE,CAC/E,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,WAAW,IAAI,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,23 +1,34 @@
1
1
  {
2
2
  "name": "webforai",
3
- "version": "3.0.0",
4
- "description": "A library that provides a web interface for AI",
3
+ "version": "4.0.0",
4
+ "description": "Convert web pages and local HTML to clean, LLM-ready Markdown: library, CLI (npx webforai) and hosted-API client.",
5
5
  "author": "inaridiy",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
8
- "web",
8
+ "html-to-markdown",
9
+ "markdown",
10
+ "llm",
9
11
  "ai",
12
+ "scraper",
13
+ "crawler",
14
+ "readability",
15
+ "web-scraping",
16
+ "cli",
17
+ "rag",
10
18
  "html",
11
19
  "html2md",
12
- "markdown",
13
20
  "mdast",
14
21
  "hast"
15
22
  ],
16
23
  "repository": {
17
24
  "type": "git",
18
- "url": "https://github.com/inaridiy/webforai.git"
25
+ "url": "https://github.com/inaridiy/webforai.git",
26
+ "directory": "packages/webforai"
19
27
  },
20
28
  "homepage": "https://webforai.dev/",
29
+ "bugs": {
30
+ "url": "https://github.com/inaridiy/webforai/issues"
31
+ },
21
32
  "files": [
22
33
  "dist",
23
34
  "!dist/types/**/*.js"