@framers/agentos-ext-citation-check 0.0.0-stage → 0.1.1

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 (48) hide show
  1. package/LICENSE +98 -0
  2. package/README.md +167 -2
  3. package/dist/bin.d.ts +10 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +11 -0
  6. package/dist/bin.js.map +1 -0
  7. package/dist/cli.d.ts +36 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +145 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/embeddings.d.ts +54 -0
  12. package/dist/embeddings.d.ts.map +1 -0
  13. package/dist/embeddings.js +52 -0
  14. package/dist/embeddings.js.map +1 -0
  15. package/dist/index.d.ts +55 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +63 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/match.d.ts +44 -0
  20. package/dist/match.d.ts.map +1 -0
  21. package/dist/match.js +108 -0
  22. package/dist/match.js.map +1 -0
  23. package/dist/page.d.ts +105 -0
  24. package/dist/page.d.ts.map +1 -0
  25. package/dist/page.js +400 -0
  26. package/dist/page.js.map +1 -0
  27. package/dist/parse.d.ts +36 -0
  28. package/dist/parse.d.ts.map +1 -0
  29. package/dist/parse.js +314 -0
  30. package/dist/parse.js.map +1 -0
  31. package/dist/report.d.ts +28 -0
  32. package/dist/report.d.ts.map +1 -0
  33. package/dist/report.js +128 -0
  34. package/dist/report.js.map +1 -0
  35. package/dist/runner.d.ts +89 -0
  36. package/dist/runner.d.ts.map +1 -0
  37. package/dist/runner.js +298 -0
  38. package/dist/runner.js.map +1 -0
  39. package/dist/tools/citationVerify.d.ts +59 -0
  40. package/dist/tools/citationVerify.d.ts.map +1 -0
  41. package/dist/tools/citationVerify.js +98 -0
  42. package/dist/tools/citationVerify.js.map +1 -0
  43. package/dist/types.d.ts +150 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +20 -0
  46. package/dist/types.js.map +1 -0
  47. package/manifest.json +66 -0
  48. package/package.json +79 -3
package/dist/page.js ADDED
@@ -0,0 +1,400 @@
1
+ /**
2
+ * @file page.ts
3
+ * @description One cited page as passages. A request goes out once per page, with a browser-like User-Agent from the
4
+ * web scraper pack, a deadline and a size cap, through Node's fetch (redirects followed) or through AgentOS's checked
5
+ * egress (every address and every redirect checked against a policy); a page that fails in a way a browser may mend is
6
+ * retried once through the web scraper pack's tiers. The answer is read by its content type: HTML and XML through
7
+ * public-sources' `htmlToBlocks` in page mode, other text by paragraphs, a PDF or another binary not at all; its
8
+ * charset from a byte order mark, the content type or a `<meta>` tag. Its sentences become passages through
9
+ * public-sources' `citationSources`, cut by grounding-guard's `sentenceSpans`. A page that fails is a status, never a
10
+ * throw; only the caller's own cancellation throws.
11
+ *
12
+ * @module agentos/extensions/research/citation-check/page
13
+ */
14
+ import { brotliDecompressSync, gunzipSync, inflateSync } from 'node:zlib';
15
+ import { citationSources, htmlToBlocks } from '@framers/agentos-ext-public-sources';
16
+ import { browserHeaders } from '@framers/agentos-ext-web-scraper';
17
+ import { collapse, sentenceSpans } from '@framers/agentos-ext-grounding-guard/values';
18
+ import { withoutInvisible } from './match.js';
19
+ /** A failure a transport names itself, such as the egress policy's refusal. */
20
+ export class PageRefusal extends Error {
21
+ failure;
22
+ detail;
23
+ /**
24
+ * @param failure - The failure it stands for.
25
+ * @param detail - More about it, such as the egress policy's reason.
26
+ */
27
+ constructor(failure, detail = null) {
28
+ super(detail === null ? `page not read: ${failure}` : `page not read: ${failure} (${detail})`);
29
+ this.failure = failure;
30
+ this.detail = detail;
31
+ this.name = 'PageRefusal';
32
+ }
33
+ }
34
+ /** The most redirects a request through checked egress follows. */
35
+ const MAX_REDIRECTS = 5;
36
+ /** Failures a browser or a second request may mend; a 404 or a 410 is never retried. */
37
+ const MENDABLE = new Set(['timeout', 'network', 'status', 'no_text']);
38
+ /** Failures of a page that answered but holds no text this check reads. */
39
+ const UNREADABLE = new Set(['too_large', 'pdf', 'binary', 'no_text']);
40
+ /** A cited page's licence is not read: its sentences grade claims and stand as evidence in a report, nothing more. */
41
+ const UNREAD_LICENCE = { name: 'not read', url: '' };
42
+ /** The address a page is fetched at: the cited address without its fragment, which never reaches a server. */
43
+ export function pageKey(url) {
44
+ const parsed = new URL(url);
45
+ parsed.hash = '';
46
+ return parsed.href;
47
+ }
48
+ /** An address's origin for a log line, which leaves out the path and the query where secrets can sit. */
49
+ export function originOf(url) {
50
+ try {
51
+ return new URL(url).origin;
52
+ }
53
+ catch {
54
+ return 'unparsable';
55
+ }
56
+ }
57
+ /** The headers a request sends: a browser's, with one User-Agent, no `Connection`, and the content coding asked for. */
58
+ function requestHeaders(userAgent, acceptEncoding) {
59
+ const headers = browserHeaders(userAgent);
60
+ delete headers.Connection;
61
+ if (acceptEncoding !== null)
62
+ headers['Accept-Encoding'] = acceptEncoding;
63
+ return headers;
64
+ }
65
+ /** A body read up to `cap` bytes: its bytes, or null past the cap with the rest of the stream cancelled. */
66
+ async function readCapped(response, cap) {
67
+ if (response.body === null)
68
+ return new Uint8Array(0);
69
+ const reader = response.body.getReader();
70
+ const chunks = [];
71
+ let total = 0;
72
+ for (;;) {
73
+ const { done, value } = await reader.read();
74
+ if (done)
75
+ break;
76
+ total += value.byteLength;
77
+ if (total > cap) {
78
+ await reader.cancel().catch(() => undefined);
79
+ return null;
80
+ }
81
+ chunks.push(value);
82
+ }
83
+ return Buffer.concat(chunks);
84
+ }
85
+ /** Requests through a `fetch`: redirects followed, the body streamed up to the cap. */
86
+ export function fetchTransport(fetchFn, userAgent) {
87
+ return async (url, signal) => {
88
+ const response = await fetchFn(url, { method: 'GET', redirect: 'follow', headers: requestHeaders(userAgent, null), signal });
89
+ return {
90
+ status: response.status,
91
+ finalUrl: response.url || url,
92
+ header: (name) => response.headers.get(name),
93
+ read: (cap) => readCapped(response, cap),
94
+ discard: async () => {
95
+ await response.body?.cancel().catch(() => undefined);
96
+ },
97
+ };
98
+ };
99
+ }
100
+ /** A header of an answer from `node:http`, whose values may be lists. */
101
+ function headerOf(headers, name) {
102
+ const value = headers[name.toLowerCase()];
103
+ if (Array.isArray(value))
104
+ return value.join(', ');
105
+ return typeof value === 'string' ? value : null;
106
+ }
107
+ /**
108
+ * A body as its content coding left it, decoded and held to `cap` bytes: null past the cap. The request asks for no
109
+ * coding, so a coded body comes only from a server that ignores the ask.
110
+ *
111
+ * @throws {PageRefusal} `binary` for a coding this check does not decode, or a body that does not decode.
112
+ */
113
+ function decodedBody(body, coding, cap) {
114
+ const name = (coding ?? '').trim().toLowerCase();
115
+ if (name === '' || name === 'identity')
116
+ return body;
117
+ try {
118
+ if (name === 'gzip' || name === 'x-gzip')
119
+ return gunzipSync(body, { maxOutputLength: cap });
120
+ if (name === 'deflate')
121
+ return inflateSync(body, { maxOutputLength: cap });
122
+ if (name === 'br')
123
+ return brotliDecompressSync(body, { maxOutputLength: cap });
124
+ }
125
+ catch (error) {
126
+ if (error.code === 'ERR_BUFFER_TOO_LARGE')
127
+ return null;
128
+ throw new PageRefusal('binary', `content-encoding ${name} that does not decode`);
129
+ }
130
+ throw new PageRefusal('binary', `content-encoding ${name}`);
131
+ }
132
+ /** The failure an egress refusal stands for, or null for an error that is not one. */
133
+ function egressFailure(error) {
134
+ if (!(error instanceof Error) || error.name !== 'EgressRefusedError')
135
+ return null;
136
+ const reason = String(error.reason ?? 'refused');
137
+ if (reason === 'timeout')
138
+ return new PageRefusal('timeout');
139
+ if (reason === 'too_large')
140
+ return new PageRefusal('too_large');
141
+ if (reason === 'redirect')
142
+ return new PageRefusal('redirects');
143
+ if (reason === 'unresolved')
144
+ return new PageRefusal('network', reason);
145
+ return new PageRefusal('refused', reason);
146
+ }
147
+ /**
148
+ * Requests through AgentOS's checked egress (`@framers/agentos/safety/egress`, from 0.13.120): each address, and each
149
+ * address a redirect names, is checked against the policy before a byte is sent, its connection pinned to the address
150
+ * checked, and the answer bounded by the deadline and the size cap. Up to five redirects are followed.
151
+ *
152
+ * @throws {Error} When the installed AgentOS has no checked egress.
153
+ */
154
+ export async function egressTransport(profile, bounds, userAgent) {
155
+ const egress = await import('@framers/agentos/safety/egress').catch(() => {
156
+ throw new Error('reading pages through checked egress needs @framers/agentos 0.13.120 or later; update it, or pass a fetch');
157
+ });
158
+ const policy = profile === 'local'
159
+ ? egress.localEgressPolicy({ timeoutMs: bounds.timeoutMs, maxResponseBytes: bounds.maxBytes })
160
+ : egress.hostedEgressPolicy({ timeoutMs: bounds.timeoutMs, maxResponseBytes: bounds.maxBytes });
161
+ return async (url, signal) => {
162
+ let current = url;
163
+ for (let hop = 0;; hop += 1) {
164
+ const answer = await egress
165
+ .checkedRequest({ url: current, method: 'GET', headers: requestHeaders(userAgent, 'identity'), policy, signal, onRedirect: 'return' })
166
+ .catch((error) => {
167
+ throw egressFailure(error) ?? error;
168
+ });
169
+ const headers = answer.headers;
170
+ const location = headerOf(headers, 'location');
171
+ if (answer.status >= 300 && answer.status < 400 && location !== null) {
172
+ if (hop >= MAX_REDIRECTS)
173
+ throw new PageRefusal('redirects');
174
+ current = new URL(location, current).href;
175
+ continue;
176
+ }
177
+ const body = answer.status >= 200 && answer.status < 300 ? decodedBody(answer.body, headerOf(headers, 'content-encoding'), bounds.maxBytes) : answer.body;
178
+ return {
179
+ status: answer.status,
180
+ finalUrl: current,
181
+ header: (name) => headerOf(headers, name),
182
+ read: async (cap) => (body === null || body.byteLength > cap ? null : body),
183
+ discard: async () => undefined,
184
+ };
185
+ }
186
+ };
187
+ }
188
+ /** A content type's media type in lower case, or '' when none came. */
189
+ function mediaType(contentType) {
190
+ return (contentType ?? '').split(';')[0]?.trim().toLowerCase() ?? '';
191
+ }
192
+ /** Whether a media type is read as HTML: HTML, XHTML and XML. */
193
+ function isMarkup(type) {
194
+ return type === 'text/html' || type === 'application/xhtml+xml' || type === 'text/xml' || type === 'application/xml' || type.endsWith('+xml');
195
+ }
196
+ /** Whether a media type is text this check reads. */
197
+ function isText(type) {
198
+ return type.startsWith('text/') || type === 'application/json' || type.endsWith('+json') || isMarkup(type);
199
+ }
200
+ /** Whether a body starts as a PDF does, whatever its content type says. */
201
+ function isPdf(bytes) {
202
+ return bytes.length >= 5 && Buffer.from(bytes.subarray(0, 5)).toString('latin1') === '%PDF-';
203
+ }
204
+ /** What the first bytes of a body say it is, for one that came with no content type or as plain text. */
205
+ function sniff(bytes) {
206
+ const head = Buffer.from(bytes.subarray(0, 1024)).toString('latin1');
207
+ if (/<(?:!doctype html|html|head|body|p|div|article)[\s>]/iu.test(head))
208
+ return 'html';
209
+ return head.includes('\u0000') ? 'binary' : 'text';
210
+ }
211
+ /** The charset a byte order mark names, or null. */
212
+ function bomCharset(bytes) {
213
+ if (bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf)
214
+ return 'utf-8';
215
+ if (bytes[0] === 0xff && bytes[1] === 0xfe)
216
+ return 'utf-16le';
217
+ if (bytes[0] === 0xfe && bytes[1] === 0xff)
218
+ return 'utf-16be';
219
+ return null;
220
+ }
221
+ /** The charset a content type names, or null. */
222
+ function headerCharset(contentType) {
223
+ return /charset\s*=\s*"?([^";\s]+)/iu.exec(contentType ?? '')?.[1] ?? null;
224
+ }
225
+ /** The charset an HTML document's `<meta>` names in its first 2,048 bytes, or null. */
226
+ function metaCharset(bytes) {
227
+ const head = Buffer.from(bytes.subarray(0, 2048)).toString('latin1');
228
+ return /<meta[^>]+charset\s*=\s*["']?([\w-]+)/iu.exec(head)?.[1] ?? null;
229
+ }
230
+ /** Bytes as text in the charset named, or in UTF-8 when it names none this runtime decodes. */
231
+ function decodeText(bytes, charset) {
232
+ try {
233
+ return new TextDecoder(charset ?? 'utf-8').decode(bytes);
234
+ }
235
+ catch {
236
+ return new TextDecoder('utf-8').decode(bytes);
237
+ }
238
+ }
239
+ /** Plain text as blocks: one a paragraph, white space collapsed, in NFC, until the budget of characters is spent. */
240
+ function textBlocks(text, budget) {
241
+ const blocks = [];
242
+ let kept = 0;
243
+ for (const paragraph of text.split(/\n\s*\n/u)) {
244
+ if (kept >= budget)
245
+ break;
246
+ let block = collapse(paragraph).normalize('NFC');
247
+ if (block.length > budget - kept) {
248
+ block = block.slice(0, budget - kept);
249
+ // A cut never leaves half of a surrogate pair.
250
+ const last = block.charCodeAt(block.length - 1);
251
+ if (last >= 0xd800 && last <= 0xdbff)
252
+ block = block.slice(0, -1);
253
+ }
254
+ if (block !== '') {
255
+ blocks.push(block);
256
+ kept += block.length;
257
+ }
258
+ }
259
+ return blocks;
260
+ }
261
+ /** A page's text as blocks, the characters a reader never sees removed. */
262
+ function pageBlocks(kind, text, budget) {
263
+ const raw = kind === 'html' ? htmlToBlocks(text, { mode: 'page', budget }) : textBlocks(text, budget);
264
+ return raw.map((block) => collapse(withoutInvisible(block))).filter((block) => block !== '');
265
+ }
266
+ /** A page that was read, as a document and its passages. */
267
+ function pageRead(url, finalUrl, status, via, blocks, readAt) {
268
+ let host = finalUrl;
269
+ try {
270
+ host = new URL(finalUrl).hostname;
271
+ }
272
+ catch {
273
+ // The address the scraper names is kept as it came.
274
+ }
275
+ const document = { site: host, key: finalUrl, title: host, url: finalUrl, revision: null, readAt, licence: UNREAD_LICENCE, blocks };
276
+ const passages = citationSources(document, sentenceSpans);
277
+ return { status: { url, outcome: 'read', finalUrl, status, failure: null, detail: null, via, passages: passages.length }, blocks, passages };
278
+ }
279
+ /** The failure an error stands for; the caller's own cancellation is thrown instead. */
280
+ function failureOf(error, deadline, caller) {
281
+ if (caller?.aborted)
282
+ throw caller.reason;
283
+ if (error instanceof PageRefusal)
284
+ return { failure: error.failure, detail: error.detail };
285
+ if (deadline.aborted)
286
+ return { failure: 'timeout', detail: null };
287
+ return { failure: 'network', detail: null };
288
+ }
289
+ /** One request for a page, and its body read as text. */
290
+ async function attempt(url, options) {
291
+ const deadline = AbortSignal.timeout(options.timeoutMs);
292
+ const signal = options.signal ? AbortSignal.any([deadline, options.signal]) : deadline;
293
+ const failed = (failure, status, detail, finalUrl) => ({ kind: 'failed', failure, status, detail, finalUrl });
294
+ let answer;
295
+ try {
296
+ answer = await options.transport(url, signal);
297
+ }
298
+ catch (error) {
299
+ const { failure, detail } = failureOf(error, deadline, options.signal);
300
+ return failed(failure, null, detail, null);
301
+ }
302
+ const { status, finalUrl } = answer;
303
+ try {
304
+ if (status < 200 || status > 299) {
305
+ await answer.discard();
306
+ return failed('status', status, null, finalUrl);
307
+ }
308
+ const contentType = answer.header('content-type');
309
+ const type = mediaType(contentType);
310
+ if (type === 'application/pdf') {
311
+ await answer.discard();
312
+ return failed('pdf', status, type, finalUrl);
313
+ }
314
+ if (type !== '' && !isText(type)) {
315
+ await answer.discard();
316
+ return failed('binary', status, type, finalUrl);
317
+ }
318
+ const declared = Number(answer.header('content-length') ?? '');
319
+ if (Number.isFinite(declared) && declared > options.maxBytes) {
320
+ await answer.discard();
321
+ return failed('too_large', status, null, finalUrl);
322
+ }
323
+ const bytes = await answer.read(options.maxBytes);
324
+ if (bytes === null)
325
+ return failed('too_large', status, null, finalUrl);
326
+ if (isPdf(bytes))
327
+ return failed('pdf', status, type === '' ? null : type, finalUrl);
328
+ // A body with no type is read by what it looks like; one served as plain text that is an HTML document is read as HTML.
329
+ const looks = type === '' || type === 'text/plain' ? sniff(bytes) : 'text';
330
+ const kind = isMarkup(type) || looks === 'html' ? 'html' : type === '' ? looks : 'text';
331
+ if (kind === 'binary')
332
+ return failed('binary', status, null, finalUrl);
333
+ const charset = bomCharset(bytes) ?? headerCharset(contentType) ?? (kind === 'html' ? metaCharset(bytes) : null);
334
+ const blocks = pageBlocks(kind, decodeText(bytes, charset), options.textBudget);
335
+ if (blocks.length === 0)
336
+ return failed('no_text', status, null, finalUrl);
337
+ return { kind: 'read', page: pageRead(url, finalUrl, status, 'fetch', blocks, options.now()) };
338
+ }
339
+ catch (error) {
340
+ await answer.discard().catch(() => undefined);
341
+ const { failure, detail } = failureOf(error, deadline, options.signal);
342
+ return failed(failure, status, detail, finalUrl);
343
+ }
344
+ }
345
+ /** The page through the fallback scraper, or null when it fails too. */
346
+ async function scrape(url, scraper, options) {
347
+ let result;
348
+ try {
349
+ result = await scraper.scrape({ url, options: { tier: 2, maxTier: 4, timeout: options.timeoutMs } });
350
+ }
351
+ catch {
352
+ if (options.signal?.aborted)
353
+ throw options.signal.reason;
354
+ return null;
355
+ }
356
+ if (options.signal?.aborted)
357
+ throw options.signal.reason;
358
+ const status = typeof result.statusCode === 'number' && result.statusCode > 0 ? result.statusCode : 200;
359
+ // A tier can answer with the page of an error status; that is no page of the claim's.
360
+ if (!result.success || status < 200 || status > 299)
361
+ return null;
362
+ let blocks = [];
363
+ if (typeof result.html === 'string' && result.html !== '')
364
+ blocks = pageBlocks('html', result.html.slice(0, options.maxBytes), options.textBudget);
365
+ else if (typeof result.text === 'string')
366
+ blocks = pageBlocks('text', result.text.slice(0, options.maxBytes), options.textBudget);
367
+ if (blocks.length === 0)
368
+ return null;
369
+ const finalUrl = typeof result.url === 'string' && /^https?:\/\//iu.test(result.url) ? result.url : url;
370
+ return pageRead(url, finalUrl, status, 'fallback', blocks, options.now());
371
+ }
372
+ /**
373
+ * Reads one page: one request, then for a failure the fallback may mend (a deadline, no connection, an error status
374
+ * other than 404 and 410, a page with no text) one try through the fallback scraper. Answers a status for a page that
375
+ * is not read; throws only the caller's own cancellation.
376
+ *
377
+ * @param url - The address to fetch, from {@link pageKey}.
378
+ * @param options - How to read it.
379
+ */
380
+ export async function readPage(url, options) {
381
+ const first = await attempt(url, options);
382
+ if (first.kind === 'read')
383
+ return first.page;
384
+ const mendable = MENDABLE.has(first.failure) && first.status !== 404 && first.status !== 410;
385
+ if (options.scraper !== null && mendable) {
386
+ const mended = await scrape(url, options.scraper, options);
387
+ if (mended !== null) {
388
+ options.logger?.info('citation_check.page_read_by_fallback', { origin: originOf(url), failure: first.failure });
389
+ return mended;
390
+ }
391
+ }
392
+ const outcome = UNREADABLE.has(first.failure) ? 'unreadable' : 'unreachable';
393
+ options.logger?.warn(`citation_check.page_${outcome}`, { origin: originOf(url), failure: first.failure, status: first.status, detail: first.detail });
394
+ return {
395
+ status: { url, outcome, finalUrl: first.finalUrl, status: first.status, failure: first.failure, detail: first.detail, via: null, passages: 0 },
396
+ blocks: [],
397
+ passages: [],
398
+ };
399
+ }
400
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,YAAY,EAA4C,MAAM,qCAAqC,CAAC;AAC9H,OAAO,EAAE,cAAc,EAAuC,MAAM,kCAAkC,CAAC;AACvG,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA+B9C,+EAA+E;AAC/E,MAAM,OAAO,WAAY,SAAQ,KAAK;IAMzB;IACA;IANX;;;OAGG;IACH,YACW,OAAoB,EACpB,SAAwB,IAAI;QAErC,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAkB,OAAO,EAAE,CAAC,CAAC,CAAC,kBAAkB,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC;QAHtF,YAAO,GAAP,OAAO,CAAa;QACpB,WAAM,GAAN,MAAM,CAAsB;QAGrC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,wFAAwF;AACxF,MAAM,QAAQ,GAA6B,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAChG,2EAA2E;AAC3E,MAAM,UAAU,GAA6B,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK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AE;QACV,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file parse.ts
3
+ * @description The cited claims of a document, with the line each starts on. Markdown: each quotation ("…", “…” or
4
+ * „…“) and the first http or https address after it in its sentence, whether in parentheses (`(https://…, read 1 Mar
5
+ * 2026)`), in a markdown link, between angle brackets or bare, on the same line or a later line of the paragraph;
6
+ * several quotations waiting in a sentence share the address that follows them. A quotation of four words or more that
7
+ * no address follows before its sentence ends is uncited; a shorter one is a term or a title and is passed over.
8
+ * Fenced code, code spans and escaped quotation marks hold no claim. JSON: an array of `{ claim, url, exact }`.
9
+ *
10
+ * @module agentos/extensions/research/citation-check/parse
11
+ */
12
+ import type { CitedClaim } from './types.js';
13
+ /** How {@link parseCitedClaims} reads a document: `json`, `markdown`, or `auto` (JSON when it is a JSON array). */
14
+ export type CitedClaimFormat = 'auto' | 'markdown' | 'json';
15
+ /** A document the parser cannot read: a JSON entry that is no claim, an address that is not http or https. */
16
+ export declare class CitationInputError extends Error {
17
+ /** @param message - What is wrong, and where. */
18
+ constructor(message: string);
19
+ }
20
+ /** Whether a string is an absolute http or https address with a host. */
21
+ export declare function isHttpUrl(value: string): boolean;
22
+ /**
23
+ * The cited claims of a document, in the order they stand, each with its line.
24
+ *
25
+ * @param text - Markdown, or a JSON array of `{ "claim": string, "url"?: string, "exact"?: boolean }`; an entry with no
26
+ * `url`, or an empty one, is uncited, and `exact` is true when left out.
27
+ * @param options - `format`: `auto` (the default) reads a document that is a JSON array as JSON and any other as
28
+ * markdown.
29
+ * @returns The claims; one with no address has `url: null`.
30
+ * @throws {CitationInputError} For a JSON document that is not an array of claims, or that `format: 'json'` names and
31
+ * that is not JSON.
32
+ */
33
+ export declare function parseCitedClaims(text: string, options?: {
34
+ format?: CitedClaimFormat;
35
+ }): CitedClaim[];
36
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,mHAAmH;AACnH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;AAE5D,8GAA8G;AAC9G,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,iDAAiD;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAuBD,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOhD;AAyND;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAAO,GAAG,UAAU,EAAE,CAiBxG"}