@keenable/mastra 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/index.cjs +78 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +78 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[Keenable](https://keenable.ai) web search and page-fetch tools for [Mastra](https://mastra.ai) agents.
|
|
4
4
|
|
|
5
|
-
**Keyless by default.** The tools work with no account or API key against Keenable's public endpoints (rate-limited). An optional `KEENABLE_API_KEY` lifts the hourly cap; it is never a prerequisite.
|
|
5
|
+
**Keyless by default.** The tools work with no account or API key against Keenable's public endpoints (rate-limited). An optional `KEENABLE_API_KEY` lifts the keyless hourly cap (the per-second limit stays); it is never a prerequisite.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ import { Agent } from '@mastra/core/agent';
|
|
|
21
21
|
import { createKeenableTools } from '@keenable/mastra';
|
|
22
22
|
|
|
23
23
|
const tools = createKeenableTools();
|
|
24
|
-
// Keyless by default. To lift the
|
|
24
|
+
// Keyless by default. To lift the keyless hourly cap, set KEENABLE_API_KEY
|
|
25
25
|
// or pass an explicit key:
|
|
26
26
|
// const tools = createKeenableTools({ apiKey: 'keen_...' });
|
|
27
27
|
|
|
@@ -53,9 +53,14 @@ Queries the Keenable web index. Accepts:
|
|
|
53
53
|
|
|
54
54
|
- `query` (required)
|
|
55
55
|
- `site`: restrict to a single domain, e.g. `'techcrunch.com'`
|
|
56
|
-
- `
|
|
57
|
-
- `
|
|
58
|
-
- `
|
|
56
|
+
- `excludeDomains`: domains to leave out, e.g. `['pinterest.com']` (up to 2000); each also excludes its subdomains
|
|
57
|
+
- `publishedAfter` / `publishedBefore`: filter by publication time. Takes a date (`YYYY-MM-DD`), an ISO 8601 timestamp or a relative offset such as `7d` or `24h`. `publishedAfter: '7d'` is how to get recent results.
|
|
58
|
+
- `acquiredAfter` / `acquiredBefore`: filter by index time (same formats)
|
|
59
|
+
- `queryTime`: search the index as it stood at this moment; pages indexed later are left out. It is an upper bound, not a recency filter (use `publishedAfter` for that), and rarely needed.
|
|
60
|
+
- `objective`: what the search is for, what the query leaves out, what earlier searches found (up to 1,000 characters). Used for ranking; worth passing for multi-step or ambiguous searches, not every search.
|
|
61
|
+
- `maxResults`: number of results, 1-50 (default 10)
|
|
62
|
+
|
|
63
|
+
Unset or blank values are not sent.
|
|
59
64
|
|
|
60
65
|
Returns `{ query, results: [{ title, url, description?, publishedAt?, acquiredAt? }] }`.
|
|
61
66
|
|
|
@@ -65,7 +70,7 @@ Fetches a single URL and returns its main content as markdown:
|
|
|
65
70
|
|
|
66
71
|
- `url` (required)
|
|
67
72
|
|
|
68
|
-
Returns `{ url, title?, content?, description?, author?, publishedAt? }`.
|
|
73
|
+
Returns `{ url, title?, content?, description?, author?, publishedAt?, image?, favicon? }`. A page that cannot be read (not found, unreachable) fails the call with the API's message, e.g. `Keenable fetch failed (404): The page does not exist at this URL...`.
|
|
69
74
|
|
|
70
75
|
## Configuration
|
|
71
76
|
|
|
@@ -74,6 +79,7 @@ Returns `{ url, title?, content?, description?, author?, publishedAt? }`.
|
|
|
74
79
|
- `apiKey`: optional, falls back to `KEENABLE_API_KEY`. Keyless when unset.
|
|
75
80
|
- `baseUrl`: optional, falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`.
|
|
76
81
|
- `clientSource`: attribution tag Keenable segments integration traffic by (defaults to `'Mastra'`).
|
|
82
|
+
- `maxResults`: default number of search results (1-50) when the agent does not pass one; the API default is 10.
|
|
77
83
|
|
|
78
84
|
Get a key at [keenable.ai/console](https://keenable.ai/console).
|
|
79
85
|
|
package/dist/index.cjs
CHANGED
|
@@ -16,6 +16,31 @@ function toIsoDate(value) {
|
|
|
16
16
|
if (typeof value === "number" && Number.isFinite(value)) return new Date(value * 1e3).toISOString();
|
|
17
17
|
return typeof value === "string" && value ? value : void 0;
|
|
18
18
|
}
|
|
19
|
+
var STRING_PARAMS = [
|
|
20
|
+
["publishedAfter", "published_after"],
|
|
21
|
+
["publishedBefore", "published_before"],
|
|
22
|
+
["acquiredAfter", "acquired_after"],
|
|
23
|
+
["acquiredBefore", "acquired_before"],
|
|
24
|
+
["queryTime", "query_time"],
|
|
25
|
+
["objective", "objective"]
|
|
26
|
+
];
|
|
27
|
+
function nonBlank(value) {
|
|
28
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
29
|
+
return trimmed || void 0;
|
|
30
|
+
}
|
|
31
|
+
function pageError(error) {
|
|
32
|
+
if (!error) return void 0;
|
|
33
|
+
let status = 500;
|
|
34
|
+
let detail = "";
|
|
35
|
+
if (typeof error === "object") {
|
|
36
|
+
const e = error;
|
|
37
|
+
if (typeof e.status === "number" && Number.isInteger(e.status)) status = e.status;
|
|
38
|
+
detail = String(e.message || e.error || "");
|
|
39
|
+
} else {
|
|
40
|
+
detail = String(error);
|
|
41
|
+
}
|
|
42
|
+
return new Error(`Keenable fetch failed (${status}): ${detail}`.trim());
|
|
43
|
+
}
|
|
19
44
|
async function readError(res) {
|
|
20
45
|
let raw = "";
|
|
21
46
|
try {
|
|
@@ -36,28 +61,33 @@ function getKeenableClient(config) {
|
|
|
36
61
|
const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || void 0;
|
|
37
62
|
const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
38
63
|
const clientSource = config?.clientSource ?? "Mastra";
|
|
39
|
-
function headers(
|
|
64
|
+
function headers() {
|
|
40
65
|
const h = {
|
|
41
66
|
Accept: "application/json",
|
|
67
|
+
"Content-Type": "application/json",
|
|
42
68
|
"User-Agent": "keenable-mastra",
|
|
43
69
|
"X-Keenable-Title": clientSource
|
|
44
70
|
};
|
|
45
|
-
if (json) h["Content-Type"] = "application/json";
|
|
46
71
|
if (apiKey) h["X-API-Key"] = apiKey;
|
|
47
72
|
return h;
|
|
48
73
|
}
|
|
49
74
|
return {
|
|
50
75
|
async search(query, options = {}) {
|
|
51
76
|
const payload = { query, mode: "pro" };
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
77
|
+
const site = nonBlank(options.site);
|
|
78
|
+
if (site) payload.site = site;
|
|
79
|
+
const excludeDomains = (options.excludeDomains ?? []).map(nonBlank).filter(Boolean);
|
|
80
|
+
if (excludeDomains.length) payload.exclude_domains = excludeDomains;
|
|
81
|
+
for (const [option, field] of STRING_PARAMS) {
|
|
82
|
+
const value = nonBlank(options[option]);
|
|
83
|
+
if (value) payload[field] = value;
|
|
84
|
+
}
|
|
85
|
+
const maxResults = options.maxResults ?? config?.maxResults;
|
|
86
|
+
if (typeof maxResults === "number") payload.max_results = maxResults;
|
|
57
87
|
const path = apiKey ? "/v1/search" : "/v1/search/public";
|
|
58
88
|
const res = await fetch(`${baseUrl}${path}`, {
|
|
59
89
|
method: "POST",
|
|
60
|
-
headers: headers(
|
|
90
|
+
headers: headers(),
|
|
61
91
|
body: JSON.stringify(payload)
|
|
62
92
|
});
|
|
63
93
|
if (!res.ok) {
|
|
@@ -72,40 +102,57 @@ function getKeenableClient(config) {
|
|
|
72
102
|
publishedAt: toIsoDate(r.published_at),
|
|
73
103
|
acquiredAt: r.acquired_at || void 0
|
|
74
104
|
}));
|
|
75
|
-
if (typeof
|
|
76
|
-
results = results.slice(0,
|
|
105
|
+
if (typeof maxResults === "number") {
|
|
106
|
+
results = results.slice(0, maxResults);
|
|
77
107
|
}
|
|
78
108
|
return { query: data?.query ?? query, results };
|
|
79
109
|
},
|
|
80
110
|
async fetch(url) {
|
|
81
111
|
const path = apiKey ? "/v1/fetch" : "/v1/fetch/public";
|
|
82
|
-
const res = await fetch(`${baseUrl}${path}
|
|
83
|
-
method: "
|
|
84
|
-
headers: headers(
|
|
112
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: headers(),
|
|
115
|
+
body: JSON.stringify({ urls: [url] })
|
|
85
116
|
});
|
|
86
117
|
if (!res.ok) {
|
|
87
118
|
throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());
|
|
88
119
|
}
|
|
89
120
|
const data = await res.json();
|
|
121
|
+
const page = Array.isArray(data?.results) ? data.results[0] : void 0;
|
|
122
|
+
if (!page || typeof page !== "object") {
|
|
123
|
+
throw new Error("Keenable fetch failed: no page in the response");
|
|
124
|
+
}
|
|
125
|
+
const error = pageError(page.error);
|
|
126
|
+
if (error) throw error;
|
|
90
127
|
return {
|
|
91
|
-
url:
|
|
92
|
-
title:
|
|
93
|
-
content:
|
|
94
|
-
description:
|
|
95
|
-
author:
|
|
96
|
-
publishedAt: toIsoDate(
|
|
128
|
+
url: page.url || url,
|
|
129
|
+
title: page.title || void 0,
|
|
130
|
+
content: page.content || void 0,
|
|
131
|
+
description: page.description || void 0,
|
|
132
|
+
author: page.author || void 0,
|
|
133
|
+
publishedAt: toIsoDate(page.published_at),
|
|
134
|
+
image: page.image || void 0,
|
|
135
|
+
favicon: page.favicon || void 0
|
|
97
136
|
};
|
|
98
137
|
}
|
|
99
138
|
};
|
|
100
139
|
}
|
|
140
|
+
var timeFormats = "a date (YYYY-MM-DD), ISO 8601 timestamp or offset like 7d / 24h";
|
|
101
141
|
var inputSchema = zod.z.object({
|
|
102
142
|
query: zod.z.string().describe("The search query"),
|
|
103
143
|
site: zod.z.string().optional().describe("Restrict results to a single domain, e.g. 'techcrunch.com'"),
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
144
|
+
excludeDomains: zod.z.array(zod.z.string()).max(2e3).optional().describe("Domains to leave out, e.g. ['pinterest.com']; each also excludes its subdomains"),
|
|
145
|
+
publishedAfter: zod.z.string().optional().describe(`Only pages published on or after this: ${timeFormats}. Use this to get recent results`),
|
|
146
|
+
publishedBefore: zod.z.string().optional().describe(`Only pages published on or before this: ${timeFormats}`),
|
|
147
|
+
acquiredAfter: zod.z.string().optional().describe(`Only pages indexed on or after this: ${timeFormats}`),
|
|
148
|
+
acquiredBefore: zod.z.string().optional().describe(`Only pages indexed on or before this: ${timeFormats}`),
|
|
149
|
+
queryTime: zod.z.string().optional().describe(
|
|
150
|
+
"Search the index as it stood at this moment; newer pages are left out. An upper bound, not a recency filter (use publishedAfter for recent results). Rarely needed"
|
|
151
|
+
),
|
|
152
|
+
objective: zod.z.string().max(1e3).optional().describe(
|
|
153
|
+
"What the search is for, what the query leaves out, what earlier searches found. Helps ranking; pass it for multi-step or ambiguous searches, not every search"
|
|
154
|
+
),
|
|
155
|
+
maxResults: zod.z.number().int().min(1).max(50).optional().describe("Number of results to return (1-50, default 10)")
|
|
109
156
|
});
|
|
110
157
|
var outputSchema = zod.z.object({
|
|
111
158
|
query: zod.z.string(),
|
|
@@ -129,16 +176,19 @@ function createKeenableSearchTool(config) {
|
|
|
129
176
|
}
|
|
130
177
|
return tools.createTool({
|
|
131
178
|
id: "keenable-search",
|
|
132
|
-
description: "Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet.
|
|
179
|
+
description: "Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet. Filter by site, excluded domains and publication/index date; publishedAfter (e.g. 7d) is how to get recent results. Keyless by default.",
|
|
133
180
|
inputSchema,
|
|
134
181
|
outputSchema,
|
|
135
182
|
execute: async (input) => {
|
|
136
183
|
return getClient().search(input.query, {
|
|
137
184
|
site: input.site,
|
|
185
|
+
excludeDomains: input.excludeDomains,
|
|
138
186
|
publishedAfter: input.publishedAfter,
|
|
139
187
|
publishedBefore: input.publishedBefore,
|
|
140
188
|
acquiredAfter: input.acquiredAfter,
|
|
141
189
|
acquiredBefore: input.acquiredBefore,
|
|
190
|
+
queryTime: input.queryTime,
|
|
191
|
+
objective: input.objective,
|
|
142
192
|
maxResults: input.maxResults
|
|
143
193
|
});
|
|
144
194
|
}
|
|
@@ -153,7 +203,9 @@ var outputSchema2 = zod.z.object({
|
|
|
153
203
|
content: zod.z.string().optional(),
|
|
154
204
|
description: zod.z.string().optional(),
|
|
155
205
|
author: zod.z.string().optional(),
|
|
156
|
-
publishedAt: zod.z.string().optional()
|
|
206
|
+
publishedAt: zod.z.string().optional(),
|
|
207
|
+
image: zod.z.string().optional(),
|
|
208
|
+
favicon: zod.z.string().optional()
|
|
157
209
|
});
|
|
158
210
|
function createKeenableFetchTool(config) {
|
|
159
211
|
let client = null;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["z","createTool","inputSchema","outputSchema"],"mappings":";;;;;;AAAA,IAAM,gBAAA,GAAmB,yBAAA;AAmEzB,SAAS,UAAA,CAAW,QAAa,QAAA,EAA0B;AACzD,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,MAAA,EAAQ,OAAA,IAAW,QAAQ,WAAA,IAAe,EAAE,CAAA,CAC7D,KAAA,CAAM,KAAK,CAAA,CACX,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AACX,EAAA,IAAI,QAAA,GAAW,CAAA,IAAK,IAAA,CAAK,MAAA,GAAS,QAAA,EAAU;AAC1C,IAAA,OAAO,KAAK,KAAA,CAAM,CAAA,EAAG,QAAQ,CAAA,CAAE,SAAQ,GAAI,QAAA;AAAA,EAC7C;AACA,EAAA,OAAO,IAAA;AACT;AAQO,SAAS,UAAU,KAAA,EAAoC;AAC5D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG,OAAO,IAAI,IAAA,CAAK,KAAA,GAAQ,GAAI,EAAE,WAAA,EAAY;AAC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aAAAA,GAAeH,MAAE,MAAA,CAAO;AAAA,EAC5B,GAAA,EAAKA,MAAE,MAAA,EAAO;AAAA,EACd,KAAA,EAAOA,KAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,OAAA,EAASA,KAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC7B,WAAA,EAAaA,KAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,MAAA,EAAQA,KAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC5B,WAAA,EAAaA,KAAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AAC1B,CAAC,CAAA;AAEM,SAAS,wBAAwB,MAAA,EAAgC;AACtE,EAAA,IAAI,MAAA,GAAgC,IAAA;AAEpC,EAAA,SAAS,SAAA,GAA4B;AACnC,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAA,GAAS,kBAAkB,MAAM,CAAA;AAAA,IACnC;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAOC,gBAAAA,CAAW;AAAA,IAChB,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,mMAAA;AAAA,IACF,WAAA,EAAAC,YAAAA;AAAA,IACA,YAAA,EAAAC,aAAAA;AAAA,IACA,OAAA,EAAS,OAAM,KAAA,KAAS;AACtB,MAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA;AAAA,IACpC;AAAA,GACD,CAAA;AACH;;;ACnCO,SAAS,oBAAoB,MAAA,EAAgC;AAClE,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,yBAAyB,MAAM,CAAA;AAAA,IAC/C,aAAA,EAAe,wBAAwB,MAAM;AAAA,GAC/C;AACF","file":"index.cjs","sourcesContent":["const DEFAULT_BASE_URL = 'https://api.keenable.ai';\n\nexport interface KeenableClientOptions {\n /** Keenable API key. Keyless by default (rate-limited); a key lifts the hourly cap. Falls back to `KEENABLE_API_KEY`. */\n apiKey?: string;\n /** API base URL. Falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`. */\n baseUrl?: string;\n /** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */\n clientSource?: string;\n}\n\nexport interface KeenableSearchOptions {\n /** Restrict results to a single domain, e.g. `'techcrunch.com'`. */\n site?: string;\n /** Only pages published on or after this date (YYYY-MM-DD). */\n publishedAfter?: string;\n /** Only pages published on or before this date (YYYY-MM-DD). */\n publishedBefore?: string;\n /** Only pages indexed on or after this date (YYYY-MM-DD). */\n acquiredAfter?: string;\n /** Only pages indexed on or before this date (YYYY-MM-DD). */\n acquiredBefore?: string;\n /** Cap the number of results returned (the API returns a fixed-size set; extras are trimmed client-side). */\n maxResults?: number;\n /**\n * Truncate each result's `description` to this many characters (default 500).\n * Keenable returns page text rather than a short search snippet, so without a\n * cap a full result set can crowd the agent's context. Pass `0` to disable.\n */\n maxSnippetChars?: number;\n}\n\nexport interface KeenableSearchResult {\n title: string;\n url: string;\n description?: string;\n publishedAt?: string;\n acquiredAt?: string;\n}\n\nexport interface KeenableSearchResponse {\n query: string;\n results: KeenableSearchResult[];\n}\n\nexport interface KeenablePage {\n url: string;\n title?: string;\n content?: string;\n description?: string;\n author?: string;\n publishedAt?: string;\n}\n\nexport interface KeenableClient {\n search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;\n fetch(url: string): Promise<KeenablePage>;\n}\n\n/**\n * A result's text, whitespace-collapsed and length-capped.\n *\n * The API returns both `snippet` and `description`: `snippet` holds the page text\n * and `description` is usually empty, so reading `description` first returns\n * results with no text at all. Snippets are raw page text and arrive with\n * newlines, hence the collapse.\n */\nfunction resultText(result: any, maxChars: number): string {\n const text = String(result?.snippet || result?.description || '')\n .split(/\\s+/)\n .filter(Boolean)\n .join(' ');\n if (maxChars > 0 && text.length > maxChars) {\n return text.slice(0, maxChars).trimEnd() + '…';\n }\n return text;\n}\n\n/**\n * Keenable reports publication times either as an ISO 8601 string or as Unix\n * seconds (fetch does the latter). The tools' output schemas declare a string,\n * and Mastra rejects a tool result that does not match its schema, so a number\n * here turned every dated page into a tool error.\n */\nexport function toIsoDate(value: unknown): string | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return new Date(value * 1000).toISOString();\n return typeof value === 'string' && value ? value : undefined;\n}\n\nasync function readError(res: Response): Promise<string> {\n // Read the body exactly once: a Response stream can only be consumed a single\n // time, so we cannot call json() and then fall back to text(). Read text and\n // opportunistically parse it as JSON.\n let raw = '';\n try {\n raw = await res.text();\n } catch {\n return '';\n }\n try {\n const body: any = JSON.parse(raw);\n if (body && typeof body === 'object') {\n return String(body.message || body.error || body.detail || '');\n }\n } catch {\n // Not JSON; fall through to the raw text.\n }\n return raw.trim();\n}\n\n/**\n * Build a Keenable API client. Keyless by default: with no key it calls the\n * public endpoints (rate-limited); a key switches to the authenticated\n * endpoints and lifts the cap. No third-party SDK, just a thin `fetch` wrapper.\n */\nexport function getKeenableClient(config?: KeenableClientOptions): KeenableClient {\n const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || undefined;\n const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n const clientSource = config?.clientSource ?? 'Mastra';\n\n function headers(json: boolean): Record<string, string> {\n const h: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': 'keenable-mastra',\n 'X-Keenable-Title': clientSource,\n };\n if (json) h['Content-Type'] = 'application/json';\n if (apiKey) h['X-API-Key'] = apiKey;\n return h;\n }\n\n return {\n async search(query, options = {}) {\n const payload: Record<string, unknown> = { query, mode: 'pro' };\n if (options.site) payload.site = options.site;\n if (options.publishedAfter) payload.published_after = options.publishedAfter;\n if (options.publishedBefore) payload.published_before = options.publishedBefore;\n if (options.acquiredAfter) payload.acquired_after = options.acquiredAfter;\n if (options.acquiredBefore) payload.acquired_before = options.acquiredBefore;\n\n const path = apiKey ? '/v1/search' : '/v1/search/public';\n const res = await fetch(`${baseUrl}${path}`, {\n method: 'POST',\n headers: headers(true),\n body: JSON.stringify(payload),\n });\n if (!res.ok) {\n throw new Error(`Keenable search failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n const maxSnippetChars = options.maxSnippetChars ?? 500;\n let results: KeenableSearchResult[] = (data?.results ?? []).map((r: any) => ({\n title: r.title,\n url: r.url,\n description: resultText(r, maxSnippetChars) || undefined,\n publishedAt: toIsoDate(r.published_at),\n acquiredAt: r.acquired_at || undefined,\n }));\n if (typeof options.maxResults === 'number') {\n results = results.slice(0, options.maxResults);\n }\n return { query: data?.query ?? query, results };\n },\n\n async fetch(url) {\n const path = apiKey ? '/v1/fetch' : '/v1/fetch/public';\n const res = await fetch(`${baseUrl}${path}?url=${encodeURIComponent(url)}`, {\n method: 'GET',\n headers: headers(false),\n });\n if (!res.ok) {\n throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n return {\n url: data?.url ?? url,\n title: data?.title || undefined,\n content: data?.content || undefined,\n description: data?.description || undefined,\n author: data?.author || undefined,\n publishedAt: toIsoDate(data?.published_at),\n };\n },\n };\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n site: z.string().optional().describe(\"Restrict results to a single domain, e.g. 'techcrunch.com'\"),\n publishedAfter: z.string().optional().describe('Only pages published on or after this date (YYYY-MM-DD)'),\n publishedBefore: z.string().optional().describe('Only pages published on or before this date (YYYY-MM-DD)'),\n acquiredAfter: z.string().optional().describe('Only pages indexed on or after this date (YYYY-MM-DD)'),\n acquiredBefore: z.string().optional().describe('Only pages indexed on or before this date (YYYY-MM-DD)'),\n maxResults: z.number().min(1).max(20).optional().describe('Maximum number of results to return (1-20)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n title: z.string(),\n url: z.string(),\n description: z.string().optional(),\n publishedAt: z.string().optional(),\n acquiredAt: z.string().optional(),\n }),\n ),\n});\n\nexport function createKeenableSearchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-search',\n description:\n 'Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet. Supports filtering by site and publication/index date. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().search(input.query, {\n site: input.site,\n publishedAfter: input.publishedAfter,\n publishedBefore: input.publishedBefore,\n acquiredAfter: input.acquiredAfter,\n acquiredBefore: input.acquiredBefore,\n maxResults: input.maxResults,\n });\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL of the page to fetch and extract as markdown'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n title: z.string().optional(),\n content: z.string().optional(),\n description: z.string().optional(),\n author: z.string().optional(),\n publishedAt: z.string().optional(),\n});\n\nexport function createKeenableFetchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-fetch',\n description:\n 'Fetch a web page via Keenable and return its main content as markdown, along with title, description, author, and publication date. Use this to read a page found via search. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().fetch(input.url);\n },\n });\n}\n","import type { KeenableClientOptions } from './client.js';\nimport { createKeenableFetchTool } from './fetch.js';\nimport { createKeenableSearchTool } from './search.js';\n\nexport function createKeenableTools(config?: KeenableClientOptions) {\n return {\n keenableSearch: createKeenableSearchTool(config),\n keenableFetch: createKeenableFetchTool(config),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["z","createTool","inputSchema","outputSchema"],"mappings":";;;;;;AAAA,IAAM,gBAAA,GAAmB,yBAAA;AAsFzB,SAAS,UAAA,CAAW,QAAa,QAAA,EAA0B;AACzD,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,MAAA,EAAQ,OAAA,IAAW,QAAQ,WAAA,IAAe,EAAE,CAAA,CAC7D,KAAA,CAAM,KAAK,CAAA,CACX,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AACX,EAAA,IAAI,QAAA,GAAW,CAAA,IAAK,IAAA,CAAK,MAAA,GAAS,QAAA,EAAU;AAC1C,IAAA,OAAO,KAAK,KAAA,CAAM,CAAA,EAAG,QAAQ,CAAA,CAAE,SAAQ,GAAI,QAAA;AAAA,EAC7C;AACA,EAAA,OAAO,IAAA;AACT;AAQO,SAAS,UAAU,KAAA,EAAoC;AAC5D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG,OAAO,IAAI,IAAA,CAAK,KAAA,GAAQ,GAAI,EAAE,WAAA,EAAY;AACnG,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,GAAQ,KAAA,GAAQ,MAAA;AACtD;AAGA,IAAM,aAAA,GAAgB;AAAA,EACpB,CAAC,kBAAkB,iBAAiB,CAAA;AAAA,EACpC,CAAC,mBAAmB,kBAAkB,CAAA;AAAA,EACtC,CAAC,iBAAiB,gBAAgB,CAAA;AAAA,EAClC,CAAC,kBAAkB,iBAAiB,CAAA;AAAA,EACpC,CAAC,aAAa,YAAY,CAAA;AAAA,EAC1B,CAAC,aAAa,WAAW;AAC3B,CAAA;AAGA,SAAS,SAAS,KAAA,EAA+C;AAC/D,EAAA,MAAM,UAAU,OAAO,KAAA,KAAU,QAAA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EM,SAAS,wBAAwB,MAAA,EAAgC;AACtE,EAAA,IAAI,MAAA,GAAgC,IAAA;AAEpC,EAAA,SAAS,SAAA,GAA4B;AACnC,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAA,GAAS,kBAAkB,MAAM,CAAA;AAAA,IACnC;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAOC,gBAAAA,CAAW;AAAA,IAChB,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,mMAAA;AAAA,IACF,WAAA,EAAAC,YAAAA;AAAA,IACA,YAAA,EAAAC,aAAAA;AAAA,IACA,OAAA,EAAS,OAAM,KAAA,KAAS;AACtB,MAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA;AAAA,IACpC;AAAA,GACD,CAAA;AACH;;;ACrCO,SAAS,oBAAoB,MAAA,EAAgC;AAClE,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,yBAAyB,MAAM,CAAA;AAAA,IAC/C,aAAA,EAAe,wBAAwB,MAAM;AAAA,GAC/C;AACF","file":"index.cjs","sourcesContent":["const DEFAULT_BASE_URL = 'https://api.keenable.ai';\n\nexport interface KeenableClientOptions {\n /** Keenable API key. Keyless by default (rate-limited); a key lifts the hourly cap. Falls back to `KEENABLE_API_KEY`. */\n apiKey?: string;\n /** API base URL. Falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`. */\n baseUrl?: string;\n /** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */\n clientSource?: string;\n /** Default number of search results (1-50) when a call does not set `maxResults`. The API default is 10. */\n maxResults?: number;\n}\n\nexport interface KeenableSearchOptions {\n /** Restrict results to a single domain, e.g. `'techcrunch.com'`. */\n site?: string;\n /** Leave out these hosts (and their subdomains), e.g. `['pinterest.com']`. Up to 2000. */\n excludeDomains?: string[];\n /**\n * Only pages published on or after this time. Takes a date (`YYYY-MM-DD`), an\n * ISO 8601 timestamp or a relative offset such as `7d` or `24h`.\n */\n publishedAfter?: string;\n /** Only pages published on or before this time (same formats as `publishedAfter`). */\n publishedBefore?: string;\n /** Only pages indexed on or after this time (same formats as `publishedAfter`). */\n acquiredAfter?: string;\n /** Only pages indexed on or before this time (same formats as `publishedAfter`). */\n acquiredBefore?: string;\n /**\n * Search the index as it stood at this moment: pages acquired later are left\n * out. An upper bound only, not a recency filter (use `publishedAfter` for that).\n */\n queryTime?: string;\n /**\n * What the search is for, up to 1,000 characters: context the query leaves\n * out or what earlier searches found. Used for ranking only.\n */\n objective?: string;\n /** Number of results, 1-50 (sent to the API as `max_results`; API default 10). */\n maxResults?: number;\n /**\n * Truncate each result's `description` to this many characters (default 500).\n * Keenable returns page text rather than a short search snippet, so without a\n * cap a full result set can crowd the agent's context. Pass `0` to disable.\n */\n maxSnippetChars?: number;\n}\n\nexport interface KeenableSearchResult {\n title: string;\n url: string;\n description?: string;\n publishedAt?: string;\n acquiredAt?: string;\n}\n\nexport interface KeenableSearchResponse {\n query: string;\n results: KeenableSearchResult[];\n}\n\nexport interface KeenablePage {\n url: string;\n title?: string;\n content?: string;\n description?: string;\n author?: string;\n publishedAt?: string;\n image?: string;\n favicon?: string;\n}\n\nexport interface KeenableClient {\n search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;\n fetch(url: string): Promise<KeenablePage>;\n}\n\n/**\n * A result's text, whitespace-collapsed and length-capped.\n *\n * The API returns both `snippet` and `description`: `snippet` holds the page text\n * and `description` is usually empty, so reading `description` first returns\n * results with no text at all. Snippets are raw page text and arrive with\n * newlines, hence the collapse.\n */\nfunction resultText(result: any, maxChars: number): string {\n const text = String(result?.snippet || result?.description || '')\n .split(/\\s+/)\n .filter(Boolean)\n .join(' ');\n if (maxChars > 0 && text.length > maxChars) {\n return text.slice(0, maxChars).trimEnd() + '…';\n }\n return text;\n}\n\n/**\n * Keenable reports publication times either as an ISO 8601 string or as Unix\n * seconds (fetch does the latter). The tools' output schemas declare a string,\n * and Mastra rejects a tool result that does not match its schema, so a number\n * here turned every dated page into a tool error.\n */\nexport function toIsoDate(value: unknown): string | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return new Date(value * 1000).toISOString();\n return typeof value === 'string' && value ? value : undefined;\n}\n\n/** String search options and the API fields they map to; each is sent only when non-blank. */\nconst STRING_PARAMS = [\n ['publishedAfter', 'published_after'],\n ['publishedBefore', 'published_before'],\n ['acquiredAfter', 'acquired_after'],\n ['acquiredBefore', 'acquired_before'],\n ['queryTime', 'query_time'],\n ['objective', 'objective'],\n] as const;\n\n/** A trimmed string, or `undefined` when it is missing or blank. */\nfunction nonBlank(value: string | undefined): string | undefined {\n const trimmed = typeof value === 'string' ? value.trim() : '';\n return trimmed || undefined;\n}\n\n/**\n * The error a fetch reports for one page. `POST /v1/fetch` answers 200 for the\n * request as a whole and puts a failed page's error in that page's slot, as\n * `{ status, error, message, ... }` (a bare string is handled too).\n */\nfunction pageError(error: unknown): Error | undefined {\n if (!error) return undefined;\n let status = 500;\n let detail = '';\n if (typeof error === 'object') {\n const e = error as Record<string, unknown>;\n if (typeof e.status === 'number' && Number.isInteger(e.status)) status = e.status;\n detail = String(e.message || e.error || '');\n } else {\n detail = String(error);\n }\n return new Error(`Keenable fetch failed (${status}): ${detail}`.trim());\n}\n\nasync function readError(res: Response): Promise<string> {\n // Read the body exactly once: a Response stream can only be consumed a single\n // time, so we cannot call json() and then fall back to text(). Read text and\n // opportunistically parse it as JSON.\n let raw = '';\n try {\n raw = await res.text();\n } catch {\n return '';\n }\n try {\n const body: any = JSON.parse(raw);\n if (body && typeof body === 'object') {\n return String(body.message || body.error || body.detail || '');\n }\n } catch {\n // Not JSON; fall through to the raw text.\n }\n return raw.trim();\n}\n\n/**\n * Build a Keenable API client. Keyless by default: with no key it calls the\n * public endpoints (rate-limited); a key switches to the authenticated\n * endpoints and lifts the cap. No third-party SDK, just a thin `fetch` wrapper.\n */\nexport function getKeenableClient(config?: KeenableClientOptions): KeenableClient {\n const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || undefined;\n const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n const clientSource = config?.clientSource ?? 'Mastra';\n\n function headers(): Record<string, string> {\n const h: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'User-Agent': 'keenable-mastra',\n 'X-Keenable-Title': clientSource,\n };\n if (apiKey) h['X-API-Key'] = apiKey;\n return h;\n }\n\n return {\n async search(query, options = {}) {\n const payload: Record<string, unknown> = { query, mode: 'pro' };\n const site = nonBlank(options.site);\n if (site) payload.site = site;\n const excludeDomains = (options.excludeDomains ?? []).map(nonBlank).filter(Boolean);\n if (excludeDomains.length) payload.exclude_domains = excludeDomains;\n for (const [option, field] of STRING_PARAMS) {\n const value = nonBlank(options[option]);\n if (value) payload[field] = value;\n }\n const maxResults = options.maxResults ?? config?.maxResults;\n if (typeof maxResults === 'number') payload.max_results = maxResults;\n\n const path = apiKey ? '/v1/search' : '/v1/search/public';\n const res = await fetch(`${baseUrl}${path}`, {\n method: 'POST',\n headers: headers(),\n body: JSON.stringify(payload),\n });\n if (!res.ok) {\n throw new Error(`Keenable search failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n const maxSnippetChars = options.maxSnippetChars ?? 500;\n let results: KeenableSearchResult[] = (data?.results ?? []).map((r: any) => ({\n title: r.title,\n url: r.url,\n description: resultText(r, maxSnippetChars) || undefined,\n publishedAt: toIsoDate(r.published_at),\n acquiredAt: r.acquired_at || undefined,\n }));\n // The API honours max_results; this only guards against a longer list.\n if (typeof maxResults === 'number') {\n results = results.slice(0, maxResults);\n }\n return { query: data?.query ?? query, results };\n },\n\n async fetch(url) {\n const path = apiKey ? '/v1/fetch' : '/v1/fetch/public';\n const res = await fetch(`${baseUrl}${path}`, {\n method: 'POST',\n headers: headers(),\n body: JSON.stringify({ urls: [url] }),\n });\n if (!res.ok) {\n throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n const page = Array.isArray(data?.results) ? data.results[0] : undefined;\n if (!page || typeof page !== 'object') {\n throw new Error('Keenable fetch failed: no page in the response');\n }\n const error = pageError(page.error);\n if (error) throw error;\n // Missing fields come back as `null` or `''` (e.g. `image: null`); the\n // output schema takes strings or nothing, so map those to undefined.\n return {\n url: page.url || url,\n title: page.title || undefined,\n content: page.content || undefined,\n description: page.description || undefined,\n author: page.author || undefined,\n publishedAt: toIsoDate(page.published_at),\n image: page.image || undefined,\n favicon: page.favicon || undefined,\n };\n },\n };\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst timeFormats = 'a date (YYYY-MM-DD), ISO 8601 timestamp or offset like 7d / 24h';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n site: z.string().optional().describe(\"Restrict results to a single domain, e.g. 'techcrunch.com'\"),\n excludeDomains: z\n .array(z.string())\n .max(2000)\n .optional()\n .describe(\"Domains to leave out, e.g. ['pinterest.com']; each also excludes its subdomains\"),\n publishedAfter: z\n .string()\n .optional()\n .describe(`Only pages published on or after this: ${timeFormats}. Use this to get recent results`),\n publishedBefore: z.string().optional().describe(`Only pages published on or before this: ${timeFormats}`),\n acquiredAfter: z.string().optional().describe(`Only pages indexed on or after this: ${timeFormats}`),\n acquiredBefore: z.string().optional().describe(`Only pages indexed on or before this: ${timeFormats}`),\n queryTime: z\n .string()\n .optional()\n .describe(\n 'Search the index as it stood at this moment; newer pages are left out. An upper bound, not a recency filter (use publishedAfter for recent results). Rarely needed',\n ),\n objective: z\n .string()\n .max(1000)\n .optional()\n .describe(\n 'What the search is for, what the query leaves out, what earlier searches found. Helps ranking; pass it for multi-step or ambiguous searches, not every search',\n ),\n maxResults: z.number().int().min(1).max(50).optional().describe('Number of results to return (1-50, default 10)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n title: z.string(),\n url: z.string(),\n description: z.string().optional(),\n publishedAt: z.string().optional(),\n acquiredAt: z.string().optional(),\n }),\n ),\n});\n\nexport function createKeenableSearchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-search',\n description:\n 'Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet. Filter by site, excluded domains and publication/index date; publishedAfter (e.g. 7d) is how to get recent results. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().search(input.query, {\n site: input.site,\n excludeDomains: input.excludeDomains,\n publishedAfter: input.publishedAfter,\n publishedBefore: input.publishedBefore,\n acquiredAfter: input.acquiredAfter,\n acquiredBefore: input.acquiredBefore,\n queryTime: input.queryTime,\n objective: input.objective,\n maxResults: input.maxResults,\n });\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL of the page to fetch and extract as markdown'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n title: z.string().optional(),\n content: z.string().optional(),\n description: z.string().optional(),\n author: z.string().optional(),\n publishedAt: z.string().optional(),\n image: z.string().optional(),\n favicon: z.string().optional(),\n});\n\nexport function createKeenableFetchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-fetch',\n description:\n 'Fetch a web page via Keenable and return its main content as markdown, along with title, description, author, and publication date. Use this to read a page found via search. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().fetch(input.url);\n },\n });\n}\n","import type { KeenableClientOptions } from './client.js';\nimport { createKeenableFetchTool } from './fetch.js';\nimport { createKeenableSearchTool } from './search.js';\n\nexport function createKeenableTools(config?: KeenableClientOptions) {\n return {\n keenableSearch: createKeenableSearchTool(config),\n keenableFetch: createKeenableFetchTool(config),\n };\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -7,19 +7,36 @@ interface KeenableClientOptions {
|
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
/** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */
|
|
9
9
|
clientSource?: string;
|
|
10
|
+
/** Default number of search results (1-50) when a call does not set `maxResults`. The API default is 10. */
|
|
11
|
+
maxResults?: number;
|
|
10
12
|
}
|
|
11
13
|
interface KeenableSearchOptions {
|
|
12
14
|
/** Restrict results to a single domain, e.g. `'techcrunch.com'`. */
|
|
13
15
|
site?: string;
|
|
14
|
-
/**
|
|
16
|
+
/** Leave out these hosts (and their subdomains), e.g. `['pinterest.com']`. Up to 2000. */
|
|
17
|
+
excludeDomains?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Only pages published on or after this time. Takes a date (`YYYY-MM-DD`), an
|
|
20
|
+
* ISO 8601 timestamp or a relative offset such as `7d` or `24h`.
|
|
21
|
+
*/
|
|
15
22
|
publishedAfter?: string;
|
|
16
|
-
/** Only pages published on or before this
|
|
23
|
+
/** Only pages published on or before this time (same formats as `publishedAfter`). */
|
|
17
24
|
publishedBefore?: string;
|
|
18
|
-
/** Only pages indexed on or after this
|
|
25
|
+
/** Only pages indexed on or after this time (same formats as `publishedAfter`). */
|
|
19
26
|
acquiredAfter?: string;
|
|
20
|
-
/** Only pages indexed on or before this
|
|
27
|
+
/** Only pages indexed on or before this time (same formats as `publishedAfter`). */
|
|
21
28
|
acquiredBefore?: string;
|
|
22
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Search the index as it stood at this moment: pages acquired later are left
|
|
31
|
+
* out. An upper bound only, not a recency filter (use `publishedAfter` for that).
|
|
32
|
+
*/
|
|
33
|
+
queryTime?: string;
|
|
34
|
+
/**
|
|
35
|
+
* What the search is for, up to 1,000 characters: context the query leaves
|
|
36
|
+
* out or what earlier searches found. Used for ranking only.
|
|
37
|
+
*/
|
|
38
|
+
objective?: string;
|
|
39
|
+
/** Number of results, 1-50 (sent to the API as `max_results`; API default 10). */
|
|
23
40
|
maxResults?: number;
|
|
24
41
|
/**
|
|
25
42
|
* Truncate each result's `description` to this many characters (default 500).
|
|
@@ -46,6 +63,8 @@ interface KeenablePage {
|
|
|
46
63
|
description?: string;
|
|
47
64
|
author?: string;
|
|
48
65
|
publishedAt?: string;
|
|
66
|
+
image?: string;
|
|
67
|
+
favicon?: string;
|
|
49
68
|
}
|
|
50
69
|
interface KeenableClient {
|
|
51
70
|
search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;
|
|
@@ -61,10 +80,13 @@ declare function getKeenableClient(config?: KeenableClientOptions): KeenableClie
|
|
|
61
80
|
declare function createKeenableSearchTool(config?: KeenableClientOptions): _mastra_core_tools.Tool<{
|
|
62
81
|
query: string;
|
|
63
82
|
site?: string | undefined;
|
|
83
|
+
excludeDomains?: string[] | undefined;
|
|
64
84
|
publishedAfter?: string | undefined;
|
|
65
85
|
publishedBefore?: string | undefined;
|
|
66
86
|
acquiredAfter?: string | undefined;
|
|
67
87
|
acquiredBefore?: string | undefined;
|
|
88
|
+
queryTime?: string | undefined;
|
|
89
|
+
objective?: string | undefined;
|
|
68
90
|
maxResults?: number | undefined;
|
|
69
91
|
}, {
|
|
70
92
|
query: string;
|
|
@@ -86,16 +108,21 @@ declare function createKeenableFetchTool(config?: KeenableClientOptions): _mastr
|
|
|
86
108
|
description?: string | undefined;
|
|
87
109
|
author?: string | undefined;
|
|
88
110
|
publishedAt?: string | undefined;
|
|
111
|
+
image?: string | undefined;
|
|
112
|
+
favicon?: string | undefined;
|
|
89
113
|
}, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
|
|
90
114
|
|
|
91
115
|
declare function createKeenableTools(config?: KeenableClientOptions): {
|
|
92
116
|
keenableSearch: _mastra_core_tools.Tool<{
|
|
93
117
|
query: string;
|
|
94
118
|
site?: string | undefined;
|
|
119
|
+
excludeDomains?: string[] | undefined;
|
|
95
120
|
publishedAfter?: string | undefined;
|
|
96
121
|
publishedBefore?: string | undefined;
|
|
97
122
|
acquiredAfter?: string | undefined;
|
|
98
123
|
acquiredBefore?: string | undefined;
|
|
124
|
+
queryTime?: string | undefined;
|
|
125
|
+
objective?: string | undefined;
|
|
99
126
|
maxResults?: number | undefined;
|
|
100
127
|
}, {
|
|
101
128
|
query: string;
|
|
@@ -116,6 +143,8 @@ declare function createKeenableTools(config?: KeenableClientOptions): {
|
|
|
116
143
|
description?: string | undefined;
|
|
117
144
|
author?: string | undefined;
|
|
118
145
|
publishedAt?: string | undefined;
|
|
146
|
+
image?: string | undefined;
|
|
147
|
+
favicon?: string | undefined;
|
|
119
148
|
}, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
|
|
120
149
|
};
|
|
121
150
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,19 +7,36 @@ interface KeenableClientOptions {
|
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
/** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */
|
|
9
9
|
clientSource?: string;
|
|
10
|
+
/** Default number of search results (1-50) when a call does not set `maxResults`. The API default is 10. */
|
|
11
|
+
maxResults?: number;
|
|
10
12
|
}
|
|
11
13
|
interface KeenableSearchOptions {
|
|
12
14
|
/** Restrict results to a single domain, e.g. `'techcrunch.com'`. */
|
|
13
15
|
site?: string;
|
|
14
|
-
/**
|
|
16
|
+
/** Leave out these hosts (and their subdomains), e.g. `['pinterest.com']`. Up to 2000. */
|
|
17
|
+
excludeDomains?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Only pages published on or after this time. Takes a date (`YYYY-MM-DD`), an
|
|
20
|
+
* ISO 8601 timestamp or a relative offset such as `7d` or `24h`.
|
|
21
|
+
*/
|
|
15
22
|
publishedAfter?: string;
|
|
16
|
-
/** Only pages published on or before this
|
|
23
|
+
/** Only pages published on or before this time (same formats as `publishedAfter`). */
|
|
17
24
|
publishedBefore?: string;
|
|
18
|
-
/** Only pages indexed on or after this
|
|
25
|
+
/** Only pages indexed on or after this time (same formats as `publishedAfter`). */
|
|
19
26
|
acquiredAfter?: string;
|
|
20
|
-
/** Only pages indexed on or before this
|
|
27
|
+
/** Only pages indexed on or before this time (same formats as `publishedAfter`). */
|
|
21
28
|
acquiredBefore?: string;
|
|
22
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Search the index as it stood at this moment: pages acquired later are left
|
|
31
|
+
* out. An upper bound only, not a recency filter (use `publishedAfter` for that).
|
|
32
|
+
*/
|
|
33
|
+
queryTime?: string;
|
|
34
|
+
/**
|
|
35
|
+
* What the search is for, up to 1,000 characters: context the query leaves
|
|
36
|
+
* out or what earlier searches found. Used for ranking only.
|
|
37
|
+
*/
|
|
38
|
+
objective?: string;
|
|
39
|
+
/** Number of results, 1-50 (sent to the API as `max_results`; API default 10). */
|
|
23
40
|
maxResults?: number;
|
|
24
41
|
/**
|
|
25
42
|
* Truncate each result's `description` to this many characters (default 500).
|
|
@@ -46,6 +63,8 @@ interface KeenablePage {
|
|
|
46
63
|
description?: string;
|
|
47
64
|
author?: string;
|
|
48
65
|
publishedAt?: string;
|
|
66
|
+
image?: string;
|
|
67
|
+
favicon?: string;
|
|
49
68
|
}
|
|
50
69
|
interface KeenableClient {
|
|
51
70
|
search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;
|
|
@@ -61,10 +80,13 @@ declare function getKeenableClient(config?: KeenableClientOptions): KeenableClie
|
|
|
61
80
|
declare function createKeenableSearchTool(config?: KeenableClientOptions): _mastra_core_tools.Tool<{
|
|
62
81
|
query: string;
|
|
63
82
|
site?: string | undefined;
|
|
83
|
+
excludeDomains?: string[] | undefined;
|
|
64
84
|
publishedAfter?: string | undefined;
|
|
65
85
|
publishedBefore?: string | undefined;
|
|
66
86
|
acquiredAfter?: string | undefined;
|
|
67
87
|
acquiredBefore?: string | undefined;
|
|
88
|
+
queryTime?: string | undefined;
|
|
89
|
+
objective?: string | undefined;
|
|
68
90
|
maxResults?: number | undefined;
|
|
69
91
|
}, {
|
|
70
92
|
query: string;
|
|
@@ -86,16 +108,21 @@ declare function createKeenableFetchTool(config?: KeenableClientOptions): _mastr
|
|
|
86
108
|
description?: string | undefined;
|
|
87
109
|
author?: string | undefined;
|
|
88
110
|
publishedAt?: string | undefined;
|
|
111
|
+
image?: string | undefined;
|
|
112
|
+
favicon?: string | undefined;
|
|
89
113
|
}, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
|
|
90
114
|
|
|
91
115
|
declare function createKeenableTools(config?: KeenableClientOptions): {
|
|
92
116
|
keenableSearch: _mastra_core_tools.Tool<{
|
|
93
117
|
query: string;
|
|
94
118
|
site?: string | undefined;
|
|
119
|
+
excludeDomains?: string[] | undefined;
|
|
95
120
|
publishedAfter?: string | undefined;
|
|
96
121
|
publishedBefore?: string | undefined;
|
|
97
122
|
acquiredAfter?: string | undefined;
|
|
98
123
|
acquiredBefore?: string | undefined;
|
|
124
|
+
queryTime?: string | undefined;
|
|
125
|
+
objective?: string | undefined;
|
|
99
126
|
maxResults?: number | undefined;
|
|
100
127
|
}, {
|
|
101
128
|
query: string;
|
|
@@ -116,6 +143,8 @@ declare function createKeenableTools(config?: KeenableClientOptions): {
|
|
|
116
143
|
description?: string | undefined;
|
|
117
144
|
author?: string | undefined;
|
|
118
145
|
publishedAt?: string | undefined;
|
|
146
|
+
image?: string | undefined;
|
|
147
|
+
favicon?: string | undefined;
|
|
119
148
|
}, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
|
|
120
149
|
};
|
|
121
150
|
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,31 @@ function toIsoDate(value) {
|
|
|
14
14
|
if (typeof value === "number" && Number.isFinite(value)) return new Date(value * 1e3).toISOString();
|
|
15
15
|
return typeof value === "string" && value ? value : void 0;
|
|
16
16
|
}
|
|
17
|
+
var STRING_PARAMS = [
|
|
18
|
+
["publishedAfter", "published_after"],
|
|
19
|
+
["publishedBefore", "published_before"],
|
|
20
|
+
["acquiredAfter", "acquired_after"],
|
|
21
|
+
["acquiredBefore", "acquired_before"],
|
|
22
|
+
["queryTime", "query_time"],
|
|
23
|
+
["objective", "objective"]
|
|
24
|
+
];
|
|
25
|
+
function nonBlank(value) {
|
|
26
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
27
|
+
return trimmed || void 0;
|
|
28
|
+
}
|
|
29
|
+
function pageError(error) {
|
|
30
|
+
if (!error) return void 0;
|
|
31
|
+
let status = 500;
|
|
32
|
+
let detail = "";
|
|
33
|
+
if (typeof error === "object") {
|
|
34
|
+
const e = error;
|
|
35
|
+
if (typeof e.status === "number" && Number.isInteger(e.status)) status = e.status;
|
|
36
|
+
detail = String(e.message || e.error || "");
|
|
37
|
+
} else {
|
|
38
|
+
detail = String(error);
|
|
39
|
+
}
|
|
40
|
+
return new Error(`Keenable fetch failed (${status}): ${detail}`.trim());
|
|
41
|
+
}
|
|
17
42
|
async function readError(res) {
|
|
18
43
|
let raw = "";
|
|
19
44
|
try {
|
|
@@ -34,28 +59,33 @@ function getKeenableClient(config) {
|
|
|
34
59
|
const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || void 0;
|
|
35
60
|
const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
36
61
|
const clientSource = config?.clientSource ?? "Mastra";
|
|
37
|
-
function headers(
|
|
62
|
+
function headers() {
|
|
38
63
|
const h = {
|
|
39
64
|
Accept: "application/json",
|
|
65
|
+
"Content-Type": "application/json",
|
|
40
66
|
"User-Agent": "keenable-mastra",
|
|
41
67
|
"X-Keenable-Title": clientSource
|
|
42
68
|
};
|
|
43
|
-
if (json) h["Content-Type"] = "application/json";
|
|
44
69
|
if (apiKey) h["X-API-Key"] = apiKey;
|
|
45
70
|
return h;
|
|
46
71
|
}
|
|
47
72
|
return {
|
|
48
73
|
async search(query, options = {}) {
|
|
49
74
|
const payload = { query, mode: "pro" };
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
75
|
+
const site = nonBlank(options.site);
|
|
76
|
+
if (site) payload.site = site;
|
|
77
|
+
const excludeDomains = (options.excludeDomains ?? []).map(nonBlank).filter(Boolean);
|
|
78
|
+
if (excludeDomains.length) payload.exclude_domains = excludeDomains;
|
|
79
|
+
for (const [option, field] of STRING_PARAMS) {
|
|
80
|
+
const value = nonBlank(options[option]);
|
|
81
|
+
if (value) payload[field] = value;
|
|
82
|
+
}
|
|
83
|
+
const maxResults = options.maxResults ?? config?.maxResults;
|
|
84
|
+
if (typeof maxResults === "number") payload.max_results = maxResults;
|
|
55
85
|
const path = apiKey ? "/v1/search" : "/v1/search/public";
|
|
56
86
|
const res = await fetch(`${baseUrl}${path}`, {
|
|
57
87
|
method: "POST",
|
|
58
|
-
headers: headers(
|
|
88
|
+
headers: headers(),
|
|
59
89
|
body: JSON.stringify(payload)
|
|
60
90
|
});
|
|
61
91
|
if (!res.ok) {
|
|
@@ -70,40 +100,57 @@ function getKeenableClient(config) {
|
|
|
70
100
|
publishedAt: toIsoDate(r.published_at),
|
|
71
101
|
acquiredAt: r.acquired_at || void 0
|
|
72
102
|
}));
|
|
73
|
-
if (typeof
|
|
74
|
-
results = results.slice(0,
|
|
103
|
+
if (typeof maxResults === "number") {
|
|
104
|
+
results = results.slice(0, maxResults);
|
|
75
105
|
}
|
|
76
106
|
return { query: data?.query ?? query, results };
|
|
77
107
|
},
|
|
78
108
|
async fetch(url) {
|
|
79
109
|
const path = apiKey ? "/v1/fetch" : "/v1/fetch/public";
|
|
80
|
-
const res = await fetch(`${baseUrl}${path}
|
|
81
|
-
method: "
|
|
82
|
-
headers: headers(
|
|
110
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: headers(),
|
|
113
|
+
body: JSON.stringify({ urls: [url] })
|
|
83
114
|
});
|
|
84
115
|
if (!res.ok) {
|
|
85
116
|
throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());
|
|
86
117
|
}
|
|
87
118
|
const data = await res.json();
|
|
119
|
+
const page = Array.isArray(data?.results) ? data.results[0] : void 0;
|
|
120
|
+
if (!page || typeof page !== "object") {
|
|
121
|
+
throw new Error("Keenable fetch failed: no page in the response");
|
|
122
|
+
}
|
|
123
|
+
const error = pageError(page.error);
|
|
124
|
+
if (error) throw error;
|
|
88
125
|
return {
|
|
89
|
-
url:
|
|
90
|
-
title:
|
|
91
|
-
content:
|
|
92
|
-
description:
|
|
93
|
-
author:
|
|
94
|
-
publishedAt: toIsoDate(
|
|
126
|
+
url: page.url || url,
|
|
127
|
+
title: page.title || void 0,
|
|
128
|
+
content: page.content || void 0,
|
|
129
|
+
description: page.description || void 0,
|
|
130
|
+
author: page.author || void 0,
|
|
131
|
+
publishedAt: toIsoDate(page.published_at),
|
|
132
|
+
image: page.image || void 0,
|
|
133
|
+
favicon: page.favicon || void 0
|
|
95
134
|
};
|
|
96
135
|
}
|
|
97
136
|
};
|
|
98
137
|
}
|
|
138
|
+
var timeFormats = "a date (YYYY-MM-DD), ISO 8601 timestamp or offset like 7d / 24h";
|
|
99
139
|
var inputSchema = z.object({
|
|
100
140
|
query: z.string().describe("The search query"),
|
|
101
141
|
site: z.string().optional().describe("Restrict results to a single domain, e.g. 'techcrunch.com'"),
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
142
|
+
excludeDomains: z.array(z.string()).max(2e3).optional().describe("Domains to leave out, e.g. ['pinterest.com']; each also excludes its subdomains"),
|
|
143
|
+
publishedAfter: z.string().optional().describe(`Only pages published on or after this: ${timeFormats}. Use this to get recent results`),
|
|
144
|
+
publishedBefore: z.string().optional().describe(`Only pages published on or before this: ${timeFormats}`),
|
|
145
|
+
acquiredAfter: z.string().optional().describe(`Only pages indexed on or after this: ${timeFormats}`),
|
|
146
|
+
acquiredBefore: z.string().optional().describe(`Only pages indexed on or before this: ${timeFormats}`),
|
|
147
|
+
queryTime: z.string().optional().describe(
|
|
148
|
+
"Search the index as it stood at this moment; newer pages are left out. An upper bound, not a recency filter (use publishedAfter for recent results). Rarely needed"
|
|
149
|
+
),
|
|
150
|
+
objective: z.string().max(1e3).optional().describe(
|
|
151
|
+
"What the search is for, what the query leaves out, what earlier searches found. Helps ranking; pass it for multi-step or ambiguous searches, not every search"
|
|
152
|
+
),
|
|
153
|
+
maxResults: z.number().int().min(1).max(50).optional().describe("Number of results to return (1-50, default 10)")
|
|
107
154
|
});
|
|
108
155
|
var outputSchema = z.object({
|
|
109
156
|
query: z.string(),
|
|
@@ -127,16 +174,19 @@ function createKeenableSearchTool(config) {
|
|
|
127
174
|
}
|
|
128
175
|
return createTool({
|
|
129
176
|
id: "keenable-search",
|
|
130
|
-
description: "Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet.
|
|
177
|
+
description: "Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet. Filter by site, excluded domains and publication/index date; publishedAfter (e.g. 7d) is how to get recent results. Keyless by default.",
|
|
131
178
|
inputSchema,
|
|
132
179
|
outputSchema,
|
|
133
180
|
execute: async (input) => {
|
|
134
181
|
return getClient().search(input.query, {
|
|
135
182
|
site: input.site,
|
|
183
|
+
excludeDomains: input.excludeDomains,
|
|
136
184
|
publishedAfter: input.publishedAfter,
|
|
137
185
|
publishedBefore: input.publishedBefore,
|
|
138
186
|
acquiredAfter: input.acquiredAfter,
|
|
139
187
|
acquiredBefore: input.acquiredBefore,
|
|
188
|
+
queryTime: input.queryTime,
|
|
189
|
+
objective: input.objective,
|
|
140
190
|
maxResults: input.maxResults
|
|
141
191
|
});
|
|
142
192
|
}
|
|
@@ -151,7 +201,9 @@ var outputSchema2 = z.object({
|
|
|
151
201
|
content: z.string().optional(),
|
|
152
202
|
description: z.string().optional(),
|
|
153
203
|
author: z.string().optional(),
|
|
154
|
-
publishedAt: z.string().optional()
|
|
204
|
+
publishedAt: z.string().optional(),
|
|
205
|
+
image: z.string().optional(),
|
|
206
|
+
favicon: z.string().optional()
|
|
155
207
|
});
|
|
156
208
|
function createKeenableFetchTool(config) {
|
|
157
209
|
let client = null;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["inputSchema","z","outputSchema","createTool"],"mappings":";;;;AAAA,IAAM,gBAAA,GAAmB,yBAAA;AAmEzB,SAAS,UAAA,CAAW,QAAa,QAAA,EAA0B;AACzD,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,MAAA,EAAQ,OAAA,IAAW,QAAQ,WAAA,IAAe,EAAE,CAAA,CAC7D,KAAA,CAAM,KAAK,CAAA,CACX,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA;AACX,EAAA,IAAI,QAAA,GAAW,CAAA,IAAK,IAAA,CAAK,MAAA,GAAS,QAAA,EAAU;AAC1C,IAAA,OAAO,KAAK,KAAA,CAAM,CAAA,EAAG,QAAQ,CAAA,CAAE,SAAQ,GAAI,QAAA;AAAA,EAC7C;AACA,EAAA,OAAO,IAAA;AACT;AAQO,SAAS,UAAU,KAAA,EAAoC;AAC5D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG,OAAO,IAAI,IAAA,CAAK,KAAA,GAAQ,GAAI,EAAE,WAAA,EAAY;AACnG,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,GAAQ,KAAA,G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KAAA,EAAOA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,OAAA,EAASA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC7B,WAAA,EAAaA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,MAAA,EAAQA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC5B,WAAA,EAAaA,CAAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AAC1B,CAAC,CAAA;AAEM,SAAS,wBAAwB,MAAA,EAAgC;AACtE,EAAA,IAAI,MAAA,GAAgC,IAAA;AAEpC,EAAA,SAAS,SAAA,GAA4B;AACnC,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAA,GAAS,kBAAkB,MAAM,CAAA;AAAA,IACnC;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAOE,UAAAA,CAAW;AAAA,IAChB,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,mMAAA;AAAA,IACF,WAAA,EAAAH,YAAAA;AAAA,IACA,YAAA,EAAAE,aAAAA;AAAA,IACA,OAAA,EAAS,OAAM,KAAA,KAAS;AACtB,MAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA;AAAA,IACpC;AAAA,GACD,CAAA;AACH;;;ACnCO,SAAS,oBAAoB,MAAA,EAAgC;AAClE,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,yBAAyB,MAAM,CAAA;AAAA,IAC/C,aAAA,EAAe,wBAAwB,MAAM;AAAA,GAC/C;AACF","file":"index.js","sourcesContent":["const DEFAULT_BASE_URL = 'https://api.keenable.ai';\n\nexport interface KeenableClientOptions {\n /** Keenable API key. Keyless by default (rate-limited); a key lifts the hourly cap. Falls back to `KEENABLE_API_KEY`. */\n apiKey?: string;\n /** API base URL. Falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`. */\n baseUrl?: string;\n /** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */\n clientSource?: string;\n}\n\nexport interface KeenableSearchOptions {\n /** Restrict results to a single domain, e.g. `'techcrunch.com'`. */\n site?: string;\n /** Only pages published on or after this date (YYYY-MM-DD). */\n publishedAfter?: string;\n /** Only pages published on or before this date (YYYY-MM-DD). */\n publishedBefore?: string;\n /** Only pages indexed on or after this date (YYYY-MM-DD). */\n acquiredAfter?: string;\n /** Only pages indexed on or before this date (YYYY-MM-DD). */\n acquiredBefore?: string;\n /** Cap the number of results returned (the API returns a fixed-size set; extras are trimmed client-side). */\n maxResults?: number;\n /**\n * Truncate each result's `description` to this many characters (default 500).\n * Keenable returns page text rather than a short search snippet, so without a\n * cap a full result set can crowd the agent's context. Pass `0` to disable.\n */\n maxSnippetChars?: number;\n}\n\nexport interface KeenableSearchResult {\n title: string;\n url: string;\n description?: string;\n publishedAt?: string;\n acquiredAt?: string;\n}\n\nexport interface KeenableSearchResponse {\n query: string;\n results: KeenableSearchResult[];\n}\n\nexport interface KeenablePage {\n url: string;\n title?: string;\n content?: string;\n description?: string;\n author?: string;\n publishedAt?: string;\n}\n\nexport interface KeenableClient {\n search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;\n fetch(url: string): Promise<KeenablePage>;\n}\n\n/**\n * A result's text, whitespace-collapsed and length-capped.\n *\n * The API returns both `snippet` and `description`: `snippet` holds the page text\n * and `description` is usually empty, so reading `description` first returns\n * results with no text at all. Snippets are raw page text and arrive with\n * newlines, hence the collapse.\n */\nfunction resultText(result: any, maxChars: number): string {\n const text = String(result?.snippet || result?.description || '')\n .split(/\\s+/)\n .filter(Boolean)\n .join(' ');\n if (maxChars > 0 && text.length > maxChars) {\n return text.slice(0, maxChars).trimEnd() + '…';\n }\n return text;\n}\n\n/**\n * Keenable reports publication times either as an ISO 8601 string or as Unix\n * seconds (fetch does the latter). The tools' output schemas declare a string,\n * and Mastra rejects a tool result that does not match its schema, so a number\n * here turned every dated page into a tool error.\n */\nexport function toIsoDate(value: unknown): string | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return new Date(value * 1000).toISOString();\n return typeof value === 'string' && value ? value : undefined;\n}\n\nasync function readError(res: Response): Promise<string> {\n // Read the body exactly once: a Response stream can only be consumed a single\n // time, so we cannot call json() and then fall back to text(). Read text and\n // opportunistically parse it as JSON.\n let raw = '';\n try {\n raw = await res.text();\n } catch {\n return '';\n }\n try {\n const body: any = JSON.parse(raw);\n if (body && typeof body === 'object') {\n return String(body.message || body.error || body.detail || '');\n }\n } catch {\n // Not JSON; fall through to the raw text.\n }\n return raw.trim();\n}\n\n/**\n * Build a Keenable API client. Keyless by default: with no key it calls the\n * public endpoints (rate-limited); a key switches to the authenticated\n * endpoints and lifts the cap. No third-party SDK, just a thin `fetch` wrapper.\n */\nexport function getKeenableClient(config?: KeenableClientOptions): KeenableClient {\n const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || undefined;\n const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n const clientSource = config?.clientSource ?? 'Mastra';\n\n function headers(json: boolean): Record<string, string> {\n const h: Record<string, string> = {\n Accept: 'application/json',\n 'User-Agent': 'keenable-mastra',\n 'X-Keenable-Title': clientSource,\n };\n if (json) h['Content-Type'] = 'application/json';\n if (apiKey) h['X-API-Key'] = apiKey;\n return h;\n }\n\n return {\n async search(query, options = {}) {\n const payload: Record<string, unknown> = { query, mode: 'pro' };\n if (options.site) payload.site = options.site;\n if (options.publishedAfter) payload.published_after = options.publishedAfter;\n if (options.publishedBefore) payload.published_before = options.publishedBefore;\n if (options.acquiredAfter) payload.acquired_after = options.acquiredAfter;\n if (options.acquiredBefore) payload.acquired_before = options.acquiredBefore;\n\n const path = apiKey ? '/v1/search' : '/v1/search/public';\n const res = await fetch(`${baseUrl}${path}`, {\n method: 'POST',\n headers: headers(true),\n body: JSON.stringify(payload),\n });\n if (!res.ok) {\n throw new Error(`Keenable search failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n const maxSnippetChars = options.maxSnippetChars ?? 500;\n let results: KeenableSearchResult[] = (data?.results ?? []).map((r: any) => ({\n title: r.title,\n url: r.url,\n description: resultText(r, maxSnippetChars) || undefined,\n publishedAt: toIsoDate(r.published_at),\n acquiredAt: r.acquired_at || undefined,\n }));\n if (typeof options.maxResults === 'number') {\n results = results.slice(0, options.maxResults);\n }\n return { query: data?.query ?? query, results };\n },\n\n async fetch(url) {\n const path = apiKey ? '/v1/fetch' : '/v1/fetch/public';\n const res = await fetch(`${baseUrl}${path}?url=${encodeURIComponent(url)}`, {\n method: 'GET',\n headers: headers(false),\n });\n if (!res.ok) {\n throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n return {\n url: data?.url ?? url,\n title: data?.title || undefined,\n content: data?.content || undefined,\n description: data?.description || undefined,\n author: data?.author || undefined,\n publishedAt: toIsoDate(data?.published_at),\n };\n },\n };\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n site: z.string().optional().describe(\"Restrict results to a single domain, e.g. 'techcrunch.com'\"),\n publishedAfter: z.string().optional().describe('Only pages published on or after this date (YYYY-MM-DD)'),\n publishedBefore: z.string().optional().describe('Only pages published on or before this date (YYYY-MM-DD)'),\n acquiredAfter: z.string().optional().describe('Only pages indexed on or after this date (YYYY-MM-DD)'),\n acquiredBefore: z.string().optional().describe('Only pages indexed on or before this date (YYYY-MM-DD)'),\n maxResults: z.number().min(1).max(20).optional().describe('Maximum number of results to return (1-20)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n title: z.string(),\n url: z.string(),\n description: z.string().optional(),\n publishedAt: z.string().optional(),\n acquiredAt: z.string().optional(),\n }),\n ),\n});\n\nexport function createKeenableSearchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-search',\n description:\n 'Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet. Supports filtering by site and publication/index date. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().search(input.query, {\n site: input.site,\n publishedAfter: input.publishedAfter,\n publishedBefore: input.publishedBefore,\n acquiredAfter: input.acquiredAfter,\n acquiredBefore: input.acquiredBefore,\n maxResults: input.maxResults,\n });\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL of the page to fetch and extract as markdown'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n title: z.string().optional(),\n content: z.string().optional(),\n description: z.string().optional(),\n author: z.string().optional(),\n publishedAt: z.string().optional(),\n});\n\nexport function createKeenableFetchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-fetch',\n description:\n 'Fetch a web page via Keenable and return its main content as markdown, along with title, description, author, and publication date. Use this to read a page found via search. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().fetch(input.url);\n },\n });\n}\n","import type { KeenableClientOptions } from './client.js';\nimport { createKeenableFetchTool } from './fetch.js';\nimport { createKeenableSearchTool } from './search.js';\n\nexport function createKeenableTools(config?: KeenableClientOptions) {\n return {\n keenableSearch: createKeenableSearchTool(config),\n keenableFetch: createKeenableFetchTool(config),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts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AAC,MAAA,EAAQ;AACX,MAAA,MAAA,GAAS,kBAAkB,MAAM,CAAA;AAAA,IACnC;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,OAAOE,UAAAA,CAAW;AAAA,IAChB,EAAA,EAAI,gBAAA;AAAA,IACJ,WAAA,EACE,mMAAA;AAAA,IACF,WAAA,EAAAH,YAAAA;AAAA,IACA,YAAA,EAAAE,aAAAA;AAAA,IACA,OAAA,EAAS,OAAM,KAAA,KAAS;AACtB,MAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA;AAAA,IACpC;AAAA,GACD,CAAA;AACH;;;ACrCO,SAAS,oBAAoB,MAAA,EAAgC;AAClE,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,yBAAyB,MAAM,CAAA;AAAA,IAC/C,aAAA,EAAe,wBAAwB,MAAM;AAAA,GAC/C;AACF","file":"index.js","sourcesContent":["const DEFAULT_BASE_URL = 'https://api.keenable.ai';\n\nexport interface KeenableClientOptions {\n /** Keenable API key. Keyless by default (rate-limited); a key lifts the hourly cap. Falls back to `KEENABLE_API_KEY`. */\n apiKey?: string;\n /** API base URL. Falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`. */\n baseUrl?: string;\n /** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */\n clientSource?: string;\n /** Default number of search results (1-50) when a call does not set `maxResults`. The API default is 10. */\n maxResults?: number;\n}\n\nexport interface KeenableSearchOptions {\n /** Restrict results to a single domain, e.g. `'techcrunch.com'`. */\n site?: string;\n /** Leave out these hosts (and their subdomains), e.g. `['pinterest.com']`. Up to 2000. */\n excludeDomains?: string[];\n /**\n * Only pages published on or after this time. Takes a date (`YYYY-MM-DD`), an\n * ISO 8601 timestamp or a relative offset such as `7d` or `24h`.\n */\n publishedAfter?: string;\n /** Only pages published on or before this time (same formats as `publishedAfter`). */\n publishedBefore?: string;\n /** Only pages indexed on or after this time (same formats as `publishedAfter`). */\n acquiredAfter?: string;\n /** Only pages indexed on or before this time (same formats as `publishedAfter`). */\n acquiredBefore?: string;\n /**\n * Search the index as it stood at this moment: pages acquired later are left\n * out. An upper bound only, not a recency filter (use `publishedAfter` for that).\n */\n queryTime?: string;\n /**\n * What the search is for, up to 1,000 characters: context the query leaves\n * out or what earlier searches found. Used for ranking only.\n */\n objective?: string;\n /** Number of results, 1-50 (sent to the API as `max_results`; API default 10). */\n maxResults?: number;\n /**\n * Truncate each result's `description` to this many characters (default 500).\n * Keenable returns page text rather than a short search snippet, so without a\n * cap a full result set can crowd the agent's context. Pass `0` to disable.\n */\n maxSnippetChars?: number;\n}\n\nexport interface KeenableSearchResult {\n title: string;\n url: string;\n description?: string;\n publishedAt?: string;\n acquiredAt?: string;\n}\n\nexport interface KeenableSearchResponse {\n query: string;\n results: KeenableSearchResult[];\n}\n\nexport interface KeenablePage {\n url: string;\n title?: string;\n content?: string;\n description?: string;\n author?: string;\n publishedAt?: string;\n image?: string;\n favicon?: string;\n}\n\nexport interface KeenableClient {\n search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;\n fetch(url: string): Promise<KeenablePage>;\n}\n\n/**\n * A result's text, whitespace-collapsed and length-capped.\n *\n * The API returns both `snippet` and `description`: `snippet` holds the page text\n * and `description` is usually empty, so reading `description` first returns\n * results with no text at all. Snippets are raw page text and arrive with\n * newlines, hence the collapse.\n */\nfunction resultText(result: any, maxChars: number): string {\n const text = String(result?.snippet || result?.description || '')\n .split(/\\s+/)\n .filter(Boolean)\n .join(' ');\n if (maxChars > 0 && text.length > maxChars) {\n return text.slice(0, maxChars).trimEnd() + '…';\n }\n return text;\n}\n\n/**\n * Keenable reports publication times either as an ISO 8601 string or as Unix\n * seconds (fetch does the latter). The tools' output schemas declare a string,\n * and Mastra rejects a tool result that does not match its schema, so a number\n * here turned every dated page into a tool error.\n */\nexport function toIsoDate(value: unknown): string | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return new Date(value * 1000).toISOString();\n return typeof value === 'string' && value ? value : undefined;\n}\n\n/** String search options and the API fields they map to; each is sent only when non-blank. */\nconst STRING_PARAMS = [\n ['publishedAfter', 'published_after'],\n ['publishedBefore', 'published_before'],\n ['acquiredAfter', 'acquired_after'],\n ['acquiredBefore', 'acquired_before'],\n ['queryTime', 'query_time'],\n ['objective', 'objective'],\n] as const;\n\n/** A trimmed string, or `undefined` when it is missing or blank. */\nfunction nonBlank(value: string | undefined): string | undefined {\n const trimmed = typeof value === 'string' ? value.trim() : '';\n return trimmed || undefined;\n}\n\n/**\n * The error a fetch reports for one page. `POST /v1/fetch` answers 200 for the\n * request as a whole and puts a failed page's error in that page's slot, as\n * `{ status, error, message, ... }` (a bare string is handled too).\n */\nfunction pageError(error: unknown): Error | undefined {\n if (!error) return undefined;\n let status = 500;\n let detail = '';\n if (typeof error === 'object') {\n const e = error as Record<string, unknown>;\n if (typeof e.status === 'number' && Number.isInteger(e.status)) status = e.status;\n detail = String(e.message || e.error || '');\n } else {\n detail = String(error);\n }\n return new Error(`Keenable fetch failed (${status}): ${detail}`.trim());\n}\n\nasync function readError(res: Response): Promise<string> {\n // Read the body exactly once: a Response stream can only be consumed a single\n // time, so we cannot call json() and then fall back to text(). Read text and\n // opportunistically parse it as JSON.\n let raw = '';\n try {\n raw = await res.text();\n } catch {\n return '';\n }\n try {\n const body: any = JSON.parse(raw);\n if (body && typeof body === 'object') {\n return String(body.message || body.error || body.detail || '');\n }\n } catch {\n // Not JSON; fall through to the raw text.\n }\n return raw.trim();\n}\n\n/**\n * Build a Keenable API client. Keyless by default: with no key it calls the\n * public endpoints (rate-limited); a key switches to the authenticated\n * endpoints and lifts the cap. No third-party SDK, just a thin `fetch` wrapper.\n */\nexport function getKeenableClient(config?: KeenableClientOptions): KeenableClient {\n const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || undefined;\n const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n const clientSource = config?.clientSource ?? 'Mastra';\n\n function headers(): Record<string, string> {\n const h: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'User-Agent': 'keenable-mastra',\n 'X-Keenable-Title': clientSource,\n };\n if (apiKey) h['X-API-Key'] = apiKey;\n return h;\n }\n\n return {\n async search(query, options = {}) {\n const payload: Record<string, unknown> = { query, mode: 'pro' };\n const site = nonBlank(options.site);\n if (site) payload.site = site;\n const excludeDomains = (options.excludeDomains ?? []).map(nonBlank).filter(Boolean);\n if (excludeDomains.length) payload.exclude_domains = excludeDomains;\n for (const [option, field] of STRING_PARAMS) {\n const value = nonBlank(options[option]);\n if (value) payload[field] = value;\n }\n const maxResults = options.maxResults ?? config?.maxResults;\n if (typeof maxResults === 'number') payload.max_results = maxResults;\n\n const path = apiKey ? '/v1/search' : '/v1/search/public';\n const res = await fetch(`${baseUrl}${path}`, {\n method: 'POST',\n headers: headers(),\n body: JSON.stringify(payload),\n });\n if (!res.ok) {\n throw new Error(`Keenable search failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n const maxSnippetChars = options.maxSnippetChars ?? 500;\n let results: KeenableSearchResult[] = (data?.results ?? []).map((r: any) => ({\n title: r.title,\n url: r.url,\n description: resultText(r, maxSnippetChars) || undefined,\n publishedAt: toIsoDate(r.published_at),\n acquiredAt: r.acquired_at || undefined,\n }));\n // The API honours max_results; this only guards against a longer list.\n if (typeof maxResults === 'number') {\n results = results.slice(0, maxResults);\n }\n return { query: data?.query ?? query, results };\n },\n\n async fetch(url) {\n const path = apiKey ? '/v1/fetch' : '/v1/fetch/public';\n const res = await fetch(`${baseUrl}${path}`, {\n method: 'POST',\n headers: headers(),\n body: JSON.stringify({ urls: [url] }),\n });\n if (!res.ok) {\n throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());\n }\n const data: any = await res.json();\n const page = Array.isArray(data?.results) ? data.results[0] : undefined;\n if (!page || typeof page !== 'object') {\n throw new Error('Keenable fetch failed: no page in the response');\n }\n const error = pageError(page.error);\n if (error) throw error;\n // Missing fields come back as `null` or `''` (e.g. `image: null`); the\n // output schema takes strings or nothing, so map those to undefined.\n return {\n url: page.url || url,\n title: page.title || undefined,\n content: page.content || undefined,\n description: page.description || undefined,\n author: page.author || undefined,\n publishedAt: toIsoDate(page.published_at),\n image: page.image || undefined,\n favicon: page.favicon || undefined,\n };\n },\n };\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst timeFormats = 'a date (YYYY-MM-DD), ISO 8601 timestamp or offset like 7d / 24h';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n site: z.string().optional().describe(\"Restrict results to a single domain, e.g. 'techcrunch.com'\"),\n excludeDomains: z\n .array(z.string())\n .max(2000)\n .optional()\n .describe(\"Domains to leave out, e.g. ['pinterest.com']; each also excludes its subdomains\"),\n publishedAfter: z\n .string()\n .optional()\n .describe(`Only pages published on or after this: ${timeFormats}. Use this to get recent results`),\n publishedBefore: z.string().optional().describe(`Only pages published on or before this: ${timeFormats}`),\n acquiredAfter: z.string().optional().describe(`Only pages indexed on or after this: ${timeFormats}`),\n acquiredBefore: z.string().optional().describe(`Only pages indexed on or before this: ${timeFormats}`),\n queryTime: z\n .string()\n .optional()\n .describe(\n 'Search the index as it stood at this moment; newer pages are left out. An upper bound, not a recency filter (use publishedAfter for recent results). Rarely needed',\n ),\n objective: z\n .string()\n .max(1000)\n .optional()\n .describe(\n 'What the search is for, what the query leaves out, what earlier searches found. Helps ranking; pass it for multi-step or ambiguous searches, not every search',\n ),\n maxResults: z.number().int().min(1).max(50).optional().describe('Number of results to return (1-50, default 10)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n title: z.string(),\n url: z.string(),\n description: z.string().optional(),\n publishedAt: z.string().optional(),\n acquiredAt: z.string().optional(),\n }),\n ),\n});\n\nexport function createKeenableSearchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-search',\n description:\n 'Search the web using Keenable, a search index built for AI agents. Returns relevant results with title, URL, and snippet. Filter by site, excluded domains and publication/index date; publishedAfter (e.g. 7d) is how to get recent results. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().search(input.query, {\n site: input.site,\n excludeDomains: input.excludeDomains,\n publishedAfter: input.publishedAfter,\n publishedBefore: input.publishedBefore,\n acquiredAfter: input.acquiredAfter,\n acquiredBefore: input.acquiredBefore,\n queryTime: input.queryTime,\n objective: input.objective,\n maxResults: input.maxResults,\n });\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { getKeenableClient } from './client.js';\nimport type { KeenableClient, KeenableClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL of the page to fetch and extract as markdown'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n title: z.string().optional(),\n content: z.string().optional(),\n description: z.string().optional(),\n author: z.string().optional(),\n publishedAt: z.string().optional(),\n image: z.string().optional(),\n favicon: z.string().optional(),\n});\n\nexport function createKeenableFetchTool(config?: KeenableClientOptions) {\n let client: KeenableClient | null = null;\n\n function getClient(): KeenableClient {\n if (!client) {\n client = getKeenableClient(config);\n }\n return client;\n }\n\n return createTool({\n id: 'keenable-fetch',\n description:\n 'Fetch a web page via Keenable and return its main content as markdown, along with title, description, author, and publication date. Use this to read a page found via search. Keyless by default.',\n inputSchema,\n outputSchema,\n execute: async input => {\n return getClient().fetch(input.url);\n },\n });\n}\n","import type { KeenableClientOptions } from './client.js';\nimport { createKeenableFetchTool } from './fetch.js';\nimport { createKeenableSearchTool } from './search.js';\n\nexport function createKeenableTools(config?: KeenableClientOptions) {\n return {\n keenableSearch: createKeenableSearchTool(config),\n keenableFetch: createKeenableFetchTool(config),\n };\n}\n"]}
|