@mammothb/pi-websearch 0.1.0

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 ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mammothb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # pi-websearch
2
+
3
+ A [pi](https://pi.dev) extension that adds a `websearch` tool for searching the web.
4
+
5
+ ## Usage
6
+
7
+ Once installed, the LLM can call the `websearch` tool to search the web for current information.
8
+
9
+ ## Development
10
+
11
+ ```bash
12
+ # Test locally
13
+ pi -e ./index.ts
14
+ ```
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { createWebsearchTool } from "./src/websearch.js";
3
+
4
+ export default function (pi: ExtensionAPI) {
5
+ pi.registerTool(createWebsearchTool());
6
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@mammothb/pi-websearch",
3
+ "version": "0.1.0",
4
+ "description": "A pi extension that adds a websearch tool for searching the web",
5
+ "keywords": [
6
+ "pi-package"
7
+ ],
8
+ "license": "MIT",
9
+ "files": [
10
+ "index.ts",
11
+ "src"
12
+ ],
13
+ "pi": {
14
+ "extensions": [
15
+ "./index.ts"
16
+ ]
17
+ },
18
+ "scripts": {
19
+ "test": "vitest run",
20
+ "test:coverage": "vitest run --coverage"
21
+ },
22
+ "devDependencies": {
23
+ "@vitest/coverage-v8": "4.1.7",
24
+ "typescript": "6.0.3",
25
+ "vitest": "4.1.7"
26
+ },
27
+ "peerDependencies": {
28
+ "@earendil-works/pi-ai": "*",
29
+ "@earendil-works/pi-coding-agent": "*",
30
+ "@earendil-works/pi-tui": "*",
31
+ "typebox": "*"
32
+ }
33
+ }
@@ -0,0 +1,50 @@
1
+ import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
2
+ import Type from "typebox";
3
+
4
+ interface WebsearchDetails {
5
+ query: string;
6
+ numResults: number;
7
+ }
8
+
9
+ const Parameters = Type.Object({
10
+ query: Type.String({ description: "Search query" }),
11
+ numResults: Type.Optional(
12
+ Type.Number({ description: "Number of results (default: 8)" }),
13
+ ),
14
+ });
15
+
16
+ export function createWebsearchTool(): ToolDefinition<
17
+ typeof Parameters,
18
+ WebsearchDetails
19
+ > {
20
+ return {
21
+ name: "websearch",
22
+ label: "Web Search",
23
+ description: `- Search the web using the session's web search provider - performs real-time web searches and can scrape content from specific URLs.
24
+ - Provides up-to-date information for current events and recent data.
25
+ - Supports configurable result counts and returns the content from the most relevant websites.
26
+ - Use this tool for accessing information beyond knowledge cutoff.
27
+ - Searches are performed automatically within a single API call.
28
+
29
+ Usage notes:
30
+ - Supports live crawling modes when available: 'fallback' (backup if cached unavailable) or 'preferred' (prioritize live crawling)
31
+ - Search types when available: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search)
32
+ - Configurable context length for optimal LLM integration`,
33
+ promptSnippet: "Search the web",
34
+ parameters: Parameters,
35
+ async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
36
+ const query = params.query;
37
+ const numResults = params.numResults ?? 8;
38
+
39
+ return {
40
+ content: [
41
+ {
42
+ type: "text",
43
+ text: `Search results for: ${query} (${numResults} results requested)`,
44
+ },
45
+ ],
46
+ details: { query, numResults },
47
+ };
48
+ },
49
+ };
50
+ }