openclaw-webrouter 0.0.0-stage → 0.1.1
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 +201 -0
- package/README.md +60 -2
- package/assets/icon.png +0 -0
- package/index.js +13 -0
- package/openclaw.plugin.json +67 -0
- package/package.json +66 -4
- package/src/client.js +190 -0
- package/src/provider.js +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Nimble
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WebRouter search for OpenClaw
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An OpenClaw `web_search` provider backed by [WebRouter](https://github.com/Nimbleway/webrouter).
|
|
4
|
+
It works with no API key: WebRouter routes each search to a keyless backend.
|
|
5
|
+
See the [WebRouter documentation](https://docs.webrouter.net/) for how backends are chosen.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- OpenClaw 2026.12.3 or later
|
|
10
|
+
- [uv](https://docs.astral.sh/uv/) on `PATH` (the plugin runs `uvx --from "webrouter>=0.17,<1" webrouter`), or
|
|
11
|
+
WebRouter installed some other way and set as `webSearch.command`
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
openclaw plugins install openclaw-webrouter
|
|
17
|
+
openclaw plugins enable webrouter
|
|
18
|
+
openclaw config set tools.web.search.provider webrouter
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Try it:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
openclaw infer web search --query "rust async runtimes" --limit 3
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Settings
|
|
28
|
+
|
|
29
|
+
All optional, under `plugins.entries.webrouter.config.webSearch`:
|
|
30
|
+
|
|
31
|
+
| Setting | Default | What it does |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `command` | `["uvx", "--from", "webrouter>=0.17,<1", "webrouter"]` | How to run the WebRouter CLI, e.g. `["webrouter"]` if it is installed. |
|
|
34
|
+
| `provider` | none (WebRouter picks) | Pin one backend, such as `exa` or `tavily`. |
|
|
35
|
+
| `forwardEnv` | `[]` | Environment variables passed to WebRouter, such as `["TAVILY_API_KEY"]`. |
|
|
36
|
+
| `timeoutSeconds` | `30` | Seconds WebRouter waits for a backend. |
|
|
37
|
+
|
|
38
|
+
## Keys
|
|
39
|
+
|
|
40
|
+
WebRouter runs as a child process with a minimal environment: `PATH`, `HOME`, locale,
|
|
41
|
+
temp, proxy and uv cache variables. Provider keys in OpenClaw's environment are **not**
|
|
42
|
+
passed on, so searches stay keyless and nothing is billed. To use a key you hold, list
|
|
43
|
+
its variable in `forwardEnv`; WebRouter then may route searches to that paid backend.
|
|
44
|
+
|
|
45
|
+
Results are wrapped as untrusted external content, like OpenClaw's other search providers.
|
|
46
|
+
|
|
47
|
+
## Development
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install --no-save openclaw@2026.12.3
|
|
51
|
+
npm test
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Cancelling a search stops OpenClaw from waiting, but the WebRouter process runs until its own timeout.
|
|
55
|
+
|
|
56
|
+
## About
|
|
57
|
+
|
|
58
|
+
Maintained by Yogev, one of the maintainers of [WebRouter](https://github.com/Nimbleway/webrouter).
|
|
59
|
+
Issues and pull requests are welcome here.
|
|
60
|
+
|
|
61
|
+
License: Apache-2.0
|
package/assets/icon.png
ADDED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
2
|
+
import { createWebRouterWebSearchProvider } from "./src/provider.js";
|
|
3
|
+
|
|
4
|
+
export default definePluginEntry({
|
|
5
|
+
id: "webrouter",
|
|
6
|
+
name: "WebRouter",
|
|
7
|
+
description: "Keyless web search for OpenClaw, powered by WebRouter. No API key or signup needed.",
|
|
8
|
+
register(api) {
|
|
9
|
+
api.registerWebSearchProvider(createWebRouterWebSearchProvider());
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { createWebRouterWebSearchProvider };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "webrouter",
|
|
3
|
+
"name": "WebRouter",
|
|
4
|
+
"description": "Keyless web search for OpenClaw, powered by WebRouter. No API key or signup needed.",
|
|
5
|
+
"categories": ["web"],
|
|
6
|
+
"activation": {
|
|
7
|
+
"onStartup": false
|
|
8
|
+
},
|
|
9
|
+
"uiHints": {
|
|
10
|
+
"webSearch.command": {
|
|
11
|
+
"label": "WebRouter command",
|
|
12
|
+
"help": "Command that runs the WebRouter CLI. Defaults to uvx --from 'webrouter>=0.17,<1' webrouter."
|
|
13
|
+
},
|
|
14
|
+
"webSearch.provider": {
|
|
15
|
+
"label": "WebRouter backend",
|
|
16
|
+
"help": "Optional backend to pin, such as tavily or exa. Leave empty to let WebRouter choose."
|
|
17
|
+
},
|
|
18
|
+
"webSearch.forwardEnv": {
|
|
19
|
+
"label": "Forwarded key variables",
|
|
20
|
+
"help": "Environment variables passed to WebRouter, such as TAVILY_API_KEY. Empty keeps searches keyless."
|
|
21
|
+
},
|
|
22
|
+
"webSearch.timeoutSeconds": {
|
|
23
|
+
"label": "Timeout (seconds)",
|
|
24
|
+
"help": "Seconds WebRouter waits for a backend before giving up."
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"contracts": {
|
|
28
|
+
"webSearchProviders": ["webrouter"]
|
|
29
|
+
},
|
|
30
|
+
"configGroups": [
|
|
31
|
+
{
|
|
32
|
+
"id": "web-search",
|
|
33
|
+
"title": "Web search",
|
|
34
|
+
"order": 10,
|
|
35
|
+
"properties": ["webSearch"]
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"configSchema": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"additionalProperties": false,
|
|
41
|
+
"properties": {
|
|
42
|
+
"webSearch": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"additionalProperties": false,
|
|
45
|
+
"properties": {
|
|
46
|
+
"command": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"items": { "type": "string", "minLength": 1 },
|
|
49
|
+
"minItems": 1
|
|
50
|
+
},
|
|
51
|
+
"provider": {
|
|
52
|
+
"type": "string"
|
|
53
|
+
},
|
|
54
|
+
"forwardEnv": {
|
|
55
|
+
"type": "array",
|
|
56
|
+
"items": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" }
|
|
57
|
+
},
|
|
58
|
+
"timeoutSeconds": {
|
|
59
|
+
"type": "integer",
|
|
60
|
+
"minimum": 1,
|
|
61
|
+
"maximum": 300
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-webrouter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Keyless web search for OpenClaw, powered by WebRouter. No API key or signup needed; add your own search provider keys only if you want them.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/yogev-nimble/openclaw-webrouter.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/yogev-nimble/openclaw-webrouter#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/yogev-nimble/openclaw-webrouter/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./index.js",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"openclaw",
|
|
18
|
+
"openclaw-plugin",
|
|
19
|
+
"web-search",
|
|
20
|
+
"web_search",
|
|
21
|
+
"search-provider",
|
|
22
|
+
"keyless",
|
|
23
|
+
"no-api-key",
|
|
24
|
+
"free-web-search",
|
|
25
|
+
"agent-search",
|
|
26
|
+
"webrouter"
|
|
27
|
+
],
|
|
28
|
+
"openclaw": {
|
|
29
|
+
"extensions": [
|
|
30
|
+
"./index.js"
|
|
31
|
+
],
|
|
32
|
+
"runtimeExtensions": [
|
|
33
|
+
"./index.js"
|
|
34
|
+
],
|
|
35
|
+
"compat": {
|
|
36
|
+
"pluginApi": ">=2026.12.3"
|
|
37
|
+
},
|
|
38
|
+
"build": {
|
|
39
|
+
"openclawVersion": "2026.12.3",
|
|
40
|
+
"bundledDist": false
|
|
41
|
+
},
|
|
42
|
+
"install": {
|
|
43
|
+
"npmSpec": "openclaw-webrouter",
|
|
44
|
+
"clawhubSpec": "clawhub:openclaw-webrouter",
|
|
45
|
+
"defaultChoice": "npm",
|
|
46
|
+
"minHostVersion": ">=2026.12.3"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"index.js",
|
|
51
|
+
"src/**",
|
|
52
|
+
"assets/**",
|
|
53
|
+
"openclaw.plugin.json",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "node --test test/*.test.mjs"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"openclaw": ">=2026.12.3"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"openclaw": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { tmpdir } from "node:os";
|
|
2
|
+
import { runPluginCommandWithTimeout } from "openclaw/plugin-sdk/run-command";
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_SEARCH_COUNT,
|
|
5
|
+
externalContentStamp,
|
|
6
|
+
readCachedSearchPayload,
|
|
7
|
+
resolveProviderWebSearchPluginConfig,
|
|
8
|
+
resolveSearchCacheTtlMs,
|
|
9
|
+
resolveSearchCount,
|
|
10
|
+
resolveSiteName,
|
|
11
|
+
resolveTimeoutSeconds,
|
|
12
|
+
wrapWebContent,
|
|
13
|
+
writeCachedSearchPayload,
|
|
14
|
+
} from "openclaw/plugin-sdk/provider-web-search";
|
|
15
|
+
|
|
16
|
+
export const PLUGIN_ID = "webrouter";
|
|
17
|
+
export const DEFAULT_COMMAND = ["uvx", "--from", "webrouter>=0.17,<1", "webrouter"];
|
|
18
|
+
export const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
19
|
+
// Extra time for the first `uvx` run, which installs WebRouter before searching.
|
|
20
|
+
const STARTUP_GRACE_SECONDS = 60;
|
|
21
|
+
const MAX_SNIPPET_CHARS = 600;
|
|
22
|
+
const RECENCY = new Set(["day", "week", "month", "year"]);
|
|
23
|
+
// Variables the child needs to find and run the command. Provider keys are not
|
|
24
|
+
// passed unless the operator lists them in `forwardEnv`.
|
|
25
|
+
const BASE_ENV_KEYS = [
|
|
26
|
+
"PATH",
|
|
27
|
+
"HOME",
|
|
28
|
+
"USERPROFILE",
|
|
29
|
+
"SYSTEMROOT",
|
|
30
|
+
"TMPDIR",
|
|
31
|
+
"TEMP",
|
|
32
|
+
"TMP",
|
|
33
|
+
"LANG",
|
|
34
|
+
"LC_ALL",
|
|
35
|
+
"XDG_CACHE_HOME",
|
|
36
|
+
"XDG_DATA_HOME",
|
|
37
|
+
"UV_CACHE_DIR",
|
|
38
|
+
"UV_TOOL_DIR",
|
|
39
|
+
"UV_PYTHON_INSTALL_DIR",
|
|
40
|
+
"SSL_CERT_FILE",
|
|
41
|
+
"REQUESTS_CA_BUNDLE",
|
|
42
|
+
"HTTPS_PROXY",
|
|
43
|
+
"HTTP_PROXY",
|
|
44
|
+
"NO_PROXY",
|
|
45
|
+
];
|
|
46
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
47
|
+
// Option values reach the CLI as separate argv entries; refuse anything that could read as a flag.
|
|
48
|
+
const OPTION_VALUE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
|
|
49
|
+
|
|
50
|
+
function optionValue(value) {
|
|
51
|
+
return typeof value === "string" && OPTION_VALUE.test(value.trim()) ? value.trim() : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveWebRouterConfig(config) {
|
|
55
|
+
const raw = resolveProviderWebSearchPluginConfig(config, PLUGIN_ID) ?? {};
|
|
56
|
+
const command =
|
|
57
|
+
Array.isArray(raw.command) && raw.command.length > 0 && raw.command.every((part) => typeof part === "string" && part)
|
|
58
|
+
? [...raw.command]
|
|
59
|
+
: DEFAULT_COMMAND;
|
|
60
|
+
const backend = optionValue(raw.provider);
|
|
61
|
+
const forwardEnv = Array.isArray(raw.forwardEnv)
|
|
62
|
+
? raw.forwardEnv.filter((name) => typeof name === "string" && ENV_NAME.test(name))
|
|
63
|
+
: [];
|
|
64
|
+
const timeoutSeconds = typeof raw.timeoutSeconds === "number" ? raw.timeoutSeconds : undefined;
|
|
65
|
+
return { command, backend, forwardEnv, timeoutSeconds };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function buildChildEnv(sourceEnv, forwardEnv) {
|
|
69
|
+
const env = {};
|
|
70
|
+
for (const name of [...BASE_ENV_KEYS, ...forwardEnv]) {
|
|
71
|
+
const value = sourceEnv[name];
|
|
72
|
+
if (typeof value === "string" && value) env[name] = value;
|
|
73
|
+
}
|
|
74
|
+
return env;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function buildSearchArgv(command, params) {
|
|
78
|
+
const argv = [...command, "search", "--no-data-apis", "-n", String(params.count), "--timeout", String(params.timeoutSeconds)];
|
|
79
|
+
if (params.backend) argv.push("-p", params.backend);
|
|
80
|
+
if (params.country) argv.push("--country", params.country);
|
|
81
|
+
if (params.locale) argv.push("--locale", params.locale);
|
|
82
|
+
if (params.recency) argv.push("--recency", params.recency);
|
|
83
|
+
// `--` ends option parsing, so a query that starts with "-" stays a query.
|
|
84
|
+
argv.push("--", params.query);
|
|
85
|
+
return argv;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function readError(stderr) {
|
|
89
|
+
const text = (stderr ?? "").trim();
|
|
90
|
+
const lastLine = text.split("\n").filter(Boolean).at(-1) ?? "";
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(lastLine);
|
|
93
|
+
if (parsed?.error?.message) return `${parsed.error.type ?? "error"}: ${parsed.error.message}`;
|
|
94
|
+
} catch {
|
|
95
|
+
// Not WebRouter's JSON error line; fall through to the raw text.
|
|
96
|
+
}
|
|
97
|
+
return text.slice(-500) || "no output";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function failureMessage(result, command) {
|
|
101
|
+
const detail = readError(result.stderr);
|
|
102
|
+
if (/ENOENT|not found|No such file/i.test(detail)) {
|
|
103
|
+
return `WebRouter could not start \`${command[0]}\`. Install uv (https://docs.astral.sh/uv/) or set plugins.entries.webrouter.config.webSearch.command. (${detail})`;
|
|
104
|
+
}
|
|
105
|
+
return `WebRouter search failed (exit ${result.code}): ${detail}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function snippetOf(result) {
|
|
109
|
+
const text = typeof result.description === "string" && result.description ? result.description : result.content;
|
|
110
|
+
if (typeof text !== "string" || !text) return "";
|
|
111
|
+
return text.length > MAX_SNIPPET_CHARS ? `${text.slice(0, MAX_SNIPPET_CHARS)}…` : text;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function runWebRouterSearch(params) {
|
|
115
|
+
const settings = resolveWebRouterConfig(params.config);
|
|
116
|
+
const count = resolveSearchCount(params.count, DEFAULT_SEARCH_COUNT);
|
|
117
|
+
const timeoutSeconds = resolveTimeoutSeconds(params.timeoutSeconds ?? settings.timeoutSeconds, DEFAULT_TIMEOUT_SECONDS);
|
|
118
|
+
const recency = RECENCY.has(params.recency) ? params.recency : undefined;
|
|
119
|
+
const country = optionValue(params.country);
|
|
120
|
+
const locale = optionValue(params.locale);
|
|
121
|
+
const cacheTtlMs = resolveSearchCacheTtlMs(params.config?.tools?.web?.search);
|
|
122
|
+
const cacheKey = JSON.stringify({
|
|
123
|
+
provider: PLUGIN_ID,
|
|
124
|
+
query: params.query,
|
|
125
|
+
count,
|
|
126
|
+
backend: settings.backend ?? "",
|
|
127
|
+
command: settings.command,
|
|
128
|
+
forwardEnv: settings.forwardEnv,
|
|
129
|
+
country: country ?? "",
|
|
130
|
+
locale: locale ?? "",
|
|
131
|
+
recency: recency ?? "",
|
|
132
|
+
});
|
|
133
|
+
const cached = readCachedSearchPayload(cacheKey, cacheTtlMs);
|
|
134
|
+
if (cached) return cached;
|
|
135
|
+
|
|
136
|
+
params.signal?.throwIfAborted();
|
|
137
|
+
const argv = buildSearchArgv(settings.command, {
|
|
138
|
+
query: params.query,
|
|
139
|
+
count,
|
|
140
|
+
timeoutSeconds,
|
|
141
|
+
backend: settings.backend,
|
|
142
|
+
country,
|
|
143
|
+
locale,
|
|
144
|
+
recency,
|
|
145
|
+
});
|
|
146
|
+
const startedAt = Date.now();
|
|
147
|
+
const run = params.runCommand ?? runPluginCommandWithTimeout;
|
|
148
|
+
const result = await run({
|
|
149
|
+
argv,
|
|
150
|
+
timeoutMs: (timeoutSeconds + STARTUP_GRACE_SECONDS) * 1000,
|
|
151
|
+
// Run outside OpenClaw's working directory so no project file there is picked up.
|
|
152
|
+
cwd: tmpdir(),
|
|
153
|
+
env: buildChildEnv(params.env ?? process.env, settings.forwardEnv),
|
|
154
|
+
});
|
|
155
|
+
params.signal?.throwIfAborted();
|
|
156
|
+
if (result.code !== 0) {
|
|
157
|
+
throw new Error(failureMessage(result, settings.command));
|
|
158
|
+
}
|
|
159
|
+
let response;
|
|
160
|
+
try {
|
|
161
|
+
response = JSON.parse(result.stdout);
|
|
162
|
+
} catch {
|
|
163
|
+
throw new Error("WebRouter search returned output that is not JSON.");
|
|
164
|
+
}
|
|
165
|
+
const rows = Array.isArray(response?.results) ? response.results : [];
|
|
166
|
+
const results = rows
|
|
167
|
+
.filter((row) => row && typeof row.url === "string" && row.url)
|
|
168
|
+
.slice(0, count)
|
|
169
|
+
.map((row) => {
|
|
170
|
+
const snippet = snippetOf(row);
|
|
171
|
+
return {
|
|
172
|
+
title: wrapWebContent(typeof row.title === "string" ? row.title : row.url, "web_search"),
|
|
173
|
+
url: row.url,
|
|
174
|
+
snippet: snippet ? wrapWebContent(snippet, "web_search") : "",
|
|
175
|
+
siteName: resolveSiteName(row.url) || undefined,
|
|
176
|
+
...(typeof row.published_date === "string" && row.published_date ? { published: row.published_date } : {}),
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
const payload = {
|
|
180
|
+
query: params.query,
|
|
181
|
+
provider: PLUGIN_ID,
|
|
182
|
+
...(typeof response?.provider === "string" ? { backend: response.provider } : {}),
|
|
183
|
+
count: results.length,
|
|
184
|
+
tookMs: Date.now() - startedAt,
|
|
185
|
+
externalContent: externalContentStamp(PLUGIN_ID),
|
|
186
|
+
results,
|
|
187
|
+
};
|
|
188
|
+
writeCachedSearchPayload(cacheKey, payload, cacheTtlMs);
|
|
189
|
+
return payload;
|
|
190
|
+
}
|
package/src/provider.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { readPositiveIntegerParam, readStringParam } from "openclaw/plugin-sdk/param-readers";
|
|
2
|
+
import {
|
|
3
|
+
WEB_SEARCH_QUERY_COUNT_PROPERTIES,
|
|
4
|
+
createWebSearchProviderContractFields,
|
|
5
|
+
} from "openclaw/plugin-sdk/provider-web-search-contract";
|
|
6
|
+
import { PLUGIN_ID, runWebRouterSearch } from "./client.js";
|
|
7
|
+
|
|
8
|
+
const WebRouterSearchSchema = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
...WEB_SEARCH_QUERY_COUNT_PROPERTIES,
|
|
12
|
+
country: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Optional two-letter country to search from, such as US or DE.",
|
|
15
|
+
},
|
|
16
|
+
locale: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Optional language of the results, such as en or fr.",
|
|
19
|
+
},
|
|
20
|
+
recency: {
|
|
21
|
+
type: "string",
|
|
22
|
+
enum: ["day", "week", "month", "year"],
|
|
23
|
+
description: "Optional: only results from this recent period.",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function createWebRouterWebSearchProvider() {
|
|
30
|
+
return {
|
|
31
|
+
id: PLUGIN_ID,
|
|
32
|
+
label: "WebRouter Search",
|
|
33
|
+
hint: "Web search through WebRouter; works with no API key",
|
|
34
|
+
onboardingScopes: ["text-inference"],
|
|
35
|
+
requiresCredential: false,
|
|
36
|
+
envVars: [],
|
|
37
|
+
placeholder: "(no key needed)",
|
|
38
|
+
signupUrl: "https://github.com/Nimbleway/webrouter",
|
|
39
|
+
docsUrl: "https://docs.webrouter.net/",
|
|
40
|
+
autoDetectOrder: 150,
|
|
41
|
+
credentialPath: "",
|
|
42
|
+
...createWebSearchProviderContractFields({
|
|
43
|
+
credentialPath: "",
|
|
44
|
+
searchCredential: { type: "scoped", scopeId: PLUGIN_ID },
|
|
45
|
+
selectionPluginId: PLUGIN_ID,
|
|
46
|
+
}),
|
|
47
|
+
createTool: (ctx) => ({
|
|
48
|
+
description:
|
|
49
|
+
"Search the web through WebRouter. Returns titles, URLs, and snippets; works with no API key.",
|
|
50
|
+
parameters: WebRouterSearchSchema,
|
|
51
|
+
execute: async (args, context) => {
|
|
52
|
+
context?.signal?.throwIfAborted();
|
|
53
|
+
const searchConfig = ctx.searchConfig;
|
|
54
|
+
return await runWebRouterSearch({
|
|
55
|
+
config: ctx.config,
|
|
56
|
+
query: readStringParam(args, "query", { required: true }),
|
|
57
|
+
count:
|
|
58
|
+
readPositiveIntegerParam(args, "count", {
|
|
59
|
+
max: 10,
|
|
60
|
+
message: "count must be an integer from 1 to 10.",
|
|
61
|
+
}) ?? searchConfig?.maxResults,
|
|
62
|
+
timeoutSeconds: searchConfig?.timeoutSeconds,
|
|
63
|
+
country: readStringParam(args, "country"),
|
|
64
|
+
locale: readStringParam(args, "locale"),
|
|
65
|
+
recency: readStringParam(args, "recency"),
|
|
66
|
+
...(context?.signal ? { signal: context.signal } : {}),
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
}
|