@framers/agentos-ext-citation-check 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/README.md +95 -8
- package/dist/claims.d.ts +281 -0
- package/dist/claims.d.ts.map +1 -0
- package/dist/claims.js +478 -0
- package/dist/claims.js.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/meta.d.ts +6 -1
- package/dist/meta.d.ts.map +1 -1
- package/dist/meta.js +14 -3
- package/dist/meta.js.map +1 -1
- package/dist/page.d.ts +23 -3
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +182 -10
- package/dist/page.js.map +1 -1
- package/dist/web-source.d.ts +36 -8
- package/dist/web-source.d.ts.map +1 -1
- package/dist/web-source.js +74 -16
- package/dist/web-source.js.map +1 -1
- package/manifest.json +2 -2
- package/package.json +8 -7
package/dist/claims.js
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file claims.ts
|
|
3
|
+
* @description A spoken claim checked against passages from any source: an encyclopedia article, a web page, a paper's
|
|
4
|
+
* abstract, a person's own notes or documents. The grounding guard's checker keeps the sentences about the claim;
|
|
5
|
+
* AgentOS's `CitationVerifier` names the best of them by cosine; one judge call, whose instruction, schema and quote
|
|
6
|
+
* rule are this pack's, says whether that sentence matches the claim, differs from it, or neither; the judge's quote is
|
|
7
|
+
* held to the sentence word for word (`verifyQuotes`); and the grounding guard decides by code over every passage
|
|
8
|
+
* found, the ones never sent to a model among them. Passages that arrive after the first decision are decided by code
|
|
9
|
+
* alone against it (`agree`), and a held "differs" is read again over every passage found by then (`revisit`).
|
|
10
|
+
*
|
|
11
|
+
* The host passes its embeddings call and its judge (`claimJudge` builds one on AgentOS's `generateObject`); the pack
|
|
12
|
+
* reads no key from the environment.
|
|
13
|
+
*
|
|
14
|
+
* @module @framers/agentos-ext-citation-check/claims
|
|
15
|
+
*/
|
|
16
|
+
import { collapse, fold, numberOf, words } from '@framers/agentos-ext-grounding-guard/values';
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
/** The most words a judge's quote may hold. */
|
|
19
|
+
export const CLAIM_QUOTE_MAX_WORDS = 20;
|
|
20
|
+
/** The judge's instruction's words for a kind of source: what the sentence is from, and the title above it. */
|
|
21
|
+
function sourceWords(kind) {
|
|
22
|
+
switch (kind) {
|
|
23
|
+
case 'encyclopedia':
|
|
24
|
+
return { from: 'an encyclopedia article', title: "its article's title" };
|
|
25
|
+
case 'official':
|
|
26
|
+
case 'news':
|
|
27
|
+
case 'page':
|
|
28
|
+
case 'forum':
|
|
29
|
+
return { from: 'a web page', title: "its page's title" };
|
|
30
|
+
case 'paper':
|
|
31
|
+
return { from: "a paper's abstract", title: "the paper's title" };
|
|
32
|
+
case 'note':
|
|
33
|
+
case 'document':
|
|
34
|
+
return { from: "the person's own notes or documents", title: "its note's or document's title" };
|
|
35
|
+
default:
|
|
36
|
+
return { from: 'a source', title: "its source's title" };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The judge's instruction for a sentence from a source of this kind: whether the sentence states the same fact as the
|
|
41
|
+
* claim (the same value, holder, place, maker or date), a different one, or neither, with the words it compared quoted
|
|
42
|
+
* from the sentence. Every instruction opens with "You compare one sentence heard in a room with one sentence from",
|
|
43
|
+
* then what the sentence is from: "an encyclopedia article" for `encyclopedia`; "a web page" for `official`, `news`,
|
|
44
|
+
* `page` and `forum`; "a paper's abstract" for `paper`; "the person's own notes or documents" for `note` and
|
|
45
|
+
* `document`; "a source" for any other word.
|
|
46
|
+
*
|
|
47
|
+
* @param kind - The named passage's kind ({@link ClaimPassage.kind}).
|
|
48
|
+
*/
|
|
49
|
+
export function claimJudgeSystem(kind) {
|
|
50
|
+
const source = sourceWords(kind);
|
|
51
|
+
return [
|
|
52
|
+
`You compare one sentence heard in a room with one sentence from ${source.from}.`,
|
|
53
|
+
`HEARD is the sentence, transcribed by machine; it may be misheard. CHECK is the part being checked, rewritten to stand alone. SOURCE is that sentence, after ${source.title}.`,
|
|
54
|
+
'relation "matches": SOURCE states the same fact for the same thing as CHECK: the same value, holder, place, maker or date, holding at the same time.',
|
|
55
|
+
'relation "differs": SOURCE states a different value, holder, place, maker or date for the same thing as CHECK, or says it held only in the past while CHECK says it holds now.',
|
|
56
|
+
'relation "none": everything else, including a sentence about something else, and a HEARD that is an opinion, a plan, a question, a joke or a hypothetical. When unsure, "none".',
|
|
57
|
+
`quote: copied character for character from SOURCE, at most ${CLAIM_QUOTE_MAX_WORDS} words, holding the words that state the fact you compared; empty for "none".`,
|
|
58
|
+
'Use no knowledge beyond SOURCE and HEARD. Never judge the speaker.',
|
|
59
|
+
].join('\n');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The judge's prompt: the heard sentence, the claim, and the one sentence with its source's title above it.
|
|
63
|
+
*
|
|
64
|
+
* @param heard - The whole sentence heard.
|
|
65
|
+
* @param statement - The claim rewritten to stand alone.
|
|
66
|
+
* @param title - The source's title; empty when it should not be sent.
|
|
67
|
+
* @param sentence - The source's sentence.
|
|
68
|
+
*/
|
|
69
|
+
export function claimJudgePrompt(heard, statement, title, sentence) {
|
|
70
|
+
return `HEARD: ${heard}\nCHECK: ${statement}\nSOURCE: ${title}\n${sentence}`;
|
|
71
|
+
}
|
|
72
|
+
/** The judge's answer's schema. */
|
|
73
|
+
const CLAIM_JUDGEMENT = z.object({
|
|
74
|
+
relation: z.enum(['matches', 'differs', 'none']),
|
|
75
|
+
quote: z.string().describe(`Copied from SOURCE, at most ${CLAIM_QUOTE_MAX_WORDS} words; empty for none.`),
|
|
76
|
+
});
|
|
77
|
+
/** `work`'s outcome, or a rejection with the signal's reason the moment the signal aborts first. */
|
|
78
|
+
function untilAbort(work, signal) {
|
|
79
|
+
if (signal.aborted) {
|
|
80
|
+
// Nobody waits for `work` now, so its own rejection is handled here.
|
|
81
|
+
work.catch(() => undefined);
|
|
82
|
+
return Promise.reject(signal.reason);
|
|
83
|
+
}
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const onAbort = () => reject(signal.reason);
|
|
86
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
87
|
+
work.then((value) => {
|
|
88
|
+
signal.removeEventListener('abort', onAbort);
|
|
89
|
+
resolve(value);
|
|
90
|
+
}, (error) => {
|
|
91
|
+
signal.removeEventListener('abort', onAbort);
|
|
92
|
+
reject(error);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A judge on AgentOS's `generateObject`, with this pack's schema: one call, sent once (`maxAttempts: 1`), with no
|
|
98
|
+
* second call for an answer that is not the schema (`maxRetries: 0`) and no other provider (`fallbackProviders: []`),
|
|
99
|
+
* ended at `deadlineMs` or by the caller's signal, whichever comes first, the body's read included.
|
|
100
|
+
*
|
|
101
|
+
* @param options - The model (`provider:model`, such as `openai:gpt-6-luna`), the key, the base address (a stand-in in
|
|
102
|
+
* a host's tests), each call's deadline, the most tokens it may answer, and the reasoning effort for a model that takes
|
|
103
|
+
* one.
|
|
104
|
+
* @returns The judge. It rejects with the caller's reason when the caller's signal aborts, with a timeout when the
|
|
105
|
+
* deadline passes, and with the provider's error otherwise.
|
|
106
|
+
*/
|
|
107
|
+
export function claimJudge(options) {
|
|
108
|
+
return async ({ system, prompt, signal }) => {
|
|
109
|
+
signal.throwIfAborted();
|
|
110
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(options.deadlineMs)]);
|
|
111
|
+
const call = (async () => {
|
|
112
|
+
const { generateObject } = await import('@framers/agentos');
|
|
113
|
+
return generateObject({
|
|
114
|
+
model: options.model,
|
|
115
|
+
schema: CLAIM_JUDGEMENT,
|
|
116
|
+
schemaName: 'judgement',
|
|
117
|
+
system,
|
|
118
|
+
prompt,
|
|
119
|
+
maxTokens: options.maxOutputTokens,
|
|
120
|
+
maxRetries: 0,
|
|
121
|
+
maxAttempts: 1,
|
|
122
|
+
fallbackProviders: [],
|
|
123
|
+
requestTimeout: options.deadlineMs,
|
|
124
|
+
abortSignal: bounded,
|
|
125
|
+
apiKey: options.apiKey,
|
|
126
|
+
...(options.baseUrl === undefined ? {} : { baseUrl: options.baseUrl }),
|
|
127
|
+
...(options.effort === undefined ? {} : { effort: options.effort }),
|
|
128
|
+
});
|
|
129
|
+
})();
|
|
130
|
+
const result = await untilAbort(call, bounded);
|
|
131
|
+
return {
|
|
132
|
+
value: { relation: result.object.relation, quote: result.object.quote },
|
|
133
|
+
usage: { in: result.usage.promptTokens ?? 0, out: result.usage.completionTokens ?? 0 },
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* One call's sentences: each passage read once, when the call first meets it, so everything the call sends or decides on
|
|
139
|
+
* is the passage as it was then, whatever another call or the host does to it meanwhile, and one passage is one sentence
|
|
140
|
+
* within the call.
|
|
141
|
+
*/
|
|
142
|
+
function snapshot() {
|
|
143
|
+
const sentences = new Map();
|
|
144
|
+
return (passage) => {
|
|
145
|
+
let sentence = sentences.get(passage);
|
|
146
|
+
if (sentence === undefined) {
|
|
147
|
+
sentence = { text: passage.content, group: passage.group, title: passage.title, kind: passage.kind, url: passage.url, passage };
|
|
148
|
+
sentences.set(passage, sentence);
|
|
149
|
+
}
|
|
150
|
+
return sentence;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** The first sentence of each text, in order. */
|
|
154
|
+
function firstOfEachText(sentences) {
|
|
155
|
+
const seen = new Set();
|
|
156
|
+
return sentences.filter((sentence) => {
|
|
157
|
+
if (seen.has(sentence.text))
|
|
158
|
+
return false;
|
|
159
|
+
seen.add(sentence.text);
|
|
160
|
+
return true;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** `a`, then each of `b` not in it. */
|
|
164
|
+
function unite(a, b) {
|
|
165
|
+
const seen = new Set(a);
|
|
166
|
+
return [...a, ...b.filter((item) => !seen.has(item))];
|
|
167
|
+
}
|
|
168
|
+
/** The characters of a span, or empty for none or one out of range. */
|
|
169
|
+
function spanText(text, span) {
|
|
170
|
+
if (span === null || span === undefined)
|
|
171
|
+
return '';
|
|
172
|
+
const { start, end } = span;
|
|
173
|
+
return Number.isInteger(start) && Number.isInteger(end) && start >= 0 && end <= text.length && start < end ? text.slice(start, end) : '';
|
|
174
|
+
}
|
|
175
|
+
/** Two marked values the same as written: their characters equal once white space and thousands separators are read alike. */
|
|
176
|
+
function sameAsWritten(a, b) {
|
|
177
|
+
return a !== '' && b !== '' && numberOf(collapse(a)) === numberOf(collapse(b));
|
|
178
|
+
}
|
|
179
|
+
/** Whether a judgement's quote may stand: a relation, one to {@link CLAIM_QUOTE_MAX_WORDS} words, word for word in the sentence. */
|
|
180
|
+
function quoteHolds(value, sentence, verifyQuotes) {
|
|
181
|
+
if (value.relation === 'none')
|
|
182
|
+
return false;
|
|
183
|
+
const count = words(value.quote).length;
|
|
184
|
+
return count >= 1 && count <= CLAIM_QUOTE_MAX_WORDS && verifyQuotes([{ text: value.quote, sourceIndex: 0 }], [sentence], { normalize: fold })[0]?.found === true;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Checks spoken claims against passages from any source, as `check` says, and decides later passages by code against a
|
|
188
|
+
* first decision. One checker serves many checks: it keeps nothing of a check but what `agree` and `revisit` read
|
|
189
|
+
* again, held weakly by the outcome `check` answered.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { ClaimChecker, claimJudge } from '@framers/agentos-ext-citation-check';
|
|
194
|
+
* import { ValueAgreementChecker } from '@framers/agentos-ext-grounding-guard';
|
|
195
|
+
*
|
|
196
|
+
* const checker = new ClaimChecker({
|
|
197
|
+
* embed: async (texts, signal) => myEmbeddings(texts, signal), // { vectors, usage: { in } }
|
|
198
|
+
* judge: claimJudge({ model: 'openai:gpt-6-luna', apiKey, deadlineMs: 8_000, maxOutputTokens: 400 }),
|
|
199
|
+
* checker: new ValueAgreementChecker({ names: true }),
|
|
200
|
+
* });
|
|
201
|
+
* const outcome = await checker.check(
|
|
202
|
+
* { heard, heardSentence, statement },
|
|
203
|
+
* passages, // ClaimPassage[]: { content, title, url?, group, kind }
|
|
204
|
+
* { signal },
|
|
205
|
+
* );
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export class ClaimChecker {
|
|
209
|
+
embed;
|
|
210
|
+
judge;
|
|
211
|
+
checker;
|
|
212
|
+
maxPassages;
|
|
213
|
+
/**
|
|
214
|
+
* What a decided check keeps for `agree` and `revisit`, by the outcome `check` answered: every passage it found, the
|
|
215
|
+
* held-back ones among them.
|
|
216
|
+
*/
|
|
217
|
+
decided = new WeakMap();
|
|
218
|
+
/**
|
|
219
|
+
* The texts each decision this checker answered was decided on (`check`'s and `revisit`'s alike), which the host's
|
|
220
|
+
* copy in `decision.texts` may since have been changed from. Kept by the decision's `pairs`, the offsets that index
|
|
221
|
+
* them: every decision answered holds its own copy of that array, which a host's shallow copy of the decision keeps.
|
|
222
|
+
*/
|
|
223
|
+
decisionTexts = new WeakMap();
|
|
224
|
+
/**
|
|
225
|
+
* @param options - The embeddings call, the judge, the grounding guard's checker, and the most passages compared.
|
|
226
|
+
* @throws {RangeError} For a `maxPassages` that is not a whole number of at least 1.
|
|
227
|
+
*/
|
|
228
|
+
constructor(options) {
|
|
229
|
+
const maxPassages = options.maxPassages ?? 24;
|
|
230
|
+
if (!Number.isInteger(maxPassages) || maxPassages < 1)
|
|
231
|
+
throw new RangeError(`maxPassages must be a whole number of at least 1, not ${maxPassages}`);
|
|
232
|
+
this.embed = options.embed;
|
|
233
|
+
this.judge = options.judge;
|
|
234
|
+
this.checker = options.checker;
|
|
235
|
+
this.maxPassages = maxPassages;
|
|
236
|
+
}
|
|
237
|
+
/** A decision with the host's passages in place of the grounding guard's sentences, and their texts as read. */
|
|
238
|
+
toHost(decision) {
|
|
239
|
+
const texts = decision.sentences.map((sentence) => sentence.text);
|
|
240
|
+
const host = {
|
|
241
|
+
...decision,
|
|
242
|
+
// Its own array, whatever the checker given reuses from one decision to the next.
|
|
243
|
+
...(Array.isArray(decision.pairs) ? { pairs: [...decision.pairs] } : {}),
|
|
244
|
+
sentences: decision.sentences.map((sentence) => sentence.passage),
|
|
245
|
+
texts: [...texts],
|
|
246
|
+
};
|
|
247
|
+
if (Array.isArray(host.pairs))
|
|
248
|
+
this.decisionTexts.set(host.pairs, texts);
|
|
249
|
+
return host;
|
|
250
|
+
}
|
|
251
|
+
/** Every passage found for a decided check; the decision's own passages when the outcome is not one `check` answered. */
|
|
252
|
+
foundOf(first) {
|
|
253
|
+
const kept = this.decided.get(first)?.found;
|
|
254
|
+
return kept ?? unite(first.decision.sentences, [first.named]);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Checks a claim against passages, in order:
|
|
258
|
+
*
|
|
259
|
+
* 1. the grounding guard's `passages` keeps the sentences of `given` about the claim; none ends `no_passage`, with
|
|
260
|
+
* nothing sent anywhere;
|
|
261
|
+
* 2. AgentOS's `CitationVerifier`, both its thresholds 0 and its `embedFn` the host's `embed` (one call for the claim
|
|
262
|
+
* and the first `maxPassages` sentences kept, one a text: a text two sources share is compared as the first of
|
|
263
|
+
* them, whose title and kind the judge then reads), names the best of them by cosine; none ends `no_best`;
|
|
264
|
+
* 3. the judge is asked once about that sentence, under {@link claimJudgeSystem} for its kind, with
|
|
265
|
+
* {@link claimJudgePrompt}; `none` ends `judge_none`;
|
|
266
|
+
* 4. the judge's quote must hold one to {@link CLAIM_QUOTE_MAX_WORDS} words and stand in the sentence word for word
|
|
267
|
+
* (`verifyQuotes` with `fold`); else it ends `quote`;
|
|
268
|
+
* 5. the grounding guard's `decide` takes the judge's relation as its proposal, the named sentence, the quote, and as
|
|
269
|
+
* `found` every sentence kept in step 1 and every one of `options.found`; `null` ends `undecided`.
|
|
270
|
+
*
|
|
271
|
+
* `options.found` is every passage about the claim the host holds, the ones it may not send included (a sentence that
|
|
272
|
+
* holds personal data, for example): they are never embedded, judged or sent, and take part in step 5 alone, where a
|
|
273
|
+
* passage that agrees with every heard value stops a "differs". Left out, it is `given`'s sentences about the claim.
|
|
274
|
+
*
|
|
275
|
+
* @param claim - The claim heard.
|
|
276
|
+
* @param given - The passages that may be sent to the embeddings and the judge.
|
|
277
|
+
* @param options - The check's signal, and every passage found.
|
|
278
|
+
* @throws The signal's reason when it aborts, at once, whatever is pending; the embeddings' or the judge's error as it
|
|
279
|
+
* came, which the verifier alone would have swallowed.
|
|
280
|
+
*/
|
|
281
|
+
async check(claim, given, options) {
|
|
282
|
+
const { signal } = options;
|
|
283
|
+
signal.throwIfAborted();
|
|
284
|
+
const usage = { judgeIn: 0, judgeOut: 0, embedIn: 0 };
|
|
285
|
+
const state = {
|
|
286
|
+
judged: 0,
|
|
287
|
+
judgement: null,
|
|
288
|
+
failure: null,
|
|
289
|
+
};
|
|
290
|
+
const ended = (reason) => ({
|
|
291
|
+
kind: 'ended',
|
|
292
|
+
reason,
|
|
293
|
+
judged: state.judged,
|
|
294
|
+
usage: { ...usage },
|
|
295
|
+
});
|
|
296
|
+
// The passages as they are now: this call reads nothing of them later.
|
|
297
|
+
const sentenceOf = snapshot();
|
|
298
|
+
// 1. The sentences about the claim that may be sent.
|
|
299
|
+
const kept = this.checker.passages(claim.heard, given.map((passage) => sentenceOf(passage))).found;
|
|
300
|
+
if (kept.length === 0)
|
|
301
|
+
return ended('no_passage');
|
|
302
|
+
// One passage a text, the first found: the verifier hands its NLI function the text alone, so the judge reads the
|
|
303
|
+
// title and the kind of the very passage the outcome names. Every passage found still meets the rule in step 5.
|
|
304
|
+
const compared = firstOfEachText(kept).slice(0, this.maxPassages);
|
|
305
|
+
const found = unite(kept, (options.found ?? []).map((passage) => sentenceOf(passage)));
|
|
306
|
+
// The title and the kind the judge reads, by the sentence the verifier hands its NLI function.
|
|
307
|
+
const about = new Map(compared.map((sentence) => [sentence.text, { title: sentence.title, kind: sentence.kind }]));
|
|
308
|
+
const [{ CitationVerifier }, { verifyQuotes }] = await untilAbort(Promise.all([import('@framers/agentos/cognition/rag/citation/index'), import('@framers/agentos-ext-grounding-guard')]), signal);
|
|
309
|
+
const verifier = new CitationVerifier({
|
|
310
|
+
// The cosine names the best passage and decides nothing: the judge and the grounding guard's rule decide.
|
|
311
|
+
supportThreshold: 0,
|
|
312
|
+
unverifiableThreshold: 0,
|
|
313
|
+
embedFn: async (texts) => {
|
|
314
|
+
signal.throwIfAborted();
|
|
315
|
+
const embedded = await this.embed(texts, signal);
|
|
316
|
+
usage.embedIn += embedded.usage.in;
|
|
317
|
+
if (embedded.vectors.length !== texts.length) {
|
|
318
|
+
throw new Error(`the embeddings answered ${embedded.vectors.length} vectors for ${texts.length} texts`);
|
|
319
|
+
}
|
|
320
|
+
return embedded.vectors;
|
|
321
|
+
},
|
|
322
|
+
// The verifier keeps its cosine verdict when its NLI function throws, so a judge that failed is held here and
|
|
323
|
+
// thrown after `verify`, as the embeddings' failure is.
|
|
324
|
+
nliFn: async (premise, hypothesis) => {
|
|
325
|
+
try {
|
|
326
|
+
signal.throwIfAborted();
|
|
327
|
+
const source = about.get(premise) ?? { title: '', kind: '' };
|
|
328
|
+
state.judged += 1;
|
|
329
|
+
const answer = await this.judge({
|
|
330
|
+
system: claimJudgeSystem(source.kind),
|
|
331
|
+
prompt: claimJudgePrompt(claim.heardSentence, hypothesis, source.title, premise),
|
|
332
|
+
signal,
|
|
333
|
+
});
|
|
334
|
+
usage.judgeIn += answer.usage.in;
|
|
335
|
+
usage.judgeOut += answer.usage.out;
|
|
336
|
+
const holds = quoteHolds(answer.value, premise, verifyQuotes);
|
|
337
|
+
state.judgement = { value: answer.value, holds };
|
|
338
|
+
if (answer.value.relation === 'none' || !holds)
|
|
339
|
+
return { label: 'neutral', score: 0 };
|
|
340
|
+
return { label: answer.value.relation === 'matches' ? 'entailment' : 'contradiction', score: 1 };
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
state.failure = { error };
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
// 2 and 3: the verifier's best, and the judge on it.
|
|
349
|
+
const verified = await untilAbort(verifier.verify([claim.statement], compared.map((sentence) => ({ content: sentence.text, title: sentence.title, ...(sentence.url === undefined ? {} : { url: sentence.url }) }))), signal);
|
|
350
|
+
if (state.failure !== null)
|
|
351
|
+
throw state.failure.error;
|
|
352
|
+
signal.throwIfAborted();
|
|
353
|
+
const verdict = verified.claims[0];
|
|
354
|
+
const named = verdict?.sourceIndex === undefined ? undefined : compared[verdict.sourceIndex];
|
|
355
|
+
if (verdict === undefined || named === undefined)
|
|
356
|
+
return ended('no_best');
|
|
357
|
+
const judgement = state.judgement;
|
|
358
|
+
if (judgement === null || judgement.value.relation === 'none')
|
|
359
|
+
return ended('judge_none');
|
|
360
|
+
// 4. The quote.
|
|
361
|
+
if (!judgement.holds)
|
|
362
|
+
return ended('quote');
|
|
363
|
+
// 5. The rule, by code, over every passage found.
|
|
364
|
+
const decision = this.checker.decide({
|
|
365
|
+
heardWords: claim.heard,
|
|
366
|
+
heardSentence: claim.heardSentence,
|
|
367
|
+
proposed: judgement.value.relation,
|
|
368
|
+
named: [named],
|
|
369
|
+
found,
|
|
370
|
+
quote: judgement.value.quote,
|
|
371
|
+
});
|
|
372
|
+
if (decision === null)
|
|
373
|
+
return ended('undecided');
|
|
374
|
+
const outcome = {
|
|
375
|
+
kind: 'decided',
|
|
376
|
+
decision: this.toHost(decision),
|
|
377
|
+
named: named.passage,
|
|
378
|
+
quote: judgement.value.quote,
|
|
379
|
+
verdict,
|
|
380
|
+
judged: state.judged,
|
|
381
|
+
usage: { ...usage },
|
|
382
|
+
};
|
|
383
|
+
this.decided.set(outcome, { found: found.map((sentence) => sentence.passage) });
|
|
384
|
+
return outcome;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The passages that arrived after a first decision and agree with it, decided by code alone, with no model call. Each
|
|
388
|
+
* source of `more` (by `group`) other than the first decision's is read once, by its passage the grounding guard
|
|
389
|
+
* ranks first about the claim, which joins when:
|
|
390
|
+
*
|
|
391
|
+
* 1. it holds every content stem of the heard words;
|
|
392
|
+
* 2. the grounding guard decides the first decision's relation for it, on the values, over every passage found (the
|
|
393
|
+
* first check's and every one of `more`, whatever its length);
|
|
394
|
+
* 3. its first value pair pairs the same heard value as the first decision's;
|
|
395
|
+
* 4. for a "differs", its marked value is the first decision's as written; for a "matches", each of the first
|
|
396
|
+
* decision's pairs finds its partner written alike, the decision's sentence read as the call that answered it
|
|
397
|
+
* (`check`, or `revisit` for a decision the host put in the outcome's place) read it, whatever the host has
|
|
398
|
+
* written into `decision.texts` since.
|
|
399
|
+
*
|
|
400
|
+
* A "disagree", a decision on the judge's quote alone, and a decision with no value pair take no passage.
|
|
401
|
+
*
|
|
402
|
+
* @param first - The decided outcome `check` answered.
|
|
403
|
+
* @param claim - The claim it checked.
|
|
404
|
+
* @param more - The later passages.
|
|
405
|
+
* @returns The passages that join, in the grounding guard's order.
|
|
406
|
+
*/
|
|
407
|
+
agree(first, claim, more) {
|
|
408
|
+
const { decision } = first;
|
|
409
|
+
if (decision.relation === 'disagree' || decision.basis !== 'values')
|
|
410
|
+
return [];
|
|
411
|
+
const firstPairs = Array.isArray(decision.pairs) ? decision.pairs : [];
|
|
412
|
+
const lead = firstPairs[0];
|
|
413
|
+
if (lead === undefined)
|
|
414
|
+
return [];
|
|
415
|
+
// The decision's marks and pairs are offsets into its sentence as it was decided: the text kept with those pairs for
|
|
416
|
+
// a decision this checker answered (`check`'s, or `revisit`'s the host put in its place, a shallow copy of either
|
|
417
|
+
// included), whatever the host has written into `decision.texts` since.
|
|
418
|
+
const firstSentence = this.decisionTexts.get(firstPairs)?.[0] ?? decision.texts?.[0] ?? (decision.sentences[0] ?? first.named).content;
|
|
419
|
+
// Every passage as it is now, the first check's included (a host may have changed one since).
|
|
420
|
+
const sentenceOf = snapshot();
|
|
421
|
+
const later = more.map((passage) => sentenceOf(passage));
|
|
422
|
+
// The passages that may join are those about the claim; the veto reads every passage, as `check`'s `found`.
|
|
423
|
+
const candidates = this.checker.passages(claim.heard, later).found;
|
|
424
|
+
const found = unite(this.foundOf(first).map((passage) => sentenceOf(passage)), later);
|
|
425
|
+
const heardStems = this.checker.stems(claim.heard);
|
|
426
|
+
const considered = new Set(decision.sentences.map((passage) => passage.group));
|
|
427
|
+
const joined = [];
|
|
428
|
+
for (const sentence of candidates) {
|
|
429
|
+
if (considered.has(sentence.group))
|
|
430
|
+
continue;
|
|
431
|
+
// Each other source once: its best-ranked passage stands for it.
|
|
432
|
+
considered.add(sentence.group);
|
|
433
|
+
const own = this.checker.stems(sentence.text);
|
|
434
|
+
if (![...heardStems].every((stem) => own.has(stem)))
|
|
435
|
+
continue;
|
|
436
|
+
const decided = this.checker.decide({ heardWords: claim.heard, heardSentence: claim.heardSentence, proposed: decision.relation, named: [sentence], found });
|
|
437
|
+
if (decided === null || decided.relation !== decision.relation || decided.basis !== 'values')
|
|
438
|
+
continue;
|
|
439
|
+
const pairs = Array.isArray(decided.pairs) ? decided.pairs : [];
|
|
440
|
+
const other = pairs[0];
|
|
441
|
+
if (other === undefined || other.heard.start !== lead.heard.start || other.heard.end !== lead.heard.end)
|
|
442
|
+
continue;
|
|
443
|
+
const same = decision.relation === 'differs'
|
|
444
|
+
? sameAsWritten(spanText(firstSentence, decision.marks[0]), spanText(sentence.text, decided.marks[0]))
|
|
445
|
+
: firstPairs.every((pair) => {
|
|
446
|
+
const at = pairs.find((candidate) => candidate.heard.start === pair.heard.start && candidate.heard.end === pair.heard.end);
|
|
447
|
+
return at !== undefined && sameAsWritten(spanText(firstSentence, pair.source), spanText(sentence.text, at.source));
|
|
448
|
+
});
|
|
449
|
+
if (same)
|
|
450
|
+
joined.push(sentence.passage);
|
|
451
|
+
}
|
|
452
|
+
return joined;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* The first decision read again over every passage found by then: the grounding guard's rule with the same proposal,
|
|
456
|
+
* named passage and quote, its `found` every passage the check found (held-back ones among them) and every passage of
|
|
457
|
+
* `found`, as `check` reads its own `found`, whatever its length. A "differs" a later passage stops (one that agrees with every heard value) answers `null`,
|
|
458
|
+
* so a host that holds a "differs" until its slower sources have answered shows nothing.
|
|
459
|
+
*
|
|
460
|
+
* @param first - The decided outcome `check` answered.
|
|
461
|
+
* @param claim - The claim it checked.
|
|
462
|
+
* @param found - Every passage found by then.
|
|
463
|
+
* @returns The decision, its relation the first's, or `null`.
|
|
464
|
+
*/
|
|
465
|
+
revisit(first, claim, found) {
|
|
466
|
+
const { decision } = first;
|
|
467
|
+
// Every passage as it is now, the first check's included; none is held to the sentence limits a passage the judge
|
|
468
|
+
// reads is, as `check`'s `found`.
|
|
469
|
+
const sentenceOf = snapshot();
|
|
470
|
+
const named = decision.relation === 'disagree' ? decision.sentences.map((passage) => sentenceOf(passage)) : [sentenceOf(first.named)];
|
|
471
|
+
const all = unite(unite(named, this.foundOf(first).map((passage) => sentenceOf(passage))), found.map((passage) => sentenceOf(passage)));
|
|
472
|
+
const again = this.checker.decide({ heardWords: claim.heard, heardSentence: claim.heardSentence, proposed: decision.relation, named, found: all, quote: first.quote });
|
|
473
|
+
if (again === null || again.relation !== decision.relation)
|
|
474
|
+
return null;
|
|
475
|
+
return this.toHost(again);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
//# sourceMappingURL=claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.js","sourceRoot":"","sources":["../src/claims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+CAA+C;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,EA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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* the result. The pack's one tool is `citation_verify`; the `agentos-citations` command runs the same check. The page
|
|
8
8
|
* reader is exported (`readPage` with its transports, the host rule and robots.txt on every hop, the licence read),
|
|
9
9
|
* and `WebPageSourceProvider` makes the open web a public source over a search the host gives. `FirecrawlPageReader`
|
|
10
|
-
* reads a page with no text through Firecrawl's scrape endpoint with the host's key.
|
|
10
|
+
* reads a page with no text through Firecrawl's scrape endpoint with the host's key. `ClaimChecker` checks a claim heard
|
|
11
|
+
* in a room against passages from any source, with one judge call (`claimJudge` on AgentOS's `generateObject`) and the
|
|
12
|
+
* grounding guard's decision by code.
|
|
11
13
|
*
|
|
12
14
|
* @module @framers/agentos-ext-citation-check
|
|
13
15
|
*/
|
|
@@ -17,16 +19,17 @@ import type { EmbedFn, NliFn } from './types.js';
|
|
|
17
19
|
export * from './types.js';
|
|
18
20
|
export { parseCitedClaims, CitationInputError, isHttpUrl, type CitedClaimFormat } from './parse.js';
|
|
19
21
|
export { normalizeForMatch, quoteFragments, locateQuote, lexicalNearest, withoutInvisible } from './match.js';
|
|
20
|
-
export { pageKey, readPage, fetchTransport, egressTransport, PageRefusal, UNREAD_LICENCE, type EgressProfile, type PageScraper, type PageReaderOptions, type PageRead, type PageFallbackReader, type Transport, type TransportAnswer, type TransportRules, } from './page.js';
|
|
22
|
+
export { pageKey, readPage, fetchTransport, egressTransport, PageRefusal, UNREAD_LICENCE, type EgressProfile, type PageScraper, type PageReaderOptions, type PageRead, type PageFallbackReader, type Transport, type TransportAnswer, type TransportRules, type TransportLimits, } from './page.js';
|
|
21
23
|
export { readRobots, robotsAllows, parseRobots, ROBOTS_PARSING_FLOOR, type RobotsRule, type RobotsFile, type RobotsGroup, type RobotsLine, type ReadRobotsOptions } from './robots.js';
|
|
22
24
|
export { readLicence } from './licence.js';
|
|
23
|
-
export { WebPageSourceProvider, DEFAULT_ROBOTS, type WebPageSourceOptions } from './web-source.js';
|
|
25
|
+
export { WebPageSourceProvider, DEFAULT_ROBOTS, type WebPageSourceOptions, type WebSearchAnswer } from './web-source.js';
|
|
24
26
|
export { FirecrawlPageReader, FIRECRAWL_SCRAPE_URL, type FirecrawlPageReaderOptions } from './firecrawl.js';
|
|
25
27
|
export { checkCitations, checkCitationDocument, CitationSetupError, type CitationCheckOptions } from './runner.js';
|
|
26
28
|
export { renderCitationLog, citationReportFails, FAILING_VERDICTS, type CitationReportOptions } from './report.js';
|
|
27
29
|
export { openAIEmbeddings, managerEmbeddings, type OpenAIEmbeddingOptions, type EmbeddingManagerLike } from './embeddings.js';
|
|
28
30
|
export { CitationVerifyTool, type CitationVerifyInput, type CitationVerifyOutput } from './tools/citationVerify.js';
|
|
29
31
|
export { runCitationCli, CITATION_CLI_USAGE, type CitationCliIO } from './cli.js';
|
|
32
|
+
export { ClaimChecker, claimJudge, claimJudgeSystem, claimJudgePrompt, CLAIM_QUOTE_MAX_WORDS, type SpokenClaim, type ClaimPassage, type ClaimUsage, type ClaimJudgement, type ClaimJudge, type ClaimCheckerOptions, type ClaimCheckOutcome, type ClaimDecision, } from './claims.js';
|
|
30
33
|
/** The pack's options, from its manifest entry or from the host's code. */
|
|
31
34
|
export interface CitationCheckPackOptions {
|
|
32
35
|
/** `none` (the default) or `openai`: grade a claim not found word for word with OpenAI embeddings through AgentOS. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAA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agentos-citations` command runs the same check. The page
|
|
8
8
|
* reader is exported (`readPage` with its transports, the host rule and robots.txt on every hop, the licence read),
|
|
9
9
|
* and `WebPageSourceProvider` makes the open web a public source over a search the host gives. `FirecrawlPageReader`
|
|
10
|
-
* reads a page with no text through Firecrawl's scrape endpoint with the host's key.
|
|
10
|
+
* reads a page with no text through Firecrawl's scrape endpoint with the host's key. `ClaimChecker` checks a claim heard
|
|
11
|
+
* in a room against passages from any source, with one judge call (`claimJudge` on AgentOS's `generateObject`) and the
|
|
12
|
+
* grounding guard's decision by code.
|
|
11
13
|
*
|
|
12
14
|
* @module @framers/agentos-ext-citation-check
|
|
13
15
|
*/
|
|
@@ -26,6 +28,7 @@ export { renderCitationLog, citationReportFails, FAILING_VERDICTS } from './repo
|
|
|
26
28
|
export { openAIEmbeddings, managerEmbeddings } from './embeddings.js';
|
|
27
29
|
export { CitationVerifyTool } from './tools/citationVerify.js';
|
|
28
30
|
export { runCitationCli, CITATION_CLI_USAGE } from './cli.js';
|
|
31
|
+
export { ClaimChecker, claimJudge, claimJudgeSystem, claimJudgePrompt, CLAIM_QUOTE_MAX_WORDS, } from './claims.js';
|
|
29
32
|
/**
|
|
30
33
|
* The pack: one tool, `citation_verify`. With `embeddings: 'openai'` the OpenAI key comes from the `openai.apiKey`
|
|
31
34
|
* secret, or `OPENAI_API_KEY` when the secret is not set.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB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,CAAC;QAChE,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpE,CAAC,CAAC;IACH,OAAO;QACL,IAAI,EAAE,qCAAqC;QAC3C,WAAW,EAAE;YACX;gBACE,EAAE,EAAE,IAAI,CAAC,IAAI;gBACb,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;gBAChC,OAAO,EAAE,IAAI;gBACb,eAAe,EAAE,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;aAC3D;SACF;KACF,CAAC;AACJ,CAAC;AAED,eAAe,mBAAmB,CAAC"}
|
package/dist/meta.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface MarkupScan {
|
|
|
24
24
|
metas: Map<string, string>;
|
|
25
25
|
/** Each `<link>` whose `rel` names `license`, its attributes, in document order; at most 1,000. */
|
|
26
26
|
links: Attributes[];
|
|
27
|
+
/** Each `<link>` whose `rel` names `icon` (`icon`, `shortcut icon`), its attributes, in document order; at most 32. */
|
|
28
|
+
icons: Attributes[];
|
|
27
29
|
/**
|
|
28
30
|
* Each `<a>` a licence is read from, in document order: one whose `rel` names `license`, with the start of its
|
|
29
31
|
* content as written, and one whose address, resolved against the page's own, is on creativecommons.org, with no
|
|
@@ -49,7 +51,10 @@ export declare function cleanAttribute(value: string): string;
|
|
|
49
51
|
* @param baseUrl - The page's own address, which an anchor's address is resolved against.
|
|
50
52
|
*/
|
|
51
53
|
export declare function scanMarkup(html: string, baseUrl: string): MarkupScan;
|
|
52
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Whether an element's `rel` names a link type: its tokens split on ASCII white space alone and read without ASCII case,
|
|
56
|
+
* as HTML reads them, so a no-break space (` ` or U+00A0) joins one token.
|
|
57
|
+
*/
|
|
53
58
|
export declare function relNames(attributes: Attributes, type: string): boolean;
|
|
54
59
|
/** An address as an attribute writes it, its references read and resolved against the page's own; null when it does not parse or is not http or https. */
|
|
55
60
|
export declare function resolveHttp(href: string | undefined, base: string): string | null;
|
package/dist/meta.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,wEAAwE;AACxE,eAAO,MAAM,QAAQ,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,wEAAwE;AACxE,eAAO,MAAM,QAAQ,MAAM,CAAC;AAkB5B,uGAAuG;AACvG,MAAM,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7C,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mHAAmH;IACnH,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,mGAAmG;IACnG,KAAK,EAAE,UAAU,EAAE,CAAC;IACp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