@automatelab/citation-intelligence 0.4.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.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +302 -0
  3. package/dist/adapters/anthropic.d.ts +3 -0
  4. package/dist/adapters/anthropic.d.ts.map +1 -0
  5. package/dist/adapters/anthropic.js +52 -0
  6. package/dist/adapters/anthropic.js.map +1 -0
  7. package/dist/adapters/bing.d.ts +3 -0
  8. package/dist/adapters/bing.d.ts.map +1 -0
  9. package/dist/adapters/bing.js +31 -0
  10. package/dist/adapters/bing.js.map +1 -0
  11. package/dist/adapters/gemini.d.ts +3 -0
  12. package/dist/adapters/gemini.d.ts.map +1 -0
  13. package/dist/adapters/gemini.js +47 -0
  14. package/dist/adapters/gemini.js.map +1 -0
  15. package/dist/adapters/openai.d.ts +3 -0
  16. package/dist/adapters/openai.d.ts.map +1 -0
  17. package/dist/adapters/openai.js +49 -0
  18. package/dist/adapters/openai.js.map +1 -0
  19. package/dist/adapters/perplexity.d.ts +3 -0
  20. package/dist/adapters/perplexity.d.ts.map +1 -0
  21. package/dist/adapters/perplexity.js +55 -0
  22. package/dist/adapters/perplexity.js.map +1 -0
  23. package/dist/adapters/predictors.d.ts +42 -0
  24. package/dist/adapters/predictors.d.ts.map +1 -0
  25. package/dist/adapters/predictors.js +495 -0
  26. package/dist/adapters/predictors.js.map +1 -0
  27. package/dist/adapters/serpapi.d.ts +8 -0
  28. package/dist/adapters/serpapi.d.ts.map +1 -0
  29. package/dist/adapters/serpapi.js +45 -0
  30. package/dist/adapters/serpapi.js.map +1 -0
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +132 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/lib/cache.d.ts +33 -0
  36. package/dist/lib/cache.d.ts.map +1 -0
  37. package/dist/lib/cache.js +110 -0
  38. package/dist/lib/cache.js.map +1 -0
  39. package/dist/lib/config.d.ts +6 -0
  40. package/dist/lib/config.d.ts.map +1 -0
  41. package/dist/lib/config.js +12 -0
  42. package/dist/lib/config.js.map +1 -0
  43. package/dist/lib/fetch.d.ts +18 -0
  44. package/dist/lib/fetch.d.ts.map +1 -0
  45. package/dist/lib/fetch.js +75 -0
  46. package/dist/lib/fetch.js.map +1 -0
  47. package/dist/lib/log.d.ts +11 -0
  48. package/dist/lib/log.d.ts.map +1 -0
  49. package/dist/lib/log.js +37 -0
  50. package/dist/lib/log.js.map +1 -0
  51. package/dist/lib/panels.d.ts +30 -0
  52. package/dist/lib/panels.d.ts.map +1 -0
  53. package/dist/lib/panels.js +69 -0
  54. package/dist/lib/panels.js.map +1 -0
  55. package/dist/tools/ai-overview.d.ts +29 -0
  56. package/dist/tools/ai-overview.d.ts.map +1 -0
  57. package/dist/tools/ai-overview.js +47 -0
  58. package/dist/tools/ai-overview.js.map +1 -0
  59. package/dist/tools/am-i-cited.d.ts +39 -0
  60. package/dist/tools/am-i-cited.d.ts.map +1 -0
  61. package/dist/tools/am-i-cited.js +73 -0
  62. package/dist/tools/am-i-cited.js.map +1 -0
  63. package/dist/tools/audit-sitemap.d.ts +49 -0
  64. package/dist/tools/audit-sitemap.d.ts.map +1 -0
  65. package/dist/tools/audit-sitemap.js +100 -0
  66. package/dist/tools/audit-sitemap.js.map +1 -0
  67. package/dist/tools/check-citations.d.ts +30 -0
  68. package/dist/tools/check-citations.d.ts.map +1 -0
  69. package/dist/tools/check-citations.js +101 -0
  70. package/dist/tools/check-citations.js.map +1 -0
  71. package/dist/tools/citation-freshness-score.d.ts +53 -0
  72. package/dist/tools/citation-freshness-score.d.ts.map +1 -0
  73. package/dist/tools/citation-freshness-score.js +89 -0
  74. package/dist/tools/citation-freshness-score.js.map +1 -0
  75. package/dist/tools/citation-trend.d.ts +47 -0
  76. package/dist/tools/citation-trend.d.ts.map +1 -0
  77. package/dist/tools/citation-trend.js +48 -0
  78. package/dist/tools/citation-trend.js.map +1 -0
  79. package/dist/tools/cited-for-diff.d.ts +54 -0
  80. package/dist/tools/cited-for-diff.d.ts.map +1 -0
  81. package/dist/tools/cited-for-diff.js +89 -0
  82. package/dist/tools/cited-for-diff.js.map +1 -0
  83. package/dist/tools/cited-for.d.ts +39 -0
  84. package/dist/tools/cited-for.d.ts.map +1 -0
  85. package/dist/tools/cited-for.js +28 -0
  86. package/dist/tools/cited-for.js.map +1 -0
  87. package/dist/tools/compare-domains.d.ts +36 -0
  88. package/dist/tools/compare-domains.d.ts.map +1 -0
  89. package/dist/tools/compare-domains.js +54 -0
  90. package/dist/tools/compare-domains.js.map +1 -0
  91. package/dist/tools/compete-for-query.d.ts +72 -0
  92. package/dist/tools/compete-for-query.d.ts.map +1 -0
  93. package/dist/tools/compete-for-query.js +91 -0
  94. package/dist/tools/compete-for-query.js.map +1 -0
  95. package/dist/tools/gsc-citation-gap.d.ts +77 -0
  96. package/dist/tools/gsc-citation-gap.d.ts.map +1 -0
  97. package/dist/tools/gsc-citation-gap.js +121 -0
  98. package/dist/tools/gsc-citation-gap.js.map +1 -0
  99. package/dist/tools/predict-citation.d.ts +25 -0
  100. package/dist/tools/predict-citation.d.ts.map +1 -0
  101. package/dist/tools/predict-citation.js +32 -0
  102. package/dist/tools/predict-citation.js.map +1 -0
  103. package/dist/tools/run-panel.d.ts +46 -0
  104. package/dist/tools/run-panel.d.ts.map +1 -0
  105. package/dist/tools/run-panel.js +60 -0
  106. package/dist/tools/run-panel.js.map +1 -0
  107. package/dist/tools/track-queries.d.ts +52 -0
  108. package/dist/tools/track-queries.d.ts.map +1 -0
  109. package/dist/tools/track-queries.js +52 -0
  110. package/dist/tools/track-queries.js.map +1 -0
  111. package/dist/tools/wikipedia-mentions.d.ts +32 -0
  112. package/dist/tools/wikipedia-mentions.d.ts.map +1 -0
  113. package/dist/tools/wikipedia-mentions.js +56 -0
  114. package/dist/tools/wikipedia-mentions.js.map +1 -0
  115. package/dist/types.d.ts +42 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +2 -0
  118. package/dist/types.js.map +1 -0
  119. package/package.json +57 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 automatelab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,302 @@
1
+ # Citation Intelligence MCP
2
+
3
+ **A free, self-hosted MCP server that tells your agent what LLMs cite - across Perplexity, Google AI Overviews, ChatGPT, Claude, Gemini, and Bing.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@automatelab/citation-intelligence.svg)](https://www.npmjs.com/package/@automatelab/citation-intelligence)
6
+ [![license](https://img.shields.io/npm/l/@automatelab/citation-intelligence.svg)](./LICENSE)
7
+ [![node](https://img.shields.io/node/v/@automatelab/citation-intelligence.svg)](https://nodejs.org)
8
+
9
+ ## What this is
10
+
11
+ An MCP server for agents and developers who need to know which URLs get cited by AI search engines for any query. Install once, query from any MCP-compatible client (Claude Desktop, Cursor, Claude Code, Continue, Cline, n8n, LangGraph). Self-hosted, no account, no centralized backend. Bring your own API keys; nothing is stored on a remote server.
12
+
13
+ ## Who this is for
14
+
15
+ Install this if you're:
16
+
17
+ - Building an agent that does research and want it to cite sources LLMs already trust
18
+ - A solo dev or indie hacker checking whether your SaaS is showing up in AI search
19
+ - A content creator confirming your articles are being cited by ChatGPT, Claude, or Perplexity
20
+ - An SEO or GEO practitioner who wants programmatic citation data without a $295-$499/mo dashboard
21
+ - Running an editorial pipeline and want citation-deficit-driven topic selection
22
+ - Comparing competitor visibility across AI engines for any niche
23
+
24
+ Do NOT install this if you want:
25
+
26
+ - A polished marketing dashboard with charts and team seats - try Profound, AthenaHQ, or Otterly.AI
27
+ - A hosted service with SLAs - this is self-hosted by design
28
+ - Citation tracking for academic papers - try citecheck
29
+ - 350M+ pre-modeled prompts - that's Ahrefs Brand Radar
30
+
31
+ ## Why this exists
32
+
33
+ The AI citation tracking market is dominated by VC-funded dashboards starting at $295/mo. None ships MCP-first. If you're an agent or developer who wants citation data piped directly into your workflow - not into a SaaS login - there isn't a tool for you. This is that tool.
34
+
35
+ ---
36
+
37
+ ## Tools
38
+
39
+ | Tool | Purpose |
40
+ |---|---|
41
+ | `check_citations` | URLs cited by Perplexity / Claude / ChatGPT / Gemini / Bing for a query |
42
+ | `am_i_cited` | Presence + rank for a domain across a query cluster |
43
+ | `ai_overview` | Google AI Overview presence + cited sources |
44
+ | `cited_for` | Queries the domain has been cited for, from local cache |
45
+ | `predict_citation` | Citation likelihood from public signals - no LLM fired |
46
+ | `track_queries` | Save / load / list named query panels (editorial watchlists) |
47
+ | `run_panel` | Run a panel through `am_i_cited` and snapshot to disk |
48
+ | `citation_trend` | Time-series report of citation rate + per-query gained/lost deltas |
49
+ | `compare_domains` | Side-by-side `predict_citation` across 2-10 URLs |
50
+ | `wikipedia_mentions` | List Wikipedia articles referencing a domain (zero keys) |
51
+ | `audit_sitemap` | Bulk `predict_citation` across every URL in a sitemap, worst-first |
52
+ | `gsc_citation_gap` | Join Google Search Console performance with AI citation status |
53
+
54
+ ## Quick start
55
+
56
+ ```bash
57
+ npx -y @automatelab/citation-intelligence
58
+ ```
59
+
60
+ Requires Node 20 or later.
61
+
62
+ ### Claude Desktop
63
+
64
+ Add to `%APPDATA%\Claude\claude_desktop_config.json` (Windows) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "citation-intelligence": {
70
+ "command": "npx",
71
+ "args": ["-y", "@automatelab/citation-intelligence"],
72
+ "env": {
73
+ "PERPLEXITY_API_KEY": "pplx-...",
74
+ "SERPAPI_KEY": "...",
75
+ "ANTHROPIC_API_KEY": "sk-ant-...",
76
+ "OPENAI_API_KEY": "sk-...",
77
+ "GEMINI_API_KEY": "..."
78
+ }
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ Set only the keys you have. Any MCP client that supports stdio transport works - same `command` / `args` pattern.
85
+
86
+ ## How it stays free
87
+
88
+ - **No central backend.** The server runs on your machine. Nothing is uploaded.
89
+ - **Free tier first.** SerpAPI gives 100 free Google AI Overview lookups/month. Bing Web Search has a free tier. Perplexity offers free Sonar access on signup.
90
+ - **Bring your own paid keys** if you want the premium engines (Claude, ChatGPT, Gemini). Keys pass through to the vendor and never touch any third party.
91
+ - **Local cache** at `~/.config/citation-intelligence/cache.json`. Repeated queries hit cache, not API. Default TTL: 7 days.
92
+ - **predict_citation runs with zero keys** - it scores citation likelihood from public signals (Wikipedia, schema.org, llms.txt, GitHub) without firing any LLM.
93
+
94
+ ## Privacy
95
+
96
+ - All API calls go from your machine directly to the vendor (Anthropic, OpenAI, Google, Perplexity, Bing, SerpAPI).
97
+ - No proxy. No analytics. No telemetry by default.
98
+ - API keys are read from environment variables on the MCP process - never logged, never persisted.
99
+ - Cache file lives at `~/.config/citation-intelligence/cache.json`. Delete it any time.
100
+
101
+ ## Environment variables
102
+
103
+ | Var | Purpose | Free tier? |
104
+ |---|---|---|
105
+ | `PERPLEXITY_API_KEY` | check_citations (Perplexity) | Yes |
106
+ | `SERPAPI_KEY` | ai_overview | 100/month free |
107
+ | `BING_API_KEY` | check_citations (Bing) | Yes |
108
+ | `ANTHROPIC_API_KEY` | check_citations (Claude) | Paid only |
109
+ | `OPENAI_API_KEY` | check_citations (ChatGPT) | Paid only |
110
+ | `GEMINI_API_KEY` | check_citations (Gemini) | Yes |
111
+ | `CITATION_CACHE_TTL_DAYS` | Cache TTL for citation_check entries (default 7) | n/a |
112
+ | `CITATION_AI_OVERVIEW_TTL_DAYS` | Cache TTL for ai_overview entries (default 1) | n/a |
113
+ | `CITATION_CONFIG_DIR` | Override config dir (default `~/.config/citation-intelligence`) | n/a |
114
+
115
+ ## Example: am I cited?
116
+
117
+ ```
118
+ You: For the queries "best AI citation tracker", "MCP for AI search", "self-hosted GEO tool",
119
+ is automatelab.tech cited?
120
+
121
+ (agent invokes am_i_cited)
122
+
123
+ Result:
124
+ {
125
+ "domain": "automatelab.tech",
126
+ "engine": "perplexity",
127
+ "results": [
128
+ { "query": "best AI citation tracker", "cited": true, "rank": 4 },
129
+ { "query": "MCP for AI search", "cited": true, "rank": 1 },
130
+ { "query": "self-hosted GEO tool", "cited": false, "matching_urls": [] }
131
+ ],
132
+ "summary": {
133
+ "queries_total": 3,
134
+ "queries_cited": 2,
135
+ "citation_rate": 0.67,
136
+ "average_rank": 2.5
137
+ }
138
+ }
139
+ ```
140
+
141
+ ## Example: predict citation likelihood (no key required)
142
+
143
+ ```
144
+ You: How likely is https://example.com/blog/post to be cited by AI?
145
+
146
+ (agent invokes predict_citation)
147
+
148
+ Result:
149
+ {
150
+ "url": "https://example.com/blog/post",
151
+ "score": 62,
152
+ "grade": "C",
153
+ "signals": {
154
+ "wikipedia_linked": false,
155
+ "github_referenced": false,
156
+ "reddit_referenced": true,
157
+ "llms_txt_present": true,
158
+ "https": true,
159
+ "has_article_schema": true,
160
+ "has_faq_schema": false,
161
+ "has_breadcrumb_schema": true,
162
+ "canonical_clean": true,
163
+ "word_count": 1850,
164
+ "reading_time_minutes": 8,
165
+ "h2_count": 7,
166
+ "h2_question_count": 1,
167
+ "authority_link_count": 2,
168
+ "external_link_count": 6,
169
+ "internal_link_count": 11,
170
+ "last_modified_days_ago": 42,
171
+ "has_open_graph": true
172
+ },
173
+ "fixes": [
174
+ { "signal": "has_faq_schema", "suggestion": "Page already has question-style H2s. Wrap them in FAQPage JSON-LD - high-leverage win.", "estimated_lift": "high" },
175
+ { "signal": "h2_question_count", "suggestion": "Reframe at least 2 H2s as questions users actually ask...", "estimated_lift": "medium" }
176
+ ]
177
+ }
178
+ ```
179
+
180
+ The Wikipedia signal is measured (it correlates with citation) but no "go get a Wikipedia article" suggestion is emitted - the advice would be non-actionable. Scoring is split across six buckets - domain authority, structured data, content depth, link graph, freshness, metadata - so a thin page and a deep page on the same domain get meaningfully different scores.
181
+
182
+ ---
183
+
184
+ ## Workflow recipes
185
+
186
+ Concrete patterns that compose the 12 tools into something useful. Costs assume ChatGPT or Perplexity at ~$0.01-0.03/query.
187
+
188
+ ### 1. Weekly citation tracker
189
+
190
+ The single highest-ROI pattern. Pick 20-30 queries from your editorial backlog, snapshot weekly, watch the rate trend.
191
+
192
+ ```
193
+ # One-time setup
194
+ track_queries name="editorial-watchlist" domain="example.com" action="save"
195
+ queries=["best widget tutorial", "how to set up X", ...]
196
+
197
+ # Weekly cron (5 min, ~$0.20-0.60 per run)
198
+ run_panel name="editorial-watchlist"
199
+
200
+ # Anytime
201
+ citation_trend panel="editorial-watchlist"
202
+ ```
203
+
204
+ `citation_trend` returns per-query deltas: which queries flipped from `cited: false` to `cited: true` since the first snapshot. That's your real editorial-impact metric.
205
+
206
+ ### 2. Pre-publish gate
207
+
208
+ Before publishing a post, find out who owns the citation slot and whether the slot is worth competing for.
209
+
210
+ ```
211
+ # 1. Is there an AI Overview to compete for?
212
+ ai_overview query="<target query>"
213
+
214
+ # 2. Who is cited today?
215
+ check_citations query="<target query>"
216
+
217
+ # 3. After publish + 14 days: did the post break in?
218
+ am_i_cited domain="example.com" queries=["<target query>"]
219
+ ```
220
+
221
+ If `check_citations` returns 5+ strong incumbents on a low-volume query, pick a different angle. If `ai_overview_present: false`, the query has no AI surface - reconsider.
222
+
223
+ ### 3. Bulk site audit
224
+
225
+ Catch site-wide structural issues across every page in one pass. Zero API spend.
226
+
227
+ ```
228
+ audit_sitemap sitemap_url="https://example.com/sitemap.xml" limit=200
229
+ ```
230
+
231
+ Returns `worst_first` sorted by citation-likelihood score. Surfaces missing schema, conflicting canonicals, missing `/llms.txt`, broken HTTPS.
232
+
233
+ ### 4. Competitor signal gap
234
+
235
+ You're not cited; they are. Why?
236
+
237
+ ```
238
+ # 1. Find the top-cited URLs for your target query
239
+ check_citations query="<query>"
240
+
241
+ # 2. Compare your URL to theirs signal-by-signal
242
+ compare_domains urls=[
243
+ "https://example.com/your-post",
244
+ "https://competitor-1.com/their-post",
245
+ "https://competitor-2.com/their-post"
246
+ ]
247
+ ```
248
+
249
+ `diverging_signals` is the list of where you're losing. Usually obvious once you see it - they have FAQ schema, GitHub references, Wikipedia links - you don't.
250
+
251
+ ### 5. Google-rank vs AI-citation gap
252
+
253
+ The closest editorial wins are queries where you already rank in Google's top 10 but are invisible to AI. Requires a GCP service account with `webmasters.readonly` scope.
254
+
255
+ ```
256
+ gsc_citation_gap
257
+ domain="example.com"
258
+ queries=["...editorial watchlist..."]
259
+ start_date="2026-04-01"
260
+ end_date="2026-05-01"
261
+ ```
262
+
263
+ `closest_wins` returns queries with `position <= 10` and `ai_cited: false`, sorted by impressions desc. Push citation signals on those specific URLs first.
264
+
265
+ ### 6. Wikipedia mention monitor
266
+
267
+ Wikipedia is the top-correlation signal but the advice "get on Wikipedia" is useless. So instead: watch when it happens organically.
268
+
269
+ ```
270
+ wikipedia_mentions domain="example.com" limit=50
271
+ ```
272
+
273
+ Returns Wikipedia article URLs that already link to the domain. Re-run quarterly; the diff is your "we got a Wikipedia citation" alert.
274
+
275
+ ## Schema.org
276
+
277
+ ```json
278
+ {
279
+ "@context": "https://schema.org",
280
+ "@type": "SoftwareApplication",
281
+ "name": "Citation Intelligence MCP",
282
+ "applicationCategory": "DeveloperApplication",
283
+ "operatingSystem": "Cross-platform",
284
+ "description": "Self-hosted MCP server for querying AI citation data from Perplexity, Claude, ChatGPT, Gemini, Bing, and Google AI Overviews.",
285
+ "offers": { "@type": "Offer", "price": "0" },
286
+ "url": "https://github.com/AutomateLab-tech/citation-intelligence"
287
+ }
288
+ ```
289
+
290
+ ## Contributing
291
+
292
+ Bug reports, feature ideas, and PRs welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md).
293
+
294
+ ## Security
295
+
296
+ Report a vulnerability via [SECURITY.md](./SECURITY.md).
297
+
298
+ ## License
299
+
300
+ MIT - see [LICENSE](./LICENSE).
301
+
302
+ Built by [automatelab.tech](https://automatelab.tech)
@@ -0,0 +1,3 @@
1
+ import type { AdapterResult } from "../types.js";
2
+ export declare function claudeSearch(query: string, maxResults: number): Promise<AdapterResult>;
3
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAa3D,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAsDxB"}
@@ -0,0 +1,52 @@
1
+ import { envKey } from "../lib/config.js";
2
+ import { fetchJson, ToolFetchError } from "../lib/fetch.js";
3
+ export async function claudeSearch(query, maxResults) {
4
+ const key = envKey("ANTHROPIC_API_KEY");
5
+ if (!key) {
6
+ throw new ToolFetchError({
7
+ type: "missing_key",
8
+ engine: "claude",
9
+ env_var: "ANTHROPIC_API_KEY",
10
+ message: "Set ANTHROPIC_API_KEY to use the Claude engine. Get a key at https://console.anthropic.com.",
11
+ });
12
+ }
13
+ const body = JSON.stringify({
14
+ model: "claude-sonnet-4-6",
15
+ max_tokens: 1024,
16
+ tools: [{ type: "web_search_20250305", name: "web_search", max_uses: 3 }],
17
+ messages: [{ role: "user", content: query }],
18
+ });
19
+ const res = await fetchJson("https://api.anthropic.com/v1/messages", {
20
+ method: "POST",
21
+ headers: {
22
+ "x-api-key": key,
23
+ "anthropic-version": "2023-06-01",
24
+ "content-type": "application/json",
25
+ },
26
+ body,
27
+ });
28
+ const citations = [];
29
+ const seen = new Set();
30
+ const textParts = [];
31
+ for (const block of res.content ?? []) {
32
+ if (block.type === "text") {
33
+ textParts.push(block.text);
34
+ }
35
+ else if (block.type === "web_search_tool_result") {
36
+ for (const r of block.content ?? []) {
37
+ if (!r.url || seen.has(r.url))
38
+ continue;
39
+ seen.add(r.url);
40
+ citations.push({
41
+ url: r.url,
42
+ title: r.title,
43
+ rank: citations.length + 1,
44
+ });
45
+ if (citations.length >= maxResults)
46
+ break;
47
+ }
48
+ }
49
+ }
50
+ return { citations, raw_answer: textParts.join("\n") || undefined };
51
+ }
52
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAc5D,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAa,EACb,UAAkB;IAElB,MAAM,GAAG,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACxC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,cAAc,CAAC;YACvB,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,mBAAmB;YAC5B,OAAO,EACL,6FAA6F;SAChG,CAAC,CAAC;IACL,CAAC;I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AC,KAAK;oBACd,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC;iBAC3B,CAAC,CAAC;gBACH,IAAI,SAAS,CAAC,MAAM,IAAI,UAAU;oBAAE,MAAM;YAC5C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AdapterResult } from "../types.js";
2
+ export declare function bingSearch(query: string, maxResults: number): Promise<AdapterResult>;
3
+ //# sourceMappingURL=bing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bing.d.ts","sourceRoot":"","sources":["../../src/adapters/bing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAQ3D,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAgCxB"}
@@ -0,0 +1,31 @@
1
+ import { envKey } from "../lib/config.js";
2
+ import { fetchJson, ToolFetchError } from "../lib/fetch.js";
3
+ export async function bingSearch(query, maxResults) {
4
+ const key = envKey("BING_API_KEY");
5
+ if (!key) {
6
+ throw new ToolFetchError({
7
+ type: "missing_key",
8
+ engine: "bing",
9
+ env_var: "BING_API_KEY",
10
+ message: "Set BING_API_KEY to use the Bing engine. Free tier at https://www.microsoft.com/en-us/bing/apis/bing-web-search-api.",
11
+ });
12
+ }
13
+ const params = new URLSearchParams({ q: query, count: String(maxResults) });
14
+ const res = await fetchJson(`https://api.bing.microsoft.com/v7.0/search?${params.toString()}`, { headers: { "ocp-apim-subscription-key": key } });
15
+ const citations = [];
16
+ let rank = 1;
17
+ for (const v of res.webPages?.value ?? []) {
18
+ if (!v.url)
19
+ continue;
20
+ citations.push({
21
+ url: v.url,
22
+ title: v.name,
23
+ snippet: v.snippet,
24
+ rank: rank++,
25
+ });
26
+ if (citations.length >= maxResults)
27
+ break;
28
+ }
29
+ return { citations };
30
+ }
31
+ //# sourceMappingURL=bing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bing.js","sourceRoot":"","sources":["../../src/adapters/bing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAS5D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,KAAa,EACb,UAAkB;IAElB,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,cAAc,CAAC;YACvB,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,cAAc;YACvB,OAAO,EACL,sHAAsH;SACzH,CAAC,CAAC;IACL,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAG,MAAM,SAAS,CACzB,8CAA8C,MAAM,CAAC,QAAQ,EAAE,EAAE,EACjE,EAAE,OAAO,EAAE,EAAE,2BAA2B,EAAE,GAAG,EAAE,EAAE,CAClD,CAAC;IAEF,MAAM,SAAS,GAAe,EAAE,CAAC;IACjC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC;QAC1C,IAAI,CAAC,CAAC,CAAC,GAAG;YAAE,SAAS;QACrB,SAAS,CAAC,IAAI,CAAC;YACb,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,KAAK,EAAE,CAAC,CAAC,IAAI;YACb,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,IAAI,EAAE,IAAI,EAAE;SACb,CAAC,CAAC;QACH,IAAI,SAAS,CAAC,MAAM,IAAI,UAAU;YAAE,MAAM;IAC5C,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AdapterResult } from "../types.js";
2
+ export declare function geminiSearch(query: string, maxResults: number): Promise<AdapterResult>;
3
+ //# sourceMappingURL=gemini.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/adapters/gemini.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAW3D,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CA+CxB"}
@@ -0,0 +1,47 @@
1
+ import { envKey } from "../lib/config.js";
2
+ import { fetchJson, ToolFetchError } from "../lib/fetch.js";
3
+ export async function geminiSearch(query, maxResults) {
4
+ const key = envKey("GEMINI_API_KEY");
5
+ if (!key) {
6
+ throw new ToolFetchError({
7
+ type: "missing_key",
8
+ engine: "gemini",
9
+ env_var: "GEMINI_API_KEY",
10
+ message: "Set GEMINI_API_KEY to use the Gemini engine. Get a key at https://aistudio.google.com/apikey.",
11
+ });
12
+ }
13
+ const body = JSON.stringify({
14
+ contents: [{ parts: [{ text: query }] }],
15
+ tools: [{ google_search: {} }],
16
+ });
17
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${encodeURIComponent(key)}`;
18
+ const res = await fetchJson(url, {
19
+ method: "POST",
20
+ headers: { "content-type": "application/json" },
21
+ body,
22
+ });
23
+ const citations = [];
24
+ const seen = new Set();
25
+ const textParts = [];
26
+ for (const cand of res.candidates ?? []) {
27
+ for (const p of cand.content?.parts ?? []) {
28
+ if (p.text)
29
+ textParts.push(p.text);
30
+ }
31
+ for (const chunk of cand.groundingMetadata?.groundingChunks ?? []) {
32
+ const u = chunk.web?.uri;
33
+ if (!u || seen.has(u))
34
+ continue;
35
+ seen.add(u);
36
+ citations.push({
37
+ url: u,
38
+ title: chunk.web?.title,
39
+ rank: citations.length + 1,
40
+ });
41
+ if (citations.length >= maxResults)
42
+ break;
43
+ }
44
+ }
45
+ return { citations, raw_answer: textParts.join("\n") || undefined };
46
+ }
47
+ //# sourceMappingURL=gemini.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../src/adapters/gemini.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAY5D,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAa,EACb,UAAkB;IAElB,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,cAAc,CAAC;YACvB,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,gBAAgB;YACzB,OAAO,EACL,+FAA+F;SAClG,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACxC,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;KAC/B,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,gGAAgG,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;IAEtI,MAAM,GAAG,GAAG,MAAM,SAAS,CAAiB,GAAG,EAAE;QAC/C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI;KACL,CAAC,CAAC;IAEH,MAAM,SAAS,GAAe,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,SAAS,GAAa,EAAE,CAAC;IAE/B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,CAAC,IAAI;gBAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,iBAAiB,EAAE,eAAe,IAAI,EAAE,EAAE,CAAC;YAClE,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC;YACzB,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,SAAS;YAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACZ,SAAS,CAAC,IAAI,CAAC;gBACb,GAAG,EAAE,CAAC;gBACN,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK;gBACvB,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC;aAC3B,CAAC,CAAC;YACH,IAAI,SAAS,CAAC,MAAM,IAAI,UAAU;gBAAE,MAAM;QAC5C,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AdapterResult } from "../types.js";
2
+ export declare function openaiSearch(query: string, maxResults: number): Promise<AdapterResult>;
3
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAiB3D,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAoDxB"}
@@ -0,0 +1,49 @@
1
+ import { envKey } from "../lib/config.js";
2
+ import { fetchJson, ToolFetchError } from "../lib/fetch.js";
3
+ export async function openaiSearch(query, maxResults) {
4
+ const key = envKey("OPENAI_API_KEY");
5
+ if (!key) {
6
+ throw new ToolFetchError({
7
+ type: "missing_key",
8
+ engine: "openai",
9
+ env_var: "OPENAI_API_KEY",
10
+ message: "Set OPENAI_API_KEY to use the ChatGPT engine. Get a key at https://platform.openai.com.",
11
+ });
12
+ }
13
+ const body = JSON.stringify({
14
+ model: "gpt-4.1",
15
+ tools: [{ type: "web_search_preview" }],
16
+ input: query,
17
+ });
18
+ const res = await fetchJson("https://api.openai.com/v1/responses", {
19
+ method: "POST",
20
+ headers: {
21
+ authorization: `Bearer ${key}`,
22
+ "content-type": "application/json",
23
+ },
24
+ body,
25
+ });
26
+ const citations = [];
27
+ const seen = new Set();
28
+ const textParts = [];
29
+ for (const out of res.output ?? []) {
30
+ for (const c of out.content ?? []) {
31
+ if (c.type === "output_text" && c.text)
32
+ textParts.push(c.text);
33
+ for (const ann of c.annotations ?? []) {
34
+ if (ann.type !== "url_citation" || !ann.url || seen.has(ann.url))
35
+ continue;
36
+ seen.add(ann.url);
37
+ citations.push({
38
+ url: ann.url,
39
+ title: ann.title,
40
+ rank: citations.length + 1,
41
+ });
42
+ if (citations.length >= maxResults)
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ return { citations, raw_answer: textParts.join("\n") || undefined };
48
+ }
49
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAA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AAE,CAAC;gBACtC,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;oBAC9D,SAAS;gBACX,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAClB,SAAS,CAAC,IAAI,CAAC;oBACb,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,KAAK,EAAE,GAAG,CAAC,KAAK;oBAChB,IAAI,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC;iBAC3B,CAAC,CAAC;gBACH,IAAI,SAAS,CAAC,MAAM,IAAI,UAAU;oBAAE,MAAM;YAC5C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AdapterResult } from "../types.js";
2
+ export declare function perplexitySearch(query: string, maxResults: number): Promise<AdapterResult>;
3
+ //# sourceMappingURL=perplexity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perplexity.d.ts","sourceRoot":"","sources":["../../src/adapters/perplexity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAU3D,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAwDxB"}
@@ -0,0 +1,55 @@
1
+ import { envKey } from "../lib/config.js";
2
+ import { fetchJson, ToolFetchError } from "../lib/fetch.js";
3
+ export async function perplexitySearch(query, maxResults) {
4
+ const key = envKey("PERPLEXITY_API_KEY");
5
+ if (!key) {
6
+ throw new ToolFetchError({
7
+ type: "missing_key",
8
+ engine: "perplexity",
9
+ env_var: "PERPLEXITY_API_KEY",
10
+ message: "Set PERPLEXITY_API_KEY to use the Perplexity engine. Sign up at https://www.perplexity.ai/settings/api",
11
+ });
12
+ }
13
+ const body = JSON.stringify({
14
+ model: "sonar",
15
+ messages: [{ role: "user", content: query }],
16
+ return_citations: true,
17
+ });
18
+ const res = await fetchJson("https://api.perplexity.ai/chat/completions", {
19
+ method: "POST",
20
+ headers: {
21
+ authorization: `Bearer ${key}`,
22
+ "content-type": "application/json",
23
+ },
24
+ body,
25
+ });
26
+ const citations = [];
27
+ const seen = new Set();
28
+ if (res.search_results) {
29
+ for (const r of res.search_results) {
30
+ if (!r.url || seen.has(r.url))
31
+ continue;
32
+ seen.add(r.url);
33
+ citations.push({
34
+ url: r.url,
35
+ title: r.title,
36
+ rank: citations.length + 1,
37
+ });
38
+ if (citations.length >= maxResults)
39
+ break;
40
+ }
41
+ }
42
+ if (citations.length < maxResults && res.citations) {
43
+ for (const url of res.citations) {
44
+ if (!url || seen.has(url))
45
+ continue;
46
+ seen.add(url);
47
+ citations.push({ url, rank: citations.length + 1 });
48
+ if (citations.length >= maxResults)
49
+ break;
50
+ }
51
+ }
52
+ const raw_answer = res.choices?.[0]?.message?.content;
53
+ return { citations, raw_answer };
54
+ }
55
+ //# sourceMappingURL=perplexity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perplexity.js","sourceRoot":"","sources":["../../src/adapters/perplexity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAW5D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAa,EACb,UAAkB;IAElB,MAAM,GAAG,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACzC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,cAAc,CAAC;YACvB,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,oBAAoB;Y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