@framers/agentos-ext-citation-verifier 0.1.0 → 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.
- package/README.md +20 -81
- package/dist/VerifyCitationsTool.d.ts.map +1 -1
- package/dist/VerifyCitationsTool.js +0 -3
- package/dist/VerifyCitationsTool.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/manifest.json +5 -3
- package/package.json +20 -7
- package/src/VerifyCitationsTool.ts +0 -149
- package/src/index.ts +0 -13
- package/src/types.ts +0 -24
- package/test/VerifyCitationsTool.spec.ts +0 -49
- package/tsconfig.json +0 -8
package/README.md
CHANGED
|
@@ -1,98 +1,37 @@
|
|
|
1
|
-
# Citation Verifier
|
|
1
|
+
# Citation Verifier — DEPRECATED
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Citation verification is a first-class feature in `@framers/agentos`.
|
|
4
|
+
> Import the `CitationVerifier` engine directly instead of consuming this extension.
|
|
4
5
|
|
|
5
|
-
##
|
|
6
|
+
## Use the core API
|
|
6
7
|
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
8
|
+
```ts
|
|
9
|
+
import { CitationVerifier } from '@framers/agentos';
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const pack = createExtensionPack({
|
|
17
|
-
config: {
|
|
18
|
-
embedFn: async (texts) => myEmbeddingProvider.embed(texts),
|
|
19
|
-
},
|
|
11
|
+
const verifier = new CitationVerifier({
|
|
12
|
+
embedFn: async (texts) => embeddingManager.embedBatch(texts),
|
|
20
13
|
});
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Tool: `verify_citations`
|
|
24
|
-
|
|
25
|
-
| Parameter | Type | Required | Description |
|
|
26
|
-
|-----------|------|----------|-------------|
|
|
27
|
-
| `text` | string | Yes | Text containing claims to verify |
|
|
28
|
-
| `sources` | array | No | Sources to verify against (`{ title, content, url }`) |
|
|
29
|
-
| `webFallback` | boolean | No | Search the web for unverifiable claims |
|
|
30
|
-
|
|
31
|
-
### Example
|
|
32
14
|
|
|
15
|
+
const result = await verifier.verify(reportText, sources);
|
|
33
16
|
```
|
|
34
|
-
User: "Verify this research summary"
|
|
35
|
-
Agent: verify_citations({
|
|
36
|
-
text: "The Earth's core temperature is approximately 5,400°C. Mars has two moons.",
|
|
37
|
-
sources: [
|
|
38
|
-
{ content: "Earth's inner core reaches temperatures of 5,400°C.", url: "https://example.com/earth" }
|
|
39
|
-
],
|
|
40
|
-
webFallback: true
|
|
41
|
-
})
|
|
42
|
-
Result: {
|
|
43
|
-
totalClaims: 2,
|
|
44
|
-
supportedCount: 1, // "Earth's core" matched the source
|
|
45
|
-
unverifiableCount: 0, // "Mars has two moons" verified via web
|
|
46
|
-
summary: "2/2 claims verified (100%)"
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## How It Works
|
|
51
|
-
|
|
52
|
-
1. **Claim extraction** — splits text into atomic factual claims using sentence boundaries
|
|
53
|
-
2. **Batch embedding** — embeds all claims + all sources in one call
|
|
54
|
-
3. **Cosine similarity matrix** — computes claim × source similarity
|
|
55
|
-
4. **Verdict assignment**:
|
|
56
|
-
- `similarity >= 0.6` → **supported** (claim matches a source)
|
|
57
|
-
- `similarity 0.3-0.6` → **weak** (partial match)
|
|
58
|
-
- `similarity < 0.3` → **unverifiable** (no matching source)
|
|
59
|
-
5. **Web fallback** — for unverifiable claims, searches the web via FactCheckTool
|
|
60
|
-
|
|
61
|
-
## Verdicts
|
|
62
17
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
| `supported` | Claim semantically matches a source | Safe to present |
|
|
66
|
-
| `weak` | Partial match, lower confidence | Present with caveat |
|
|
67
|
-
| `unverifiable` | No source matches | Mark as "[unverified]" or search web |
|
|
68
|
-
| `contradicted` | Source contradicts the claim (via NLI) | Do not present as fact |
|
|
18
|
+
Full API, verdict ladder (`supported` / `weak` / `unverifiable` / `contradicted`), NLI contradiction checks, web-search fallback, and `QueryRouter` auto-integration are documented at
|
|
19
|
+
**https://docs.agentos.sh/features/citation-verification**.
|
|
69
20
|
|
|
70
|
-
##
|
|
21
|
+
## Why deprecated
|
|
71
22
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Configure in `agent.config.json`:
|
|
75
|
-
|
|
76
|
-
```json
|
|
77
|
-
{
|
|
78
|
-
"queryRouter": {
|
|
79
|
-
"verifyCitations": true
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
```
|
|
23
|
+
This package was a 13-line `createExtensionPack` wrapper that registered the same `VerifyCitationsTool` already exported by `@framers/agentos`. It exists only as a tool descriptor for ad-hoc registration. The core `CitationVerifier` covers every real use case — direct calls from a host loop, automatic invocation through `QueryRouter` (`verifyCitations: true`), and the built-in `verify_citations` agent tool.
|
|
83
24
|
|
|
84
|
-
##
|
|
25
|
+
## Migration
|
|
85
26
|
|
|
86
|
-
|
|
|
87
|
-
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
27
|
+
| If you were doing this | Do this instead |
|
|
28
|
+
| ------------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
|
29
|
+
| `import { createExtensionPack } from '@framers/agentos-ext-citation-verifier'` | `import { CitationVerifier } from '@framers/agentos'` |
|
|
30
|
+
| Registering `verify_citations` via this extension's pack | Set `verifyCitations: true` on `QueryRouter`, or call the verifier directly |
|
|
90
31
|
|
|
91
|
-
##
|
|
32
|
+
## Status
|
|
92
33
|
|
|
93
|
-
|
|
94
|
-
- **Guardrail**: `grounding-guard` — real-time NLI-based grounding (streaming)
|
|
95
|
-
- **Tool**: `fact_check` — web-based fact verification (single claim)
|
|
34
|
+
No further releases. The package is left published at `0.1.0` so existing installs keep resolving; the npm `deprecated` field surfaces this notice in `npm install` output. Removed in a future major.
|
|
96
35
|
|
|
97
36
|
## License
|
|
98
37
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VerifyCitationsTool.d.ts","sourceRoot":"","sources":["../src/VerifyCitationsTool.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA0B9E,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,EAAE,sBAAsB;IACjC,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,WAAW,sBAAsB;IAC1C,QAAQ,CAAC,WAAW,4IAA4I;IAChK,QAAQ,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAejB;IAEF,OAAO,CAAC,OAAO,CAAC,CAA2C;gBAE/C,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;KAAE;IAI3E,UAAU,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,IAAI;IAIxD,OAAO,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"VerifyCitationsTool.d.ts","sourceRoot":"","sources":["../src/VerifyCitationsTool.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA0B9E,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,EAAE,sBAAsB;IACjC,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,WAAW,sBAAsB;IAC1C,QAAQ,CAAC,WAAW,4IAA4I;IAChK,QAAQ,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAejB;IAEF,OAAO,CAAC,OAAO,CAAC,CAA2C;gBAE/C,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;KAAE;IAI3E,UAAU,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,IAAI;IAIxD,OAAO,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CA6E3E"}
|
|
@@ -62,7 +62,6 @@ export class VerifyCitationsTool {
|
|
|
62
62
|
return {
|
|
63
63
|
claims: [], totalClaims: 0, supportedCount: 0,
|
|
64
64
|
contradictedCount: 0, unverifiableCount: 0, supportedRatio: 0,
|
|
65
|
-
summary: 'No embedding function available. Configure an embedding provider.',
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
67
|
const claims = extractClaims(input.text);
|
|
@@ -70,7 +69,6 @@ export class VerifyCitationsTool {
|
|
|
70
69
|
return {
|
|
71
70
|
claims: [], totalClaims: 0, supportedCount: 0,
|
|
72
71
|
contradictedCount: 0, unverifiableCount: 0, supportedRatio: 1,
|
|
73
|
-
summary: 'No verifiable claims found.',
|
|
74
72
|
};
|
|
75
73
|
}
|
|
76
74
|
const sources = input.sources ?? [];
|
|
@@ -135,7 +133,6 @@ export class VerifyCitationsTool {
|
|
|
135
133
|
contradictedCount: contradicted,
|
|
136
134
|
unverifiableCount: unverifiable,
|
|
137
135
|
supportedRatio: verdicts.length > 0 ? supported / verdicts.length : 1,
|
|
138
|
-
summary: `${supported}/${verdicts.length} claims verified (${Math.round((supported / verdicts.length) * 100)}%)`,
|
|
139
136
|
};
|
|
140
137
|
}
|
|
141
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VerifyCitationsTool.js","sour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AC,CAAC,CAAC,CAAC,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACtE,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Citation verification is a first-class feature in `@framers/agentos`.
|
|
3
|
+
* Import `CitationVerifier` directly from `@framers/agentos` instead of consuming this
|
|
4
|
+
* extension. This package is a thin tool wrapper kept only for backwards compatibility
|
|
5
|
+
* and will be removed in a future major. See https://docs.agentos.sh/features/citation-verification
|
|
6
|
+
*/
|
|
1
7
|
import { VerifyCitationsTool } from './VerifyCitationsTool.js';
|
|
2
8
|
export { VerifyCitationsTool } from './VerifyCitationsTool.js';
|
|
3
9
|
export type { VerifyCitationsInput, VerifyCitationsOutput } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated See module-level deprecation. Use the first-class `CitationVerifier`
|
|
12
|
+
* from `@framers/agentos` directly instead of registering this tool wrapper.
|
|
13
|
+
*/
|
|
4
14
|
export declare function createExtensionPack(ctx?: {
|
|
5
15
|
config?: {
|
|
6
16
|
embedFn?: (texts: string[]) => Promise<number[][]>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAc9E;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;KAAE,CAAA;CAAE;;;;;;;;;EAQ5G"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Citation verification is a first-class feature in `@framers/agentos`.
|
|
4
|
+
* Import `CitationVerifier` directly from `@framers/agentos` instead of consuming this
|
|
5
|
+
* extension. This package is a thin tool wrapper kept only for backwards compatibility
|
|
6
|
+
* and will be removed in a future major. See https://docs.agentos.sh/features/citation-verification
|
|
7
|
+
*/
|
|
2
8
|
import { VerifyCitationsTool } from './VerifyCitationsTool.js';
|
|
3
9
|
export { VerifyCitationsTool } from './VerifyCitationsTool.js';
|
|
10
|
+
let warned = false;
|
|
11
|
+
function warnDeprecated() {
|
|
12
|
+
if (warned)
|
|
13
|
+
return;
|
|
14
|
+
warned = true;
|
|
15
|
+
if (typeof process !== 'undefined' && process.emitWarning) {
|
|
16
|
+
process.emitWarning('@framers/agentos-ext-citation-verifier is deprecated. Import CitationVerifier from @framers/agentos directly. https://docs.agentos.sh/features/citation-verification', 'DeprecationWarning');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated See module-level deprecation. Use the first-class `CitationVerifier`
|
|
21
|
+
* from `@framers/agentos` directly instead of registering this tool wrapper.
|
|
22
|
+
*/
|
|
4
23
|
export function createExtensionPack(ctx) {
|
|
24
|
+
warnDeprecated();
|
|
5
25
|
const tool = new VerifyCitationsTool(ctx?.config);
|
|
6
26
|
return {
|
|
7
27
|
name: '@framers/agentos-ext-citation-verifier',
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,MAAM,UAAU,mBAAmB,CAAC,GAAyE;IAC3G,MAAM,IAAI,GAAG,IAAI,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAClD,OAAO;QACL,IAAI,EAAE,wCAAwC;QAC9C,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;KAC9F,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,SAAS,cAAc;IACrB,IAAI,MAAM;QAAE,OAAO;IACnB,MAAM,GAAG,IAAI,CAAC;IACd,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QAC1D,OAAO,CAAC,WAAW,CACjB,sKAAsK,EACtK,oBAAoB,CACrB,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAyE;IAC3G,cAAc,EAAE,CAAC;IACjB,MAAM,IAAI,GAAG,IAAI,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAClD,OAAO;QACL,IAAI,EAAE,wCAAwC;QAC9C,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;KAC9F,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,2CAA2C;AAC3C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,2CAA2C;AAC3C,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,WAAW,GAAG,cAAc,GAAG,cAAc,GAAG,MAAM,CAAC;QAChE,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,GAAG,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC,CAAC;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,2CAA2C;AAC3C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,2CAA2C;AAC3C,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,WAAW,GAAG,cAAc,GAAG,cAAc,GAAG,MAAM,CAAC;QAChE,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,GAAG,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC,CAAC;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
package/manifest.json
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
"$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
|
|
3
3
|
"id": "com.framers.tools.citation-verifier",
|
|
4
4
|
"name": "Citation Verifier",
|
|
5
|
-
"version": "0.1.
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"version": "0.1.1",
|
|
6
|
+
"deprecated": true,
|
|
7
|
+
"deprecationMessage": "Use the first-class CitationVerifier from @framers/agentos. See https://docs.agentos.sh/features/citation-verification",
|
|
8
|
+
"description": "DEPRECATED — thin tool wrapper around the first-class @framers/agentos CitationVerifier. Kept for backwards compatibility.",
|
|
9
|
+
"author": { "name": "Frame", "url": "https://frame.dev" },
|
|
8
10
|
"license": "MIT",
|
|
9
11
|
"keywords": ["citation", "verification", "claims", "grounding", "fact-check"],
|
|
10
12
|
"agentosVersion": "^2.0.0",
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framers/agentos-ext-citation-verifier",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "DEPRECATED — use the first-class CitationVerifier from @framers/agentos. This extension is a thin tool wrapper kept for backwards compatibility.",
|
|
5
|
+
"deprecated": "Citation verification is a first-class feature in @framers/agentos. Import { CitationVerifier } from '@framers/agentos' instead. See https://docs.agentos.sh/features/citation-verification",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
"./package.json": "./package.json"
|
|
15
16
|
},
|
|
16
17
|
"peerDependencies": {
|
|
17
|
-
"@framers/agentos": "
|
|
18
|
+
"@framers/agentos": ">=0.10.40"
|
|
18
19
|
},
|
|
19
20
|
"keywords": [
|
|
20
21
|
"agentos",
|
|
@@ -29,16 +30,28 @@
|
|
|
29
30
|
},
|
|
30
31
|
"repository": {
|
|
31
32
|
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/
|
|
33
|
+
"url": "git+https://github.com/framerslab/agentos-extensions.git",
|
|
33
34
|
"directory": "registry/curated/research/citation-verifier"
|
|
34
35
|
},
|
|
35
|
-
"homepage": "https://github.com/
|
|
36
|
+
"homepage": "https://github.com/framerslab/agentos-extensions/tree/master/registry/curated/research/citation-verifier#readme",
|
|
36
37
|
"bugs": {
|
|
37
|
-
"url": "https://github.com/
|
|
38
|
+
"url": "https://github.com/framerslab/agentos-extensions/issues"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"manifest.json",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@framers/agentos": "^0.10.40",
|
|
47
|
+
"@types/node": "^20.12.12",
|
|
48
|
+
"rimraf": "^5.0.7",
|
|
49
|
+
"typescript": "^5.4.5",
|
|
50
|
+
"vitest": "^3.2.7"
|
|
38
51
|
},
|
|
39
52
|
"scripts": {
|
|
40
53
|
"build": "tsc",
|
|
41
|
-
"test": "vitest run",
|
|
54
|
+
"test": "vitest run --passWithNoTests",
|
|
42
55
|
"clean": "rimraf dist"
|
|
43
56
|
}
|
|
44
57
|
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview verify_citations tool — on-demand claim verification with web fallback.
|
|
4
|
-
*
|
|
5
|
-
* Self-contained: includes inline cosine similarity and claim extraction
|
|
6
|
-
* so the extension works without depending on @framers/agentos at runtime.
|
|
7
|
-
*
|
|
8
|
-
* @module agentos-ext-citation-verifier/VerifyCitationsTool
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { VerifyCitationsInput, VerifyCitationsOutput } from './types.js';
|
|
12
|
-
|
|
13
|
-
/** Cosine similarity between two vectors. */
|
|
14
|
-
function cosine(a: number[], b: number[]): number {
|
|
15
|
-
let dot = 0, magA = 0, magB = 0;
|
|
16
|
-
for (let i = 0; i < a.length; i++) {
|
|
17
|
-
dot += a[i] * b[i];
|
|
18
|
-
magA += a[i] * a[i];
|
|
19
|
-
magB += b[i] * b[i];
|
|
20
|
-
}
|
|
21
|
-
const d = Math.sqrt(magA) * Math.sqrt(magB);
|
|
22
|
-
return d === 0 ? 0 : dot / d;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Simple sentence splitting for claim extraction. */
|
|
26
|
-
function extractClaims(text: string): string[] {
|
|
27
|
-
return text
|
|
28
|
-
.replace(/```[\s\S]*?```/g, '')
|
|
29
|
-
.split(/(?<=[.!?])\s+/)
|
|
30
|
-
.map(s => s.trim())
|
|
31
|
-
.filter(s => s.length > 15)
|
|
32
|
-
.filter(s => !s.startsWith('I think') && !s.startsWith('Maybe'))
|
|
33
|
-
.filter(s => !s.endsWith('?'))
|
|
34
|
-
.filter(s => !s.startsWith('I hope') && !s.startsWith('Let me know'));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class VerifyCitationsTool {
|
|
38
|
-
readonly id = 'verify_citations';
|
|
39
|
-
readonly name = 'verify_citations';
|
|
40
|
-
readonly displayName = 'Verify Citations';
|
|
41
|
-
readonly description = 'Verify claims in text against provided sources using semantic similarity. Optionally falls back to web search for unverifiable claims.';
|
|
42
|
-
readonly parameters = {
|
|
43
|
-
type: 'object' as const,
|
|
44
|
-
properties: {
|
|
45
|
-
text: { type: 'string', description: 'Text containing claims to verify' },
|
|
46
|
-
sources: {
|
|
47
|
-
type: 'array',
|
|
48
|
-
items: {
|
|
49
|
-
type: 'object',
|
|
50
|
-
properties: { title: { type: 'string' }, content: { type: 'string' }, url: { type: 'string' } },
|
|
51
|
-
},
|
|
52
|
-
description: 'Sources to verify against',
|
|
53
|
-
},
|
|
54
|
-
webFallback: { type: 'boolean', description: 'Search web for unverifiable claims' },
|
|
55
|
-
},
|
|
56
|
-
required: ['text'],
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
private embedFn?: (texts: string[]) => Promise<number[][]>;
|
|
60
|
-
|
|
61
|
-
constructor(config?: { embedFn?: (texts: string[]) => Promise<number[][]> }) {
|
|
62
|
-
this.embedFn = config?.embedFn;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
setEmbedFn(fn: (texts: string[]) => Promise<number[][]>): void {
|
|
66
|
-
this.embedFn = fn;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async execute(input: VerifyCitationsInput): Promise<VerifyCitationsOutput> {
|
|
70
|
-
if (!this.embedFn) {
|
|
71
|
-
return {
|
|
72
|
-
claims: [], totalClaims: 0, supportedCount: 0,
|
|
73
|
-
contradictedCount: 0, unverifiableCount: 0, supportedRatio: 0,
|
|
74
|
-
summary: 'No embedding function available. Configure an embedding provider.',
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const claims = extractClaims(input.text);
|
|
79
|
-
if (claims.length === 0) {
|
|
80
|
-
return {
|
|
81
|
-
claims: [], totalClaims: 0, supportedCount: 0,
|
|
82
|
-
contradictedCount: 0, unverifiableCount: 0, supportedRatio: 1,
|
|
83
|
-
summary: 'No verifiable claims found.',
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const sources = input.sources ?? [];
|
|
88
|
-
const allTexts = [...claims, ...sources.map(s => s.content)];
|
|
89
|
-
const allEmbeddings = await this.embedFn(allTexts);
|
|
90
|
-
const claimEmbeddings = allEmbeddings.slice(0, claims.length);
|
|
91
|
-
const sourceEmbeddings = allEmbeddings.slice(claims.length);
|
|
92
|
-
|
|
93
|
-
const SUPPORT = 0.6;
|
|
94
|
-
const UNVERIFIABLE = 0.3;
|
|
95
|
-
|
|
96
|
-
const verdicts = claims.map((claim, i) => {
|
|
97
|
-
let bestSim = 0, bestIdx = -1;
|
|
98
|
-
for (let j = 0; j < sources.length; j++) {
|
|
99
|
-
const sim = cosine(claimEmbeddings[i], sourceEmbeddings[j]);
|
|
100
|
-
if (sim > bestSim) { bestSim = sim; bestIdx = j; }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const verdict = bestSim >= SUPPORT ? 'supported' as const
|
|
104
|
-
: bestSim < UNVERIFIABLE ? 'unverifiable' as const
|
|
105
|
-
: 'weak' as const;
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
text: claim,
|
|
109
|
-
verdict,
|
|
110
|
-
confidence: bestSim,
|
|
111
|
-
source: bestIdx >= 0 ? {
|
|
112
|
-
title: sources[bestIdx]?.title,
|
|
113
|
-
snippet: sources[bestIdx]?.content.slice(0, 200),
|
|
114
|
-
url: sources[bestIdx]?.url,
|
|
115
|
-
} : undefined,
|
|
116
|
-
webVerified: false,
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Web fallback
|
|
121
|
-
if (input.webFallback) {
|
|
122
|
-
for (const v of verdicts) {
|
|
123
|
-
if (v.verdict === 'unverifiable') {
|
|
124
|
-
try {
|
|
125
|
-
const webMod = await import('@framers/agentos-ext-web-search');
|
|
126
|
-
const fc = new (webMod as any).FactCheckTool({});
|
|
127
|
-
const r = await fc.execute({ statement: v.text });
|
|
128
|
-
if (r?.verdict === 'TRUE') { v.verdict = 'supported'; v.webVerified = true; }
|
|
129
|
-
else if (r?.verdict === 'FALSE') { v.verdict = 'contradicted'; v.webVerified = true; }
|
|
130
|
-
} catch { /* unavailable */ }
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const supported = verdicts.filter(v => v.verdict === 'supported').length;
|
|
136
|
-
const contradicted = verdicts.filter(v => v.verdict === 'contradicted').length;
|
|
137
|
-
const unverifiable = verdicts.filter(v => v.verdict === 'unverifiable').length;
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
claims: verdicts,
|
|
141
|
-
totalClaims: verdicts.length,
|
|
142
|
-
supportedCount: supported,
|
|
143
|
-
contradictedCount: contradicted,
|
|
144
|
-
unverifiableCount: unverifiable,
|
|
145
|
-
supportedRatio: verdicts.length > 0 ? supported / verdicts.length : 1,
|
|
146
|
-
summary: `${supported}/${verdicts.length} claims verified (${Math.round((supported / verdicts.length) * 100)}%)`,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { VerifyCitationsTool } from './VerifyCitationsTool.js';
|
|
3
|
-
export { VerifyCitationsTool } from './VerifyCitationsTool.js';
|
|
4
|
-
export type { VerifyCitationsInput, VerifyCitationsOutput } from './types.js';
|
|
5
|
-
|
|
6
|
-
export function createExtensionPack(ctx?: { config?: { embedFn?: (texts: string[]) => Promise<number[][]> } }) {
|
|
7
|
-
const tool = new VerifyCitationsTool(ctx?.config);
|
|
8
|
-
return {
|
|
9
|
-
name: '@framers/agentos-ext-citation-verifier',
|
|
10
|
-
version: '0.1.0',
|
|
11
|
-
descriptors: [{ id: 'verify_citations', kind: 'tool' as const, priority: 40, payload: tool }],
|
|
12
|
-
};
|
|
13
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/** Input for the verify_citations tool. */
|
|
3
|
-
export interface VerifyCitationsInput {
|
|
4
|
-
text: string;
|
|
5
|
-
sources?: Array<{ title?: string; content: string; url?: string }>;
|
|
6
|
-
webFallback?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Output of the verify_citations tool. */
|
|
10
|
-
export interface VerifyCitationsOutput {
|
|
11
|
-
claims: Array<{
|
|
12
|
-
text: string;
|
|
13
|
-
verdict: 'supported' | 'contradicted' | 'unverifiable' | 'weak';
|
|
14
|
-
confidence: number;
|
|
15
|
-
source?: { title?: string; snippet: string; url?: string };
|
|
16
|
-
webVerified?: boolean;
|
|
17
|
-
}>;
|
|
18
|
-
totalClaims: number;
|
|
19
|
-
supportedCount: number;
|
|
20
|
-
contradictedCount: number;
|
|
21
|
-
unverifiableCount: number;
|
|
22
|
-
supportedRatio: number;
|
|
23
|
-
summary: string;
|
|
24
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
3
|
-
import { VerifyCitationsTool } from '../src/VerifyCitationsTool.js';
|
|
4
|
-
|
|
5
|
-
function mockEmbedFn(texts: string[]): Promise<number[][]> {
|
|
6
|
-
return Promise.resolve(texts.map(t => {
|
|
7
|
-
const vec = new Array(8).fill(0);
|
|
8
|
-
for (let i = 0; i < t.length; i++) vec[i % 8] += t.charCodeAt(i) / 1000;
|
|
9
|
-
const mag = Math.sqrt(vec.reduce((s, v) => s + v * v, 0));
|
|
10
|
-
return mag > 0 ? vec.map(v => v / mag) : vec;
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe('VerifyCitationsTool', () => {
|
|
15
|
-
it('has correct metadata', () => {
|
|
16
|
-
const tool = new VerifyCitationsTool();
|
|
17
|
-
expect(tool.id).toBe('verify_citations');
|
|
18
|
-
expect(tool.parameters.required).toContain('text');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('returns empty when no embed function', async () => {
|
|
22
|
-
const tool = new VerifyCitationsTool();
|
|
23
|
-
const result = await tool.execute({ text: 'Some claim.' });
|
|
24
|
-
expect(result.totalClaims).toBe(0);
|
|
25
|
-
expect(result.summary).toContain('No embedding');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('verifies claims against sources', async () => {
|
|
29
|
-
const tool = new VerifyCitationsTool({ embedFn: mockEmbedFn });
|
|
30
|
-
const result = await tool.execute({
|
|
31
|
-
text: 'The sky appears blue during the daytime hours.',
|
|
32
|
-
sources: [{ content: 'The sky appears blue due to Rayleigh scattering of light.' }],
|
|
33
|
-
});
|
|
34
|
-
expect(result.totalClaims).toBeGreaterThanOrEqual(1);
|
|
35
|
-
expect(result.summary).toMatch(/claims verified/);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('returns proper counts that add up', async () => {
|
|
39
|
-
const tool = new VerifyCitationsTool({ embedFn: mockEmbedFn });
|
|
40
|
-
const result = await tool.execute({
|
|
41
|
-
text: 'Cats are domesticated mammals that purr loudly. Fish can fly through the upper atmosphere.',
|
|
42
|
-
sources: [{ content: 'Cats are domesticated mammals known for purring.' }],
|
|
43
|
-
});
|
|
44
|
-
// weakCount not in output type — count weak claims from array
|
|
45
|
-
const weakCount = result.claims.filter(c => c.verdict === 'weak').length;
|
|
46
|
-
expect(result.supportedCount + result.unverifiableCount + weakCount + result.contradictedCount)
|
|
47
|
-
.toBe(result.totalClaims);
|
|
48
|
-
});
|
|
49
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022", "module": "ESNext", "moduleResolution": "bundler",
|
|
4
|
-
"declaration": true, "declarationMap": true, "sourceMap": true,
|
|
5
|
-
"outDir": "dist", "rootDir": "src", "strict": true, "esModuleInterop": true, "skipLibCheck": true
|
|
6
|
-
},
|
|
7
|
-
"include": ["src"], "exclude": ["dist", "test", "node_modules"]
|
|
8
|
-
}
|