@mammothb/pi-websearch 0.1.0 → 0.3.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/bin/searxng +48 -0
- package/index.ts +36 -2
- package/package.json +7 -2
- package/searxng/.env +16 -0
- package/searxng/core-config/settings.yml +2458 -0
- package/searxng/docker-compose.yml +24 -0
- package/src/config.ts +128 -0
- package/src/lib/parsers.ts +42 -0
- package/src/lib/providers/exa-mcp.ts +84 -0
- package/src/lib/providers/index.ts +29 -0
- package/src/lib/providers/searxng.ts +100 -0
- package/src/lib/searxng-manager.ts +161 -0
- package/src/lib/types.ts +60 -0
- package/src/websearch.ts +136 -30
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
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { loadConfig } from "./src/config";
|
|
3
|
+
import {
|
|
4
|
+
registerInstance,
|
|
5
|
+
unregisterInstance,
|
|
6
|
+
} from "./src/lib/searxng-manager";
|
|
7
|
+
import { createWebsearchTool } from "./src/websearch";
|
|
3
8
|
|
|
4
9
|
export default function (pi: ExtensionAPI) {
|
|
5
|
-
|
|
10
|
+
let registered = false;
|
|
11
|
+
let searxngActive = false;
|
|
12
|
+
let searxngScript: string | undefined;
|
|
13
|
+
|
|
14
|
+
pi.on("session_start", async (_, ctx) => {
|
|
15
|
+
const config = loadConfig(ctx.cwd);
|
|
16
|
+
pi.registerTool(createWebsearchTool(config));
|
|
17
|
+
|
|
18
|
+
searxngActive = config.provider === "searxng";
|
|
19
|
+
if (searxngActive) {
|
|
20
|
+
searxngScript = config.searxng.script;
|
|
21
|
+
await registerInstance(searxngScript);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!registered) {
|
|
25
|
+
registered = true;
|
|
26
|
+
const providerDetail =
|
|
27
|
+
config.provider === "searxng" ? config.searxng.url : config.exaMcp.url;
|
|
28
|
+
ctx.ui.notify(
|
|
29
|
+
`websearch: provider ${config.provider} (${providerDetail})`,
|
|
30
|
+
"info",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
pi.on("session_shutdown", async (event, _ctx) => {
|
|
36
|
+
if (event.reason === "quit" && searxngActive) {
|
|
37
|
+
await unregisterInstance(searxngScript);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
6
40
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mammothb/pi-websearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A pi extension that adds a websearch tool for searching the web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
7
7
|
],
|
|
8
8
|
"license": "MIT",
|
|
9
|
+
"bin": {
|
|
10
|
+
"searxng": "./bin/searxng"
|
|
11
|
+
},
|
|
9
12
|
"files": [
|
|
10
13
|
"index.ts",
|
|
11
|
-
"src"
|
|
14
|
+
"src",
|
|
15
|
+
"searxng",
|
|
16
|
+
"bin"
|
|
12
17
|
],
|
|
13
18
|
"pi": {
|
|
14
19
|
"extensions": [
|
package/searxng/.env
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Read the documentation before using the `docker-compose.yml` file:
|
|
2
|
+
# https://docs.searxng.org/admin/installation-docker.html
|
|
3
|
+
#
|
|
4
|
+
# Additional ENVs:
|
|
5
|
+
# https://docs.searxng.org/admin/settings/settings_general.html#settings-general
|
|
6
|
+
# https://docs.searxng.org/admin/settings/settings_server.html#settings-server
|
|
7
|
+
|
|
8
|
+
# Use a specific version tag. E.g. "latest" or "2026.3.25-541c6c3cb".
|
|
9
|
+
#SEARXNG_VERSION=latest
|
|
10
|
+
|
|
11
|
+
# Listen to a specific address.
|
|
12
|
+
#SEARXNG_HOST=[::]
|
|
13
|
+
|
|
14
|
+
# Listen to a specific port.
|
|
15
|
+
SEARXNG_PORT=8080
|
|
16
|
+
FORCE_OWNERSHIP=false
|