@graphai/brave_search_agent 0.0.1 → 2.0.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/README.md +14 -0
- package/lib/brave_search_agent.d.ts +5 -7
- package/lib/brave_search_agent.js +26 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,6 +30,20 @@ const result = await graph.run();
|
|
|
30
30
|
|
|
31
31
|
### Input/Params example
|
|
32
32
|
- braveSearchAgent
|
|
33
|
+
- inputs
|
|
34
|
+
- query(string)
|
|
35
|
+
- The search query to send to Brave Search
|
|
36
|
+
- search_args(object)
|
|
37
|
+
- Additional search parameters to pass to the Brave Search API. See https://api-dashboard.search.brave.com/app/documentation/web-search/query
|
|
38
|
+
- params
|
|
39
|
+
- apiKey(string)
|
|
40
|
+
- Brave Search API key
|
|
41
|
+
- debug(boolean)
|
|
42
|
+
- Enable debug mode
|
|
43
|
+
- supressError(boolean)
|
|
44
|
+
- Suppress error and return onError object if the request fails
|
|
45
|
+
- search_args(object)
|
|
46
|
+
- Additional search parameters to pass to the Brave Search API. See https://api-dashboard.search.brave.com/app/documentation/web-search/query
|
|
33
47
|
|
|
34
48
|
```typescript
|
|
35
49
|
{
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { GraphAIOnError } from "@graphai/agent_utils";
|
|
1
|
+
import { GraphAIOnError, GraphAIDebug, GraphAISupressError } from "@graphai/agent_utils";
|
|
2
2
|
import { AgentFunction, AgentFunctionInfo, DefaultConfigData } from "graphai";
|
|
3
|
-
|
|
3
|
+
type BraveSearchInputs = {
|
|
4
4
|
query: string;
|
|
5
5
|
search_args?: Record<string, any>;
|
|
6
|
-
}
|
|
7
|
-
|
|
6
|
+
};
|
|
7
|
+
type BraveSearchParams = {
|
|
8
8
|
apiKey?: string;
|
|
9
|
-
debug?: boolean;
|
|
10
|
-
throwError?: boolean;
|
|
11
9
|
search_args?: Record<string, any>;
|
|
12
|
-
}
|
|
10
|
+
} & GraphAISupressError & GraphAIDebug;
|
|
13
11
|
interface BraveSearchResult {
|
|
14
12
|
title: string;
|
|
15
13
|
link: string;
|
|
@@ -14,7 +14,7 @@ const getBraveSearchToken = (params, config) => {
|
|
|
14
14
|
const braveSearchAgent = async ({ namedInputs, params, config, }) => {
|
|
15
15
|
const { query, search_args } = namedInputs;
|
|
16
16
|
(0, graphai_1.assert)(!!query, "braveSearchAgent: query is required! set inputs: { query: 'your search query' }");
|
|
17
|
-
const
|
|
17
|
+
const supressError = params?.supressError ?? false;
|
|
18
18
|
const _search_args = search_args ?? params?.search_args ?? {};
|
|
19
19
|
const braveSearchToken = getBraveSearchToken(params, config);
|
|
20
20
|
// Check if API token is provided
|
|
@@ -56,17 +56,17 @@ const braveSearchAgent = async ({ namedInputs, params, config, }) => {
|
|
|
56
56
|
if (!response.ok) {
|
|
57
57
|
const status = response.status;
|
|
58
58
|
const error = await response.text();
|
|
59
|
-
if (
|
|
60
|
-
|
|
59
|
+
if (supressError) {
|
|
60
|
+
return {
|
|
61
|
+
items: [],
|
|
62
|
+
onError: {
|
|
63
|
+
message: `Brave Search HTTP error: ${status}`,
|
|
64
|
+
status,
|
|
65
|
+
error,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
items: [],
|
|
64
|
-
onError: {
|
|
65
|
-
message: `Brave Search HTTP error: ${status}`,
|
|
66
|
-
status,
|
|
67
|
-
error,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
69
|
+
throw new Error(`Brave Search HTTP error: ${status}, ${error}`);
|
|
70
70
|
}
|
|
71
71
|
const jsonResponse = await response.json();
|
|
72
72
|
const webResults = jsonResponse.web?.results || [];
|
|
@@ -80,15 +80,18 @@ const braveSearchAgent = async ({ namedInputs, params, config, }) => {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
catch (error) {
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const isErrorInstance = error instanceof Error;
|
|
84
|
+
const errorMessage = isErrorInstance ? error.message : "Unknown error occurred";
|
|
85
|
+
const errorObject = isErrorInstance ? error : new Error(errorMessage);
|
|
86
|
+
if (supressError) {
|
|
87
|
+
return {
|
|
88
|
+
onError: {
|
|
89
|
+
message: errorMessage,
|
|
90
|
+
error: errorObject.toString(),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
85
93
|
}
|
|
86
|
-
|
|
87
|
-
onError: {
|
|
88
|
-
message: error instanceof Error ? error.message : "Unknown error occurred",
|
|
89
|
-
error: error instanceof Error ? error.toString() : String(error),
|
|
90
|
-
},
|
|
91
|
-
};
|
|
94
|
+
throw errorObject;
|
|
92
95
|
}
|
|
93
96
|
};
|
|
94
97
|
exports.braveSearchAgent = braveSearchAgent;
|
|
@@ -107,9 +110,9 @@ const braveSearchAgentInfo = {
|
|
|
107
110
|
type: "boolean",
|
|
108
111
|
description: "Enable debug mode",
|
|
109
112
|
},
|
|
110
|
-
|
|
113
|
+
supressError: {
|
|
111
114
|
type: "boolean",
|
|
112
|
-
description: "
|
|
115
|
+
description: "Suppress error and return onError object if the request fails",
|
|
113
116
|
},
|
|
114
117
|
search_args: {
|
|
115
118
|
type: "object",
|
|
@@ -215,6 +218,8 @@ const braveSearchAgentInfo = {
|
|
|
215
218
|
category: ["net"],
|
|
216
219
|
author: "kawamataryo",
|
|
217
220
|
repository: "https://github.com/receptron/graphai-agents",
|
|
221
|
+
source: "https://github.com/receptron/graphai-agents/tree/main/net/brave_search_agent/src/brave_search_agent.ts",
|
|
222
|
+
package: "@graphai/brave_search_agent",
|
|
218
223
|
license: "MIT",
|
|
219
224
|
environmentVariables: ["BRAVE_SEARCH_API_TOKEN"],
|
|
220
225
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphai/brave_search_agent",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "An agent that uses the Brave Search API",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/receptron/graphai-agents/blob/main/net/brave_search_agent/README.md",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"undici": "^
|
|
30
|
+
"undici": "^7.21.0"
|
|
31
31
|
},
|
|
32
32
|
"types": "./lib/index.d.ts",
|
|
33
33
|
"directories": {
|