@keenable/mastra 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Keenable
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,82 @@
1
+ # @keenable/mastra
2
+
3
+ [Keenable](https://keenable.ai) web search and page-fetch tools for [Mastra](https://mastra.ai) agents.
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.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @keenable/mastra
11
+ ```
12
+
13
+ `@mastra/core` and `zod` are peer dependencies (you already have them in a Mastra project). No provider SDK is required; the package talks to the Keenable HTTP API directly.
14
+
15
+ ## Quick Start
16
+
17
+ Use `createKeenableTools()` to get both tools with a shared configuration:
18
+
19
+ ```typescript
20
+ import { Agent } from '@mastra/core/agent';
21
+ import { createKeenableTools } from '@keenable/mastra';
22
+
23
+ const tools = createKeenableTools();
24
+ // Keyless by default. To lift the rate limit, set KEENABLE_API_KEY
25
+ // or pass an explicit key:
26
+ // const tools = createKeenableTools({ apiKey: 'keen_...' });
27
+
28
+ const agent = new Agent({
29
+ id: 'web-research-agent',
30
+ name: 'Web Research Agent',
31
+ instructions: 'You research topics on the web: search for sources, then read the most relevant pages.',
32
+ model: 'anthropic/claude-sonnet-4-6',
33
+ tools,
34
+ });
35
+ ```
36
+
37
+ By default the tools read `KEENABLE_API_KEY` from the environment when present; with no key they call the keyless public endpoints. Set `KEENABLE_API_URL` to point at a different base URL.
38
+
39
+ ## Individual Tools
40
+
41
+ Each tool can be created independently:
42
+
43
+ ```typescript
44
+ import { createKeenableSearchTool, createKeenableFetchTool } from '@keenable/mastra';
45
+
46
+ const searchTool = createKeenableSearchTool(); // keyless
47
+ const fetchTool = createKeenableFetchTool({ apiKey: 'keen_...' });
48
+ ```
49
+
50
+ ### Search (`keenable-search`)
51
+
52
+ Queries the Keenable web index. Accepts:
53
+
54
+ - `query` (required)
55
+ - `site`: restrict to a single domain, e.g. `'techcrunch.com'`
56
+ - `publishedAfter` / `publishedBefore`: filter by publication date (YYYY-MM-DD)
57
+ - `acquiredAfter` / `acquiredBefore`: filter by index date (YYYY-MM-DD)
58
+ - `maxResults`: cap results (1-20)
59
+
60
+ Returns `{ query, results: [{ title, url, description?, publishedAt?, acquiredAt? }] }`.
61
+
62
+ ### Fetch (`keenable-fetch`)
63
+
64
+ Fetches a single URL and returns its main content as markdown:
65
+
66
+ - `url` (required)
67
+
68
+ Returns `{ url, title?, content?, description?, author?, publishedAt? }`.
69
+
70
+ ## Configuration
71
+
72
+ `createKeenable*Tool` and `createKeenableTools` accept:
73
+
74
+ - `apiKey`: optional, falls back to `KEENABLE_API_KEY`. Keyless when unset.
75
+ - `baseUrl`: optional, falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`.
76
+ - `clientSource`: attribution tag Keenable segments integration traffic by (defaults to `'Mastra'`).
77
+
78
+ Get a key at [keenable.ai/console](https://keenable.ai/console).
79
+
80
+ ## License
81
+
82
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ var tools = require('@mastra/core/tools');
4
+ var zod = require('zod');
5
+
6
+ // src/client.ts
7
+ var DEFAULT_BASE_URL = "https://api.keenable.ai";
8
+ async function readError(res) {
9
+ let raw = "";
10
+ try {
11
+ raw = await res.text();
12
+ } catch {
13
+ return "";
14
+ }
15
+ try {
16
+ const body = JSON.parse(raw);
17
+ if (body && typeof body === "object") {
18
+ return String(body.message || body.error || body.detail || "");
19
+ }
20
+ } catch {
21
+ }
22
+ return raw.trim();
23
+ }
24
+ function getKeenableClient(config) {
25
+ const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || void 0;
26
+ const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
27
+ const clientSource = config?.clientSource ?? "Mastra";
28
+ function headers(json) {
29
+ const h = {
30
+ Accept: "application/json",
31
+ "User-Agent": "keenable-mastra",
32
+ "X-Keenable-Title": clientSource
33
+ };
34
+ if (json) h["Content-Type"] = "application/json";
35
+ if (apiKey) h["X-API-Key"] = apiKey;
36
+ return h;
37
+ }
38
+ return {
39
+ async search(query, options = {}) {
40
+ const payload = { query, mode: "pro" };
41
+ if (options.site) payload.site = options.site;
42
+ if (options.publishedAfter) payload.published_after = options.publishedAfter;
43
+ if (options.publishedBefore) payload.published_before = options.publishedBefore;
44
+ if (options.acquiredAfter) payload.acquired_after = options.acquiredAfter;
45
+ if (options.acquiredBefore) payload.acquired_before = options.acquiredBefore;
46
+ const path = apiKey ? "/v1/search" : "/v1/search/public";
47
+ const res = await fetch(`${baseUrl}${path}`, {
48
+ method: "POST",
49
+ headers: headers(true),
50
+ body: JSON.stringify(payload)
51
+ });
52
+ if (!res.ok) {
53
+ throw new Error(`Keenable search failed (${res.status}): ${await readError(res)}`.trim());
54
+ }
55
+ const data = await res.json();
56
+ let results = (data?.results ?? []).map((r) => ({
57
+ title: r.title,
58
+ url: r.url,
59
+ description: r.description || void 0,
60
+ publishedAt: r.published_at || void 0,
61
+ acquiredAt: r.acquired_at || void 0
62
+ }));
63
+ if (typeof options.maxResults === "number") {
64
+ results = results.slice(0, options.maxResults);
65
+ }
66
+ return { query: data?.query ?? query, results };
67
+ },
68
+ async fetch(url) {
69
+ const path = apiKey ? "/v1/fetch" : "/v1/fetch/public";
70
+ const res = await fetch(`${baseUrl}${path}?url=${encodeURIComponent(url)}`, {
71
+ method: "GET",
72
+ headers: headers(false)
73
+ });
74
+ if (!res.ok) {
75
+ throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());
76
+ }
77
+ const data = await res.json();
78
+ return {
79
+ url: data?.url ?? url,
80
+ title: data?.title || void 0,
81
+ content: data?.content || void 0,
82
+ description: data?.description || void 0,
83
+ author: data?.author || void 0,
84
+ publishedAt: data?.published_at || void 0
85
+ };
86
+ }
87
+ };
88
+ }
89
+ var inputSchema = zod.z.object({
90
+ query: zod.z.string().describe("The search query"),
91
+ site: zod.z.string().optional().describe("Restrict results to a single domain, e.g. 'techcrunch.com'"),
92
+ publishedAfter: zod.z.string().optional().describe("Only pages published on or after this date (YYYY-MM-DD)"),
93
+ publishedBefore: zod.z.string().optional().describe("Only pages published on or before this date (YYYY-MM-DD)"),
94
+ acquiredAfter: zod.z.string().optional().describe("Only pages indexed on or after this date (YYYY-MM-DD)"),
95
+ acquiredBefore: zod.z.string().optional().describe("Only pages indexed on or before this date (YYYY-MM-DD)"),
96
+ maxResults: zod.z.number().min(1).max(20).optional().describe("Maximum number of results to return (1-20)")
97
+ });
98
+ var outputSchema = zod.z.object({
99
+ query: zod.z.string(),
100
+ results: zod.z.array(
101
+ zod.z.object({
102
+ title: zod.z.string(),
103
+ url: zod.z.string(),
104
+ description: zod.z.string().optional(),
105
+ publishedAt: zod.z.string().optional(),
106
+ acquiredAt: zod.z.string().optional()
107
+ })
108
+ )
109
+ });
110
+ function createKeenableSearchTool(config) {
111
+ let client = null;
112
+ function getClient() {
113
+ if (!client) {
114
+ client = getKeenableClient(config);
115
+ }
116
+ return client;
117
+ }
118
+ return tools.createTool({
119
+ id: "keenable-search",
120
+ description: "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.",
121
+ inputSchema,
122
+ outputSchema,
123
+ execute: async (input) => {
124
+ return getClient().search(input.query, {
125
+ site: input.site,
126
+ publishedAfter: input.publishedAfter,
127
+ publishedBefore: input.publishedBefore,
128
+ acquiredAfter: input.acquiredAfter,
129
+ acquiredBefore: input.acquiredBefore,
130
+ maxResults: input.maxResults
131
+ });
132
+ }
133
+ });
134
+ }
135
+ var inputSchema2 = zod.z.object({
136
+ url: zod.z.url().describe("The URL of the page to fetch and extract as markdown")
137
+ });
138
+ var outputSchema2 = zod.z.object({
139
+ url: zod.z.string(),
140
+ title: zod.z.string().optional(),
141
+ content: zod.z.string().optional(),
142
+ description: zod.z.string().optional(),
143
+ author: zod.z.string().optional(),
144
+ publishedAt: zod.z.string().optional()
145
+ });
146
+ function createKeenableFetchTool(config) {
147
+ let client = null;
148
+ function getClient() {
149
+ if (!client) {
150
+ client = getKeenableClient(config);
151
+ }
152
+ return client;
153
+ }
154
+ return tools.createTool({
155
+ id: "keenable-fetch",
156
+ description: "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.",
157
+ inputSchema: inputSchema2,
158
+ outputSchema: outputSchema2,
159
+ execute: async (input) => {
160
+ return getClient().fetch(input.url);
161
+ }
162
+ });
163
+ }
164
+
165
+ // src/tools.ts
166
+ function createKeenableTools(config) {
167
+ return {
168
+ keenableSearch: createKeenableSearchTool(config),
169
+ keenableFetch: createKeenableFetchTool(config)
170
+ };
171
+ }
172
+
173
+ exports.createKeenableFetchTool = createKeenableFetchTool;
174
+ exports.createKeenableSearchTool = createKeenableSearchTool;
175
+ exports.createKeenableTools = createKeenableTools;
176
+ exports.getKeenableClient = getKeenableClient;
177
+ //# sourceMappingURL=index.cjs.map
178
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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;AAqDzB,eAAe,UAAU,GAAA,EAAgC;AAIvD,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,MAAM,IAAI,IAAA,EAAK;AAAA,EACvB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAA;AAAA,EACT;AACA,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,GAAY,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAChC,IAAA,IAAI,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AACpC,MAAA,OAAO,OAAO,IAAA,CAAK,OAAA,IAAW,KAAK,KAAA,IAAS,IAAA,CAAK,UAAU,EAAE,CAAA;AAAA,IAC/D;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,IAAI,IAAA,EAAK;AAClB;AAOO,SAAS,kBAAkB,MAAA,EAAgD;AAChF,EAAA,MAAM,UAAU,MAAA,EAAQ,MAAA,IAAU,QAAQ,GAAA,CAAI,gBAAA,GAAmB,MAAK,IAAK,MAAA;AAC3E,EAAA,MAAM,OAAA,GAAA,CAAW,QAAQ,OAAA,IAAW,OAAA,CAAQ,IAAI,gBAAA,IAAoB,gBAAA,EAAkB,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AACxG,EAAA,MAAM,YAAA,GAAe,QAAQ,YAAA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AgB,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\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\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 let results: KeenableSearchResult[] = (data?.results ?? []).map((r: any) => ({\n title: r.title,\n url: r.url,\n description: r.description || undefined,\n publishedAt: r.published_at || undefined,\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: data?.published_at || 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 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.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"]}
@@ -0,0 +1,116 @@
1
+ import * as _mastra_core_tools from '@mastra/core/tools';
2
+
3
+ interface KeenableClientOptions {
4
+ /** Keenable API key. Keyless by default (rate-limited); a key lifts the hourly cap. Falls back to `KEENABLE_API_KEY`. */
5
+ apiKey?: string;
6
+ /** API base URL. Falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`. */
7
+ baseUrl?: string;
8
+ /** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */
9
+ clientSource?: string;
10
+ }
11
+ interface KeenableSearchOptions {
12
+ /** Restrict results to a single domain, e.g. `'techcrunch.com'`. */
13
+ site?: string;
14
+ /** Only pages published on or after this date (YYYY-MM-DD). */
15
+ publishedAfter?: string;
16
+ /** Only pages published on or before this date (YYYY-MM-DD). */
17
+ publishedBefore?: string;
18
+ /** Only pages indexed on or after this date (YYYY-MM-DD). */
19
+ acquiredAfter?: string;
20
+ /** Only pages indexed on or before this date (YYYY-MM-DD). */
21
+ acquiredBefore?: string;
22
+ /** Cap the number of results returned (the API returns a fixed-size set; extras are trimmed client-side). */
23
+ maxResults?: number;
24
+ }
25
+ interface KeenableSearchResult {
26
+ title: string;
27
+ url: string;
28
+ description?: string;
29
+ publishedAt?: string;
30
+ acquiredAt?: string;
31
+ }
32
+ interface KeenableSearchResponse {
33
+ query: string;
34
+ results: KeenableSearchResult[];
35
+ }
36
+ interface KeenablePage {
37
+ url: string;
38
+ title?: string;
39
+ content?: string;
40
+ description?: string;
41
+ author?: string;
42
+ publishedAt?: string;
43
+ }
44
+ interface KeenableClient {
45
+ search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;
46
+ fetch(url: string): Promise<KeenablePage>;
47
+ }
48
+ /**
49
+ * Build a Keenable API client. Keyless by default: with no key it calls the
50
+ * public endpoints (rate-limited); a key switches to the authenticated
51
+ * endpoints and lifts the cap. No third-party SDK, just a thin `fetch` wrapper.
52
+ */
53
+ declare function getKeenableClient(config?: KeenableClientOptions): KeenableClient;
54
+
55
+ declare function createKeenableSearchTool(config?: KeenableClientOptions): _mastra_core_tools.Tool<{
56
+ query: string;
57
+ site?: string | undefined;
58
+ publishedAfter?: string | undefined;
59
+ publishedBefore?: string | undefined;
60
+ acquiredAfter?: string | undefined;
61
+ acquiredBefore?: string | undefined;
62
+ maxResults?: number | undefined;
63
+ }, {
64
+ query: string;
65
+ results: {
66
+ title: string;
67
+ url: string;
68
+ description?: string | undefined;
69
+ publishedAt?: string | undefined;
70
+ acquiredAt?: string | undefined;
71
+ }[];
72
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-search", unknown>;
73
+
74
+ declare function createKeenableFetchTool(config?: KeenableClientOptions): _mastra_core_tools.Tool<{
75
+ url: string;
76
+ }, {
77
+ url: string;
78
+ title?: string | undefined;
79
+ content?: string | undefined;
80
+ description?: string | undefined;
81
+ author?: string | undefined;
82
+ publishedAt?: string | undefined;
83
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
84
+
85
+ declare function createKeenableTools(config?: KeenableClientOptions): {
86
+ keenableSearch: _mastra_core_tools.Tool<{
87
+ query: string;
88
+ site?: string | undefined;
89
+ publishedAfter?: string | undefined;
90
+ publishedBefore?: string | undefined;
91
+ acquiredAfter?: string | undefined;
92
+ acquiredBefore?: string | undefined;
93
+ maxResults?: number | undefined;
94
+ }, {
95
+ query: string;
96
+ results: {
97
+ title: string;
98
+ url: string;
99
+ description?: string | undefined;
100
+ publishedAt?: string | undefined;
101
+ acquiredAt?: string | undefined;
102
+ }[];
103
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-search", unknown>;
104
+ keenableFetch: _mastra_core_tools.Tool<{
105
+ url: string;
106
+ }, {
107
+ url: string;
108
+ title?: string | undefined;
109
+ content?: string | undefined;
110
+ description?: string | undefined;
111
+ author?: string | undefined;
112
+ publishedAt?: string | undefined;
113
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
114
+ };
115
+
116
+ export { type KeenableClient, type KeenableClientOptions, type KeenablePage, type KeenableSearchOptions, type KeenableSearchResponse, type KeenableSearchResult, createKeenableFetchTool, createKeenableSearchTool, createKeenableTools, getKeenableClient };
@@ -0,0 +1,116 @@
1
+ import * as _mastra_core_tools from '@mastra/core/tools';
2
+
3
+ interface KeenableClientOptions {
4
+ /** Keenable API key. Keyless by default (rate-limited); a key lifts the hourly cap. Falls back to `KEENABLE_API_KEY`. */
5
+ apiKey?: string;
6
+ /** API base URL. Falls back to `KEENABLE_API_URL`, then `https://api.keenable.ai`. */
7
+ baseUrl?: string;
8
+ /** Attribution tag Keenable segments integration traffic by. Defaults to `'Mastra'`. */
9
+ clientSource?: string;
10
+ }
11
+ interface KeenableSearchOptions {
12
+ /** Restrict results to a single domain, e.g. `'techcrunch.com'`. */
13
+ site?: string;
14
+ /** Only pages published on or after this date (YYYY-MM-DD). */
15
+ publishedAfter?: string;
16
+ /** Only pages published on or before this date (YYYY-MM-DD). */
17
+ publishedBefore?: string;
18
+ /** Only pages indexed on or after this date (YYYY-MM-DD). */
19
+ acquiredAfter?: string;
20
+ /** Only pages indexed on or before this date (YYYY-MM-DD). */
21
+ acquiredBefore?: string;
22
+ /** Cap the number of results returned (the API returns a fixed-size set; extras are trimmed client-side). */
23
+ maxResults?: number;
24
+ }
25
+ interface KeenableSearchResult {
26
+ title: string;
27
+ url: string;
28
+ description?: string;
29
+ publishedAt?: string;
30
+ acquiredAt?: string;
31
+ }
32
+ interface KeenableSearchResponse {
33
+ query: string;
34
+ results: KeenableSearchResult[];
35
+ }
36
+ interface KeenablePage {
37
+ url: string;
38
+ title?: string;
39
+ content?: string;
40
+ description?: string;
41
+ author?: string;
42
+ publishedAt?: string;
43
+ }
44
+ interface KeenableClient {
45
+ search(query: string, options?: KeenableSearchOptions): Promise<KeenableSearchResponse>;
46
+ fetch(url: string): Promise<KeenablePage>;
47
+ }
48
+ /**
49
+ * Build a Keenable API client. Keyless by default: with no key it calls the
50
+ * public endpoints (rate-limited); a key switches to the authenticated
51
+ * endpoints and lifts the cap. No third-party SDK, just a thin `fetch` wrapper.
52
+ */
53
+ declare function getKeenableClient(config?: KeenableClientOptions): KeenableClient;
54
+
55
+ declare function createKeenableSearchTool(config?: KeenableClientOptions): _mastra_core_tools.Tool<{
56
+ query: string;
57
+ site?: string | undefined;
58
+ publishedAfter?: string | undefined;
59
+ publishedBefore?: string | undefined;
60
+ acquiredAfter?: string | undefined;
61
+ acquiredBefore?: string | undefined;
62
+ maxResults?: number | undefined;
63
+ }, {
64
+ query: string;
65
+ results: {
66
+ title: string;
67
+ url: string;
68
+ description?: string | undefined;
69
+ publishedAt?: string | undefined;
70
+ acquiredAt?: string | undefined;
71
+ }[];
72
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-search", unknown>;
73
+
74
+ declare function createKeenableFetchTool(config?: KeenableClientOptions): _mastra_core_tools.Tool<{
75
+ url: string;
76
+ }, {
77
+ url: string;
78
+ title?: string | undefined;
79
+ content?: string | undefined;
80
+ description?: string | undefined;
81
+ author?: string | undefined;
82
+ publishedAt?: string | undefined;
83
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
84
+
85
+ declare function createKeenableTools(config?: KeenableClientOptions): {
86
+ keenableSearch: _mastra_core_tools.Tool<{
87
+ query: string;
88
+ site?: string | undefined;
89
+ publishedAfter?: string | undefined;
90
+ publishedBefore?: string | undefined;
91
+ acquiredAfter?: string | undefined;
92
+ acquiredBefore?: string | undefined;
93
+ maxResults?: number | undefined;
94
+ }, {
95
+ query: string;
96
+ results: {
97
+ title: string;
98
+ url: string;
99
+ description?: string | undefined;
100
+ publishedAt?: string | undefined;
101
+ acquiredAt?: string | undefined;
102
+ }[];
103
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-search", unknown>;
104
+ keenableFetch: _mastra_core_tools.Tool<{
105
+ url: string;
106
+ }, {
107
+ url: string;
108
+ title?: string | undefined;
109
+ content?: string | undefined;
110
+ description?: string | undefined;
111
+ author?: string | undefined;
112
+ publishedAt?: string | undefined;
113
+ }, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "keenable-fetch", unknown>;
114
+ };
115
+
116
+ export { type KeenableClient, type KeenableClientOptions, type KeenablePage, type KeenableSearchOptions, type KeenableSearchResponse, type KeenableSearchResult, createKeenableFetchTool, createKeenableSearchTool, createKeenableTools, getKeenableClient };
package/dist/index.js ADDED
@@ -0,0 +1,173 @@
1
+ import { createTool } from '@mastra/core/tools';
2
+ import { z } from 'zod';
3
+
4
+ // src/client.ts
5
+ var DEFAULT_BASE_URL = "https://api.keenable.ai";
6
+ async function readError(res) {
7
+ let raw = "";
8
+ try {
9
+ raw = await res.text();
10
+ } catch {
11
+ return "";
12
+ }
13
+ try {
14
+ const body = JSON.parse(raw);
15
+ if (body && typeof body === "object") {
16
+ return String(body.message || body.error || body.detail || "");
17
+ }
18
+ } catch {
19
+ }
20
+ return raw.trim();
21
+ }
22
+ function getKeenableClient(config) {
23
+ const apiKey = (config?.apiKey ?? process.env.KEENABLE_API_KEY)?.trim() || void 0;
24
+ const baseUrl = (config?.baseUrl ?? process.env.KEENABLE_API_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
25
+ const clientSource = config?.clientSource ?? "Mastra";
26
+ function headers(json) {
27
+ const h = {
28
+ Accept: "application/json",
29
+ "User-Agent": "keenable-mastra",
30
+ "X-Keenable-Title": clientSource
31
+ };
32
+ if (json) h["Content-Type"] = "application/json";
33
+ if (apiKey) h["X-API-Key"] = apiKey;
34
+ return h;
35
+ }
36
+ return {
37
+ async search(query, options = {}) {
38
+ const payload = { query, mode: "pro" };
39
+ if (options.site) payload.site = options.site;
40
+ if (options.publishedAfter) payload.published_after = options.publishedAfter;
41
+ if (options.publishedBefore) payload.published_before = options.publishedBefore;
42
+ if (options.acquiredAfter) payload.acquired_after = options.acquiredAfter;
43
+ if (options.acquiredBefore) payload.acquired_before = options.acquiredBefore;
44
+ const path = apiKey ? "/v1/search" : "/v1/search/public";
45
+ const res = await fetch(`${baseUrl}${path}`, {
46
+ method: "POST",
47
+ headers: headers(true),
48
+ body: JSON.stringify(payload)
49
+ });
50
+ if (!res.ok) {
51
+ throw new Error(`Keenable search failed (${res.status}): ${await readError(res)}`.trim());
52
+ }
53
+ const data = await res.json();
54
+ let results = (data?.results ?? []).map((r) => ({
55
+ title: r.title,
56
+ url: r.url,
57
+ description: r.description || void 0,
58
+ publishedAt: r.published_at || void 0,
59
+ acquiredAt: r.acquired_at || void 0
60
+ }));
61
+ if (typeof options.maxResults === "number") {
62
+ results = results.slice(0, options.maxResults);
63
+ }
64
+ return { query: data?.query ?? query, results };
65
+ },
66
+ async fetch(url) {
67
+ const path = apiKey ? "/v1/fetch" : "/v1/fetch/public";
68
+ const res = await fetch(`${baseUrl}${path}?url=${encodeURIComponent(url)}`, {
69
+ method: "GET",
70
+ headers: headers(false)
71
+ });
72
+ if (!res.ok) {
73
+ throw new Error(`Keenable fetch failed (${res.status}): ${await readError(res)}`.trim());
74
+ }
75
+ const data = await res.json();
76
+ return {
77
+ url: data?.url ?? url,
78
+ title: data?.title || void 0,
79
+ content: data?.content || void 0,
80
+ description: data?.description || void 0,
81
+ author: data?.author || void 0,
82
+ publishedAt: data?.published_at || void 0
83
+ };
84
+ }
85
+ };
86
+ }
87
+ var inputSchema = z.object({
88
+ query: z.string().describe("The search query"),
89
+ site: z.string().optional().describe("Restrict results to a single domain, e.g. 'techcrunch.com'"),
90
+ publishedAfter: z.string().optional().describe("Only pages published on or after this date (YYYY-MM-DD)"),
91
+ publishedBefore: z.string().optional().describe("Only pages published on or before this date (YYYY-MM-DD)"),
92
+ acquiredAfter: z.string().optional().describe("Only pages indexed on or after this date (YYYY-MM-DD)"),
93
+ acquiredBefore: z.string().optional().describe("Only pages indexed on or before this date (YYYY-MM-DD)"),
94
+ maxResults: z.number().min(1).max(20).optional().describe("Maximum number of results to return (1-20)")
95
+ });
96
+ var outputSchema = z.object({
97
+ query: z.string(),
98
+ results: z.array(
99
+ z.object({
100
+ title: z.string(),
101
+ url: z.string(),
102
+ description: z.string().optional(),
103
+ publishedAt: z.string().optional(),
104
+ acquiredAt: z.string().optional()
105
+ })
106
+ )
107
+ });
108
+ function createKeenableSearchTool(config) {
109
+ let client = null;
110
+ function getClient() {
111
+ if (!client) {
112
+ client = getKeenableClient(config);
113
+ }
114
+ return client;
115
+ }
116
+ return createTool({
117
+ id: "keenable-search",
118
+ description: "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.",
119
+ inputSchema,
120
+ outputSchema,
121
+ execute: async (input) => {
122
+ return getClient().search(input.query, {
123
+ site: input.site,
124
+ publishedAfter: input.publishedAfter,
125
+ publishedBefore: input.publishedBefore,
126
+ acquiredAfter: input.acquiredAfter,
127
+ acquiredBefore: input.acquiredBefore,
128
+ maxResults: input.maxResults
129
+ });
130
+ }
131
+ });
132
+ }
133
+ var inputSchema2 = z.object({
134
+ url: z.url().describe("The URL of the page to fetch and extract as markdown")
135
+ });
136
+ var outputSchema2 = z.object({
137
+ url: z.string(),
138
+ title: z.string().optional(),
139
+ content: z.string().optional(),
140
+ description: z.string().optional(),
141
+ author: z.string().optional(),
142
+ publishedAt: z.string().optional()
143
+ });
144
+ function createKeenableFetchTool(config) {
145
+ let client = null;
146
+ function getClient() {
147
+ if (!client) {
148
+ client = getKeenableClient(config);
149
+ }
150
+ return client;
151
+ }
152
+ return createTool({
153
+ id: "keenable-fetch",
154
+ description: "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.",
155
+ inputSchema: inputSchema2,
156
+ outputSchema: outputSchema2,
157
+ execute: async (input) => {
158
+ return getClient().fetch(input.url);
159
+ }
160
+ });
161
+ }
162
+
163
+ // src/tools.ts
164
+ function createKeenableTools(config) {
165
+ return {
166
+ keenableSearch: createKeenableSearchTool(config),
167
+ keenableFetch: createKeenableFetchTool(config)
168
+ };
169
+ }
170
+
171
+ export { createKeenableFetchTool, createKeenableSearchTool, createKeenableTools, getKeenableClient };
172
+ //# sourceMappingURL=index.js.map
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AAqDzB,eAAe,UAAU,GAAA,EAAgC;AAIvD,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,IAAI;AACF,IAAA,GAAA,GAAM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,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\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\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 let results: KeenableSearchResult[] = (data?.results ?? []).map((r: any) => ({\n title: r.title,\n url: r.url,\n description: r.description || undefined,\n publishedAt: r.published_at || undefined,\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: data?.published_at || 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 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.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"]}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@keenable/mastra",
3
+ "version": "0.1.0",
4
+ "description": "Keenable web search and page-fetch tools for Mastra agents. Keyless by default.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Keenable",
8
+ "homepage": "https://keenable.ai",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/keenableai/keenable-integrations.git",
12
+ "directory": "mastra/plugin"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/keenableai/keenable-integrations/issues"
16
+ },
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "import": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "require": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.cjs"
33
+ }
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
37
+ "keywords": [
38
+ "mastra",
39
+ "keenable",
40
+ "web-search",
41
+ "search",
42
+ "fetch",
43
+ "tools",
44
+ "ai-agent"
45
+ ],
46
+ "scripts": {
47
+ "build": "tsup",
48
+ "check": "tsc --noEmit",
49
+ "test": "vitest run"
50
+ },
51
+ "engines": {
52
+ "node": ">=20"
53
+ },
54
+ "peerDependencies": {
55
+ "@mastra/core": ">=1.0.0-0 <2.0.0-0",
56
+ "zod": ">=3.25.0 || >=4.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "@mastra/core": "^1.49.0",
60
+ "@types/node": "^20.0.0",
61
+ "tsup": "^8.5.1",
62
+ "typescript": "^5.6.0",
63
+ "vitest": "^2.1.0",
64
+ "zod": "^4.0.0"
65
+ }
66
+ }