@elizaos/plugin-web-search 0.1.7-alpha.2 → 0.1.8-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/README.MD +225 -0
- package/package.json +31 -17
- package/Readme.md +0 -180
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -576
- package/dist/index.js.map +0 -1
- package/tsup.config.ts +0 -21
package/README.MD
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @elizaos/plugin-web-search
|
|
2
|
+
|
|
3
|
+
A plugin for powerful web search capabilities, providing efficient search query handling and result processing through a customizable API interface.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This plugin provides functionality to:
|
|
8
|
+
|
|
9
|
+
- Execute web search queries with customizable parameters
|
|
10
|
+
- Process and format search results
|
|
11
|
+
- Handle search API authentication
|
|
12
|
+
- Manage token limits and response sizes
|
|
13
|
+
- Optimize query performance
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm install @elizaos/plugin-web-search
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
The plugin requires the following environment variables:
|
|
24
|
+
|
|
25
|
+
```env
|
|
26
|
+
TAVILY_API_KEY=your_api_key # Required: API key for search service
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Import and register the plugin in your Eliza configuration:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { webSearchPlugin } from "@elizaos/plugin-web-search";
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
plugins: [webSearchPlugin],
|
|
38
|
+
// ... other configuration
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
### Web Search
|
|
45
|
+
|
|
46
|
+
The plugin provides comprehensive web search capabilities:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { webSearch } from "@elizaos/plugin-web-search";
|
|
50
|
+
|
|
51
|
+
// Execute a search query
|
|
52
|
+
const result = await webSearch.handler(
|
|
53
|
+
runtime,
|
|
54
|
+
{
|
|
55
|
+
content: { text: "What is the latest news about AI?" },
|
|
56
|
+
},
|
|
57
|
+
state,
|
|
58
|
+
{},
|
|
59
|
+
callback
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Token Management
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// The plugin automatically handles token limits
|
|
67
|
+
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;
|
|
68
|
+
|
|
69
|
+
// Example of token-limited response
|
|
70
|
+
const response = MaxTokens(searchResult, DEFAULT_MAX_WEB_SEARCH_TOKENS);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
### Building
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm run build
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Testing
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pnpm run test
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Development Mode
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm run dev
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Dependencies
|
|
94
|
+
|
|
95
|
+
- `@elizaos/core`: Core Eliza functionality
|
|
96
|
+
- `js-tiktoken`: Token counting and management
|
|
97
|
+
- `tsup`: Build tool
|
|
98
|
+
- Other standard dependencies listed in package.json
|
|
99
|
+
|
|
100
|
+
## API Reference
|
|
101
|
+
|
|
102
|
+
### Core Interfaces
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface Action {
|
|
106
|
+
name: "WEB_SEARCH";
|
|
107
|
+
similes: string[];
|
|
108
|
+
description: string;
|
|
109
|
+
validate: (runtime: IAgentRuntime, message: Memory) => Promise<boolean>;
|
|
110
|
+
handler: (
|
|
111
|
+
runtime: IAgentRuntime,
|
|
112
|
+
message: Memory,
|
|
113
|
+
state: State,
|
|
114
|
+
options: any,
|
|
115
|
+
callback: HandlerCallback
|
|
116
|
+
) => Promise<void>;
|
|
117
|
+
examples: Array<Array<any>>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface SearchResult {
|
|
121
|
+
title: string;
|
|
122
|
+
url: string;
|
|
123
|
+
answer?: string;
|
|
124
|
+
results?: Array<{
|
|
125
|
+
title: string;
|
|
126
|
+
url: string;
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Plugin Methods
|
|
132
|
+
|
|
133
|
+
- `webSearch.handler`: Main method for executing searches
|
|
134
|
+
- `generateWebSearch`: Core search generation function
|
|
135
|
+
- `MaxTokens`: Token limit management function
|
|
136
|
+
- `getTotalTokensFromString`: Token counting utility
|
|
137
|
+
|
|
138
|
+
## Common Issues/Troubleshooting
|
|
139
|
+
|
|
140
|
+
### Issue: API Authentication Failures
|
|
141
|
+
|
|
142
|
+
- **Cause**: Invalid or missing Tavily API key
|
|
143
|
+
- **Solution**: Verify TAVILY_API_KEY environment variable
|
|
144
|
+
|
|
145
|
+
### Issue: Token Limit Exceeded
|
|
146
|
+
|
|
147
|
+
- **Cause**: Search results exceeding maximum token limit
|
|
148
|
+
- **Solution**: Results are automatically truncated to fit within limits
|
|
149
|
+
|
|
150
|
+
### Issue: Search Rate Limiting
|
|
151
|
+
|
|
152
|
+
- **Cause**: Too many requests in short time
|
|
153
|
+
- **Solution**: Implement proper request throttling
|
|
154
|
+
|
|
155
|
+
## Security Best Practices
|
|
156
|
+
|
|
157
|
+
- Store API keys securely using environment variables
|
|
158
|
+
- Validate all search inputs
|
|
159
|
+
- Implement proper error handling
|
|
160
|
+
- Keep dependencies updated
|
|
161
|
+
- Monitor API usage and rate limits
|
|
162
|
+
- Use HTTPS for API communication
|
|
163
|
+
|
|
164
|
+
## Example Usage
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// Basic search
|
|
168
|
+
const searchQuery = "Latest developments in quantum computing";
|
|
169
|
+
const results = await generateWebSearch(searchQuery, runtime);
|
|
170
|
+
|
|
171
|
+
// With formatted response
|
|
172
|
+
if (results && results.results.length) {
|
|
173
|
+
const formattedResponse = `${results.answer}\n\nFor more details, check out:\n${results.results
|
|
174
|
+
.map(
|
|
175
|
+
(result, index) => `${index + 1}. [${result.title}](${result.url})`
|
|
176
|
+
)
|
|
177
|
+
.join("\n")}`;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Configuration Options
|
|
182
|
+
|
|
183
|
+
### Token Management
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo";
|
|
187
|
+
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Search Actions
|
|
191
|
+
|
|
192
|
+
The plugin includes multiple search action similes:
|
|
193
|
+
|
|
194
|
+
- SEARCH_WEB
|
|
195
|
+
- INTERNET_SEARCH
|
|
196
|
+
- LOOKUP
|
|
197
|
+
- QUERY_WEB
|
|
198
|
+
- FIND_ONLINE
|
|
199
|
+
- And more...
|
|
200
|
+
|
|
201
|
+
## Contributing
|
|
202
|
+
|
|
203
|
+
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
|
|
204
|
+
|
|
205
|
+
## Credits
|
|
206
|
+
|
|
207
|
+
This plugin integrates with and builds upon several key technologies:
|
|
208
|
+
|
|
209
|
+
- [Tavily API](https://tavily.com/): Advanced search and content analysis API
|
|
210
|
+
- [js-tiktoken](https://github.com/dqbd/tiktoken): Token counting for API responses
|
|
211
|
+
- [Zod](https://github.com/colinhacks/zod): TypeScript-first schema validation
|
|
212
|
+
|
|
213
|
+
Special thanks to:
|
|
214
|
+
|
|
215
|
+
- The Eliza community for their contributions and feedback
|
|
216
|
+
|
|
217
|
+
For more information about the search capabilities and tools:
|
|
218
|
+
|
|
219
|
+
- [Tavily API Documentation](https://docs.tavily.com/)
|
|
220
|
+
- [Token Management Guide](https://github.com/dqbd/tiktoken#readme)
|
|
221
|
+
- [Search API Best Practices](https://docs.tavily.com/docs/guides/best-practices)
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
This plugin is part of the Eliza project. See the main project repository for license information.
|
package/package.json
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
"name": "@elizaos/plugin-web-search",
|
|
3
|
+
"version": "0.1.8-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"@elizaos/source": "./src/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@elizaos/core": "0.1.8-alpha.1",
|
|
23
|
+
"tsup": "8.3.5"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup --format esm --dts",
|
|
27
|
+
"dev": "tsup --format esm --dts --watch"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"whatwg-url": "7.1.0"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "d5f2924d866c21b54543637b694695bd1f410621"
|
|
19
33
|
}
|
package/Readme.md
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# Plugin Web Search
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The Web Search Plugin enables powerful and customizable web search capabilities, offering flexibility and ease of integration for modern applications.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- Efficient search query handling.
|
|
10
|
-
- Configurable options for advanced customization.
|
|
11
|
-
- Optimized for performance and scalability.
|
|
12
|
-
|
|
13
|
-
## Handlers
|
|
14
|
-
|
|
15
|
-
### `search`
|
|
16
|
-
|
|
17
|
-
The `search` handler executes web search queries with specified parameters, returning results in a structured format.
|
|
18
|
-
|
|
19
|
-
#### Usage
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { WebSearch } from 'web-search-plugin';
|
|
23
|
-
|
|
24
|
-
const search = new WebSearch({
|
|
25
|
-
apiEndpoint: 'https://api.example.com/search',
|
|
26
|
-
timeout: 5000,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const results = await search.query('example query', {
|
|
31
|
-
limit: 10,
|
|
32
|
-
sortBy: 'relevance',
|
|
33
|
-
});
|
|
34
|
-
console.log('Search Results:', results);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error('Search failed:', error);
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Features
|
|
41
|
-
|
|
42
|
-
- **Query Customization**: Specify query parameters such as `limit` and `sortBy`.
|
|
43
|
-
- **Error Handling**: Handles common search errors gracefully.
|
|
44
|
-
|
|
45
|
-
## Configuration
|
|
46
|
-
|
|
47
|
-
### Environment Variables
|
|
48
|
-
|
|
49
|
-
Set the following environment variables for optimal performance:
|
|
50
|
-
|
|
51
|
-
| Variable Name | Description |
|
|
52
|
-
| ---------------- | --------------------------------- |
|
|
53
|
-
| `API_ENDPOINT` | URL for the search API endpoint. |
|
|
54
|
-
| `SEARCH_TIMEOUT` | Timeout duration in milliseconds. |
|
|
55
|
-
|
|
56
|
-
Example `.env` file:
|
|
57
|
-
|
|
58
|
-
```env
|
|
59
|
-
API_ENDPOINT=https://api.example.com/search
|
|
60
|
-
SEARCH_TIMEOUT=5000
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### TypeScript Configuration
|
|
64
|
-
|
|
65
|
-
Ensure your `tsconfig.json` is properly configured:
|
|
66
|
-
|
|
67
|
-
```json
|
|
68
|
-
{
|
|
69
|
-
"compilerOptions": {
|
|
70
|
-
"target": "ESNext",
|
|
71
|
-
"module": "CommonJS",
|
|
72
|
-
"strict": true,
|
|
73
|
-
"esModuleInterop": true,
|
|
74
|
-
"skipLibCheck": true
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Example Workflow
|
|
80
|
-
|
|
81
|
-
Streamline your search operations with the following example:
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { WebSearch } from 'web-search-plugin';
|
|
85
|
-
|
|
86
|
-
const search = new WebSearch({ apiEndpoint: 'https://api.example.com/search' });
|
|
87
|
-
|
|
88
|
-
(async () => {
|
|
89
|
-
try {
|
|
90
|
-
// Execute a search query
|
|
91
|
-
const results = await search.query('example', { limit: 5 });
|
|
92
|
-
console.log('Search Results:', results);
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error('Error executing search:', error);
|
|
95
|
-
}
|
|
96
|
-
})();
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Local Testing
|
|
100
|
-
|
|
101
|
-
To test locally, you can set up a mock server for the API endpoint:
|
|
102
|
-
|
|
103
|
-
1. Install `json-server`:
|
|
104
|
-
|
|
105
|
-
```bash
|
|
106
|
-
npm install -g json-server
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
2. Create a `db.json` file with mock search data.
|
|
110
|
-
|
|
111
|
-
3. Start the mock server:
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
json-server --watch db.json --port 3000
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
4. Update your `.env` file:
|
|
118
|
-
```env
|
|
119
|
-
API_ENDPOINT=http://localhost:3000
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
## Common Issues
|
|
123
|
-
|
|
124
|
-
### "API endpoint not defined"
|
|
125
|
-
|
|
126
|
-
- Ensure the `API_ENDPOINT` is set in your environment variables.
|
|
127
|
-
|
|
128
|
-
### "Search query timeout"
|
|
129
|
-
|
|
130
|
-
- Increase the `SEARCH_TIMEOUT` value in the configuration.
|
|
131
|
-
|
|
132
|
-
## Dependencies
|
|
133
|
-
|
|
134
|
-
This plugin relies on the following:
|
|
135
|
-
|
|
136
|
-
- `axios` for HTTP requests.
|
|
137
|
-
- `dotenv` for managing environment variables.
|
|
138
|
-
|
|
139
|
-
## Development Guide
|
|
140
|
-
|
|
141
|
-
### Setup
|
|
142
|
-
|
|
143
|
-
1. Clone the repository:
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
git clone https://github.com/your-repo/web-search-plugin.git
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
2. Install dependencies:
|
|
150
|
-
```bash
|
|
151
|
-
npm install
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Testing
|
|
155
|
-
|
|
156
|
-
Run tests with:
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
|
-
npm test
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Contribution Guidelines
|
|
163
|
-
|
|
164
|
-
- Fork the repository.
|
|
165
|
-
- Create a feature branch.
|
|
166
|
-
- Submit a pull request with a clear description.
|
|
167
|
-
|
|
168
|
-
### Security Best Practices
|
|
169
|
-
|
|
170
|
-
- Validate user inputs to prevent injection attacks.
|
|
171
|
-
- Use HTTPS for secure API communication.
|
|
172
|
-
|
|
173
|
-
## Performance Optimization
|
|
174
|
-
|
|
175
|
-
- Use caching for frequently queried terms.
|
|
176
|
-
- Optimize query parameters for faster responses.
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
This documentation aims to streamline onboarding, reduce support queries, and enable faster adoption of the Web Search Plugin.
|