@mastra/brightdata 0.0.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/CHANGELOG.md +1 -0
- package/README.md +106 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/fetch.d.ts +8 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/index.cjs +122 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/search.d.ts +15 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/tools.d.ts +23 -0
- package/dist/tools.d.ts.map +1 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @mastra/brightdata
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @mastra/brightdata
|
|
2
|
+
|
|
3
|
+
[Bright Data](https://brightdata.com) web search and web fetch tools for [Mastra](https://mastra.ai) agents.
|
|
4
|
+
|
|
5
|
+
Backed by the official [`@brightdata/sdk`](https://github.com/brightdata/sdk-js). Bright Data's SERP API and Web Unlocker bypass bot detection and CAPTCHAs, so the tools work on sites that block typical scrapers.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mastra/brightdata zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
Use `createBrightDataTools()` to get both tools with a shared configuration:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Agent } from '@mastra/core/agent';
|
|
19
|
+
import { createBrightDataTools } from '@mastra/brightdata';
|
|
20
|
+
|
|
21
|
+
const tools = createBrightDataTools();
|
|
22
|
+
// Or pass an explicit API token:
|
|
23
|
+
// const tools = createBrightDataTools({ apiKey: 'brd_...' });
|
|
24
|
+
|
|
25
|
+
const agent = new Agent({
|
|
26
|
+
id: 'realtime-information-agent',
|
|
27
|
+
name: 'Realtime Information Agent',
|
|
28
|
+
instructions:
|
|
29
|
+
'You are a realtime information agent. Use brightdata-search to find pages, and brightdata-fetch to read them.',
|
|
30
|
+
model: 'anthropic/claude-sonnet-4-6',
|
|
31
|
+
tools,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
By default the tools read `BRIGHTDATA_API_TOKEN` from your environment. You can also pass `{ apiKey }` explicitly.
|
|
36
|
+
|
|
37
|
+
## Individual Tools
|
|
38
|
+
|
|
39
|
+
Each tool can be created independently:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { createBrightDataSearchTool, createBrightDataFetchTool } from '@mastra/brightdata';
|
|
43
|
+
|
|
44
|
+
const search = createBrightDataSearchTool({ apiKey: 'brd_...' });
|
|
45
|
+
const fetch = createBrightDataFetchTool(); // uses BRIGHTDATA_API_TOKEN env var
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Web Search (`brightdata-search`)
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { createBrightDataSearchTool } from '@mastra/brightdata';
|
|
52
|
+
|
|
53
|
+
const searchTool = createBrightDataSearchTool();
|
|
54
|
+
|
|
55
|
+
// When called by an agent, accepts:
|
|
56
|
+
// - query (required)
|
|
57
|
+
// - country: 2-letter code (e.g., 'us', 'gb')
|
|
58
|
+
// - start: result offset for pagination (e.g. 10 for the second page of 10 results)
|
|
59
|
+
//
|
|
60
|
+
// Returns:
|
|
61
|
+
// {
|
|
62
|
+
// query: string,
|
|
63
|
+
// results: Array<{ link, title, description }>,
|
|
64
|
+
// currentPage: number
|
|
65
|
+
// }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Web Fetch (`brightdata-fetch`)
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { createBrightDataFetchTool } from '@mastra/brightdata';
|
|
72
|
+
|
|
73
|
+
const fetchTool = createBrightDataFetchTool();
|
|
74
|
+
|
|
75
|
+
// Accepts: url (required)
|
|
76
|
+
// Returns: { url, content } // content is Markdown
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
| Option | Type | Default | Description |
|
|
82
|
+
|---|---|---|---|
|
|
83
|
+
| `apiKey` | `string` | `process.env.BRIGHTDATA_API_TOKEN` | Your Bright Data API token |
|
|
84
|
+
|
|
85
|
+
All tools accept the full `BrightDataClientOptions` from `@brightdata/sdk` (including `timeout`, `webUnlockerZone`, `serpZone`, `rateLimit`, etc.). If no API token is found, the tool throws a clear error at execution time.
|
|
86
|
+
|
|
87
|
+
## RAG Pairing Example
|
|
88
|
+
|
|
89
|
+
Combine search and fetch for retrieval-augmented generation:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Agent } from '@mastra/core/agent';
|
|
93
|
+
import { createBrightDataTools } from '@mastra/brightdata';
|
|
94
|
+
|
|
95
|
+
const agent = new Agent({
|
|
96
|
+
id: 'rag-agent',
|
|
97
|
+
name: 'Research Assistant',
|
|
98
|
+
model: 'anthropic/claude-sonnet-4-6',
|
|
99
|
+
instructions: `You are a research assistant. Use brightdata-search to find relevant pages, then use brightdata-fetch to get full Markdown content from the best results.`,
|
|
100
|
+
tools: createBrightDataTools(),
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
Apache-2.0
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { bdclient } from '@brightdata/sdk';
|
|
2
|
+
export type BrightDataClientOptions = ConstructorParameters<typeof bdclient>[0];
|
|
3
|
+
export type BrightDataClient = bdclient;
|
|
4
|
+
export declare function getBrightDataClient(config?: BrightDataClientOptions): BrightDataClient;
|
|
5
|
+
export declare function closeClient(client: BrightDataClient): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAChF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAExC,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,gBAAgB,CAQtF;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASzE"}
|
package/dist/fetch.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BrightDataClientOptions } from './client.js';
|
|
2
|
+
export declare function createBrightDataFetchTool(config?: BrightDataClientOptions): import("@mastra/core/tools").Tool<{
|
|
3
|
+
url: string;
|
|
4
|
+
}, {
|
|
5
|
+
url: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-fetch", unknown>;
|
|
8
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAW3D,wBAAgB,yBAAyB,CAAC,MAAM,CAAC,EAAE,uBAAuB;;;;;gIAuBzE"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sdk = require('@brightdata/sdk');
|
|
4
|
+
var tools = require('@mastra/core/tools');
|
|
5
|
+
var zod = require('zod');
|
|
6
|
+
|
|
7
|
+
// src/client.ts
|
|
8
|
+
function getBrightDataClient(config) {
|
|
9
|
+
const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return new sdk.bdclient({ ...config, apiKey });
|
|
16
|
+
}
|
|
17
|
+
async function closeClient(client) {
|
|
18
|
+
const close = client.close;
|
|
19
|
+
if (typeof close === "function") {
|
|
20
|
+
try {
|
|
21
|
+
await close.call(client);
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var inputSchema = zod.z.object({
|
|
27
|
+
query: zod.z.string().describe("The search query"),
|
|
28
|
+
country: zod.z.string().length(2).optional().describe('2-letter country code for geo-targeted results (e.g., "us", "gb")'),
|
|
29
|
+
start: zod.z.number().int().nonnegative().optional().describe("Result offset for pagination (e.g. 10 to get the second page of 10 results)")
|
|
30
|
+
});
|
|
31
|
+
var outputSchema = zod.z.object({
|
|
32
|
+
query: zod.z.string(),
|
|
33
|
+
results: zod.z.array(
|
|
34
|
+
zod.z.object({
|
|
35
|
+
link: zod.z.string(),
|
|
36
|
+
title: zod.z.string(),
|
|
37
|
+
description: zod.z.string()
|
|
38
|
+
})
|
|
39
|
+
),
|
|
40
|
+
currentPage: zod.z.number()
|
|
41
|
+
});
|
|
42
|
+
function createBrightDataSearchTool(config) {
|
|
43
|
+
return tools.createTool({
|
|
44
|
+
id: "brightdata-search",
|
|
45
|
+
description: "Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.",
|
|
46
|
+
inputSchema,
|
|
47
|
+
outputSchema,
|
|
48
|
+
execute: async (input) => {
|
|
49
|
+
const client = getBrightDataClient(config);
|
|
50
|
+
try {
|
|
51
|
+
const rawResponse = await client.search.google(input.query, {
|
|
52
|
+
country: input.country,
|
|
53
|
+
start: input.start
|
|
54
|
+
});
|
|
55
|
+
const response = typeof rawResponse === "string" ? JSON.parse(rawResponse) : rawResponse;
|
|
56
|
+
const organic = Array.isArray(response.organic) ? response.organic : [];
|
|
57
|
+
const results = organic.map((entry) => {
|
|
58
|
+
if (!entry || typeof entry !== "object") return null;
|
|
59
|
+
const e = entry;
|
|
60
|
+
const link = typeof e.link === "string" ? e.link.trim() : "";
|
|
61
|
+
const title = typeof e.title === "string" ? e.title.trim() : "";
|
|
62
|
+
const description = typeof e.description === "string" ? e.description.trim() : "";
|
|
63
|
+
if (!link || !title) return null;
|
|
64
|
+
return { link, title, description };
|
|
65
|
+
}).filter((r) => r !== null);
|
|
66
|
+
const parsedPage = Number(response.current_page);
|
|
67
|
+
const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;
|
|
68
|
+
return {
|
|
69
|
+
query: input.query,
|
|
70
|
+
results,
|
|
71
|
+
currentPage
|
|
72
|
+
};
|
|
73
|
+
} finally {
|
|
74
|
+
await closeClient(client);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
var inputSchema2 = zod.z.object({
|
|
80
|
+
url: zod.z.string().url().describe("The URL to fetch")
|
|
81
|
+
});
|
|
82
|
+
var outputSchema2 = zod.z.object({
|
|
83
|
+
url: zod.z.string(),
|
|
84
|
+
content: zod.z.string().describe("Page content as Markdown")
|
|
85
|
+
});
|
|
86
|
+
function createBrightDataFetchTool(config) {
|
|
87
|
+
return tools.createTool({
|
|
88
|
+
id: "brightdata-fetch",
|
|
89
|
+
description: "Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.",
|
|
90
|
+
inputSchema: inputSchema2,
|
|
91
|
+
outputSchema: outputSchema2,
|
|
92
|
+
execute: async (input) => {
|
|
93
|
+
const client = getBrightDataClient(config);
|
|
94
|
+
try {
|
|
95
|
+
const content = await client.scrapeUrl(input.url, {
|
|
96
|
+
dataFormat: "markdown"
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
url: input.url,
|
|
100
|
+
content
|
|
101
|
+
};
|
|
102
|
+
} finally {
|
|
103
|
+
await closeClient(client);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/tools.ts
|
|
110
|
+
function createBrightDataTools(config) {
|
|
111
|
+
return {
|
|
112
|
+
webSearch: createBrightDataSearchTool(config),
|
|
113
|
+
webFetch: createBrightDataFetchTool(config)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exports.createBrightDataFetchTool = createBrightDataFetchTool;
|
|
118
|
+
exports.createBrightDataSearchTool = createBrightDataSearchTool;
|
|
119
|
+
exports.createBrightDataTools = createBrightDataTools;
|
|
120
|
+
exports.getBrightDataClient = getBrightDataClient;
|
|
121
|
+
//# sourceMappingURL=index.cjs.map
|
|
122
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["bdclient","z","createTool","inputSchema","outputSchema"],"mappings":";;;;;;;AAKO,SAAS,oBAAoB,MAAA,EAAoD;AACtF,EAAA,MAAM,MAAA,GAAS,MAAA,EAAQ,MAAA,IAAU,OAAA,CAAQ,GAAA,CAAI,oBAAA;AAC7C,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,IAAIA,YAAA,CAAS,EAAE,GAAG,MAAA,EAAQ,QAAQ,CAAA;AAC3C;AAEA,eAAsB,YAAY,MAAA,EAAyC;AACzE,EAAA,MAAM,QAAS,MAAA,CAAkD,KAAA;AACjE,EAAA,IAAI,OAAO,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Content":["import { bdclient } from '@brightdata/sdk';\n\nexport type BrightDataClientOptions = ConstructorParameters<typeof bdclient>[0];\nexport type BrightDataClient = bdclient;\n\nexport function getBrightDataClient(config?: BrightDataClientOptions): BrightDataClient {\n const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;\n if (!apiKey) {\n throw new Error(\n 'Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var.',\n );\n }\n return new bdclient({ ...config, apiKey });\n}\n\nexport async function closeClient(client: BrightDataClient): Promise<void> {\n const close = (client as { close?: () => Promise<void> | void }).close;\n if (typeof close === 'function') {\n try {\n await close.call(client);\n } catch {\n // best-effort cleanup; never mask the primary tool error from the finally block\n }\n }\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n country: z\n .string()\n .length(2)\n .optional()\n .describe('2-letter country code for geo-targeted results (e.g., \"us\", \"gb\")'),\n start: z\n .number()\n .int()\n .nonnegative()\n .optional()\n .describe('Result offset for pagination (e.g. 10 to get the second page of 10 results)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n link: z.string(),\n title: z.string(),\n description: z.string(),\n }),\n ),\n currentPage: z.number(),\n});\n\nexport function createBrightDataSearchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-search',\n description:\n \"Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const rawResponse = await client.search.google(input.query, {\n country: input.country,\n start: input.start,\n });\n\n const response: { organic?: unknown; current_page?: unknown } =\n typeof rawResponse === 'string' ? JSON.parse(rawResponse) : rawResponse;\n\n const organic = Array.isArray(response.organic) ? response.organic : [];\n const results = organic\n .map((entry: unknown) => {\n if (!entry || typeof entry !== 'object') return null;\n const e = entry as Record<string, unknown>;\n const link = typeof e.link === 'string' ? e.link.trim() : '';\n const title = typeof e.title === 'string' ? e.title.trim() : '';\n const description = typeof e.description === 'string' ? e.description.trim() : '';\n if (!link || !title) return null;\n return { link, title, description };\n })\n .filter((r): r is { link: string; title: string; description: string } => r !== null);\n\n const parsedPage = Number(response.current_page);\n const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;\n\n return {\n query: input.query,\n results,\n currentPage,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL to fetch'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n content: z.string().describe('Page content as Markdown'),\n});\n\nexport function createBrightDataFetchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-fetch',\n description:\n \"Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const content = await client.scrapeUrl(input.url, {\n dataFormat: 'markdown',\n });\n\n return {\n url: input.url,\n content,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import type { BrightDataClientOptions } from './client.js';\nimport { createBrightDataFetchTool } from './fetch.js';\nimport { createBrightDataSearchTool } from './search.js';\n\nexport function createBrightDataTools(config?: BrightDataClientOptions) {\n return {\n webSearch: createBrightDataSearchTool(config),\n webFetch: createBrightDataFetchTool(config),\n };\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getBrightDataClient, type BrightDataClientOptions, type BrightDataClient } from './client.js';
|
|
2
|
+
export { createBrightDataSearchTool } from './search.js';
|
|
3
|
+
export { createBrightDataFetchTool } from './fetch.js';
|
|
4
|
+
export { createBrightDataTools } from './tools.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { bdclient } from '@brightdata/sdk';
|
|
2
|
+
import { createTool } from '@mastra/core/tools';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
// src/client.ts
|
|
6
|
+
function getBrightDataClient(config) {
|
|
7
|
+
const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;
|
|
8
|
+
if (!apiKey) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return new bdclient({ ...config, apiKey });
|
|
14
|
+
}
|
|
15
|
+
async function closeClient(client) {
|
|
16
|
+
const close = client.close;
|
|
17
|
+
if (typeof close === "function") {
|
|
18
|
+
try {
|
|
19
|
+
await close.call(client);
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var inputSchema = z.object({
|
|
25
|
+
query: z.string().describe("The search query"),
|
|
26
|
+
country: z.string().length(2).optional().describe('2-letter country code for geo-targeted results (e.g., "us", "gb")'),
|
|
27
|
+
start: z.number().int().nonnegative().optional().describe("Result offset for pagination (e.g. 10 to get the second page of 10 results)")
|
|
28
|
+
});
|
|
29
|
+
var outputSchema = z.object({
|
|
30
|
+
query: z.string(),
|
|
31
|
+
results: z.array(
|
|
32
|
+
z.object({
|
|
33
|
+
link: z.string(),
|
|
34
|
+
title: z.string(),
|
|
35
|
+
description: z.string()
|
|
36
|
+
})
|
|
37
|
+
),
|
|
38
|
+
currentPage: z.number()
|
|
39
|
+
});
|
|
40
|
+
function createBrightDataSearchTool(config) {
|
|
41
|
+
return createTool({
|
|
42
|
+
id: "brightdata-search",
|
|
43
|
+
description: "Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.",
|
|
44
|
+
inputSchema,
|
|
45
|
+
outputSchema,
|
|
46
|
+
execute: async (input) => {
|
|
47
|
+
const client = getBrightDataClient(config);
|
|
48
|
+
try {
|
|
49
|
+
const rawResponse = await client.search.google(input.query, {
|
|
50
|
+
country: input.country,
|
|
51
|
+
start: input.start
|
|
52
|
+
});
|
|
53
|
+
const response = typeof rawResponse === "string" ? JSON.parse(rawResponse) : rawResponse;
|
|
54
|
+
const organic = Array.isArray(response.organic) ? response.organic : [];
|
|
55
|
+
const results = organic.map((entry) => {
|
|
56
|
+
if (!entry || typeof entry !== "object") return null;
|
|
57
|
+
const e = entry;
|
|
58
|
+
const link = typeof e.link === "string" ? e.link.trim() : "";
|
|
59
|
+
const title = typeof e.title === "string" ? e.title.trim() : "";
|
|
60
|
+
const description = typeof e.description === "string" ? e.description.trim() : "";
|
|
61
|
+
if (!link || !title) return null;
|
|
62
|
+
return { link, title, description };
|
|
63
|
+
}).filter((r) => r !== null);
|
|
64
|
+
const parsedPage = Number(response.current_page);
|
|
65
|
+
const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;
|
|
66
|
+
return {
|
|
67
|
+
query: input.query,
|
|
68
|
+
results,
|
|
69
|
+
currentPage
|
|
70
|
+
};
|
|
71
|
+
} finally {
|
|
72
|
+
await closeClient(client);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
var inputSchema2 = z.object({
|
|
78
|
+
url: z.string().url().describe("The URL to fetch")
|
|
79
|
+
});
|
|
80
|
+
var outputSchema2 = z.object({
|
|
81
|
+
url: z.string(),
|
|
82
|
+
content: z.string().describe("Page content as Markdown")
|
|
83
|
+
});
|
|
84
|
+
function createBrightDataFetchTool(config) {
|
|
85
|
+
return createTool({
|
|
86
|
+
id: "brightdata-fetch",
|
|
87
|
+
description: "Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.",
|
|
88
|
+
inputSchema: inputSchema2,
|
|
89
|
+
outputSchema: outputSchema2,
|
|
90
|
+
execute: async (input) => {
|
|
91
|
+
const client = getBrightDataClient(config);
|
|
92
|
+
try {
|
|
93
|
+
const content = await client.scrapeUrl(input.url, {
|
|
94
|
+
dataFormat: "markdown"
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
url: input.url,
|
|
98
|
+
content
|
|
99
|
+
};
|
|
100
|
+
} finally {
|
|
101
|
+
await closeClient(client);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/tools.ts
|
|
108
|
+
function createBrightDataTools(config) {
|
|
109
|
+
return {
|
|
110
|
+
webSearch: createBrightDataSearchTool(config),
|
|
111
|
+
webFetch: createBrightDataFetchTool(config)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { createBrightDataFetchTool, createBrightDataSearchTool, createBrightDataTools, getBrightDataClient };
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/search.ts","../src/fetch.ts","../src/tools.ts"],"names":["inputSch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AA,CAAU,MAAM,GAAA,EAAK;AAAA,UAChD,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,KAAK,KAAA,CAAM,GAAA;AAAA,UACX;AAAA,SACF;AAAA,MACF,CAAA,SAAE;AACA,QAAA,MAAM,YAAY,MAAM,CAAA;AAAA,MAC1B;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;AClCO,SAAS,sBAAsB,MAAA,EAAkC;AACtE,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,2BAA2B,MAAM,CAAA;AAAA,IAC5C,QAAA,EAAU,0BAA0B,MAAM;AAAA,GAC5C;AACF","file":"index.js","sourcesContent":["import { bdclient } from '@brightdata/sdk';\n\nexport type BrightDataClientOptions = ConstructorParameters<typeof bdclient>[0];\nexport type BrightDataClient = bdclient;\n\nexport function getBrightDataClient(config?: BrightDataClientOptions): BrightDataClient {\n const apiKey = config?.apiKey ?? process.env.BRIGHTDATA_API_TOKEN;\n if (!apiKey) {\n throw new Error(\n 'Bright Data API token is required. Pass { apiKey } or set BRIGHTDATA_API_TOKEN env var.',\n );\n }\n return new bdclient({ ...config, apiKey });\n}\n\nexport async function closeClient(client: BrightDataClient): Promise<void> {\n const close = (client as { close?: () => Promise<void> | void }).close;\n if (typeof close === 'function') {\n try {\n await close.call(client);\n } catch {\n // best-effort cleanup; never mask the primary tool error from the finally block\n }\n }\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n query: z.string().describe('The search query'),\n country: z\n .string()\n .length(2)\n .optional()\n .describe('2-letter country code for geo-targeted results (e.g., \"us\", \"gb\")'),\n start: z\n .number()\n .int()\n .nonnegative()\n .optional()\n .describe('Result offset for pagination (e.g. 10 to get the second page of 10 results)'),\n});\n\nconst outputSchema = z.object({\n query: z.string(),\n results: z.array(\n z.object({\n link: z.string(),\n title: z.string(),\n description: z.string(),\n }),\n ),\n currentPage: z.number(),\n});\n\nexport function createBrightDataSearchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-search',\n description:\n \"Search Google and get back parsed organic results (link, title, description). Uses Bright Data's SERP API which bypasses bot detection. Supports country targeting and pagination via result offset.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const rawResponse = await client.search.google(input.query, {\n country: input.country,\n start: input.start,\n });\n\n const response: { organic?: unknown; current_page?: unknown } =\n typeof rawResponse === 'string' ? JSON.parse(rawResponse) : rawResponse;\n\n const organic = Array.isArray(response.organic) ? response.organic : [];\n const results = organic\n .map((entry: unknown) => {\n if (!entry || typeof entry !== 'object') return null;\n const e = entry as Record<string, unknown>;\n const link = typeof e.link === 'string' ? e.link.trim() : '';\n const title = typeof e.title === 'string' ? e.title.trim() : '';\n const description = typeof e.description === 'string' ? e.description.trim() : '';\n if (!link || !title) return null;\n return { link, title, description };\n })\n .filter((r): r is { link: string; title: string; description: string } => r !== null);\n\n const parsedPage = Number(response.current_page);\n const currentPage = Number.isFinite(parsedPage) && parsedPage > 0 ? parsedPage : 1;\n\n return {\n query: input.query,\n results,\n currentPage,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { closeClient, getBrightDataClient } from './client.js';\nimport type { BrightDataClientOptions } from './client.js';\n\nconst inputSchema = z.object({\n url: z.string().url().describe('The URL to fetch'),\n});\n\nconst outputSchema = z.object({\n url: z.string(),\n content: z.string().describe('Page content as Markdown'),\n});\n\nexport function createBrightDataFetchTool(config?: BrightDataClientOptions) {\n return createTool({\n id: 'brightdata-fetch',\n description:\n \"Fetch a webpage and return its content as Markdown. Uses Bright Data's Web Unlocker which bypasses bot detection and CAPTCHAs. Pass any URL, including pages that block normal scrapers.\",\n inputSchema,\n outputSchema,\n execute: async input => {\n const client = getBrightDataClient(config);\n try {\n const content = await client.scrapeUrl(input.url, {\n dataFormat: 'markdown',\n });\n\n return {\n url: input.url,\n content,\n };\n } finally {\n await closeClient(client);\n }\n },\n });\n}\n","import type { BrightDataClientOptions } from './client.js';\nimport { createBrightDataFetchTool } from './fetch.js';\nimport { createBrightDataSearchTool } from './search.js';\n\nexport function createBrightDataTools(config?: BrightDataClientOptions) {\n return {\n webSearch: createBrightDataSearchTool(config),\n webFetch: createBrightDataFetchTool(config),\n };\n}\n"]}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BrightDataClientOptions } from './client.js';
|
|
2
|
+
export declare function createBrightDataSearchTool(config?: BrightDataClientOptions): import("@mastra/core/tools").Tool<{
|
|
3
|
+
query: string;
|
|
4
|
+
country?: string | undefined;
|
|
5
|
+
start?: number | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
query: string;
|
|
8
|
+
results: {
|
|
9
|
+
link: string;
|
|
10
|
+
title: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}[];
|
|
13
|
+
currentPage: number;
|
|
14
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-search", unknown>;
|
|
15
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AA6B3D,wBAAgB,0BAA0B,CAAC,MAAM,CAAC,EAAE,uBAAuB;;;;;;;;;;;;iIA4C1E"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BrightDataClientOptions } from './client.js';
|
|
2
|
+
export declare function createBrightDataTools(config?: BrightDataClientOptions): {
|
|
3
|
+
webSearch: import("@mastra/core/tools").Tool<{
|
|
4
|
+
query: string;
|
|
5
|
+
country?: string | undefined;
|
|
6
|
+
start?: number | undefined;
|
|
7
|
+
}, {
|
|
8
|
+
query: string;
|
|
9
|
+
results: {
|
|
10
|
+
link: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description: string;
|
|
13
|
+
}[];
|
|
14
|
+
currentPage: number;
|
|
15
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-search", unknown>;
|
|
16
|
+
webFetch: import("@mastra/core/tools").Tool<{
|
|
17
|
+
url: string;
|
|
18
|
+
}, {
|
|
19
|
+
url: string;
|
|
20
|
+
content: string;
|
|
21
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "brightdata-fetch", unknown>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAI3D,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;EAKrE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mastra/brightdata",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Bright Data web search and web fetch tools for Mastra agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"CHANGELOG.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build:lib": "tsup --silent --config tsup.config.ts",
|
|
27
|
+
"build:watch": "pnpm build:lib --watch",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"mastra",
|
|
33
|
+
"brightdata",
|
|
34
|
+
"brightdata-search",
|
|
35
|
+
"brightdata-fetch",
|
|
36
|
+
"tools",
|
|
37
|
+
"ai-agent"
|
|
38
|
+
],
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
43
|
+
"directory": "integrations/brightdata"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://mastra.ai",
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.13.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@brightdata/sdk": "^1.1.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@mastra/core": ">=1.0.0-0 <2.0.0-0",
|
|
57
|
+
"zod": ">=3.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@internal/lint": "workspace:*",
|
|
61
|
+
"@internal/types-builder": "workspace:*",
|
|
62
|
+
"@mastra/core": "workspace:*",
|
|
63
|
+
"tsup": "^8.5.1",
|
|
64
|
+
"typescript": "catalog:",
|
|
65
|
+
"vitest": "catalog:",
|
|
66
|
+
"zod": "catalog:"
|
|
67
|
+
}
|
|
68
|
+
}
|