@memoryblock/plugin-web-search 0.1.0-beta → 0.1.1-beta
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 +35 -0
- package/package.json +42 -5
- package/src/base.ts +0 -19
- package/src/brave/index.ts +0 -57
- package/src/index.ts +0 -53
- package/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @memoryblock/plugin-web-search
|
|
2
|
+
|
|
3
|
+
Official plugin providing web search capabilities to **memoryblock**.
|
|
4
|
+
|
|
5
|
+
This package handles:
|
|
6
|
+
- DuckDuckGo deep search queries
|
|
7
|
+
- Search result context aggregation
|
|
8
|
+
- URL extraction
|
|
9
|
+
|
|
10
|
+
## The `memoryblock` Ecosystem
|
|
11
|
+
|
|
12
|
+
**memoryblock** is a highly modular system. Here are the official packages:
|
|
13
|
+
|
|
14
|
+
**The Core**
|
|
15
|
+
* [**memoryblock**](https://www.npmjs.com/package/memoryblock) - The core engine interface and types.
|
|
16
|
+
* [**@memoryblock/daemon**](https://www.npmjs.com/package/@memoryblock/daemon) - Background daemon manager.
|
|
17
|
+
* [**@memoryblock/api**](https://www.npmjs.com/package/@memoryblock/api) - Core REST and WebSocket API server.
|
|
18
|
+
|
|
19
|
+
**Integrations & Tooling**
|
|
20
|
+
* [**@memoryblock/adapters**](https://www.npmjs.com/package/@memoryblock/adapters) - LLM adapters (OpenAI, Anthropic, Bedrock, etc).
|
|
21
|
+
* [**@memoryblock/channels**](https://www.npmjs.com/package/@memoryblock/channels) - Communication channels (CLI, Telegram, Web).
|
|
22
|
+
* [**@memoryblock/tools**](https://www.npmjs.com/package/@memoryblock/tools) - Standard tool definitions and schemas.
|
|
23
|
+
* [**@memoryblock/locale**](https://www.npmjs.com/package/@memoryblock/locale) - Localization strings and formatting.
|
|
24
|
+
* [**@memoryblock/web**](https://www.npmjs.com/package/@memoryblock/web) - Front-end dashboard and Web UI.
|
|
25
|
+
|
|
26
|
+
**Plugins**
|
|
27
|
+
* [**@memoryblock/plugin-installer**](https://www.npmjs.com/package/@memoryblock/plugin-installer) - Plugin installer and registry manager.
|
|
28
|
+
* [**@memoryblock/plugin-agents**](https://www.npmjs.com/package/@memoryblock/plugin-agents) - Secondary AI agents orchestrator.
|
|
29
|
+
* [**@memoryblock/plugin-aws**](https://www.npmjs.com/package/@memoryblock/plugin-aws) - AWS integrations.
|
|
30
|
+
* [**@memoryblock/plugin-fetch-webpage**](https://www.npmjs.com/package/@memoryblock/plugin-fetch-webpage) - Web content fetching and parsing.
|
|
31
|
+
* [**@memoryblock/plugin-web-search**](https://www.npmjs.com/package/@memoryblock/plugin-web-search) - Web search capabilities.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
Distributed under the MIT License. See `LICENSE` for more information.
|
package/package.json
CHANGED
|
@@ -1,17 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memoryblock/plugin-web-search",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-beta",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"description": "Official plugin providing web search capabilities to memoryblock.",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/"
|
|
8
|
+
],
|
|
5
9
|
"exports": {
|
|
6
10
|
".": {
|
|
7
11
|
"types": "./dist/index.d.ts",
|
|
8
12
|
"import": "./dist/index.js"
|
|
9
13
|
}
|
|
10
14
|
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"memoryblock": "0.1.0-beta"
|
|
13
|
-
},
|
|
14
15
|
"scripts": {
|
|
15
16
|
"build": "tsc -p tsconfig.json"
|
|
16
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"memoryblock": "^0.1.1-beta"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"memoryblock",
|
|
23
|
+
"ai-agent",
|
|
24
|
+
"assistants",
|
|
25
|
+
"agents",
|
|
26
|
+
"automation",
|
|
27
|
+
"multi-agent",
|
|
28
|
+
"agentic-framework",
|
|
29
|
+
"plugin",
|
|
30
|
+
"search",
|
|
31
|
+
"search-engine",
|
|
32
|
+
"search-api",
|
|
33
|
+
"web-search",
|
|
34
|
+
"brave",
|
|
35
|
+
"duckduckgo",
|
|
36
|
+
"google",
|
|
37
|
+
"bing",
|
|
38
|
+
"yahoo"
|
|
39
|
+
],
|
|
40
|
+
"author": {
|
|
41
|
+
"name": "Ghazi",
|
|
42
|
+
"url": "https://mgks.dev"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/memoryblock-io/memoryblock.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/memoryblock-io/memoryblock/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://memoryblock.io",
|
|
52
|
+
"funding": "https://github.com/sponsors/mgks",
|
|
53
|
+
"license": "MIT"
|
|
17
54
|
}
|
package/src/base.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Search provider contract.
|
|
3
|
-
* All search providers (Brave, Google, etc.) must implement this.
|
|
4
|
-
*/
|
|
5
|
-
export interface SearchResult {
|
|
6
|
-
title: string;
|
|
7
|
-
url: string;
|
|
8
|
-
snippet: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface SearchOptions {
|
|
12
|
-
count?: number;
|
|
13
|
-
language?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface SearchProvider {
|
|
17
|
-
readonly name: string;
|
|
18
|
-
search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
19
|
-
}
|
package/src/brave/index.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { loadAuth } from 'memoryblock';
|
|
2
|
-
import type { SearchProvider, SearchResult, SearchOptions } from '../base.js';
|
|
3
|
-
|
|
4
|
-
const BRAVE_API_URL = 'https://api.search.brave.com/res/v1/web/search';
|
|
5
|
-
|
|
6
|
-
interface BraveWebResult {
|
|
7
|
-
title?: string;
|
|
8
|
-
url?: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Brave Search API provider.
|
|
14
|
-
* Uses native fetch() (Node 18+ built-in).
|
|
15
|
-
*/
|
|
16
|
-
export class BraveSearchProvider implements SearchProvider {
|
|
17
|
-
readonly name = 'brave';
|
|
18
|
-
|
|
19
|
-
async search(query: string, options?: SearchOptions): Promise<SearchResult[]> {
|
|
20
|
-
const auth = await loadAuth();
|
|
21
|
-
const apiKey = auth.brave?.apiKey;
|
|
22
|
-
|
|
23
|
-
if (!apiKey) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
'Brave API key not configured. Add it to ~/.memoryblock/auth.json:\n' +
|
|
26
|
-
' { "brave": { "apiKey": "..." } }',
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const count = options?.count || 5;
|
|
31
|
-
const params = new URLSearchParams({
|
|
32
|
-
q: query,
|
|
33
|
-
count: String(count),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const response = await fetch(`${BRAVE_API_URL}?${params}`, {
|
|
37
|
-
headers: {
|
|
38
|
-
'Accept': 'application/json',
|
|
39
|
-
'Accept-Encoding': 'gzip',
|
|
40
|
-
'X-Subscription-Token': apiKey,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
throw new Error(`Brave Search API error: ${response.status} ${response.statusText}`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const data = await response.json() as { web?: { results?: BraveWebResult[] } };
|
|
49
|
-
const results = data.web?.results || [];
|
|
50
|
-
|
|
51
|
-
return results.map((r: BraveWebResult) => ({
|
|
52
|
-
title: r.title || '',
|
|
53
|
-
url: r.url || '',
|
|
54
|
-
snippet: r.description || '',
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ToolExecutionResult, ToolContext, ToolDefinition } from 'memoryblock';
|
|
2
|
-
import { BraveSearchProvider } from './brave/index.js';
|
|
3
|
-
|
|
4
|
-
export type { SearchProvider, SearchResult, SearchOptions } from './base.js';
|
|
5
|
-
export { BraveSearchProvider } from './brave/index.js';
|
|
6
|
-
|
|
7
|
-
const braveProvider = new BraveSearchProvider();
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Web search tool definition — registers as a tool in the registry.
|
|
11
|
-
*/
|
|
12
|
-
const webSearchToolDefinition: ToolDefinition = {
|
|
13
|
-
name: 'web_search',
|
|
14
|
-
description: 'Search the web for current information. Returns titles, URLs, and snippets.',
|
|
15
|
-
parameters: {
|
|
16
|
-
type: 'object',
|
|
17
|
-
properties: {
|
|
18
|
-
query: { type: 'string', description: 'The search query.' },
|
|
19
|
-
count: { type: 'number', description: 'Number of results (default: 5, max: 10).' },
|
|
20
|
-
},
|
|
21
|
-
required: ['query'],
|
|
22
|
-
additionalProperties: false,
|
|
23
|
-
},
|
|
24
|
-
requiresApproval: false,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/** Web search tool — usable by the tool registry. */
|
|
28
|
-
export const webSearchTool = {
|
|
29
|
-
definition: webSearchToolDefinition,
|
|
30
|
-
async execute(params: Record<string, unknown>, _context: ToolContext): Promise<ToolExecutionResult> {
|
|
31
|
-
try {
|
|
32
|
-
const query = params.query as string;
|
|
33
|
-
const count = Math.min((params.count as number) || 5, 10);
|
|
34
|
-
const results = await braveProvider.search(query, { count });
|
|
35
|
-
|
|
36
|
-
if (results.length === 0) {
|
|
37
|
-
return { content: 'No results found.', isError: false };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const formatted = results
|
|
41
|
-
.map((r, i) => `${i + 1}. **${r.title}**\n ${r.url}\n ${r.snippet}`)
|
|
42
|
-
.join('\n\n');
|
|
43
|
-
|
|
44
|
-
return { content: formatted, isError: false };
|
|
45
|
-
} catch (err) {
|
|
46
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
47
|
-
return { content: `Web search failed: ${message}`, isError: true };
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** Export as array for registry plugin loading. */
|
|
53
|
-
export const tools = [webSearchTool];
|