@framers/agentos-ext-citation-verifier 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,98 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License.
30
+
31
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License.
34
+
35
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36
+
37
+ 4. Redistribution.
38
+
39
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
40
+
41
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
42
+
43
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
44
+
45
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+
47
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
48
+
49
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+
51
+ 5. Submission of Contributions.
52
+
53
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
54
+
55
+ 6. Trademarks.
56
+
57
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
58
+
59
+ 7. Disclaimer of Warranty.
60
+
61
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
62
+
63
+ 8. Limitation of Liability.
64
+
65
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 9. Accepting Warranty or Additional Liability.
68
+
69
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ APPENDIX: How to apply the Apache License to your work.
74
+
75
+ To apply the Apache License to your work, attach the following
76
+ boilerplate notice, with the fields enclosed by brackets "[]"
77
+ replaced with your own identifying information. (Don't include
78
+ the brackets!) The text should be enclosed in the appropriate
79
+ comment syntax for the file format. We also recommend that a
80
+ file or class name and description of purpose be included on the
81
+ same "printed page" as the copyright notice for easier
82
+ identification within third-party archives.
83
+
84
+ Copyright (c) 2025 Framers
85
+
86
+ Licensed under the Apache License, Version 2.0 (the "License");
87
+ you may not use this file except in compliance with the License.
88
+ You may obtain a copy of the License at
89
+
90
+ http://www.apache.org/licenses/LICENSE-2.0
91
+
92
+ Unless required by applicable law or agreed to in writing, software
93
+ distributed under the License is distributed on an "AS IS" BASIS,
94
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95
+ See the License for the specific language governing permissions and
96
+ limitations under the License.
97
+
98
+
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Citation Verifier
2
+
3
+ Verify claims in text against sources using semantic similarity. Supports web search fallback for unverifiable claims.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @framers/agentos-ext-citation-verifier
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { createExtensionPack } from '@framers/agentos-ext-citation-verifier';
15
+
16
+ const pack = createExtensionPack({
17
+ config: {
18
+ embedFn: async (texts) => myEmbeddingProvider.embed(texts),
19
+ },
20
+ });
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
+
33
+ ```
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
+
63
+ | Verdict | Meaning | Action |
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 |
69
+
70
+ ## Integration with Deep Research
71
+
72
+ When using the `deep_research` tool with `depth: "deep"`, citation verification runs automatically on the synthesized output. No explicit `verify_citations` call needed.
73
+
74
+ Configure in `agent.config.json`:
75
+
76
+ ```json
77
+ {
78
+ "queryRouter": {
79
+ "verifyCitations": true
80
+ }
81
+ }
82
+ ```
83
+
84
+ ## Environment Variables
85
+
86
+ | Variable | Required | Description |
87
+ |----------|----------|-------------|
88
+ | `SERPER_API_KEY` | No | Enables web fallback for unverifiable claims |
89
+ | `TAVILY_API_KEY` | No | Alternative search provider for web fallback |
90
+
91
+ ## Related
92
+
93
+ - **Skill**: `fact-grounding` — instructs the agent to verify claims before presenting
94
+ - **Guardrail**: `grounding-guard` — real-time NLI-based grounding (streaming)
95
+ - **Tool**: `fact_check` — web-based fact verification (single claim)
96
+
97
+ ## License
98
+
99
+ MIT
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview verify_citations tool — on-demand claim verification with web fallback.
3
+ *
4
+ * Self-contained: includes inline cosine similarity and claim extraction
5
+ * so the extension works without depending on @framers/agentos at runtime.
6
+ *
7
+ * @module agentos-ext-citation-verifier/VerifyCitationsTool
8
+ */
9
+ import type { VerifyCitationsInput, VerifyCitationsOutput } from './types.js';
10
+ export declare class VerifyCitationsTool {
11
+ readonly id = "verify_citations";
12
+ readonly name = "verify_citations";
13
+ readonly displayName = "Verify Citations";
14
+ readonly description = "Verify claims in text against provided sources using semantic similarity. Optionally falls back to web search for unverifiable claims.";
15
+ readonly parameters: {
16
+ type: "object";
17
+ properties: {
18
+ text: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ sources: {
23
+ type: string;
24
+ items: {
25
+ type: string;
26
+ properties: {
27
+ title: {
28
+ type: string;
29
+ };
30
+ content: {
31
+ type: string;
32
+ };
33
+ url: {
34
+ type: string;
35
+ };
36
+ };
37
+ };
38
+ description: string;
39
+ };
40
+ webFallback: {
41
+ type: string;
42
+ description: string;
43
+ };
44
+ };
45
+ required: string[];
46
+ };
47
+ private embedFn?;
48
+ constructor(config?: {
49
+ embedFn?: (texts: string[]) => Promise<number[][]>;
50
+ });
51
+ setEmbedFn(fn: (texts: string[]) => Promise<number[][]>): void;
52
+ execute(input: VerifyCitationsInput): Promise<VerifyCitationsOutput>;
53
+ }
54
+ //# sourceMappingURL=VerifyCitationsTool.d.ts.map
@@ -0,0 +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;CAgF3E"}
@@ -0,0 +1,142 @@
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
+ /** Cosine similarity between two vectors. */
11
+ function cosine(a, b) {
12
+ let dot = 0, magA = 0, magB = 0;
13
+ for (let i = 0; i < a.length; i++) {
14
+ dot += a[i] * b[i];
15
+ magA += a[i] * a[i];
16
+ magB += b[i] * b[i];
17
+ }
18
+ const d = Math.sqrt(magA) * Math.sqrt(magB);
19
+ return d === 0 ? 0 : dot / d;
20
+ }
21
+ /** Simple sentence splitting for claim extraction. */
22
+ function extractClaims(text) {
23
+ return text
24
+ .replace(/```[\s\S]*?```/g, '')
25
+ .split(/(?<=[.!?])\s+/)
26
+ .map(s => s.trim())
27
+ .filter(s => s.length > 15)
28
+ .filter(s => !s.startsWith('I think') && !s.startsWith('Maybe'))
29
+ .filter(s => !s.endsWith('?'))
30
+ .filter(s => !s.startsWith('I hope') && !s.startsWith('Let me know'));
31
+ }
32
+ export class VerifyCitationsTool {
33
+ id = 'verify_citations';
34
+ name = 'verify_citations';
35
+ displayName = 'Verify Citations';
36
+ description = 'Verify claims in text against provided sources using semantic similarity. Optionally falls back to web search for unverifiable claims.';
37
+ parameters = {
38
+ type: 'object',
39
+ properties: {
40
+ text: { type: 'string', description: 'Text containing claims to verify' },
41
+ sources: {
42
+ type: 'array',
43
+ items: {
44
+ type: 'object',
45
+ properties: { title: { type: 'string' }, content: { type: 'string' }, url: { type: 'string' } },
46
+ },
47
+ description: 'Sources to verify against',
48
+ },
49
+ webFallback: { type: 'boolean', description: 'Search web for unverifiable claims' },
50
+ },
51
+ required: ['text'],
52
+ };
53
+ embedFn;
54
+ constructor(config) {
55
+ this.embedFn = config?.embedFn;
56
+ }
57
+ setEmbedFn(fn) {
58
+ this.embedFn = fn;
59
+ }
60
+ async execute(input) {
61
+ if (!this.embedFn) {
62
+ return {
63
+ claims: [], totalClaims: 0, supportedCount: 0,
64
+ contradictedCount: 0, unverifiableCount: 0, supportedRatio: 0,
65
+ summary: 'No embedding function available. Configure an embedding provider.',
66
+ };
67
+ }
68
+ const claims = extractClaims(input.text);
69
+ if (claims.length === 0) {
70
+ return {
71
+ claims: [], totalClaims: 0, supportedCount: 0,
72
+ contradictedCount: 0, unverifiableCount: 0, supportedRatio: 1,
73
+ summary: 'No verifiable claims found.',
74
+ };
75
+ }
76
+ const sources = input.sources ?? [];
77
+ const allTexts = [...claims, ...sources.map(s => s.content)];
78
+ const allEmbeddings = await this.embedFn(allTexts);
79
+ const claimEmbeddings = allEmbeddings.slice(0, claims.length);
80
+ const sourceEmbeddings = allEmbeddings.slice(claims.length);
81
+ const SUPPORT = 0.6;
82
+ const UNVERIFIABLE = 0.3;
83
+ const verdicts = claims.map((claim, i) => {
84
+ let bestSim = 0, bestIdx = -1;
85
+ for (let j = 0; j < sources.length; j++) {
86
+ const sim = cosine(claimEmbeddings[i], sourceEmbeddings[j]);
87
+ if (sim > bestSim) {
88
+ bestSim = sim;
89
+ bestIdx = j;
90
+ }
91
+ }
92
+ const verdict = bestSim >= SUPPORT ? 'supported'
93
+ : bestSim < UNVERIFIABLE ? 'unverifiable'
94
+ : 'weak';
95
+ return {
96
+ text: claim,
97
+ verdict,
98
+ confidence: bestSim,
99
+ source: bestIdx >= 0 ? {
100
+ title: sources[bestIdx]?.title,
101
+ snippet: sources[bestIdx]?.content.slice(0, 200),
102
+ url: sources[bestIdx]?.url,
103
+ } : undefined,
104
+ webVerified: false,
105
+ };
106
+ });
107
+ // Web fallback
108
+ if (input.webFallback) {
109
+ for (const v of verdicts) {
110
+ if (v.verdict === 'unverifiable') {
111
+ try {
112
+ const webMod = await import('@framers/agentos-ext-web-search');
113
+ const fc = new webMod.FactCheckTool({});
114
+ const r = await fc.execute({ statement: v.text });
115
+ if (r?.verdict === 'TRUE') {
116
+ v.verdict = 'supported';
117
+ v.webVerified = true;
118
+ }
119
+ else if (r?.verdict === 'FALSE') {
120
+ v.verdict = 'contradicted';
121
+ v.webVerified = true;
122
+ }
123
+ }
124
+ catch { /* unavailable */ }
125
+ }
126
+ }
127
+ }
128
+ const supported = verdicts.filter(v => v.verdict === 'supported').length;
129
+ const contradicted = verdicts.filter(v => v.verdict === 'contradicted').length;
130
+ const unverifiable = verdicts.filter(v => v.verdict === 'unverifiable').length;
131
+ return {
132
+ claims: verdicts,
133
+ totalClaims: verdicts.length,
134
+ supportedCount: supported,
135
+ contradictedCount: contradicted,
136
+ unverifiableCount: unverifiable,
137
+ supportedRatio: verdicts.length > 0 ? supported / verdicts.length : 1,
138
+ summary: `${supported}/${verdicts.length} claims verified (${Math.round((supported / verdicts.length) * 100)}%)`,
139
+ };
140
+ }
141
+ }
142
+ //# sourceMappingURL=VerifyCitationsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifyCitationsTool.js","sourceRoot":"","sources":["../src/VerifyCitationsTool.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;GAOG;AAIH,6CAA6C;AAC7C,SAAS,MAAM,CAAC,CAAW,EAAE,CAAW;IACtC,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IACD,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED,sDAAsD;AACtD,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI;SACR,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,KAAK,CAAC,eAAe,CAAC;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC;SAC1B,MAAM,CAA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,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACrE,OAAO,EAAE,GAAG,SAAS,IAAI,QAAQ,CAAC,MAAM,qBAAqB,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI;SACjH,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import { VerifyCitationsTool } from './VerifyCitationsTool.js';
2
+ export { VerifyCitationsTool } from './VerifyCitationsTool.js';
3
+ export type { VerifyCitationsInput, VerifyCitationsOutput } from './types.js';
4
+ export declare function createExtensionPack(ctx?: {
5
+ config?: {
6
+ embedFn?: (texts: string[]) => Promise<number[][]>;
7
+ };
8
+ }): {
9
+ name: string;
10
+ version: string;
11
+ descriptors: {
12
+ id: string;
13
+ kind: "tool";
14
+ priority: number;
15
+ payload: VerifyCitationsTool;
16
+ }[];
17
+ };
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAE9E,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;;;;;;;;;EAO5G"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // @ts-nocheck
2
+ import { VerifyCitationsTool } from './VerifyCitationsTool.js';
3
+ export { VerifyCitationsTool } from './VerifyCitationsTool.js';
4
+ export function createExtensionPack(ctx) {
5
+ const tool = new VerifyCitationsTool(ctx?.config);
6
+ return {
7
+ name: '@framers/agentos-ext-citation-verifier',
8
+ version: '0.1.0',
9
+ descriptors: [{ id: 'verify_citations', kind: 'tool', priority: 40, payload: tool }],
10
+ };
11
+ }
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,31 @@
1
+ /** Input for the verify_citations tool. */
2
+ export interface VerifyCitationsInput {
3
+ text: string;
4
+ sources?: Array<{
5
+ title?: string;
6
+ content: string;
7
+ url?: string;
8
+ }>;
9
+ webFallback?: boolean;
10
+ }
11
+ /** Output of the verify_citations tool. */
12
+ export interface VerifyCitationsOutput {
13
+ claims: Array<{
14
+ text: string;
15
+ verdict: 'supported' | 'contradicted' | 'unverifiable' | 'weak';
16
+ confidence: number;
17
+ source?: {
18
+ title?: string;
19
+ snippet: string;
20
+ url?: string;
21
+ };
22
+ webVerified?: boolean;
23
+ }>;
24
+ totalClaims: number;
25
+ supportedCount: number;
26
+ contradictedCount: number;
27
+ unverifiableCount: number;
28
+ supportedRatio: number;
29
+ summary: string;
30
+ }
31
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/manifest.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
3
+ "id": "com.framers.tools.citation-verifier",
4
+ "name": "Citation Verifier",
5
+ "version": "0.1.0",
6
+ "description": "Verify claims in text against sources using semantic similarity. Supports web search fallback for unverifiable claims.",
7
+ "author": { "name": "Manic Agency LLC", "url": "https://manic.agency" },
8
+ "license": "MIT",
9
+ "keywords": ["citation", "verification", "claims", "grounding", "fact-check"],
10
+ "agentosVersion": "^2.0.0",
11
+ "categories": ["tool", "research"],
12
+ "extensions": [{ "kind": "tool", "id": "verify_citations", "displayName": "Verify Citations", "description": "Verify claims against sources with cosine similarity", "entry": "./dist/VerifyCitationsTool.js" }],
13
+ "requiredSecrets": [],
14
+ "features": ["citation-verification", "semantic-similarity"]
15
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@framers/agentos-ext-citation-verifier",
3
+ "version": "0.1.0",
4
+ "description": "Verify claims in text against sources using semantic similarity with optional web fallback",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./manifest.json": "./manifest.json",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "peerDependencies": {
17
+ "@framers/agentos": "^0.5.2"
18
+ },
19
+ "keywords": [
20
+ "agentos",
21
+ "extension",
22
+ "citation",
23
+ "verification",
24
+ "semantic-similarity"
25
+ ],
26
+ "license": "MIT",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/framersai/agentos-extensions.git",
33
+ "directory": "registry/curated/research/citation-verifier"
34
+ },
35
+ "homepage": "https://github.com/framersai/agentos-extensions/tree/master/registry/curated/research/citation-verifier#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/framersai/agentos-extensions/issues"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc",
41
+ "test": "vitest run",
42
+ "clean": "rimraf dist"
43
+ }
44
+ }
@@ -0,0 +1,149 @@
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 ADDED
@@ -0,0 +1,13 @@
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 ADDED
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,49 @@
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 ADDED
@@ -0,0 +1,8 @@
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
+ }