@jaco-tech/dsh-web-search-searxng 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,21 @@
1
+ MIT
2
+
3
+ Copyright (c) 2026 Jaco
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,95 @@
1
+ # dsh-web-search-searxng
2
+
3
+ [![dsh-plugin](https://img.shields.io/badge/dsh-plugin-blue)](https://github.com/topics/dsh-plugin)
4
+ [![CI/CD](https://github.com/jaco-tech/dsh-web-search-searxng/actions/workflows/ci.yml/badge.svg)](https://github.com/jaco-tech/dsh-web-search-searxng/actions/workflows/ci.yml)
5
+
6
+ SearXNG-backed search provider plugin for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
7
+
8
+ Registers a `WebSearchProvider` into `ctx.web` so that the existing `web_search` model tool routes through your [SearXNG](https://github.com/searxng/searxng) instance. No auth, no API key, no model calls — just a plain HTTP GET against SearXNG's JSON endpoint.
9
+
10
+ ## Status
11
+
12
+ ⚠️ **Not yet published to npm.** The CI/CD workflow builds on every push and publishes automatically when a `v*` tag is pushed. Once the first release is cut:
13
+
14
+ ```bash
15
+ npm install @jaco-tech/dsh-web-search-searxng
16
+ ```
17
+
18
+ ## Configure
19
+
20
+ Add to your DSH profile's `cordis.patch.yml`:
21
+
22
+ ```yaml
23
+ - insert:
24
+ - id: web-search-searxng
25
+ name: '@jaco-tech/dsh-web-search-searxng'
26
+ config:
27
+ baseURL: 'http://your-searxng-instance:8888'
28
+ # Optional filters:
29
+ language: 'en'
30
+ categories: 'general'
31
+ timeRange: ''
32
+ ```
33
+
34
+ Optionally pin `ctx.web` to use this provider explicitly:
35
+
36
+ ```yaml
37
+ - replace:
38
+ - id: web
39
+ config:
40
+ searchProvider: searxng
41
+ ```
42
+
43
+ ## How it works
44
+
45
+ This is a [Cordis](https://github.com/cordiverse/cordis) plugin that implements the `WebSearchProvider` interface from `@deepseek-ai/dsh-web`:
46
+
47
+ ```typescript
48
+ export const name = "web-search-searxng"
49
+ export const inject = ["web"]
50
+
51
+ export function apply(ctx, config) {
52
+ ctx.web.registerSearchProvider({
53
+ id: "searxng",
54
+ available() { /* URL.canParse(config.baseURL) */ },
55
+ async search(request, signal) {
56
+ // GET /search?q=<query>&format=json
57
+ // maps response to WebSearchResult
58
+ }
59
+ })
60
+ }
61
+ ```
62
+
63
+ The existing `@deepseek-ai/dsh-tool-web` consumer calls `ctx.web.search()` — your SearXNG instance serves the results automatically.
64
+
65
+ ## Provider interface
66
+
67
+ | Method | Behavior |
68
+ |---|---|
69
+ | `available()` | Returns `true` when `baseURL` is a valid URL |
70
+ | `search(request, signal?)` | `GET /search` with `q`, `format=json`, optional `language`/`categories`/`time_range` params. Dedupes results by URL. Surfaces `answers` and `infoboxes` as provider-generated answer text. |
71
+
72
+ ## Upstream
73
+
74
+ This plugin communicates with [SearXNG](https://github.com/searxng/searxng) via its JSON API (`/search?format=json`). SearXNG is a free internet metasearch engine which aggregates results from more than 70 search services. You need a running SearXNG instance to use this plugin.
75
+
76
+ ## Release process
77
+
78
+ ```bash
79
+ # Tag and push — the CI workflow builds and publishes to npm automatically
80
+ git tag v0.1.0
81
+ git push origin v0.1.0
82
+ ```
83
+
84
+ Requires the `NPM_TOKEN` secret to be set in the repository.
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ npm install
90
+ npm run build
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT
package/lib/index.js ADDED
@@ -0,0 +1,162 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { WebError } from "@deepseek-ai/dsh-web";
3
+ //#endregion
4
+ //#region provider
5
+ /**
6
+ * Stable id this search provider registers under.
7
+ */
8
+ const SEARXNG_PROVIDER_ID = "searxng";
9
+ /**
10
+ * Project one SearXNG result item to a normalized source, omitting absent
11
+ * optional fields.
12
+ */
13
+ function projectSource(item) {
14
+ return {
15
+ url: item.url,
16
+ ...(item.title != null && item.title.length > 0) ? { title: item.title } : {},
17
+ ...(item.content != null && item.content.length > 0) ? { snippet: item.content } : {},
18
+ ...(item.publishedDate != null && item.publishedDate.length > 0) ? { publishedAt: item.publishedDate } : {},
19
+ };
20
+ }
21
+ /**
22
+ * Map a SearXNG JSON response to the seam's normalized `WebSearchResult`.
23
+ * Dedupes by URL (SearXNG may return the same URL from multiple engines).
24
+ */
25
+ function mapSearXngResponse(body, maxResults) {
26
+ const seen = new Set();
27
+ const sources = [];
28
+ const items = body.results ?? [];
29
+ for (const item of items) {
30
+ if (!item.url || item.url.length === 0 || seen.has(item.url))
31
+ continue;
32
+ seen.add(item.url);
33
+ sources.push(projectSource(item));
34
+ }
35
+ const truncated = maxResults !== void 0 && sources.length > maxResults;
36
+ if (truncated)
37
+ sources.length = maxResults;
38
+ // SearXNG may return an answer or infobox — surface as provider-generated
39
+ // answer text.
40
+ let content;
41
+ if (body.answers != null && body.answers.length > 0) {
42
+ content = body.answers.join("\n");
43
+ }
44
+ else if (body.infoboxes != null && body.infoboxes.length > 0) {
45
+ content = body.infoboxes.map((infobox) => infobox.content ?? infobox.infobox ?? "").filter(Boolean).join("\n\n");
46
+ }
47
+ return { ...content !== void 0 ? { content } : {}, sources, truncated };
48
+ }
49
+ /**
50
+ * The SearXNG-backed search provider. Every operation issues a plain GET
51
+ * against the instance's JSON endpoint and maps the response directly to the
52
+ * seam's normalized `WebSearchResult`. No auth, no API key, no model calls.
53
+ */
54
+ class SearXngSearchProvider {
55
+ resolveOptions;
56
+ id = SEARXNG_PROVIDER_ID;
57
+ constructor(resolveOptions) {
58
+ this.resolveOptions = resolveOptions;
59
+ }
60
+ available() {
61
+ const options = this.resolveOptions();
62
+ return URL.canParse(options.baseURL);
63
+ }
64
+ async search(request, signal) {
65
+ const options = this.resolveOptions();
66
+ throwIfAborted(signal);
67
+ const url = new URL(`${options.baseURL}/search`);
68
+ url.searchParams.set("q", request.query);
69
+ url.searchParams.set("format", "json");
70
+ if (options.language)
71
+ url.searchParams.set("language", options.language);
72
+ if (options.categories)
73
+ url.searchParams.set("categories", options.categories);
74
+ if (options.timeRange)
75
+ url.searchParams.set("time_range", options.timeRange);
76
+ url.searchParams.set("pageno", "1");
77
+ throwIfAborted(signal);
78
+ let response;
79
+ try {
80
+ response = await fetch(url.toString(), {
81
+ method: "GET",
82
+ headers: {
83
+ accept: "application/json",
84
+ "user-agent": "deepseek-harness/0.0.1",
85
+ },
86
+ ...signal !== void 0 ? { signal } : {},
87
+ });
88
+ }
89
+ catch (error) {
90
+ if (signal?.aborted === true || isAbortError(error))
91
+ throw aborted(signal, error);
92
+ throw new WebError(`SearXNG search request failed: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
93
+ }
94
+ if (!response.ok) {
95
+ let message = `SearXNG API error (HTTP ${response.status})`;
96
+ try {
97
+ const parsed = (await response.json());
98
+ if (parsed.message != null && parsed.message.length > 0)
99
+ message = parsed.message;
100
+ }
101
+ catch { /* ignore parse failure on error body */ }
102
+ throw new WebError(message, "WEB_PROVIDER_ERROR");
103
+ }
104
+ try {
105
+ return mapSearXngResponse((await response.json()), request.maxResults);
106
+ }
107
+ catch (error) {
108
+ if (signal?.aborted === true || isAbortError(error))
109
+ throw aborted(signal, error);
110
+ if (error instanceof WebError)
111
+ throw error;
112
+ throw new WebError(`SearXNG returned an unprocessable response: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
113
+ }
114
+ }
115
+ }
116
+ //#endregion
117
+ //#region plugin
118
+ /**
119
+ * Register a SearXNG-backed search provider in `ctx.web`. No auth, no API
120
+ * key — just point `baseURL` at your SearXNG instance.
121
+ *
122
+ * ## Usage
123
+ *
124
+ * ```yaml
125
+ * # cordis.patch.yml
126
+ * - insert:
127
+ * - id: web-search-searxng
128
+ * name: '@jaco-tech/dsh-web-search-searxng'
129
+ * config:
130
+ * baseURL: 'http://your-searxng-instance:8888'
131
+ * language: 'en'
132
+ * ```
133
+ * @module @jaco-tech/dsh-web-search-searxng
134
+ */
135
+ /** Cordis plugin name used by loader diagnostics. */
136
+ const name = "web-search-searxng";
137
+ /** The web seam this provider registers into. */
138
+ const inject = ["web"];
139
+ const Config = z.object({
140
+ baseURL: z.string().required(),
141
+ language: z.string().default(""),
142
+ categories: z.string().default(""),
143
+ timeRange: z.string().default(""),
144
+ });
145
+ function apply(ctx, config) {
146
+ const current = () => config;
147
+ ctx.web.registerSearchProvider(new SearXngSearchProvider(() => current()));
148
+ }
149
+ //#endregion
150
+ //#region helpers
151
+ function throwIfAborted(signal) {
152
+ if (signal?.aborted === true)
153
+ throw aborted(signal);
154
+ }
155
+ function aborted(signal, fallback) {
156
+ return new WebError("SearXNG search aborted", "WEB_ABORTED", { cause: signal?.aborted === true ? signal.reason : fallback });
157
+ }
158
+ function isAbortError(error) {
159
+ return error instanceof DOMException && error.name === "AbortError";
160
+ }
161
+ //#endregion
162
+ export { Config, SEARXNG_PROVIDER_ID, SearXngSearchProvider, apply, inject, name, mapSearXngResponse };
@@ -0,0 +1,82 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import type { Context } from "@deepseek-ai/cordis";
3
+ import type { WebSearchProvider, WebSearchRequest, WebSearchResult } from "@deepseek-ai/dsh-web";
4
+ interface SearXngResultItem {
5
+ url: string;
6
+ title?: string | null;
7
+ content?: string | null;
8
+ publishedDate?: string | null;
9
+ engine?: string;
10
+ category?: string;
11
+ score?: number;
12
+ }
13
+ interface SearXngResponseBody {
14
+ query: string;
15
+ results?: SearXngResultItem[];
16
+ answers?: string[];
17
+ infoboxes?: Array<{
18
+ content?: string;
19
+ infobox?: string;
20
+ url?: string;
21
+ }>;
22
+ suggestions?: string[];
23
+ unresponsive_engines?: string[];
24
+ }
25
+ /**
26
+ * Stable id this search provider registers under.
27
+ */
28
+ declare const SEARXNG_PROVIDER_ID = "searxng";
29
+ /**
30
+ * Map a SearXNG JSON response to the seam's normalized `WebSearchResult`.
31
+ * Dedupes by URL (SearXNG may return the same URL from multiple engines).
32
+ */
33
+ declare function mapSearXngResponse(body: SearXngResponseBody, maxResults?: number): WebSearchResult;
34
+ /**
35
+ * The SearXNG-backed search provider. Every operation issues a plain GET
36
+ * against the instance's JSON endpoint and maps the response directly to the
37
+ * seam's normalized `WebSearchResult`. No auth, no API key, no model calls.
38
+ */
39
+ declare class SearXngSearchProvider implements WebSearchProvider {
40
+ readonly resolveOptions: () => Config;
41
+ readonly id = "searxng";
42
+ constructor(resolveOptions: () => Config);
43
+ available(): boolean;
44
+ search(request: WebSearchRequest, signal?: AbortSignal): Promise<WebSearchResult>;
45
+ }
46
+ /**
47
+ * Register a SearXNG-backed search provider in `ctx.web`. No auth, no API
48
+ * key — just point `baseURL` at your SearXNG instance.
49
+ *
50
+ * ## Usage
51
+ *
52
+ * ```yaml
53
+ * # cordis.patch.yml
54
+ * - insert:
55
+ * - id: web-search-searxng
56
+ * name: '@jaco-tech/dsh-web-search-searxng'
57
+ * config:
58
+ * baseURL: 'http://your-searxng-instance:8888'
59
+ * language: 'en'
60
+ * ```
61
+ * @module @jaco-tech/dsh-web-search-searxng
62
+ */
63
+ /** Cordis plugin name used by loader diagnostics. */
64
+ declare const name = "web-search-searxng";
65
+ /** The web seam this provider registers into. */
66
+ declare const inject: string[];
67
+ /**
68
+ * Plugin configuration. `baseURL` is required (point at your SearXNG instance).
69
+ */
70
+ interface Config {
71
+ /** Base URL of the SearXNG instance (without trailing /search). */
72
+ baseURL: string;
73
+ /** Language filter (e.g. "en", "nl", "fr"). Empty = no filter. */
74
+ language?: string;
75
+ /** Categories filter (e.g. "general", "news", "images"). Empty = no filter. */
76
+ categories?: string;
77
+ /** Time range filter (e.g. "day", "week", "month", "year"). Empty = no filter. */
78
+ timeRange?: string;
79
+ }
80
+ declare const Config: z<Config>;
81
+ declare function apply(ctx: Context, config: Config): void;
82
+ export { Config, SEARXNG_PROVIDER_ID, SearXngSearchProvider, apply, inject, name, mapSearXngResponse };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@jaco-tech/dsh-web-search-searxng",
3
+ "description": "SearXNG-backed search provider for the DeepSeek Harness web capability seam (ctx.web). No auth, no API key.",
4
+ "version": "0.1.0",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/jaco-tech/dsh-web-search-searxng.git"
11
+ },
12
+ "type": "module",
13
+ "main": "lib/index.js",
14
+ "types": "lib/types/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/types/index.d.ts",
18
+ "default": "./lib/index.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "lib/index.js",
24
+ "lib/types/**/*.d.ts"
25
+ ],
26
+ "license": "MIT",
27
+ "keywords": [
28
+ "dsh-plugin",
29
+ "deepseek-harness",
30
+ "searxng",
31
+ "web-search",
32
+ "cordis-plugin"
33
+ ],
34
+ "peerDependencies": {
35
+ "@deepseek-ai/dsh-web": "^0.1.0-rc.7",
36
+ "@deepseek-ai/cordis": "^4.0.1"
37
+ },
38
+ "dependencies": {
39
+ "@deepseek-ai/schemastery": "^3.18.1"
40
+ },
41
+ "devDependencies": {
42
+ "@deepseek-ai/dsh-web": "^0.1.0-rc.7",
43
+ "@deepseek-ai/cordis": "^4.0.1",
44
+ "typescript": "^5.7.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "prepublishOnly": "tsc"
49
+ }
50
+ }