indusagi-coding-agent 0.1.25 → 0.1.26
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 +60 -0
- package/dist/cli/file-processor.js +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -3
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/task-session-manager.d.ts.map +1 -1
- package/dist/core/task-session-manager.js +1 -7
- package/dist/core/task-session-manager.js.map +1 -1
- package/dist/core/tools/bg-process.d.ts +1 -1
- package/dist/core/tools/index.d.ts +57 -50
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +89 -21
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/todo.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/package.json +3 -3
- package/dist/core/tools/bash.d.ts +0 -428
- package/dist/core/tools/bash.d.ts.map +0 -1
- package/dist/core/tools/bash.js +0 -498
- package/dist/core/tools/bash.js.map +0 -1
- package/dist/core/tools/edit-diff.d.ts +0 -63
- package/dist/core/tools/edit-diff.d.ts.map +0 -1
- package/dist/core/tools/edit-diff.js +0 -243
- package/dist/core/tools/edit-diff.js.map +0 -1
- package/dist/core/tools/edit.d.ts +0 -315
- package/dist/core/tools/edit.d.ts.map +0 -1
- package/dist/core/tools/edit.js +0 -384
- package/dist/core/tools/edit.js.map +0 -1
- package/dist/core/tools/find.d.ts +0 -201
- package/dist/core/tools/find.d.ts.map +0 -1
- package/dist/core/tools/find.js +0 -342
- package/dist/core/tools/find.js.map +0 -1
- package/dist/core/tools/grep.d.ts +0 -323
- package/dist/core/tools/grep.d.ts.map +0 -1
- package/dist/core/tools/grep.js +0 -486
- package/dist/core/tools/grep.js.map +0 -1
- package/dist/core/tools/ls.d.ts +0 -44
- package/dist/core/tools/ls.d.ts.map +0 -1
- package/dist/core/tools/ls.js +0 -124
- package/dist/core/tools/ls.js.map +0 -1
- package/dist/core/tools/path-utils.d.ts +0 -8
- package/dist/core/tools/path-utils.d.ts.map +0 -1
- package/dist/core/tools/path-utils.js +0 -53
- package/dist/core/tools/path-utils.js.map +0 -1
- package/dist/core/tools/read.d.ts +0 -338
- package/dist/core/tools/read.d.ts.map +0 -1
- package/dist/core/tools/read.js +0 -397
- package/dist/core/tools/read.js.map +0 -1
- package/dist/core/tools/truncate.d.ts +0 -70
- package/dist/core/tools/truncate.d.ts.map +0 -1
- package/dist/core/tools/truncate.js +0 -205
- package/dist/core/tools/truncate.js.map +0 -1
- package/dist/core/tools/webfetch.d.ts +0 -174
- package/dist/core/tools/webfetch.d.ts.map +0 -1
- package/dist/core/tools/webfetch.js +0 -380
- package/dist/core/tools/webfetch.js.map +0 -1
- package/dist/core/tools/websearch.d.ts +0 -190
- package/dist/core/tools/websearch.d.ts.map +0 -1
- package/dist/core/tools/websearch.js +0 -267
- package/dist/core/tools/websearch.js.map +0 -1
- package/dist/core/tools/write.d.ts +0 -273
- package/dist/core/tools/write.d.ts.map +0 -1
- package/dist/core/tools/write.js +0 -288
- package/dist/core/tools/write.js.map +0 -1
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Web Search Tool - Real-time search using Exa AI API
|
|
3
|
-
*
|
|
4
|
-
* @module core/tools/websearch
|
|
5
|
-
* @description
|
|
6
|
-
* Implements the web search tool for the agent. Performs real-time web searches with:
|
|
7
|
-
* - Query-based information retrieval
|
|
8
|
-
* - Configurable result count
|
|
9
|
-
* - Search type options (fast, deep, auto)
|
|
10
|
-
* - Live crawling options
|
|
11
|
-
* - LLM-optimized context
|
|
12
|
-
* - Exa AI API integration
|
|
13
|
-
*
|
|
14
|
-
* ## Tool Interface
|
|
15
|
-
*
|
|
16
|
-
* **Input Parameters:**
|
|
17
|
-
* - `query` (required): Search query
|
|
18
|
-
* - `numResults` (optional): Number of results (1-10; default: 8)
|
|
19
|
-
* - `livecrawl` (optional): Crawling mode (fallback, preferred; default: fallback)
|
|
20
|
-
* - `type` (optional): Search type (auto, fast, deep; default: auto)
|
|
21
|
-
* - `contextMaxCharacters` (optional): Max context chars (default: 10000)
|
|
22
|
-
*
|
|
23
|
-
* **Output:**
|
|
24
|
-
* - Search results with snippets
|
|
25
|
-
* - URLs and relevance info
|
|
26
|
-
* - LLM-optimized context string
|
|
27
|
-
* - Error if API fails or disabled
|
|
28
|
-
*
|
|
29
|
-
* **Error Behavior:**
|
|
30
|
-
* - No API key: Tool error "Web search not available (no API key)"
|
|
31
|
-
* - Network error: Tool error "Search failed: ..."
|
|
32
|
-
* - API error: Tool error "Search API error: ..."
|
|
33
|
-
* - Timeout: Tool error "Search request timed out"
|
|
34
|
-
*
|
|
35
|
-
* ## Usage in Agent
|
|
36
|
-
*
|
|
37
|
-
* The agent uses this tool to:
|
|
38
|
-
* - Search for current information
|
|
39
|
-
* - Find recent news and events
|
|
40
|
-
* - Look up facts and statistics
|
|
41
|
-
* - Research new topics
|
|
42
|
-
* - Answer questions about current events
|
|
43
|
-
*
|
|
44
|
-
* ## Features
|
|
45
|
-
*
|
|
46
|
-
* **Search Types:**
|
|
47
|
-
* - **auto**: Balanced search (recommended)
|
|
48
|
-
* - **fast**: Quick results, less comprehensive
|
|
49
|
-
* - **deep**: Comprehensive search, more thorough
|
|
50
|
-
*
|
|
51
|
-
* **Live Crawling:**
|
|
52
|
-
* - **fallback**: Use cached content, crawl if needed
|
|
53
|
-
* - **preferred**: Prioritize live crawling for fresh content
|
|
54
|
-
*
|
|
55
|
-
* **LLM Optimization:**
|
|
56
|
-
* - Context formatted for language models
|
|
57
|
-
* - Configurable max characters
|
|
58
|
-
* - Snippets and relevance info included
|
|
59
|
-
* - Structured for easy parsing
|
|
60
|
-
*
|
|
61
|
-
* **Result Limiting:**
|
|
62
|
-
* - Min 1, max 10 results
|
|
63
|
-
* - Default 8 results
|
|
64
|
-
* - Configurable per query
|
|
65
|
-
*
|
|
66
|
-
* ## Security
|
|
67
|
-
*
|
|
68
|
-
* **API Authentication:**
|
|
69
|
-
* - Requires Exa AI API key
|
|
70
|
-
* - Key from environment variable or options
|
|
71
|
-
* - No key = tool not available
|
|
72
|
-
*
|
|
73
|
-
* **Query Validation:**
|
|
74
|
-
* - Non-empty query required
|
|
75
|
-
* - No injection attacks (sent to API as-is)
|
|
76
|
-
* - Safe to include user input
|
|
77
|
-
*
|
|
78
|
-
* **Rate Limiting:**
|
|
79
|
-
* - API enforces rate limits
|
|
80
|
-
* - Errors returned if exceeded
|
|
81
|
-
* - Exponential backoff recommended
|
|
82
|
-
*
|
|
83
|
-
* ## Customization
|
|
84
|
-
*
|
|
85
|
-
* **Custom Search Provider:**
|
|
86
|
-
* ```typescript
|
|
87
|
-
* const customTool = createWebSearchTool({
|
|
88
|
-
* operations: {
|
|
89
|
-
* search: async (request, signal) => {
|
|
90
|
-
* // Custom search implementation
|
|
91
|
-
* return JSON.stringify(results);
|
|
92
|
-
* },
|
|
93
|
-
* },
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* ## Examples
|
|
98
|
-
*
|
|
99
|
-
* ### Basic search
|
|
100
|
-
* ```typescript
|
|
101
|
-
* // Agent calls: websearch {query: "latest news about AI"}
|
|
102
|
-
* // Returns: Top 8 news results
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* ### Deep search with more results
|
|
106
|
-
* ```typescript
|
|
107
|
-
* // Agent calls: websearch {
|
|
108
|
-
* // query: "TypeScript generics best practices",
|
|
109
|
-
* // numResults: 10,
|
|
110
|
-
* // type: "deep"
|
|
111
|
-
* // }
|
|
112
|
-
* // Returns: 10 comprehensive results
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* ### Fast search with live crawling
|
|
116
|
-
* ```typescript
|
|
117
|
-
* // Agent calls: websearch {
|
|
118
|
-
* // query: "stock market today",
|
|
119
|
-
* // type: "fast",
|
|
120
|
-
* // livecrawl: "preferred"
|
|
121
|
-
* // }
|
|
122
|
-
* // Returns: Quick results with live data
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* ## Attribution
|
|
126
|
-
*
|
|
127
|
-
* Based on: indusagi-agent websearch tool
|
|
128
|
-
* Modifications:
|
|
129
|
-
* - Added search type options
|
|
130
|
-
* - Added live crawl configuration
|
|
131
|
-
* - Added context optimization
|
|
132
|
-
* - Improved error handling
|
|
133
|
-
*/
|
|
134
|
-
import type { AgentTool } from "indusagi/agent";
|
|
135
|
-
declare const webSearchSchema: import("@sinclair/typebox").TObject<{
|
|
136
|
-
query: import("@sinclair/typebox").TString;
|
|
137
|
-
numResults: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
138
|
-
livecrawl: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"fallback">, import("@sinclair/typebox").TLiteral<"preferred">]>>;
|
|
139
|
-
type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"auto">, import("@sinclair/typebox").TLiteral<"fast">, import("@sinclair/typebox").TLiteral<"deep">]>>;
|
|
140
|
-
contextMaxCharacters: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
141
|
-
}>;
|
|
142
|
-
export interface WebSearchToolDetails {
|
|
143
|
-
query: string;
|
|
144
|
-
numResults?: number;
|
|
145
|
-
livecrawl?: "fallback" | "preferred";
|
|
146
|
-
type?: "auto" | "fast" | "deep";
|
|
147
|
-
contextMaxCharacters?: number;
|
|
148
|
-
}
|
|
149
|
-
export interface WebSearchToolOptions {
|
|
150
|
-
/** Custom API base URL (for testing or alternative endpoints) */
|
|
151
|
-
baseUrl?: string;
|
|
152
|
-
/** API key for Exa AI (if required) */
|
|
153
|
-
apiKey?: string;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Pluggable operations for the web search tool.
|
|
157
|
-
* Override these to delegate search to alternative providers.
|
|
158
|
-
*/
|
|
159
|
-
export interface WebSearchOperations {
|
|
160
|
-
/**
|
|
161
|
-
* Execute a web search query
|
|
162
|
-
*/
|
|
163
|
-
search: (request: McpSearchRequest, signal?: AbortSignal) => Promise<string>;
|
|
164
|
-
}
|
|
165
|
-
interface McpSearchRequest {
|
|
166
|
-
jsonrpc: string;
|
|
167
|
-
id: number;
|
|
168
|
-
method: string;
|
|
169
|
-
params: {
|
|
170
|
-
name: string;
|
|
171
|
-
arguments: {
|
|
172
|
-
query: string;
|
|
173
|
-
numResults?: number;
|
|
174
|
-
livecrawl?: "fallback" | "preferred";
|
|
175
|
-
type?: "auto" | "fast" | "deep";
|
|
176
|
-
contextMaxCharacters?: number;
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
export declare function createWebSearchTool(options?: WebSearchToolOptions): AgentTool<typeof webSearchSchema>;
|
|
181
|
-
/** Default web search tool */
|
|
182
|
-
export declare const webSearchTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
183
|
-
query: import("@sinclair/typebox").TString;
|
|
184
|
-
numResults: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
185
|
-
livecrawl: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"fallback">, import("@sinclair/typebox").TLiteral<"preferred">]>>;
|
|
186
|
-
type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"auto">, import("@sinclair/typebox").TLiteral<"fast">, import("@sinclair/typebox").TLiteral<"deep">]>>;
|
|
187
|
-
contextMaxCharacters: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
188
|
-
}>, any>;
|
|
189
|
-
export {};
|
|
190
|
-
//# sourceMappingURL=websearch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websearch.d.ts","sourceRoot":"","sources":["../../../src/core/tools/websearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAYhD,QAAA,MAAM,eAAe;;;;;;EA6BnB,CAAC;AAEH,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACpC,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7E;AAED,UAAU,gBAAgB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE;YACV,KAAK,EAAE,MAAM,CAAC;YACd,UAAU,CAAC,EAAE,MAAM,CAAC;YACpB,SAAS,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;YACrC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;YAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;SAC9B,CAAC;KACF,CAAC;CACF;AAqED,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC,OAAO,eAAe,CAAC,CAoErG;AAED,8BAA8B;AAC9B,eAAO,MAAM,aAAa;;;;;;QAAwB,CAAC"}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Web Search Tool - Real-time search using Exa AI API
|
|
3
|
-
*
|
|
4
|
-
* @module core/tools/websearch
|
|
5
|
-
* @description
|
|
6
|
-
* Implements the web search tool for the agent. Performs real-time web searches with:
|
|
7
|
-
* - Query-based information retrieval
|
|
8
|
-
* - Configurable result count
|
|
9
|
-
* - Search type options (fast, deep, auto)
|
|
10
|
-
* - Live crawling options
|
|
11
|
-
* - LLM-optimized context
|
|
12
|
-
* - Exa AI API integration
|
|
13
|
-
*
|
|
14
|
-
* ## Tool Interface
|
|
15
|
-
*
|
|
16
|
-
* **Input Parameters:**
|
|
17
|
-
* - `query` (required): Search query
|
|
18
|
-
* - `numResults` (optional): Number of results (1-10; default: 8)
|
|
19
|
-
* - `livecrawl` (optional): Crawling mode (fallback, preferred; default: fallback)
|
|
20
|
-
* - `type` (optional): Search type (auto, fast, deep; default: auto)
|
|
21
|
-
* - `contextMaxCharacters` (optional): Max context chars (default: 10000)
|
|
22
|
-
*
|
|
23
|
-
* **Output:**
|
|
24
|
-
* - Search results with snippets
|
|
25
|
-
* - URLs and relevance info
|
|
26
|
-
* - LLM-optimized context string
|
|
27
|
-
* - Error if API fails or disabled
|
|
28
|
-
*
|
|
29
|
-
* **Error Behavior:**
|
|
30
|
-
* - No API key: Tool error "Web search not available (no API key)"
|
|
31
|
-
* - Network error: Tool error "Search failed: ..."
|
|
32
|
-
* - API error: Tool error "Search API error: ..."
|
|
33
|
-
* - Timeout: Tool error "Search request timed out"
|
|
34
|
-
*
|
|
35
|
-
* ## Usage in Agent
|
|
36
|
-
*
|
|
37
|
-
* The agent uses this tool to:
|
|
38
|
-
* - Search for current information
|
|
39
|
-
* - Find recent news and events
|
|
40
|
-
* - Look up facts and statistics
|
|
41
|
-
* - Research new topics
|
|
42
|
-
* - Answer questions about current events
|
|
43
|
-
*
|
|
44
|
-
* ## Features
|
|
45
|
-
*
|
|
46
|
-
* **Search Types:**
|
|
47
|
-
* - **auto**: Balanced search (recommended)
|
|
48
|
-
* - **fast**: Quick results, less comprehensive
|
|
49
|
-
* - **deep**: Comprehensive search, more thorough
|
|
50
|
-
*
|
|
51
|
-
* **Live Crawling:**
|
|
52
|
-
* - **fallback**: Use cached content, crawl if needed
|
|
53
|
-
* - **preferred**: Prioritize live crawling for fresh content
|
|
54
|
-
*
|
|
55
|
-
* **LLM Optimization:**
|
|
56
|
-
* - Context formatted for language models
|
|
57
|
-
* - Configurable max characters
|
|
58
|
-
* - Snippets and relevance info included
|
|
59
|
-
* - Structured for easy parsing
|
|
60
|
-
*
|
|
61
|
-
* **Result Limiting:**
|
|
62
|
-
* - Min 1, max 10 results
|
|
63
|
-
* - Default 8 results
|
|
64
|
-
* - Configurable per query
|
|
65
|
-
*
|
|
66
|
-
* ## Security
|
|
67
|
-
*
|
|
68
|
-
* **API Authentication:**
|
|
69
|
-
* - Requires Exa AI API key
|
|
70
|
-
* - Key from environment variable or options
|
|
71
|
-
* - No key = tool not available
|
|
72
|
-
*
|
|
73
|
-
* **Query Validation:**
|
|
74
|
-
* - Non-empty query required
|
|
75
|
-
* - No injection attacks (sent to API as-is)
|
|
76
|
-
* - Safe to include user input
|
|
77
|
-
*
|
|
78
|
-
* **Rate Limiting:**
|
|
79
|
-
* - API enforces rate limits
|
|
80
|
-
* - Errors returned if exceeded
|
|
81
|
-
* - Exponential backoff recommended
|
|
82
|
-
*
|
|
83
|
-
* ## Customization
|
|
84
|
-
*
|
|
85
|
-
* **Custom Search Provider:**
|
|
86
|
-
* ```typescript
|
|
87
|
-
* const customTool = createWebSearchTool({
|
|
88
|
-
* operations: {
|
|
89
|
-
* search: async (request, signal) => {
|
|
90
|
-
* // Custom search implementation
|
|
91
|
-
* return JSON.stringify(results);
|
|
92
|
-
* },
|
|
93
|
-
* },
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* ## Examples
|
|
98
|
-
*
|
|
99
|
-
* ### Basic search
|
|
100
|
-
* ```typescript
|
|
101
|
-
* // Agent calls: websearch {query: "latest news about AI"}
|
|
102
|
-
* // Returns: Top 8 news results
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* ### Deep search with more results
|
|
106
|
-
* ```typescript
|
|
107
|
-
* // Agent calls: websearch {
|
|
108
|
-
* // query: "TypeScript generics best practices",
|
|
109
|
-
* // numResults: 10,
|
|
110
|
-
* // type: "deep"
|
|
111
|
-
* // }
|
|
112
|
-
* // Returns: 10 comprehensive results
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* ### Fast search with live crawling
|
|
116
|
-
* ```typescript
|
|
117
|
-
* // Agent calls: websearch {
|
|
118
|
-
* // query: "stock market today",
|
|
119
|
-
* // type: "fast",
|
|
120
|
-
* // livecrawl: "preferred"
|
|
121
|
-
* // }
|
|
122
|
-
* // Returns: Quick results with live data
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* ## Attribution
|
|
126
|
-
*
|
|
127
|
-
* Based on: indusagi-agent websearch tool
|
|
128
|
-
* Modifications:
|
|
129
|
-
* - Added search type options
|
|
130
|
-
* - Added live crawl configuration
|
|
131
|
-
* - Added context optimization
|
|
132
|
-
* - Improved error handling
|
|
133
|
-
*/
|
|
134
|
-
import { Type } from "@sinclair/typebox";
|
|
135
|
-
const API_CONFIG = {
|
|
136
|
-
BASE_URL: "https://mcp.exa.ai",
|
|
137
|
-
ENDPOINTS: {
|
|
138
|
-
SEARCH: "/mcp",
|
|
139
|
-
},
|
|
140
|
-
DEFAULT_NUM_RESULTS: 8,
|
|
141
|
-
};
|
|
142
|
-
const webSearchSchema = Type.Object({
|
|
143
|
-
query: Type.String({ description: "Web search query" }),
|
|
144
|
-
numResults: Type.Optional(Type.Number({ description: "Number of search results to return (default: 8, max: 10)" })),
|
|
145
|
-
livecrawl: Type.Optional(Type.Union([
|
|
146
|
-
Type.Literal("fallback"),
|
|
147
|
-
Type.Literal("preferred"),
|
|
148
|
-
], {
|
|
149
|
-
description: "Live crawl mode - 'fallback': use live crawling as backup if cached content unavailable, 'preferred': prioritize live crawling (default: 'fallback')",
|
|
150
|
-
})),
|
|
151
|
-
type: Type.Optional(Type.Union([
|
|
152
|
-
Type.Literal("auto"),
|
|
153
|
-
Type.Literal("fast"),
|
|
154
|
-
Type.Literal("deep"),
|
|
155
|
-
], {
|
|
156
|
-
description: "Search type - 'auto': balanced search (default), 'fast': quick results, 'deep': comprehensive search",
|
|
157
|
-
})),
|
|
158
|
-
contextMaxCharacters: Type.Optional(Type.Number({
|
|
159
|
-
description: "Maximum characters for context string optimized for LLMs (default: 10000)",
|
|
160
|
-
})),
|
|
161
|
-
});
|
|
162
|
-
const defaultWebSearchOperations = {
|
|
163
|
-
search: async (request, signal) => {
|
|
164
|
-
const baseUrl = API_CONFIG.BASE_URL;
|
|
165
|
-
const endpoint = API_CONFIG.ENDPOINTS.SEARCH;
|
|
166
|
-
const headers = {
|
|
167
|
-
accept: "application/json, text/event-stream",
|
|
168
|
-
"content-type": "application/json",
|
|
169
|
-
};
|
|
170
|
-
const response = await fetch(`${baseUrl}${endpoint}`, {
|
|
171
|
-
method: "POST",
|
|
172
|
-
headers,
|
|
173
|
-
body: JSON.stringify(request),
|
|
174
|
-
signal,
|
|
175
|
-
});
|
|
176
|
-
if (!response.ok) {
|
|
177
|
-
const errorText = await response.text();
|
|
178
|
-
throw new Error(`Search error (${response.status}): ${errorText}`);
|
|
179
|
-
}
|
|
180
|
-
const responseText = await response.text();
|
|
181
|
-
// Parse SSE response
|
|
182
|
-
const lines = responseText.split("\n");
|
|
183
|
-
for (const line of lines) {
|
|
184
|
-
if (line.startsWith("data: ")) {
|
|
185
|
-
const data = JSON.parse(line.substring(6));
|
|
186
|
-
if (data.result && data.result.content && data.result.content.length > 0) {
|
|
187
|
-
return data.result.content[0].text;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return "";
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
function createSearchRequest(params) {
|
|
195
|
-
return {
|
|
196
|
-
jsonrpc: "2.0",
|
|
197
|
-
id: 1,
|
|
198
|
-
method: "tools/call",
|
|
199
|
-
params: {
|
|
200
|
-
name: "web_search_exa",
|
|
201
|
-
arguments: {
|
|
202
|
-
query: params.query,
|
|
203
|
-
type: params.type || "auto",
|
|
204
|
-
numResults: Math.min(params.numResults || API_CONFIG.DEFAULT_NUM_RESULTS, 10),
|
|
205
|
-
livecrawl: params.livecrawl || "fallback",
|
|
206
|
-
contextMaxCharacters: params.contextMaxCharacters,
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
export function createWebSearchTool(options) {
|
|
212
|
-
const baseUrl = options?.baseUrl || API_CONFIG.BASE_URL;
|
|
213
|
-
return {
|
|
214
|
-
name: "websearch",
|
|
215
|
-
label: "websearch",
|
|
216
|
-
description: "Search the web using Exa AI - performs real-time web searches and can scrape content from specific URLs. Provides up-to-date information for current events and recent data. Supports configurable result counts and returns the content from the most relevant websites. Use this tool for accessing information beyond knowledge cutoff. The current year is 2026. You MUST use this year when searching for recent information or current events (e.g., search for 'AI news 2026', NOT 'AI news 2025').",
|
|
217
|
-
parameters: webSearchSchema,
|
|
218
|
-
execute: async (_toolCallId, params, signal) => {
|
|
219
|
-
// Check if already aborted
|
|
220
|
-
if (signal?.aborted) {
|
|
221
|
-
throw new Error("Web search aborted");
|
|
222
|
-
}
|
|
223
|
-
const details = {
|
|
224
|
-
query: params.query,
|
|
225
|
-
numResults: params.numResults,
|
|
226
|
-
livecrawl: params.livecrawl,
|
|
227
|
-
type: params.type,
|
|
228
|
-
contextMaxCharacters: params.contextMaxCharacters,
|
|
229
|
-
};
|
|
230
|
-
// Build request
|
|
231
|
-
const request = createSearchRequest(details);
|
|
232
|
-
// Execute search
|
|
233
|
-
let resultText;
|
|
234
|
-
try {
|
|
235
|
-
resultText = await defaultWebSearchOperations.search(request, signal);
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
if (error.name === "AbortError") {
|
|
239
|
-
throw new Error("Web search request timed out or was aborted");
|
|
240
|
-
}
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
// Build output
|
|
244
|
-
let content;
|
|
245
|
-
if (!resultText || resultText.trim() === "") {
|
|
246
|
-
content = [
|
|
247
|
-
{
|
|
248
|
-
type: "text",
|
|
249
|
-
text: "No search results found. Please try a different query.",
|
|
250
|
-
},
|
|
251
|
-
];
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
content = [
|
|
255
|
-
{
|
|
256
|
-
type: "text",
|
|
257
|
-
text: resultText,
|
|
258
|
-
},
|
|
259
|
-
];
|
|
260
|
-
}
|
|
261
|
-
return { content, details };
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
/** Default web search tool */
|
|
266
|
-
export const webSearchTool = createWebSearchTool();
|
|
267
|
-
//# sourceMappingURL=websearch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websearch.js","sourceRoot":"","sources":["../../../src/core/tools/websearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoIG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,UAAU,GAAG;IAClB,QAAQ,EAAE,oBAAoB;IAC9B,SAAS,EAAE;QACV,MAAM,EAAE,MAAM;KACd;IACD,mBAAmB,EAAE,CAAC;CACb,CAAC;AAEX,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IACvD,UAAU,EAAE,IAAI,CAAC,QAAQ,CACxB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,0DAA0D,EAAE,CAAC,CACxF;IACD,SAAS,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,KAAK,CAAC;QACV,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;KACzB,EAAE;QACF,WAAW,EACV,sJAAsJ;KACvJ,CAAC,CACF;IACD,IAAI,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,KAAK,CAAC;QACV,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;KACpB,EAAE;QACF,WAAW,EACV,sGAAsG;KACvG,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