llms-ink 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Espindola
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,101 @@
1
- # Temporary Holding Version
1
+ # llms-ink
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Turn any link — site, docs section, page, GitHub repo, PDF or video — into llms.txt and llms-full.txt. A typed
4
+ client for the [llms.ink](https://llms.ink) API with no dependencies. Runs on Node 18+, Bun, Deno, Cloudflare
5
+ Workers and browsers.
6
+
7
+ ```sh
8
+ npm install llms-ink # or: bun add llms-ink
9
+ deno add jsr:@lukax/llms-ink # or: npx jsr add @lukax/llms-ink
10
+ ```
11
+
12
+ ```ts
13
+ import { LlmsInk } from 'llms-ink'; // Deno/JSR: from 'jsr:@lukax/llms-ink'
14
+
15
+ const ink = new LlmsInk();
16
+
17
+ const index = await ink.llms('developers.cloudflare.com/kv/'); // llms.txt: an index of links
18
+ const full = await ink.llms('github.com/honojs/hono', { mode: 'full' }); // llms-full.txt: the content
19
+ console.log(full.title, full.tokens, full.text);
20
+
21
+ const report = await ink.check('llmstxt.org'); // is a site's own llms.txt valid, do its links answer?
22
+ console.log(report.found, report.summary, report.issues);
23
+ ```
24
+
25
+ ## API
26
+
27
+ ### `new LlmsInk({ key?, baseUrl?, fetch? })`
28
+
29
+ - `key`: an API key (`lk_…`), sent as `Authorization: Bearer`. Defaults to the `LLMS_INK_KEY` environment
30
+ variable where there is one (Node, Bun, Deno with `--allow-env`). Without a key, requests are anonymous and
31
+ share the free limits. An invalid or revoked key throws `InvalidKeyError`; it never falls back to anonymous.
32
+ - `baseUrl`: defaults to `LLMS_INK_API`, else `https://llms.ink`.
33
+ - `fetch`: a `fetch` to use instead of the global one.
34
+
35
+ ### `ink.llms(url, { mode?, fresh?, signal? })` → `Promise<Result>`
36
+
37
+ `mode` is `'llms'` (default) or `'full'` (up to 20 pages inlined). `fresh: true` skips the cache and rebuilds
38
+ (counts against the daily quota). The result:
39
+
40
+ ```ts
41
+ { url, kind, source, mode, title, text, tokens, pages, model, cached, generatedAt, media? }
42
+ ```
43
+
44
+ `kind` is `site | section | page | repo | document | video`; `source` is `native` (the site publishes it) or
45
+ `generated`. `media` is set for videos (duration, thumbnail, downloads, transcript segments).
46
+
47
+ Building a big site or a video can take minutes. Bound a call with a signal:
48
+ `ink.llms(url, { signal: AbortSignal.timeout(120_000) })`. Aborts are rethrown as is.
49
+
50
+ ### `ink.check(url, { signal? })` → `Promise<CheckResult>`
51
+
52
+ Checks the site's (or docs section's) published llms.txt against the llmstxt.org format and fetches its first
53
+ 25 links: `{ site, url, found, status, title, tokens, sections, links, llmsFull, issues, summary, checkedAt }`.
54
+
55
+ ### `ink.stream(url, { mode?, fresh?, signal? })` → `AsyncGenerator<StreamEvent>`
56
+
57
+ The same build as `llms()`, as it happens:
58
+
59
+ ```ts
60
+ for await (const event of ink.stream('docs.astro.build', { mode: 'full' })) {
61
+ if (event.type === 'progress') console.log(event.stage, event.detail);
62
+ if (event.type === 'partial') preview(event.text); // incomplete so far
63
+ if (event.type === 'result') save(event.result); // always last
64
+ }
65
+ ```
66
+
67
+ Breaking out of the loop cancels the request.
68
+
69
+ ## Errors
70
+
71
+ Every failure is an `LlmsInkError` with `status`, `code`, `title`, `detail`, `errors` (per-parameter issues of
72
+ `invalid_request`) and `retryAfter` (seconds, from `Retry-After`). When llms.ink can't be reached, `status` and
73
+ `code` are undefined and `cause` holds the network error. Codes are listed at
74
+ [llms.ink/docs](https://llms.ink/docs/#errors).
75
+
76
+ | Class | Status | Code | When |
77
+ |---|---|---|---|
78
+ | `InvalidKeyError` | 401 | `invalid_key` | The key is malformed, unknown or revoked. |
79
+ | `RateLimitedError` | 429 | `rate_limited` | Too many requests this minute; wait `retryAfter` seconds. |
80
+ | `QuotaExceededError` | 429 | `quota_exceeded` | Daily quota of new links used up; `retryAfter` is the seconds until midnight UTC. Cached links still work. |
81
+
82
+ ```ts
83
+ import { LlmsInk, RateLimitedError } from 'llms-ink';
84
+
85
+ try {
86
+ await ink.llms('example.com');
87
+ } catch (err) {
88
+ if (err instanceof RateLimitedError) await new Promise((r) => setTimeout(r, err.retryAfter! * 1000));
89
+ else throw err;
90
+ }
91
+ ```
92
+
93
+ ## Limits
94
+
95
+ Anonymous: 10 requests a minute per IP, 60 new (uncached) links a day per IP. Cached results are free. A key
96
+ gets its own daily quota (1000 new links by default) and 60 requests a minute;
97
+ [ask for one](https://lucasespindola.com/message?text=Hi+Lucas%2C+I%E2%80%99d+like+an+llms.ink+API+key+for+...).
98
+
99
+ ## License
100
+
101
+ MIT
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Client for the llms.ink JSON API (https://llms.ink/docs/): any public link — site, docs section, page,
3
+ * GitHub repo, PDF or video — as llms.txt or llms-full.txt. No dependencies; uses the global `fetch`, so it
4
+ * runs on Node ≥ 18, Bun, Deno, Cloudflare Workers and browsers.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { LlmsInk } from "llms-ink";
9
+ *
10
+ * const ink = new LlmsInk();
11
+ * const { title, text } = await ink.llms("developers.cloudflare.com/kv/", { mode: "full" });
12
+ * ```
13
+ *
14
+ * @module
15
+ */
16
+ export declare const VERSION = "0.1.0";
17
+ export declare const DEFAULT_BASE_URL = "https://llms.ink";
18
+ /** `llms` for the index (llms.txt), `full` for llms-full.txt. */
19
+ export type Mode = 'llms' | 'full';
20
+ /** What the link is. */
21
+ export type Kind = 'site' | 'section' | 'page' | 'repo' | 'document' | 'video';
22
+ /** `native` = published by the site; `generated` = made by llms.ink. */
23
+ export type Source = 'native' | 'generated';
24
+ /** A transcript line; `start` and `end` are seconds into the source video. */
25
+ export interface Segment {
26
+ start: number;
27
+ end: number;
28
+ text: string;
29
+ }
30
+ /** Video results only: what `/api/v0/frame` and `/api/v0/media` can serve. */
31
+ export interface Media {
32
+ /** Seconds. */
33
+ duration: number | null;
34
+ hasVideo: boolean;
35
+ hasAudio: boolean;
36
+ thumbnail: string | null;
37
+ downloads: Array<'mp4' | 'm4a'>;
38
+ isLive?: boolean;
39
+ transcript?: {
40
+ source: string;
41
+ segments: Segment[];
42
+ };
43
+ }
44
+ /** `GET /api/v0/llms`: the llms.txt or llms-full.txt of a link and what it was built from. */
45
+ export interface Result {
46
+ /** The link after normalization. */
47
+ url: string;
48
+ kind: Kind;
49
+ source: Source;
50
+ mode: Mode;
51
+ title: string;
52
+ /** The llms.txt or llms-full.txt content (Markdown). */
53
+ text: string;
54
+ /** Approximate token count (characters ÷ 4). */
55
+ tokens: number;
56
+ /** Links in llms.txt (mode `llms`) or pages inlined (mode `full`). */
57
+ pages: number;
58
+ /** Model that wrote the descriptions; null for native files or path-based grouping. */
59
+ model: string | null;
60
+ cached: boolean;
61
+ /** ISO 8601 date-time. */
62
+ generatedAt: string;
63
+ media?: Media;
64
+ }
65
+ /** One finding of the checker. */
66
+ export interface CheckIssue {
67
+ /** `error` breaks the format or a link; `warning` is worth fixing; `info` is a note. */
68
+ level: 'error' | 'warning' | 'info';
69
+ /** Stable name of the check, e.g. `missing_title`, `broken_link`. */
70
+ code: string;
71
+ /** Line in the file, when the issue has one. */
72
+ line: number | null;
73
+ message: string;
74
+ }
75
+ /** `GET /api/v0/check`: a published llms.txt checked against the format and its links. */
76
+ export interface CheckResult {
77
+ /** The site's origin. */
78
+ site: string;
79
+ /** The llms.txt that was checked (or the last place looked when none was found). */
80
+ url: string;
81
+ found: boolean;
82
+ /** HTTP status of the llms.txt request. */
83
+ status: number;
84
+ title: string | null;
85
+ tokens: number;
86
+ /** H2 sections. */
87
+ sections: number;
88
+ links: {
89
+ total: number;
90
+ /** Links fetched this run (the first 25). */
91
+ checked: number;
92
+ /** `status` is 0 when the link didn't answer in time. */
93
+ broken: Array<{
94
+ url: string;
95
+ status: number;
96
+ }>;
97
+ };
98
+ /** Whether llms-full.txt is published next to it. */
99
+ llmsFull: boolean;
100
+ /** Errors first, then warnings and notes, in line order. */
101
+ issues: CheckIssue[];
102
+ summary: {
103
+ errors: number;
104
+ warnings: number;
105
+ };
106
+ /** ISO 8601 date-time. */
107
+ checkedAt: string;
108
+ }
109
+ /** Every error code the API answers with (https://llms.ink/docs/#errors). */
110
+ export type ErrorCode = 'invalid_request' | 'invalid_url' | 'invalid_key' | 'not_found' | 'unknown_version' | 'method_not_allowed' | 'payload_too_large' | 'unprocessable' | 'rate_limited' | 'quota_exceeded' | 'internal' | 'upstream_error' | 'unavailable' | 'timeout';
111
+ /** `invalid_request` only: one invalid parameter. */
112
+ export interface Issue {
113
+ path: string;
114
+ message: string;
115
+ }
116
+ /** An error body (RFC 9457 problem details), sent as `application/problem+json`. */
117
+ export interface Problem {
118
+ type: string;
119
+ title: string;
120
+ status: number;
121
+ code: ErrorCode;
122
+ detail: string;
123
+ errors?: Issue[];
124
+ }
125
+ /** Build stages reported while streaming. */
126
+ export type Stage = 'cache' | 'index' | 'extract' | 'ready';
127
+ /**
128
+ * One line of the `application/x-ndjson` stream of `GET /api/v0/llms`. `partial` text is explicitly
129
+ * incomplete; `result` is the last event. A terminal `error` event is thrown as an {@link LlmsInkError}.
130
+ */
131
+ export type StreamEvent = {
132
+ type: 'progress';
133
+ stage: Stage;
134
+ detail: string;
135
+ } | {
136
+ type: 'partial';
137
+ text: string;
138
+ } | {
139
+ type: 'result';
140
+ result: Result;
141
+ };
142
+ /** Fields of an {@link LlmsInkError} besides the message. */
143
+ export interface LlmsInkErrorInit {
144
+ status?: number;
145
+ code?: string;
146
+ title?: string;
147
+ errors?: Issue[];
148
+ retryAfter?: number;
149
+ cause?: unknown;
150
+ }
151
+ /**
152
+ * An API error, or llms.ink couldn't be reached (then `status` and `code` are undefined).
153
+ * `code` is the problem's machine-readable code (`invalid_url`, `unprocessable`, `upstream_error`…),
154
+ * `detail` the human-readable message, `errors` the per-parameter issues of `invalid_request`.
155
+ * `retryAfter` is the `Retry-After` header in seconds, when the response had one.
156
+ */
157
+ export declare class LlmsInkError extends Error {
158
+ readonly detail: string;
159
+ readonly status: number | undefined;
160
+ readonly code: string | undefined;
161
+ readonly title: string | undefined;
162
+ readonly errors: Issue[];
163
+ readonly retryAfter: number | undefined;
164
+ constructor(detail: string, init?: LlmsInkErrorInit);
165
+ }
166
+ /** 401 `invalid_key`: the API key is malformed, unknown or revoked. Requests never fall back to anonymous. */
167
+ export declare class InvalidKeyError extends LlmsInkError {
168
+ }
169
+ /** 429 `rate_limited`: too many requests this minute; wait `retryAfter` seconds. */
170
+ export declare class RateLimitedError extends LlmsInkError {
171
+ }
172
+ /**
173
+ * 429 `quota_exceeded`: the daily quota of new links is used up; `retryAfter` is the seconds until it resets
174
+ * (midnight UTC). Cached links still work.
175
+ */
176
+ export declare class QuotaExceededError extends LlmsInkError {
177
+ }
178
+ /** Options for {@link LlmsInk}. */
179
+ export interface LlmsInkOptions {
180
+ /**
181
+ * API key (`lk_…`), sent as `Authorization: Bearer`. Defaults to the `LLMS_INK_KEY` environment variable
182
+ * where there is one; without a key, requests are anonymous and share the free limits.
183
+ */
184
+ key?: string;
185
+ /** Defaults to the `LLMS_INK_API` environment variable, else https://llms.ink. */
186
+ baseUrl?: string;
187
+ /** A `fetch` to use instead of the global one. */
188
+ fetch?: typeof fetch;
189
+ }
190
+ /** Options for {@link LlmsInk.llms} and {@link LlmsInk.stream}. */
191
+ export interface LlmsOptions {
192
+ /** `llms` (default) for the index, `full` for llms-full.txt (the content inlined, up to 20 pages). */
193
+ mode?: Mode;
194
+ /** Skip the cache and rebuild (counts against the daily quota). */
195
+ fresh?: boolean;
196
+ /** Aborts the request; the abort error is rethrown as is. */
197
+ signal?: AbortSignal;
198
+ }
199
+ /** Options for {@link LlmsInk.check}. */
200
+ export interface CheckOptions {
201
+ signal?: AbortSignal;
202
+ }
203
+ /**
204
+ * A client for https://llms.ink.
205
+ *
206
+ * Building a big site or a video can take minutes; pass a `signal` (e.g. `AbortSignal.timeout(300_000)`) to
207
+ * bound a call, or use {@link LlmsInk.stream} to watch progress.
208
+ */
209
+ export declare class LlmsInk {
210
+ #private;
211
+ /** The API key in use, if any. */
212
+ readonly key: string | undefined;
213
+ /** Origin of the API, without a trailing slash. */
214
+ readonly baseUrl: string;
215
+ constructor(options?: LlmsInkOptions);
216
+ /**
217
+ * llms.txt (`mode: 'llms'`, an index of links) or llms-full.txt (`mode: 'full'`, the content inlined) for
218
+ * any public link.
219
+ */
220
+ llms(url: string, options?: LlmsOptions): Promise<Result>;
221
+ /** Checks a site's published llms.txt against the llmstxt.org format and that its links answer. */
222
+ check(url: string, options?: CheckOptions): Promise<CheckResult>;
223
+ /**
224
+ * Like {@link LlmsInk.llms}, as the build happens: yields `progress` and `partial` events, then one
225
+ * `result`. Errors — including a terminal `error` event — are thrown as {@link LlmsInkError}s.
226
+ * Breaking out of the loop cancels the request.
227
+ */
228
+ stream(url: string, options?: LlmsOptions): AsyncGenerator<StreamEvent, void, undefined>;
229
+ }
package/dist/index.js ADDED
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Client for the llms.ink JSON API (https://llms.ink/docs/): any public link — site, docs section, page,
3
+ * GitHub repo, PDF or video — as llms.txt or llms-full.txt. No dependencies; uses the global `fetch`, so it
4
+ * runs on Node ≥ 18, Bun, Deno, Cloudflare Workers and browsers.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { LlmsInk } from "llms-ink";
9
+ *
10
+ * const ink = new LlmsInk();
11
+ * const { title, text } = await ink.llms("developers.cloudflare.com/kv/", { mode: "full" });
12
+ * ```
13
+ *
14
+ * @module
15
+ */
16
+ export const VERSION = '0.1.0';
17
+ export const DEFAULT_BASE_URL = 'https://llms.ink';
18
+ /**
19
+ * An API error, or llms.ink couldn't be reached (then `status` and `code` are undefined).
20
+ * `code` is the problem's machine-readable code (`invalid_url`, `unprocessable`, `upstream_error`…),
21
+ * `detail` the human-readable message, `errors` the per-parameter issues of `invalid_request`.
22
+ * `retryAfter` is the `Retry-After` header in seconds, when the response had one.
23
+ */
24
+ export class LlmsInkError extends Error {
25
+ detail;
26
+ status;
27
+ code;
28
+ title;
29
+ errors;
30
+ retryAfter;
31
+ constructor(detail, init = {}) {
32
+ super(detail, init.cause === undefined ? undefined : { cause: init.cause });
33
+ this.name = new.target.name;
34
+ this.detail = detail;
35
+ this.status = init.status;
36
+ this.code = init.code;
37
+ this.title = init.title;
38
+ this.errors = init.errors ?? [];
39
+ this.retryAfter = init.retryAfter;
40
+ }
41
+ }
42
+ /** 401 `invalid_key`: the API key is malformed, unknown or revoked. Requests never fall back to anonymous. */
43
+ export class InvalidKeyError extends LlmsInkError {
44
+ }
45
+ /** 429 `rate_limited`: too many requests this minute; wait `retryAfter` seconds. */
46
+ export class RateLimitedError extends LlmsInkError {
47
+ }
48
+ /**
49
+ * 429 `quota_exceeded`: the daily quota of new links is used up; `retryAfter` is the seconds until it resets
50
+ * (midnight UTC). Cached links still work.
51
+ */
52
+ export class QuotaExceededError extends LlmsInkError {
53
+ }
54
+ const BY_CODE = {
55
+ invalid_key: InvalidKeyError,
56
+ rate_limited: RateLimitedError,
57
+ quota_exceeded: QuotaExceededError,
58
+ };
59
+ const errorFor = (detail, init) => new (BY_CODE[init.code ?? ''] ?? LlmsInkError)(detail, init);
60
+ /** `process.env[name]` where there is a `process` (Node, Bun, Deno with env access); undefined elsewhere. */
61
+ function env(name) {
62
+ try {
63
+ return (typeof process === 'undefined' ? undefined : process.env?.[name]?.trim()) || undefined;
64
+ }
65
+ catch {
66
+ return undefined; // Deno without --allow-env throws
67
+ }
68
+ }
69
+ /** Browsers refuse or preflight a custom User-Agent, so it's only sent from servers. */
70
+ const IS_BROWSER = 'document' in globalThis || 'WorkerGlobalScope' in globalThis;
71
+ /** `Retry-After` as seconds: delta-seconds, or an HTTP date turned into seconds from now. */
72
+ function retryAfter(value) {
73
+ if (!value)
74
+ return undefined;
75
+ const v = value.trim();
76
+ if (/^\d+$/.test(v))
77
+ return Number(v);
78
+ const when = Date.parse(v);
79
+ return Number.isNaN(when) ? undefined : Math.max(0, Math.ceil((when - Date.now()) / 1000));
80
+ }
81
+ /** Aborts (`signal`, `AbortSignal.timeout`) are the caller's doing and pass through unwrapped. */
82
+ const isAbort = (err) => err instanceof Error && (err.name === 'AbortError' || err.name === 'TimeoutError');
83
+ /**
84
+ * A client for https://llms.ink.
85
+ *
86
+ * Building a big site or a video can take minutes; pass a `signal` (e.g. `AbortSignal.timeout(300_000)`) to
87
+ * bound a call, or use {@link LlmsInk.stream} to watch progress.
88
+ */
89
+ export class LlmsInk {
90
+ /** The API key in use, if any. */
91
+ key;
92
+ /** Origin of the API, without a trailing slash. */
93
+ baseUrl;
94
+ #fetch;
95
+ constructor(options = {}) {
96
+ const key = (options.key ?? env('LLMS_INK_KEY'))?.trim();
97
+ this.key = key || undefined;
98
+ this.baseUrl = (options.baseUrl ?? env('LLMS_INK_API') ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
99
+ if (!options.fetch && typeof globalThis.fetch !== 'function') {
100
+ throw new TypeError('No global fetch: use Node 18+ or pass options.fetch.');
101
+ }
102
+ // Wrapped so the global is called unbound-safe (browsers throw "Illegal invocation" otherwise).
103
+ this.#fetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
104
+ }
105
+ /**
106
+ * llms.txt (`mode: 'llms'`, an index of links) or llms-full.txt (`mode: 'full'`, the content inlined) for
107
+ * any public link.
108
+ */
109
+ async llms(url, options = {}) {
110
+ const res = await this.#get('/api/v0/llms', llmsParams(url, options), 'application/json', options.signal);
111
+ return (await this.#json(res));
112
+ }
113
+ /** Checks a site's published llms.txt against the llmstxt.org format and that its links answer. */
114
+ async check(url, options = {}) {
115
+ const res = await this.#get('/api/v0/check', { url }, 'application/json', options.signal);
116
+ return (await this.#json(res));
117
+ }
118
+ /**
119
+ * Like {@link LlmsInk.llms}, as the build happens: yields `progress` and `partial` events, then one
120
+ * `result`. Errors — including a terminal `error` event — are thrown as {@link LlmsInkError}s.
121
+ * Breaking out of the loop cancels the request.
122
+ */
123
+ async *stream(url, options = {}) {
124
+ const res = await this.#get('/api/v0/llms', llmsParams(url, options), 'application/x-ndjson', options.signal);
125
+ if (!res.headers.get('content-type')?.includes('ndjson')) {
126
+ yield { type: 'result', result: (await this.#json(res)) };
127
+ return;
128
+ }
129
+ if (!res.body)
130
+ throw new LlmsInkError(`${this.baseUrl} sent an empty stream.`, { status: res.status });
131
+ const reader = res.body.getReader();
132
+ const decoder = new TextDecoder();
133
+ let buffer = '';
134
+ let done = false;
135
+ try {
136
+ while (!done) {
137
+ let chunk;
138
+ try {
139
+ chunk = await reader.read();
140
+ }
141
+ catch (err) {
142
+ if (isAbort(err))
143
+ throw err;
144
+ throw new LlmsInkError(`The stream from ${this.baseUrl} broke off: ${err instanceof Error ? err.message : err}`, { cause: err });
145
+ }
146
+ done = chunk.done;
147
+ buffer += done ? decoder.decode() : decoder.decode(chunk.value, { stream: true });
148
+ const lines = buffer.split('\n');
149
+ buffer = done ? '' : lines.pop();
150
+ for (const line of lines) {
151
+ const event = line.trim() ? this.#event(line) : undefined;
152
+ if (!event)
153
+ continue;
154
+ yield event;
155
+ if (event.type === 'result')
156
+ return;
157
+ }
158
+ }
159
+ }
160
+ finally {
161
+ reader.cancel().catch(() => { });
162
+ }
163
+ throw new LlmsInkError(`The stream from ${this.baseUrl} ended without a result.`);
164
+ }
165
+ /** A stream line → its event; unknown event types (added later) are skipped, `error` is thrown. */
166
+ #event(line) {
167
+ let event;
168
+ try {
169
+ event = JSON.parse(line);
170
+ }
171
+ catch (err) {
172
+ throw new LlmsInkError(`${this.baseUrl} sent a stream line that isn't JSON.`, { cause: err });
173
+ }
174
+ if (!event || typeof event !== 'object' || !('type' in event))
175
+ return undefined;
176
+ if (event.type === 'error') {
177
+ const { detail, code, status } = event;
178
+ throw errorFor(detail || 'The build failed.', { status, code });
179
+ }
180
+ // The server's own event shapes, by type.
181
+ const known = event.type === 'progress' || event.type === 'partial' || event.type === 'result';
182
+ return known ? event : undefined;
183
+ }
184
+ async #get(path, params, accept, signal) {
185
+ const headers = { accept };
186
+ if (!IS_BROWSER)
187
+ headers['user-agent'] = `llms-ink-js/${VERSION}`;
188
+ if (this.key)
189
+ headers.authorization = `Bearer ${this.key}`;
190
+ const target = `${this.baseUrl}${path}?${new URLSearchParams(params)}`;
191
+ let res;
192
+ try {
193
+ res = await this.#fetch(target, { headers, signal });
194
+ }
195
+ catch (err) {
196
+ if (isAbort(err))
197
+ throw err;
198
+ throw new LlmsInkError(`Couldn't reach ${this.baseUrl}: ${err instanceof Error ? err.message : err}`, { cause: err });
199
+ }
200
+ if (!res.ok)
201
+ throw await problem(res);
202
+ return res;
203
+ }
204
+ async #json(res) {
205
+ const body = await res.text();
206
+ try {
207
+ return JSON.parse(body);
208
+ }
209
+ catch (err) {
210
+ throw new LlmsInkError(`${this.baseUrl} answered with something other than JSON.`, { status: res.status, cause: err });
211
+ }
212
+ }
213
+ }
214
+ function llmsParams(url, { mode = 'llms', fresh }) {
215
+ if (mode !== 'llms' && mode !== 'full') {
216
+ throw new TypeError(`mode must be 'llms' (the index) or 'full' (llms-full.txt), not ${JSON.stringify(mode)}`);
217
+ }
218
+ return fresh ? { url, mode, fresh: '1' } : { url, mode };
219
+ }
220
+ /** An HTTP error response → the typed error for its problem `code`. */
221
+ async function problem(res) {
222
+ let data = {};
223
+ try {
224
+ const parsed = JSON.parse(await res.text());
225
+ if (parsed && typeof parsed === 'object')
226
+ data = parsed;
227
+ }
228
+ catch {
229
+ // not problem+json: fall back to the status line
230
+ }
231
+ const status = typeof data.status === 'number' ? data.status : res.status;
232
+ const detail = data.detail || data.title || `HTTP ${res.status} ${res.statusText || 'error'}`.trim();
233
+ return errorFor(detail, {
234
+ status,
235
+ code: data.code,
236
+ title: data.title,
237
+ errors: data.errors,
238
+ retryAfter: retryAfter(res.headers.get('retry-after')),
239
+ });
240
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "llms-ink",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Turn any link — site, docs section, page, GitHub repo, PDF or video — into llms.txt and llms-full.txt. Typed client for llms.ink, no dependencies.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": ["dist"],
15
+ "sideEffects": false,
16
+ "engines": { "node": ">=18" },
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "prepublishOnly": "npm run build && npm test",
20
+ "test": "npm run build && node --test test/client.test.mjs",
21
+ "test:live": "npm run build && node --test test/live.test.mjs",
22
+ "test:bun": "npm run build && bun test ./test/client.test.mjs",
23
+ "test:bun:live": "npm run build && bun test --timeout 300000 ./test/live.test.mjs"
24
+ },
25
+ "keywords": ["llms.txt", "llms-full.txt", "llm", "ai", "markdown", "docs", "context", "rag", "sdk", "llms-ink"],
26
+ "homepage": "https://llms.ink/docs/",
27
+ "author": "Lucas Espindola (https://lucasespindola.com)",
28
+ "license": "MIT",
29
+ "devDependencies": {
30
+ "typescript": "^5.9.3"
31
+ }
32
+ }