@elizaos/plugin-web-search 0.1.7-alpha.1 → 0.1.7-alpha.2
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 +21 -0
- package/Readme.md +180 -0
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Shaw Walters, aka Moon aka @lalalune
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
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.
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-web-search",
|
|
3
|
-
"version": "0.1.7-alpha.
|
|
3
|
+
"version": "0.1.7-alpha.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@elizaos/core": "
|
|
8
|
+
"@elizaos/core": "0.1.7-alpha.2",
|
|
9
9
|
"tsup": "8.3.5"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
@@ -14,5 +14,6 @@
|
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"whatwg-url": "7.1.0"
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"gitHead": "256e6634696074cdb38f3f79bc383fed04376688"
|
|
18
19
|
}
|