@anubhav-choubey/web-for-agents 0.1.0 → 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/dist/vite.d.ts CHANGED
@@ -19,7 +19,7 @@ interface WebForAgentsOptions {
19
19
  disallow?: string[];
20
20
  };
21
21
  /** Generate sitemap.xml and the `Sitemap:` line in robots.txt. Default true. */
22
- sitemap?: boolean;
22
+ sitemap?: boolean | SitemapOptions;
23
23
  /** Prerender routes after the build. `false` also turns off markdown, llms and the agent map. */
24
24
  prerender?: PrerenderOptions | false;
25
25
  /** Write a `.md` version of each page. `false` also turns off llms-full.txt. */
@@ -80,17 +80,130 @@ interface PrerenderOptions {
80
80
  isolation?: {
81
81
  codeGeneration?: boolean;
82
82
  };
83
+ /**
84
+ * Where each route's HTML is written. "directory": "/about" -> about/index.html.
85
+ * "flat": "/about" -> about.html ("/" stays index.html). Default "directory".
86
+ */
87
+ fileLayout?: FileLayout;
88
+ /**
89
+ * CSS selector that marks a route as rendered: the page is ready once it matches and no request
90
+ * is in flight, even if the DOM keeps changing (animations). Default: wait for the DOM to go quiet.
91
+ */
92
+ readySelector?: string;
93
+ /**
94
+ * What to do when a route is not ready by `timeoutMs`. "fail" stops the build; "snapshot" saves the
95
+ * page as it is at the deadline and logs a warning. Default "fail".
96
+ */
97
+ onTimeout?: "fail" | "snapshot";
98
+ }
99
+ type FileLayout = "directory" | "flat";
100
+ /** What `markdown.transform` receives for each page. */
101
+ interface MarkdownTransformPage {
102
+ /** Route path, e.g. "/about". */
103
+ route: string;
104
+ /** Absolute URL of the page. */
105
+ url: string;
106
+ title: string;
107
+ description?: string;
108
+ /** The generated markdown. */
109
+ markdown: string;
110
+ /** The page's full rendered HTML. */
111
+ html: string;
83
112
  }
113
+ /** Returns the markdown to use instead, or undefined to keep the generated one. */
114
+ type MarkdownTransform = (page: MarkdownTransformPage) => string | undefined | Promise<string | undefined>;
84
115
  interface MarkdownOptions {
85
116
  /** CSS selector for the page content converted to markdown. Default "main". */
86
117
  contentSelector?: string;
118
+ /** Rewrites each page's markdown (used for the .md file and llms-full.txt). */
119
+ transform?: MarkdownTransform;
87
120
  }
88
121
  interface LlmsOptions {
89
122
  /** llms.txt heading. Default: the title of "/". */
90
123
  title?: string;
91
124
  /** llms.txt summary. Default: the description of "/". */
92
125
  description?: string;
126
+ /** Plain text after the summary, in llms.txt and llms-full.txt. Blank lines separate paragraphs. */
127
+ intro?: string;
128
+ /** Sections written before "## Pages" in llms.txt, and in the llms-full.txt header. */
129
+ sections?: LlmsSectionOptions[];
130
+ }
131
+ interface LlmsSectionOptions {
132
+ /** The section heading. */
133
+ title: string;
134
+ /** Plain text under the heading. Blank lines separate paragraphs. */
135
+ text?: string;
136
+ /** Links listed under the text. */
137
+ links?: LlmsLinkOptions[];
138
+ }
139
+ interface LlmsLinkOptions {
140
+ title: string;
141
+ /** http(s) or mailto: URL. A relative URL ("/resume.pdf") is resolved against siteUrl. */
142
+ url: string;
143
+ description?: string;
144
+ }
145
+ /** A route's last modification date: "YYYY-MM-DD", a W3C datetime, a Date, or undefined for none. */
146
+ type SitemapLastmod = (route: string) => string | Date | undefined | Promise<string | Date | undefined>;
147
+ interface SitemapOptions {
148
+ /**
149
+ * `<lastmod>` for each URL. "file": the source HTML file's modification time with `generate`, the
150
+ * build date with the plugin. A function returns the date per route. Default "none".
151
+ */
152
+ lastmod?: "file" | "none" | SitemapLastmod;
153
+ }
154
+
155
+ interface GenerateOptions {
156
+ /** Build output directory holding the prerendered HTML, e.g. "dist". */
157
+ outDir: string;
158
+ /** Absolute http(s) URL of the deployed site. */
159
+ siteUrl: string;
160
+ /** robots.txt policy. `ai.training` and `ai.search` are required. */
161
+ robots: WebForAgentsOptions["robots"];
162
+ /** Routes to leave out. A string is an exact path, or a prefix when it ends in "/*". */
163
+ exclude?: Array<string | RegExp>;
164
+ /** Write sitemap.xml and the `Sitemap:` line in robots.txt. Default true. */
165
+ sitemap?: WebForAgentsOptions["sitemap"];
166
+ /** Write a `.md` version of each page. `false` also turns off llms-full.txt. */
167
+ markdown?: MarkdownOptions | false;
168
+ /** Write llms.txt and llms-full.txt. Default on. */
169
+ llms?: LlmsOptions | false;
170
+ /** Write agents.json from the actions in each page's markup. Default true. */
171
+ agentMap?: boolean | AgentMapOptions;
172
+ /** Add `<link rel="alternate" type="text/markdown">` to each page's head. Default true. */
173
+ linkMarkdown?: boolean;
174
+ /** Replace an existing robots.txt, sitemap.xml, llms.txt, llms-full.txt or agent map that differs. Default false. */
175
+ overwrite?: boolean;
176
+ /** Where warnings and the summary go. Default console. */
177
+ logger?: {
178
+ warn(message: string): void;
179
+ info(message: string): void;
180
+ };
181
+ }
182
+ interface GeneratedPage {
183
+ route: string;
184
+ /** HTML file, relative to outDir, with "/" separators. */
185
+ file: string;
186
+ /** False for noindex pages: they get a .md file but stay out of llms.txt, the sitemap and the agent map. */
187
+ listed: boolean;
93
188
  }
189
+ interface GenerateResult {
190
+ outDir: string;
191
+ /** "flat" (about.html), "directory" (about/index.html), or "mixed". Only "/" found counts as "directory". */
192
+ fileLayout: "directory" | "flat" | "mixed";
193
+ /** Sorted by route. */
194
+ pages: GeneratedPage[];
195
+ /** Files written, relative to outDir, sorted. */
196
+ written: string[];
197
+ /** Existing files that were kept because their content differs (see `overwrite`), sorted. */
198
+ kept: string[];
199
+ warnings: string[];
200
+ }
201
+ /**
202
+ * Writes llms.txt, llms-full.txt, a `.md` copy of each page, robots.txt, sitemap.xml and agents.json
203
+ * for HTML you prerendered yourself, and links each page to its markdown. Reads every `.html`
204
+ * under outDir except 200.html, 404.html and assets/. Nothing is written if any step fails.
205
+ */
206
+ declare function generateAgentFiles(options: GenerateOptions): Promise<GenerateResult>;
94
207
 
95
208
  /** Known AI crawler user agents, grouped by robots.ai policy. */
96
209
  declare const AI_BOTS: {
@@ -104,5 +217,5 @@ declare const AI_BOTS: {
104
217
  */
105
218
  declare function webForAgents(options: WebForAgentsOptions): Plugin[];
106
219
 
107
- export { AI_BOTS, webForAgents };
108
- export type { AgentMapOptions, LlmsOptions, MarkdownOptions, OverlayPluginOptions, PrerenderOptions, RendererName, Rule, WebForAgentsOptions };
220
+ export { AI_BOTS, generateAgentFiles, webForAgents };
221
+ export type { AgentMapOptions, FileLayout, GenerateOptions, GenerateResult, GeneratedPage, LlmsLinkOptions, LlmsOptions, LlmsSectionOptions, MarkdownOptions, MarkdownTransform, MarkdownTransformPage, OverlayPluginOptions, PrerenderOptions, RendererName, Rule, SitemapLastmod, SitemapOptions, WebForAgentsOptions };