@mastra/perplexity 0.2.0 → 0.2.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -4
- package/README.md +14 -53
- package/dist/index.cjs +96 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +95 -98
- package/dist/index.js.map +1 -1
- package/dist/search.d.ts +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/package.json +11 -11
- package/CHANGELOG.md +0 -81
package/LICENSE.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Portions of this software are licensed as follows:
|
|
2
2
|
|
|
3
|
-
- All content that resides under any directory named
|
|
3
|
+
- All content that resides under any directory named `ee/` within this
|
|
4
4
|
repository, including but not limited to:
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
|
|
5
|
+
- `@mastra/core/auth/ee`
|
|
6
|
+
- `@mastra/core/agent-builder/ee`
|
|
7
|
+
- `@mastra/editor/ee`
|
|
8
|
+
|
|
9
|
+
is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
|
|
8
10
|
|
|
9
11
|
- All third-party components incorporated into the Mastra Software are
|
|
10
12
|
licensed under the original license provided by the owner of the
|
package/README.md
CHANGED
|
@@ -1,79 +1,40 @@
|
|
|
1
1
|
# @mastra/perplexity
|
|
2
2
|
|
|
3
3
|
Web search tool for [Mastra](https://mastra.ai) agents, backed by the [Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart).
|
|
4
|
-
|
|
5
4
|
## Installation
|
|
6
5
|
|
|
7
6
|
```bash
|
|
8
|
-
npm install @mastra/perplexity
|
|
7
|
+
npm install @mastra/perplexity
|
|
9
8
|
```
|
|
10
9
|
|
|
11
|
-
##
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Set `PERPLEXITY_API_KEY` before creating the search tool.
|
|
12
14
|
|
|
13
15
|
```typescript
|
|
14
16
|
import { Agent } from '@mastra/core/agent';
|
|
15
17
|
import { createPerplexitySearchTool } from '@mastra/perplexity';
|
|
16
18
|
|
|
17
|
-
const
|
|
19
|
+
export const researchAgent = new Agent({
|
|
18
20
|
id: 'research-agent',
|
|
19
21
|
name: 'Research Agent',
|
|
20
|
-
model: '
|
|
21
|
-
instructions:
|
|
22
|
-
'You are a research assistant. Use the perplexity-search tool to find up-to-date information from the web before answering.',
|
|
22
|
+
model: 'openai/gpt-5.6-sol',
|
|
23
|
+
instructions: 'Use web search to find current sources before answering.',
|
|
23
24
|
tools: {
|
|
24
25
|
search: createPerplexitySearchTool(),
|
|
25
26
|
},
|
|
26
27
|
});
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Filtering
|
|
32
|
-
|
|
33
|
-
The Search API supports filtering by domain and date. All filters are optional.
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
const tool = createPerplexitySearchTool();
|
|
37
|
-
|
|
38
|
-
await tool.execute!({
|
|
39
|
-
query: 'recent papers on agent evaluation',
|
|
40
|
-
maxResults: 10,
|
|
41
|
-
searchRecencyFilter: 'month',
|
|
42
|
-
searchDomainFilter: ['arxiv.org', 'openreview.net'],
|
|
43
|
-
}, {} as any);
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
To exclude domains, prefix them with `-`. Don't mix allow- and deny-list entries in the same call.
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
searchDomainFilter: ['-pinterest.com', '-quora.com'];
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Using Perplexity as a Model Provider
|
|
53
|
-
|
|
54
|
-
Perplexity is also a first-class model provider in Mastra's model router. To chat with Perplexity models (separate from this search tool), set `PERPLEXITY_API_KEY` and reference the model directly:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { Agent } from '@mastra/core/agent';
|
|
58
|
-
|
|
59
|
-
const agent = new Agent({
|
|
60
|
-
id: 'agent-api',
|
|
61
|
-
name: 'Perplexity Agent',
|
|
62
|
-
model: 'perplexity-agent/openai/gpt-5',
|
|
63
|
-
instructions: 'You are a research assistant powered by the Perplexity Agent API.',
|
|
64
|
-
});
|
|
65
|
-
```
|
|
30
|
+
## Documentation
|
|
66
31
|
|
|
67
|
-
|
|
32
|
+
- [@mastra/perplexity documentation](https://mastra.ai/integrations/tools/perplexity)
|
|
68
33
|
|
|
69
|
-
##
|
|
34
|
+
## Changelog
|
|
70
35
|
|
|
71
|
-
|
|
72
|
-
|--------|------|---------|-------------|
|
|
73
|
-
| `apiKey` | `string` | `PERPLEXITY_API_KEY` → `PPLX_API_KEY` | Perplexity API key. |
|
|
74
|
-
| `baseUrl` | `string` | `https://api.perplexity.ai` | Override the API base URL (useful for proxies and tests). |
|
|
75
|
-
| `fetch` | `typeof fetch` | global `fetch` | Inject a custom `fetch` implementation. |
|
|
36
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/integrations/perplexity/CHANGELOG.md) for version history and release notes.
|
|
76
37
|
|
|
77
|
-
##
|
|
38
|
+
## Support
|
|
78
39
|
|
|
79
|
-
|
|
40
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/index.cjs
CHANGED
|
@@ -1,115 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// src/client.ts
|
|
7
|
-
var DEFAULT_BASE_URL = "https://api.perplexity.ai";
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _mastra_core_tools = require("@mastra/core/tools");
|
|
3
|
+
let zod = require("zod");
|
|
4
|
+
//#region src/client.ts
|
|
5
|
+
const DEFAULT_BASE_URL = "https://api.perplexity.ai";
|
|
8
6
|
function resolveApiKey(explicit) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"Perplexity API key is required. Pass { apiKey } or set the PERPLEXITY_API_KEY (or PPLX_API_KEY) environment variable."
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
return key;
|
|
7
|
+
const key = explicit ?? process.env.PERPLEXITY_API_KEY ?? process.env.PPLX_API_KEY;
|
|
8
|
+
if (!key) throw new Error("Perplexity API key is required. Pass { apiKey } or set the PERPLEXITY_API_KEY (or PPLX_API_KEY) environment variable.");
|
|
9
|
+
return key;
|
|
16
10
|
}
|
|
17
11
|
async function perplexitySearchRequest(body, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
id: json.id,
|
|
40
|
-
results: Array.isArray(json.results) ? json.results : []
|
|
41
|
-
};
|
|
12
|
+
const apiKey = resolveApiKey(options?.apiKey);
|
|
13
|
+
const baseUrl = options?.baseUrl ?? "https://api.perplexity.ai";
|
|
14
|
+
const response = await (options?.fetch ?? fetch)(`${baseUrl.replace(/\/$/, "")}/search`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
Authorization: `Bearer ${apiKey}`
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify(body)
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const rawText = await response.text().catch(() => "");
|
|
24
|
+
const MAX_ERROR_BODY = 1e3;
|
|
25
|
+
const text = rawText.length > MAX_ERROR_BODY ? `${rawText.slice(0, MAX_ERROR_BODY)}…` : rawText;
|
|
26
|
+
throw new Error(`Perplexity Search request failed with status ${response.status}${text ? `: ${text}` : ""}`);
|
|
27
|
+
}
|
|
28
|
+
const json = await response.json();
|
|
29
|
+
return {
|
|
30
|
+
id: json.id,
|
|
31
|
+
results: Array.isArray(json.results) ? json.results : []
|
|
32
|
+
};
|
|
42
33
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/search.ts
|
|
36
|
+
const inputSchema = zod.z.object({
|
|
37
|
+
query: zod.z.string().describe("The search query."),
|
|
38
|
+
maxResults: zod.z.number().int().min(1).max(20).optional().describe("Maximum number of results to return (1-20). Defaults to the API default."),
|
|
39
|
+
searchDomainFilter: zod.z.array(zod.z.string()).optional().refine((domains) => {
|
|
40
|
+
if (!domains || domains.length === 0) return true;
|
|
41
|
+
const hasAllow = domains.some((d) => !d.startsWith("-"));
|
|
42
|
+
const hasDeny = domains.some((d) => d.startsWith("-"));
|
|
43
|
+
return !(hasAllow && hasDeny);
|
|
44
|
+
}, { message: "searchDomainFilter cannot mix allow and deny domain entries in the same call." }).describe("Restrict (or exclude) results by domain. Prefix a domain with `-` to exclude it (e.g. `-pinterest.com`). Do not mix allow and deny entries in the same call."),
|
|
45
|
+
searchRecencyFilter: zod.z.enum([
|
|
46
|
+
"hour",
|
|
47
|
+
"day",
|
|
48
|
+
"week",
|
|
49
|
+
"month",
|
|
50
|
+
"year"
|
|
51
|
+
]).optional().describe("Only return results from within the given recency window."),
|
|
52
|
+
searchAfterDateFilter: zod.z.string().optional().describe("Only return results published on or after this date. Format: m/d/yyyy (e.g. 1/1/2025)."),
|
|
53
|
+
searchBeforeDateFilter: zod.z.string().optional().describe("Only return results published on or before this date. Format: m/d/yyyy (e.g. 12/31/2025).")
|
|
60
54
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
})
|
|
70
|
-
)
|
|
55
|
+
const outputSchema = zod.z.object({
|
|
56
|
+
query: zod.z.string(),
|
|
57
|
+
results: zod.z.array(zod.z.object({
|
|
58
|
+
title: zod.z.string(),
|
|
59
|
+
url: zod.z.string(),
|
|
60
|
+
snippet: zod.z.string(),
|
|
61
|
+
date: zod.z.string().optional()
|
|
62
|
+
}))
|
|
71
63
|
});
|
|
64
|
+
/**
|
|
65
|
+
* Creates a tool that searches the web using the Perplexity Search API.
|
|
66
|
+
*
|
|
67
|
+
* Returns ranked web results with titles, URLs, snippets, and optional
|
|
68
|
+
* publication dates. Supports filtering by domain (allow- or deny-list),
|
|
69
|
+
* recency, and explicit date ranges.
|
|
70
|
+
*
|
|
71
|
+
* @see https://docs.perplexity.ai/docs/search/quickstart
|
|
72
|
+
*/
|
|
72
73
|
function createPerplexitySearchTool(config) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
74
|
+
return (0, _mastra_core_tools.createTool)({
|
|
75
|
+
id: "perplexity-search",
|
|
76
|
+
description: "Search the web for up-to-date information using the Perplexity Search API. Returns ranked results with titles, URLs, snippets, and optional publication dates. Supports filtering by domain, recency, and date range.",
|
|
77
|
+
inputSchema,
|
|
78
|
+
outputSchema,
|
|
79
|
+
execute: async (input) => {
|
|
80
|
+
const response = await perplexitySearchRequest({
|
|
81
|
+
query: input.query,
|
|
82
|
+
max_results: input.maxResults,
|
|
83
|
+
search_domain_filter: input.searchDomainFilter,
|
|
84
|
+
search_recency_filter: input.searchRecencyFilter,
|
|
85
|
+
search_after_date_filter: input.searchAfterDateFilter,
|
|
86
|
+
search_before_date_filter: input.searchBeforeDateFilter
|
|
87
|
+
}, config);
|
|
88
|
+
return {
|
|
89
|
+
query: input.query,
|
|
90
|
+
results: response.results.map((r) => ({
|
|
91
|
+
title: r.title,
|
|
92
|
+
url: r.url,
|
|
93
|
+
snippet: r.snippet,
|
|
94
|
+
date: r.date
|
|
95
|
+
}))
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
101
99
|
}
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/tools.ts
|
|
104
102
|
function createPerplexityTools(config) {
|
|
105
|
-
|
|
106
|
-
perplexitySearch: createPerplexitySearchTool(config)
|
|
107
|
-
};
|
|
103
|
+
return { perplexitySearch: createPerplexitySearchTool(config) };
|
|
108
104
|
}
|
|
109
|
-
|
|
105
|
+
//#endregion
|
|
110
106
|
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
111
107
|
exports.createPerplexitySearchTool = createPerplexitySearchTool;
|
|
112
108
|
exports.createPerplexityTools = createPerplexityTools;
|
|
113
109
|
exports.perplexitySearchRequest = perplexitySearchRequest;
|
|
114
|
-
|
|
110
|
+
|
|
115
111
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/tools.ts"],"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["z"],"sources":["../src/client.ts","../src/search.ts","../src/tools.ts"],"sourcesContent":["export const DEFAULT_BASE_URL = 'https://api.perplexity.ai';\n\nexport type PerplexityClientOptions = {\n /**\n * Perplexity API key. Falls back to `PERPLEXITY_API_KEY` then `PPLX_API_KEY`\n * environment variables when not provided.\n */\n apiKey?: string;\n /**\n * Override the API base URL. Defaults to `https://api.perplexity.ai`.\n */\n baseUrl?: string;\n /**\n * Optional `fetch` implementation. Useful for tests, retries, or instrumentation.\n * Defaults to the global `fetch`.\n */\n fetch?: typeof fetch;\n};\n\nexport type PerplexitySearchResultItem = {\n title: string;\n url: string;\n snippet: string;\n date?: string;\n};\n\nexport type PerplexitySearchResponse = {\n id?: string;\n results: PerplexitySearchResultItem[];\n};\n\nexport type PerplexitySearchRequest = {\n query: string;\n max_results?: number;\n max_tokens_per_page?: number;\n search_domain_filter?: string[];\n search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year';\n search_after_date_filter?: string;\n search_before_date_filter?: string;\n};\n\nfunction resolveApiKey(explicit?: string): string {\n const key = explicit ?? process.env.PERPLEXITY_API_KEY ?? process.env.PPLX_API_KEY;\n if (!key) {\n throw new Error(\n 'Perplexity API key is required. Pass { apiKey } or set the PERPLEXITY_API_KEY (or PPLX_API_KEY) environment variable.',\n );\n }\n return key;\n}\n\nexport async function perplexitySearchRequest(\n body: PerplexitySearchRequest,\n options?: PerplexityClientOptions,\n): Promise<PerplexitySearchResponse> {\n const apiKey = resolveApiKey(options?.apiKey);\n const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;\n const fetchImpl = options?.fetch ?? fetch;\n\n const response = await fetchImpl(`${baseUrl.replace(/\\/$/, '')}/search`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const rawText = await response.text().catch(() => '');\n const MAX_ERROR_BODY = 1000;\n const text =\n rawText.length > MAX_ERROR_BODY ? `${rawText.slice(0, MAX_ERROR_BODY)}…` : rawText;\n throw new Error(\n `Perplexity Search request failed with status ${response.status}${text ? `: ${text}` : ''}`,\n );\n }\n\n const json = (await response.json()) as Partial<PerplexitySearchResponse>;\n return {\n id: json.id,\n results: Array.isArray(json.results) ? json.results : [],\n };\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { perplexitySearchRequest } from './client.js';\nimport type { PerplexityClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query.'),\n maxResults: z\n .number()\n .int()\n .min(1)\n .max(20)\n .optional()\n .describe('Maximum number of results to return (1-20). Defaults to the API default.'),\n searchDomainFilter: z\n .array(z.string())\n .optional()\n .refine(\n domains => {\n if (!domains || domains.length === 0) return true;\n const hasAllow = domains.some(d => !d.startsWith('-'));\n const hasDeny = domains.some(d => d.startsWith('-'));\n return !(hasAllow && hasDeny);\n },\n { message: 'searchDomainFilter cannot mix allow and deny domain entries in the same call.' },\n )\n .describe(\n 'Restrict (or exclude) results by domain. Prefix a domain with `-` to exclude it (e.g. `-pinterest.com`). Do not mix allow and deny entries in the same call.',\n ),\n searchRecencyFilter: z\n .enum(['hour', 'day', 'week', 'month', 'year'])\n .optional()\n .describe('Only return results from within the given recency window.'),\n searchAfterDateFilter: z\n .string()\n .optional()\n .describe('Only return results published on or after this date. Format: m/d/yyyy (e.g. 1/1/2025).'),\n searchBeforeDateFilter: z\n .string()\n .optional()\n .describe('Only return results published on or before this date. Format: m/d/yyyy (e.g. 12/31/2025).'),\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 snippet: z.string(),\n date: z.string().optional(),\n }),\n ),\n});\n\n/**\n * Creates a tool that searches the web using the Perplexity Search API.\n *\n * Returns ranked web results with titles, URLs, snippets, and optional\n * publication dates. Supports filtering by domain (allow- or deny-list),\n * recency, and explicit date ranges.\n *\n * @see https://docs.perplexity.ai/docs/search/quickstart\n */\nexport function createPerplexitySearchTool(config?: PerplexityClientOptions) {\n return createTool({\n id: 'perplexity-search',\n description:\n 'Search the web for up-to-date information using the Perplexity Search API. Returns ranked results with titles, URLs, snippets, and optional publication dates. Supports filtering by domain, recency, and date range.',\n inputSchema,\n outputSchema,\n execute: async input => {\n const response = await perplexitySearchRequest(\n {\n query: input.query,\n max_results: input.maxResults,\n search_domain_filter: input.searchDomainFilter,\n search_recency_filter: input.searchRecencyFilter,\n search_after_date_filter: input.searchAfterDateFilter,\n search_before_date_filter: input.searchBeforeDateFilter,\n },\n config,\n );\n\n return {\n query: input.query,\n results: response.results.map(r => ({\n title: r.title,\n url: r.url,\n snippet: r.snippet,\n date: r.date,\n })),\n };\n },\n });\n}\n","import type { PerplexityClientOptions } from './client.js';\nimport { createPerplexitySearchTool } from './search.js';\n\nexport function createPerplexityTools(config?: PerplexityClientOptions) {\n return {\n perplexitySearch: createPerplexitySearchTool(config),\n };\n}\n"],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -1,110 +1,107 @@
|
|
|
1
|
-
import { createTool } from
|
|
2
|
-
import { z } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var DEFAULT_BASE_URL = "https://api.perplexity.ai";
|
|
1
|
+
import { createTool } from "@mastra/core/tools";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/client.ts
|
|
4
|
+
const DEFAULT_BASE_URL = "https://api.perplexity.ai";
|
|
6
5
|
function resolveApiKey(explicit) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"Perplexity API key is required. Pass { apiKey } or set the PERPLEXITY_API_KEY (or PPLX_API_KEY) environment variable."
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
return key;
|
|
6
|
+
const key = explicit ?? process.env.PERPLEXITY_API_KEY ?? process.env.PPLX_API_KEY;
|
|
7
|
+
if (!key) throw new Error("Perplexity API key is required. Pass { apiKey } or set the PERPLEXITY_API_KEY (or PPLX_API_KEY) environment variable.");
|
|
8
|
+
return key;
|
|
14
9
|
}
|
|
15
10
|
async function perplexitySearchRequest(body, options) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
id: json.id,
|
|
38
|
-
results: Array.isArray(json.results) ? json.results : []
|
|
39
|
-
};
|
|
11
|
+
const apiKey = resolveApiKey(options?.apiKey);
|
|
12
|
+
const baseUrl = options?.baseUrl ?? "https://api.perplexity.ai";
|
|
13
|
+
const response = await (options?.fetch ?? fetch)(`${baseUrl.replace(/\/$/, "")}/search`, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
Authorization: `Bearer ${apiKey}`
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(body)
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const rawText = await response.text().catch(() => "");
|
|
23
|
+
const MAX_ERROR_BODY = 1e3;
|
|
24
|
+
const text = rawText.length > MAX_ERROR_BODY ? `${rawText.slice(0, MAX_ERROR_BODY)}…` : rawText;
|
|
25
|
+
throw new Error(`Perplexity Search request failed with status ${response.status}${text ? `: ${text}` : ""}`);
|
|
26
|
+
}
|
|
27
|
+
const json = await response.json();
|
|
28
|
+
return {
|
|
29
|
+
id: json.id,
|
|
30
|
+
results: Array.isArray(json.results) ? json.results : []
|
|
31
|
+
};
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/search.ts
|
|
35
|
+
const inputSchema = z.object({
|
|
36
|
+
query: z.string().describe("The search query."),
|
|
37
|
+
maxResults: z.number().int().min(1).max(20).optional().describe("Maximum number of results to return (1-20). Defaults to the API default."),
|
|
38
|
+
searchDomainFilter: z.array(z.string()).optional().refine((domains) => {
|
|
39
|
+
if (!domains || domains.length === 0) return true;
|
|
40
|
+
const hasAllow = domains.some((d) => !d.startsWith("-"));
|
|
41
|
+
const hasDeny = domains.some((d) => d.startsWith("-"));
|
|
42
|
+
return !(hasAllow && hasDeny);
|
|
43
|
+
}, { message: "searchDomainFilter cannot mix allow and deny domain entries in the same call." }).describe("Restrict (or exclude) results by domain. Prefix a domain with `-` to exclude it (e.g. `-pinterest.com`). Do not mix allow and deny entries in the same call."),
|
|
44
|
+
searchRecencyFilter: z.enum([
|
|
45
|
+
"hour",
|
|
46
|
+
"day",
|
|
47
|
+
"week",
|
|
48
|
+
"month",
|
|
49
|
+
"year"
|
|
50
|
+
]).optional().describe("Only return results from within the given recency window."),
|
|
51
|
+
searchAfterDateFilter: z.string().optional().describe("Only return results published on or after this date. Format: m/d/yyyy (e.g. 1/1/2025)."),
|
|
52
|
+
searchBeforeDateFilter: z.string().optional().describe("Only return results published on or before this date. Format: m/d/yyyy (e.g. 12/31/2025).")
|
|
58
53
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
-
)
|
|
54
|
+
const outputSchema = z.object({
|
|
55
|
+
query: z.string(),
|
|
56
|
+
results: z.array(z.object({
|
|
57
|
+
title: z.string(),
|
|
58
|
+
url: z.string(),
|
|
59
|
+
snippet: z.string(),
|
|
60
|
+
date: z.string().optional()
|
|
61
|
+
}))
|
|
69
62
|
});
|
|
63
|
+
/**
|
|
64
|
+
* Creates a tool that searches the web using the Perplexity Search API.
|
|
65
|
+
*
|
|
66
|
+
* Returns ranked web results with titles, URLs, snippets, and optional
|
|
67
|
+
* publication dates. Supports filtering by domain (allow- or deny-list),
|
|
68
|
+
* recency, and explicit date ranges.
|
|
69
|
+
*
|
|
70
|
+
* @see https://docs.perplexity.ai/docs/search/quickstart
|
|
71
|
+
*/
|
|
70
72
|
function createPerplexitySearchTool(config) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
});
|
|
73
|
+
return createTool({
|
|
74
|
+
id: "perplexity-search",
|
|
75
|
+
description: "Search the web for up-to-date information using the Perplexity Search API. Returns ranked results with titles, URLs, snippets, and optional publication dates. Supports filtering by domain, recency, and date range.",
|
|
76
|
+
inputSchema,
|
|
77
|
+
outputSchema,
|
|
78
|
+
execute: async (input) => {
|
|
79
|
+
const response = await perplexitySearchRequest({
|
|
80
|
+
query: input.query,
|
|
81
|
+
max_results: input.maxResults,
|
|
82
|
+
search_domain_filter: input.searchDomainFilter,
|
|
83
|
+
search_recency_filter: input.searchRecencyFilter,
|
|
84
|
+
search_after_date_filter: input.searchAfterDateFilter,
|
|
85
|
+
search_before_date_filter: input.searchBeforeDateFilter
|
|
86
|
+
}, config);
|
|
87
|
+
return {
|
|
88
|
+
query: input.query,
|
|
89
|
+
results: response.results.map((r) => ({
|
|
90
|
+
title: r.title,
|
|
91
|
+
url: r.url,
|
|
92
|
+
snippet: r.snippet,
|
|
93
|
+
date: r.date
|
|
94
|
+
}))
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
99
98
|
}
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/tools.ts
|
|
102
101
|
function createPerplexityTools(config) {
|
|
103
|
-
|
|
104
|
-
perplexitySearch: createPerplexitySearchTool(config)
|
|
105
|
-
};
|
|
102
|
+
return { perplexitySearch: createPerplexitySearchTool(config) };
|
|
106
103
|
}
|
|
107
|
-
|
|
104
|
+
//#endregion
|
|
108
105
|
export { DEFAULT_BASE_URL, createPerplexitySearchTool, createPerplexityTools, perplexitySearchRequest };
|
|
109
|
-
|
|
106
|
+
|
|
110
107
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/tools.ts"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/client.ts","../src/search.ts","../src/tools.ts"],"sourcesContent":["export const DEFAULT_BASE_URL = 'https://api.perplexity.ai';\n\nexport type PerplexityClientOptions = {\n /**\n * Perplexity API key. Falls back to `PERPLEXITY_API_KEY` then `PPLX_API_KEY`\n * environment variables when not provided.\n */\n apiKey?: string;\n /**\n * Override the API base URL. Defaults to `https://api.perplexity.ai`.\n */\n baseUrl?: string;\n /**\n * Optional `fetch` implementation. Useful for tests, retries, or instrumentation.\n * Defaults to the global `fetch`.\n */\n fetch?: typeof fetch;\n};\n\nexport type PerplexitySearchResultItem = {\n title: string;\n url: string;\n snippet: string;\n date?: string;\n};\n\nexport type PerplexitySearchResponse = {\n id?: string;\n results: PerplexitySearchResultItem[];\n};\n\nexport type PerplexitySearchRequest = {\n query: string;\n max_results?: number;\n max_tokens_per_page?: number;\n search_domain_filter?: string[];\n search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year';\n search_after_date_filter?: string;\n search_before_date_filter?: string;\n};\n\nfunction resolveApiKey(explicit?: string): string {\n const key = explicit ?? process.env.PERPLEXITY_API_KEY ?? process.env.PPLX_API_KEY;\n if (!key) {\n throw new Error(\n 'Perplexity API key is required. Pass { apiKey } or set the PERPLEXITY_API_KEY (or PPLX_API_KEY) environment variable.',\n );\n }\n return key;\n}\n\nexport async function perplexitySearchRequest(\n body: PerplexitySearchRequest,\n options?: PerplexityClientOptions,\n): Promise<PerplexitySearchResponse> {\n const apiKey = resolveApiKey(options?.apiKey);\n const baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;\n const fetchImpl = options?.fetch ?? fetch;\n\n const response = await fetchImpl(`${baseUrl.replace(/\\/$/, '')}/search`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const rawText = await response.text().catch(() => '');\n const MAX_ERROR_BODY = 1000;\n const text =\n rawText.length > MAX_ERROR_BODY ? `${rawText.slice(0, MAX_ERROR_BODY)}…` : rawText;\n throw new Error(\n `Perplexity Search request failed with status ${response.status}${text ? `: ${text}` : ''}`,\n );\n }\n\n const json = (await response.json()) as Partial<PerplexitySearchResponse>;\n return {\n id: json.id,\n results: Array.isArray(json.results) ? json.results : [],\n };\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { perplexitySearchRequest } from './client.js';\nimport type { PerplexityClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query.'),\n maxResults: z\n .number()\n .int()\n .min(1)\n .max(20)\n .optional()\n .describe('Maximum number of results to return (1-20). Defaults to the API default.'),\n searchDomainFilter: z\n .array(z.string())\n .optional()\n .refine(\n domains => {\n if (!domains || domains.length === 0) return true;\n const hasAllow = domains.some(d => !d.startsWith('-'));\n const hasDeny = domains.some(d => d.startsWith('-'));\n return !(hasAllow && hasDeny);\n },\n { message: 'searchDomainFilter cannot mix allow and deny domain entries in the same call.' },\n )\n .describe(\n 'Restrict (or exclude) results by domain. Prefix a domain with `-` to exclude it (e.g. `-pinterest.com`). Do not mix allow and deny entries in the same call.',\n ),\n searchRecencyFilter: z\n .enum(['hour', 'day', 'week', 'month', 'year'])\n .optional()\n .describe('Only return results from within the given recency window.'),\n searchAfterDateFilter: z\n .string()\n .optional()\n .describe('Only return results published on or after this date. Format: m/d/yyyy (e.g. 1/1/2025).'),\n searchBeforeDateFilter: z\n .string()\n .optional()\n .describe('Only return results published on or before this date. Format: m/d/yyyy (e.g. 12/31/2025).'),\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 snippet: z.string(),\n date: z.string().optional(),\n }),\n ),\n});\n\n/**\n * Creates a tool that searches the web using the Perplexity Search API.\n *\n * Returns ranked web results with titles, URLs, snippets, and optional\n * publication dates. Supports filtering by domain (allow- or deny-list),\n * recency, and explicit date ranges.\n *\n * @see https://docs.perplexity.ai/docs/search/quickstart\n */\nexport function createPerplexitySearchTool(config?: PerplexityClientOptions) {\n return createTool({\n id: 'perplexity-search',\n description:\n 'Search the web for up-to-date information using the Perplexity Search API. Returns ranked results with titles, URLs, snippets, and optional publication dates. Supports filtering by domain, recency, and date range.',\n inputSchema,\n outputSchema,\n execute: async input => {\n const response = await perplexitySearchRequest(\n {\n query: input.query,\n max_results: input.maxResults,\n search_domain_filter: input.searchDomainFilter,\n search_recency_filter: input.searchRecencyFilter,\n search_after_date_filter: input.searchAfterDateFilter,\n search_before_date_filter: input.searchBeforeDateFilter,\n },\n config,\n );\n\n return {\n query: input.query,\n results: response.results.map(r => ({\n title: r.title,\n url: r.url,\n snippet: r.snippet,\n date: r.date,\n })),\n };\n },\n });\n}\n","import type { PerplexityClientOptions } from './client.js';\nimport { createPerplexitySearchTool } from './search.js';\n\nexport function createPerplexityTools(config?: PerplexityClientOptions) {\n return {\n perplexitySearch: createPerplexitySearchTool(config),\n };\n}\n"],"mappings":"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"}
|
package/dist/search.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare function createPerplexitySearchTool(config?: PerplexityClientOpti
|
|
|
12
12
|
query: string;
|
|
13
13
|
maxResults?: number | undefined;
|
|
14
14
|
searchDomainFilter?: string[] | undefined;
|
|
15
|
-
searchRecencyFilter?: "
|
|
15
|
+
searchRecencyFilter?: "day" | "hour" | "month" | "week" | "year" | undefined;
|
|
16
16
|
searchAfterDateFilter?: string | undefined;
|
|
17
17
|
searchBeforeDateFilter?: string | undefined;
|
|
18
18
|
}, {
|
package/dist/tools.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function createPerplexityTools(config?: PerplexityClientOptions):
|
|
|
4
4
|
query: string;
|
|
5
5
|
maxResults?: number | undefined;
|
|
6
6
|
searchDomainFilter?: string[] | undefined;
|
|
7
|
-
searchRecencyFilter?: "
|
|
7
|
+
searchRecencyFilter?: "day" | "hour" | "month" | "week" | "year" | undefined;
|
|
8
8
|
searchAfterDateFilter?: string | undefined;
|
|
9
9
|
searchBeforeDateFilter?: string | undefined;
|
|
10
10
|
}, {
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,uBAAuB
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,uBAAuB;IAElE,gBAAgB;;;;;;;;;;;;;;;;EAEnB"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/perplexity",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-alpha.1",
|
|
4
4
|
"description": "Perplexity Search tool for Mastra agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
"CHANGELOG.md"
|
|
9
|
+
"dist"
|
|
11
10
|
],
|
|
12
11
|
"exports": {
|
|
13
12
|
".": {
|
|
@@ -47,18 +46,19 @@
|
|
|
47
46
|
"zod": ">=3.0.0 || >=4.0.0"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"vitest": "4.1.
|
|
49
|
+
"tsdown": "0.22.9",
|
|
50
|
+
"typescript": "^7.0.2",
|
|
51
|
+
"vitest": "4.1.10",
|
|
53
52
|
"zod": "^4.4.3",
|
|
54
|
-
"@internal/
|
|
55
|
-
"@internal/
|
|
56
|
-
"@mastra/core": "1.
|
|
53
|
+
"@internal/lint": "0.0.129",
|
|
54
|
+
"@internal/types-builder": "0.0.104",
|
|
55
|
+
"@mastra/core": "1.64.0-alpha.7"
|
|
57
56
|
},
|
|
58
57
|
"scripts": {
|
|
59
|
-
"build:lib": "
|
|
58
|
+
"build:lib": "tsdown --silent --config tsdown.config.ts",
|
|
60
59
|
"build:watch": "pnpm build:lib --watch",
|
|
61
|
-
"lint": "eslint .",
|
|
60
|
+
"lint": "oxlint . && eslint .",
|
|
61
|
+
"lint:fix": "oxlint --fix . && eslint --fix .",
|
|
62
62
|
"test": "vitest run"
|
|
63
63
|
}
|
|
64
64
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# @mastra/perplexity
|
|
2
|
-
|
|
3
|
-
## 0.2.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- Random bump ([#18178](https://github.com/mastra-ai/mastra/pull/18178))
|
|
8
|
-
|
|
9
|
-
### Patch Changes
|
|
10
|
-
|
|
11
|
-
- Updated dependencies [[`7c0d868`](https://github.com/mastra-ai/mastra/commit/7c0d868d97d0fdbc04c14d0166dbf44d4c5a4a62), [`d9d2273`](https://github.com/mastra-ai/mastra/commit/d9d2273c702690c9a26eab2aebea879701d4355a), [`b04369d`](https://github.com/mastra-ai/mastra/commit/b04369d6b167c698ef103981171a8bf92808e756), [`8f3c262`](https://github.com/mastra-ai/mastra/commit/8f3c262587b335588a02d96b17fd6aca34c885b3)]:
|
|
12
|
-
- @mastra/core@1.45.0
|
|
13
|
-
|
|
14
|
-
## 0.2.0-alpha.0
|
|
15
|
-
|
|
16
|
-
### Minor Changes
|
|
17
|
-
|
|
18
|
-
- Random bump ([#18178](https://github.com/mastra-ai/mastra/pull/18178))
|
|
19
|
-
|
|
20
|
-
### Patch Changes
|
|
21
|
-
|
|
22
|
-
- Updated dependencies [[`7c0d868`](https://github.com/mastra-ai/mastra/commit/7c0d868d97d0fdbc04c14d0166dbf44d4c5a4a62), [`d9d2273`](https://github.com/mastra-ai/mastra/commit/d9d2273c702690c9a26eab2aebea879701d4355a), [`b04369d`](https://github.com/mastra-ai/mastra/commit/b04369d6b167c698ef103981171a8bf92808e756), [`8f3c262`](https://github.com/mastra-ai/mastra/commit/8f3c262587b335588a02d96b17fd6aca34c885b3)]:
|
|
23
|
-
- @mastra/core@1.45.0-alpha.0
|
|
24
|
-
|
|
25
|
-
## 0.1.3
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- Security remediation for the 2026-06-17 "easy-day-js" supply-chain incident. Patch bump to publish clean versions and move the `latest` dist-tag forward, superseding the compromised versions that declared the malicious `easy-day-js` dependency. ([#18056](https://github.com/mastra-ai/mastra/pull/18056))
|
|
30
|
-
|
|
31
|
-
- Updated dependencies [[`339c57c`](https://github.com/mastra-ai/mastra/commit/339c57c5b2c6dbe75a125e138228e0556528976f), [`1dd4117`](https://github.com/mastra-ai/mastra/commit/1dd4117dcbd8e031ede9f0489436bfbc6f0315b8), [`2b11d1f`](https://github.com/mastra-ai/mastra/commit/2b11d1f6ac7024c5dd2b2dd12a48a956ac9d63bd), [`77a2351`](https://github.com/mastra-ai/mastra/commit/77a2351ee79296e360bce822cb3391f7cfd6489d), [`b7dff0a`](https://github.com/mastra-ai/mastra/commit/b7dff0a3d1022eb6868f48dc40a2b1febd5c277f), [`02087e1`](https://github.com/mastra-ai/mastra/commit/02087e1fbc54aa07f3071f7a200df1bf5be601a8), [`49af8df`](https://github.com/mastra-ai/mastra/commit/49af8df589c4ff71a5015a4553b377b32704b691), [`30ce559`](https://github.com/mastra-ai/mastra/commit/30ce55902ecf819b8ab8697398dd68b108228063), [`c241b92`](https://github.com/mastra-ai/mastra/commit/c241b929dc8c8d6a7b7219c99ed13ac1f3124a77), [`7d6ff70`](https://github.com/mastra-ai/mastra/commit/7d6ff708727297a0526ca0e26e93eeb5bbaaa187), [`ab975d4`](https://github.com/mastra-ai/mastra/commit/ab975d4dd9488752f05bda7afa03166d207e3e2a), [`9d6aa1b`](https://github.com/mastra-ai/mastra/commit/9d6aa1bae407e2afa6a089abc2a6accbbcb287b8)]:
|
|
32
|
-
- @mastra/core@1.44.0
|
|
33
|
-
|
|
34
|
-
## 0.1.3-alpha.0
|
|
35
|
-
|
|
36
|
-
### Patch Changes
|
|
37
|
-
|
|
38
|
-
- Security remediation for the 2026-06-17 "easy-day-js" supply-chain incident. Patch bump to publish clean versions and move the `latest` dist-tag forward, superseding the compromised versions that declared the malicious `easy-day-js` dependency. ([#18056](https://github.com/mastra-ai/mastra/pull/18056))
|
|
39
|
-
|
|
40
|
-
- Updated dependencies [[`77a2351`](https://github.com/mastra-ai/mastra/commit/77a2351ee79296e360bce822cb3391f7cfd6489d)]:
|
|
41
|
-
- @mastra/core@1.43.1-alpha.0
|
|
42
|
-
|
|
43
|
-
## 0.1.0
|
|
44
|
-
|
|
45
|
-
### Minor Changes
|
|
46
|
-
|
|
47
|
-
- Added new `@mastra/perplexity` integration with the Perplexity Search tool for agents. ([#15939](https://github.com/mastra-ai/mastra/pull/15939))
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import { createPerplexityTools } from '@mastra/perplexity';
|
|
51
|
-
|
|
52
|
-
const { perplexitySearch } = createPerplexityTools({ apiKey: process.env.PERPLEXITY_API_KEY });
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Patch Changes
|
|
56
|
-
|
|
57
|
-
- Updated dependencies [[`1723e09`](https://github.com/mastra-ai/mastra/commit/1723e099829892419ddbfe49287acfeac2522724), [`629f9e9`](https://github.com/mastra-ai/mastra/commit/629f9e9a7e56aa8f129515a3923c5813298790c7), [`25168fb`](https://github.com/mastra-ai/mastra/commit/25168fb9c1de9db7f8171df4f58ceb842c53aa29), [`ab34b5a`](https://github.com/mastra-ai/mastra/commit/ab34b5a2191b8e4353df1dbf7b9155e7d6628d79), [`5fb6c2a`](https://github.com/mastra-ai/mastra/commit/5fb6c2a95c1843cc231704b91354311fc1f34a71), [`2b0f355`](https://github.com/mastra-ai/mastra/commit/2b0f3553be3e9e5524da539a66e5cf82668440a4), [`394f0cf`](https://github.com/mastra-ai/mastra/commit/394f0cfc31e6b4d801219fdef2e9cc69e5bc8682), [`b2deb29`](https://github.com/mastra-ai/mastra/commit/b2deb29412b300c868655b5840463614fbb7962d), [`66644be`](https://github.com/mastra-ai/mastra/commit/66644beac1aa560f0e417956ff007c89341dc382), [`e109607`](https://github.com/mastra-ai/mastra/commit/e10960749251e34d46b480a20648c490fd30381b), [`310b953`](https://github.com/mastra-ai/mastra/commit/310b95345f302dcd5ba3ed862bdc96f059d44122), [`3d7f709`](https://github.com/mastra-ai/mastra/commit/3d7f709b615e588050bb6283c4ee5cfe2978cbde), [`48a42f1`](https://github.com/mastra-ai/mastra/commit/48a42f114a4006a95e0b7a1b5ad1a24815a175c2), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006), [`2c83efc`](https://github.com/mastra-ai/mastra/commit/2c83efc4482b3efe50830e3b8b4ba9a8d219edff), [`43f0e1d`](https://github.com/mastra-ai/mastra/commit/43f0e1d5d5a74ba6fc746f2ad89ebe0c64777a7d), [`da0b9e2`](https://github.com/mastra-ai/mastra/commit/da0b9e2ba7ecc560213b426d6c097fe63946086e), [`282a10c`](https://github.com/mastra-ai/mastra/commit/282a10c9446e9922afe80e10e3770481c8ac8a28), [`04151c7`](https://github.com/mastra-ai/mastra/commit/04151c7dcea934b4fe9076708a23fac161195414), [`8091c7c`](https://github.com/mastra-ai/mastra/commit/8091c7c944d15e13fef6d61b6cfd903f158d4006)]:
|
|
58
|
-
- @mastra/core@1.31.0
|
|
59
|
-
|
|
60
|
-
## 0.1.0-alpha.1
|
|
61
|
-
|
|
62
|
-
### Minor Changes
|
|
63
|
-
|
|
64
|
-
- Added new `@mastra/perplexity` integration with the Perplexity Search tool for agents. ([#15939](https://github.com/mastra-ai/mastra/pull/15939))
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
import { createPerplexityTools } from '@mastra/perplexity';
|
|
68
|
-
|
|
69
|
-
const { perplexitySearch } = createPerplexityTools({ apiKey: process.env.PERPLEXITY_API_KEY });
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Patch Changes
|
|
73
|
-
|
|
74
|
-
- Updated dependencies [[`2b0f355`](https://github.com/mastra-ai/mastra/commit/2b0f3553be3e9e5524da539a66e5cf82668440a4)]:
|
|
75
|
-
- @mastra/core@1.31.0-alpha.2
|
|
76
|
-
|
|
77
|
-
## 0.1.0-alpha.0
|
|
78
|
-
|
|
79
|
-
### Minor Changes
|
|
80
|
-
|
|
81
|
-
- Initial release. Adds `createPerplexitySearchTool` and `createPerplexityTools` for the [Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart).
|