@mammothb/pi-web 6.0.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 +18 -0
- package/bin/searxng +48 -0
- package/index.ts +85 -0
- package/package.json +37 -0
- package/searxng/core-config/settings.yml +2458 -0
- package/searxng/docker-compose.yml +24 -0
- package/src/config.ts +106 -0
- package/src/lib/headers.ts +28 -0
- package/src/lib/processors.ts +57 -0
- package/src/lib/providers/exa-mcp.ts +130 -0
- package/src/lib/providers/index.ts +29 -0
- package/src/lib/providers/searxng.ts +172 -0
- package/src/lib/searxng-manager.ts +293 -0
- package/src/lib/types.ts +78 -0
- package/src/webfetch.ts +393 -0
- package/src/websearch.ts +148 -0
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/bin/searxng
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# searxng — Start/stop the local SearXNG instance for pi-websearch.
|
|
3
|
+
#
|
|
4
|
+
# Usage:
|
|
5
|
+
# searxng up Start SearXNG (docker compose up -d)
|
|
6
|
+
# searxng down Stop SearXNG (docker compose down)
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
+
COMPOSE_DIR="${SCRIPT_DIR}/../searxng"
|
|
11
|
+
COMPOSE_FILE="${COMPOSE_DIR}/docker-compose.yml"
|
|
12
|
+
|
|
13
|
+
up() {
|
|
14
|
+
# Ensure the core-config directory exists (needed for volume mount).
|
|
15
|
+
mkdir -p "${COMPOSE_DIR}/core-config"
|
|
16
|
+
|
|
17
|
+
# Check if the SearXNG core container is already running.
|
|
18
|
+
if docker compose -f "${COMPOSE_FILE}" ps --status running 2>/dev/null | grep -q "searxng-core"; then
|
|
19
|
+
echo "SearXNG is already running" >&2
|
|
20
|
+
return 0
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
echo "Starting SearXNG..." >&2
|
|
24
|
+
docker compose -f "${COMPOSE_FILE}" up -d
|
|
25
|
+
|
|
26
|
+
# Read the port from .env or default to 8080.
|
|
27
|
+
local port
|
|
28
|
+
port=$(grep -E '^SEARXNG_PORT=' "${COMPOSE_DIR}/.env" 2>/dev/null | cut -d= -f2 || echo "8080")
|
|
29
|
+
port="${port:-8080}"
|
|
30
|
+
|
|
31
|
+
echo "SearXNG is starting on http://localhost:${port}" >&2
|
|
32
|
+
echo "It may take a few seconds to become ready." >&2
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
down() {
|
|
36
|
+
echo "Stopping SearXNG..." >&2
|
|
37
|
+
docker compose -f "${COMPOSE_FILE}" down
|
|
38
|
+
echo "SearXNG stopped." >&2
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
case "${1:-}" in
|
|
42
|
+
up) up ;;
|
|
43
|
+
down) down ;;
|
|
44
|
+
*)
|
|
45
|
+
echo "Usage: $0 {up|down}" >&2
|
|
46
|
+
exit 1
|
|
47
|
+
;;
|
|
48
|
+
esac
|
package/index.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { loadConfig } from "./src/config.js";
|
|
3
|
+
import {
|
|
4
|
+
getInstancesDir,
|
|
5
|
+
inspectShutdownState,
|
|
6
|
+
registerInstance,
|
|
7
|
+
unregisterInstance,
|
|
8
|
+
} from "./src/lib/searxng-manager.js";
|
|
9
|
+
import { createWebfetchTool } from "./src/webfetch.js";
|
|
10
|
+
import { createWebsearchTool } from "./src/websearch.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Set up the SearXNG Docker lifecycle for the current pi session.
|
|
14
|
+
*
|
|
15
|
+
* Checks for unclean shutdowns from previous sessions, starts the
|
|
16
|
+
* container (fire-and-forget), and returns a shutdown handle that
|
|
17
|
+
* stops it when pi exits.
|
|
18
|
+
*/
|
|
19
|
+
function setupSearxng(scriptPath: string | undefined): {
|
|
20
|
+
shutdown: () => void;
|
|
21
|
+
} {
|
|
22
|
+
const instancesDir = getInstancesDir();
|
|
23
|
+
|
|
24
|
+
// Check for unclean shutdowns from previous sessions
|
|
25
|
+
const health = inspectShutdownState(instancesDir);
|
|
26
|
+
if (health.uncleanCount > 0) {
|
|
27
|
+
console.warn(
|
|
28
|
+
`pi-web: ${health.uncleanCount} unclean shutdown(s) detected. ` +
|
|
29
|
+
`SearXNG containers may still be running from a previous session.`,
|
|
30
|
+
);
|
|
31
|
+
health.cleanup();
|
|
32
|
+
} else if (health.stillRunning > 0) {
|
|
33
|
+
console.warn(
|
|
34
|
+
`pi-web: ${health.stillRunning} shutdown(s) still in progress from a previous session.`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Fire-and-forget: don't block pi startup waiting for Docker.
|
|
39
|
+
// The provider retries connection errors until SearXNG is ready.
|
|
40
|
+
registerInstance(scriptPath).catch((err) => {
|
|
41
|
+
console.error(`pi-web: failed to start SearXNG: ${err}`);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
shutdown: () => {
|
|
46
|
+
// Fire-and-forget: don't block pi exit waiting for Docker.
|
|
47
|
+
// The child process (docker compose down) keeps running after pi exits.
|
|
48
|
+
unregisterInstance(scriptPath).catch((err) => {
|
|
49
|
+
console.error(`pi-web: failed to stop SearXNG: ${err}`);
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default function (pi: ExtensionAPI) {
|
|
56
|
+
// ── WebFetch tool (zero-config) ──────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
pi.registerTool(createWebfetchTool());
|
|
59
|
+
|
|
60
|
+
// ── WebSearch tool + SearXNG lifecycle (config-driven) ───────────────
|
|
61
|
+
|
|
62
|
+
let searxngShutdown: (() => void) | undefined;
|
|
63
|
+
|
|
64
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
65
|
+
const config = loadConfig(ctx.cwd);
|
|
66
|
+
pi.registerTool(createWebsearchTool(config));
|
|
67
|
+
|
|
68
|
+
if (config.provider === "searxng") {
|
|
69
|
+
searxngShutdown = setupSearxng(config.searxng.script).shutdown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const providerDetail =
|
|
73
|
+
config.provider === "searxng" ? config.searxng.url : config.exaMcp.url;
|
|
74
|
+
ctx.ui.notify(
|
|
75
|
+
`Web: fetch + search ready (search: ${config.provider} @ ${providerDetail})`,
|
|
76
|
+
"info",
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
pi.on("session_shutdown", (event, _ctx) => {
|
|
81
|
+
if (event.reason === "quit" && searxngShutdown) {
|
|
82
|
+
searxngShutdown();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mammothb/pi-web",
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "A pi extension that adds WebFetch and WebSearch tools for fetching and searching web content",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"bin": {
|
|
10
|
+
"searxng": "./bin/searxng"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.ts",
|
|
14
|
+
"src",
|
|
15
|
+
"searxng",
|
|
16
|
+
"bin"
|
|
17
|
+
],
|
|
18
|
+
"pi": {
|
|
19
|
+
"extensions": [
|
|
20
|
+
"./index.ts"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"htmlparser2": "12.0.0",
|
|
25
|
+
"turndown": "7.2.4",
|
|
26
|
+
"@mammothb/pi-shared": "1.4.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/turndown": "5.0.6"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@earendil-works/pi-ai": "*",
|
|
33
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
34
|
+
"@earendil-works/pi-tui": "*",
|
|
35
|
+
"typebox": "*"
|
|
36
|
+
}
|
|
37
|
+
}
|