pi-web-kit 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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project follows the spirit of [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and uses semantic versioning for releases.
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-05-09
10
+
11
+ ### Added
12
+
13
+ - Initial `pi-web-kit` package with `web_search` and `web_fetch` Pi tools.
14
+ - Search providers: `exa_mcp`, `exa`, `tinyfish`, `brave`, and `firecrawl`.
15
+ - Fetch providers: `exa_mcp`, `exa`, `tinyfish`, `markdown_new`, and `firecrawl`.
16
+ - Provider-specific tool schemas, startup-provider mismatch guidance, and CLI provider override flags.
17
+ - In-memory fetch cache with TTL, LRU eviction, max entry count, max byte count, and fetch-affecting cache keys.
18
+ - URL validation and normalization for HTTP(S)-only URLs, credential rejection, fragment stripping, duplicate removal, and URL count/length caps.
19
+ - Request limits, bounded provider concurrency, fetch timeouts, and robust provider result mapping for canonicalized or redirected URLs.
20
+ - Tests for config precedence, provider behavior, cache safety, URL validation, concurrency, timeouts, and tool behavior.
21
+ - GitHub-ready project docs, issue templates, CI, and npm provenance publishing workflow.
@@ -0,0 +1,41 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment include:
12
+
13
+ - Demonstrating empathy and kindness toward other people
14
+ - Being respectful of differing opinions, viewpoints, and experiences
15
+ - Giving and gracefully accepting constructive feedback
16
+ - Accepting responsibility and apologizing to those affected by our mistakes
17
+ - Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ - The use of sexualized language or imagery, and sexual attention or advances
22
+ - Trolling, insulting or derogatory comments, and personal or political attacks
23
+ - Public or private harassment
24
+ - Publishing others' private information without explicit permission
25
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
26
+
27
+ ## Enforcement Responsibilities
28
+
29
+ Project maintainers are responsible for clarifying and enforcing standards of acceptable behavior and may remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies within all project spaces and also applies when an individual is officially representing the project in public spaces.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the project maintainers through GitHub. All complaints will be reviewed and investigated promptly and fairly.
38
+
39
+ ## Attribution
40
+
41
+ This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
@@ -0,0 +1,55 @@
1
+ # Contributing
2
+
3
+ Thanks for your interest in contributing to `pi-web-kit`.
4
+
5
+ ## Development setup
6
+
7
+ ```bash
8
+ npm install
9
+ npm run check
10
+ npm test
11
+ ```
12
+
13
+ This package is source-distributed: Pi loads the TypeScript extension files directly. There is no build step for runtime use.
14
+
15
+ ## Local testing
16
+
17
+ Install this checkout into a temporary Pi project:
18
+
19
+ ```bash
20
+ mkdir -p <test-project>
21
+ cd <test-project>
22
+ pi install -l /path/to/pi-web-kit
23
+ pi
24
+ ```
25
+
26
+ For a one-off run without changing settings:
27
+
28
+ ```bash
29
+ pi -e /path/to/pi-web-kit --web-provider-fetch markdown_new --print "Fetch https://example.com"
30
+ ```
31
+
32
+ ## Pull request checklist
33
+
34
+ Before opening a pull request:
35
+
36
+ - Run `npm run check`.
37
+ - Run `npm test`.
38
+ - Run `npm audit --omit=dev`.
39
+ - Run `npm run pack:dry-run` and confirm the package contents are intentional.
40
+ - Update `README.md` if user-facing behavior changes.
41
+ - Update `CHANGELOG.md` for notable changes.
42
+ - Keep examples and paths generic; do not commit machine-specific paths, API keys, tokens, or provider config containing secrets.
43
+
44
+ ## Coding guidelines
45
+
46
+ - Keep `extensions/pi-web-kit/index.ts` focused on Pi tool registration and move reusable implementation details into `src/`.
47
+ - When changing tool parameters, update the Typebox schema, runtime validation, README parameter docs, and tests together.
48
+ - Treat provider names, config keys, env vars, and cache semantics as public interface; changes to defaults or precedence are breaking changes.
49
+ - Validate and normalize external URLs before provider calls.
50
+ - Bound network work: use shared limits, timeouts, and concurrency helpers for new provider integrations.
51
+ - Keep tool `details` compact; full result text belongs in tool content and should remain bounded by `truncateText()`.
52
+
53
+ ## Code of conduct
54
+
55
+ This project follows the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jose Mocito
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,232 @@
1
+ # pi-web-kit
2
+
3
+ Context-efficient web search and fetch tools for [Pi](https://github.com/badlogic/pi-mono): `web_search` and `web_fetch`.
4
+
5
+ `pi-web-kit` provides provider-backed search and page fetching with bounded output, chunked reads, URL validation, and an in-memory fetch cache designed for agent workflows.
6
+
7
+ ## Features
8
+
9
+ - `web_search` for current/external web information, including multi-query searches.
10
+ - `web_fetch` for reading one or more URLs, with `offset` / `limit` chunk reads for long pages.
11
+ - Multiple provider backends: Exa MCP, Exa API, TinyFish, Brave Search, Firecrawl, and markdown.new.
12
+ - Provider-tailored tool schemas at Pi startup/reload.
13
+ - URL validation: HTTP(S)-only, no embedded credentials, fragment stripping, duplicate removal, and length/count limits.
14
+ - In-memory fetch cache with TTL, LRU eviction, max entry count, max byte count, and cache keys based on provider/config/fetch-affecting options.
15
+ - Bounded provider concurrency and network timeouts.
16
+
17
+ ## Installation
18
+
19
+ Install from npm:
20
+
21
+ ```bash
22
+ pi install npm:pi-web-kit
23
+ ```
24
+
25
+ Install from GitHub:
26
+
27
+ ```bash
28
+ pi install git:github.com/jvm/pi-web-kit
29
+ ```
30
+
31
+ Install project-locally with Pi's `-l` flag:
32
+
33
+ ```bash
34
+ pi install -l git:github.com/jvm/pi-web-kit
35
+ ```
36
+
37
+ During local development from this repository:
38
+
39
+ ```bash
40
+ pi install /path/to/pi-web-kit
41
+ ```
42
+
43
+ For a one-off test run without installing:
44
+
45
+ ```bash
46
+ pi -e /path/to/pi-web-kit --web-provider-fetch markdown_new --print "Fetch https://example.com"
47
+ ```
48
+
49
+ This is an npm-compatible TypeScript Pi package. Bun is not required.
50
+
51
+ ## Quick usage
52
+
53
+ Search:
54
+
55
+ ```text
56
+ Find recent documentation for the Pi extension API.
57
+ ```
58
+
59
+ Multi-query search:
60
+
61
+ ```text
62
+ Search for recent docs on Pi extensions and Pi tool schemas.
63
+ ```
64
+
65
+ Fetch a page:
66
+
67
+ ```text
68
+ Read https://example.com and summarize it.
69
+ ```
70
+
71
+ Fetch a long page in chunks:
72
+
73
+ ```text
74
+ Fetch https://example.com/long-doc with limit 8000, then continue with offset 8000.
75
+ ```
76
+
77
+ Pi chooses `web_search` or `web_fetch` automatically when the request calls for it. You can also mention provider settings explicitly in prompts, but provider changes usually require config or CLI flags.
78
+
79
+ ## Providers
80
+
81
+ Defaults: `provider_search = "exa_mcp"`, `provider_fetch = "exa_mcp"`.
82
+
83
+ | Provider | Search | Fetch | Key |
84
+ |---|---:|---:|---|
85
+ | `exa_mcp` | yes | yes | optional `EXA_API_KEY` |
86
+ | `exa` | yes | yes | `EXA_API_KEY` |
87
+ | `tinyfish` | yes | yes | `TINYFISH_API_KEY` |
88
+ | `brave` | yes | no | `BRAVE_SEARCH_API_KEY` |
89
+ | `firecrawl` | yes | yes | `FIRECRAWL_API_KEY` |
90
+ | `markdown_new` | no | yes | none |
91
+
92
+ Tool schemas are tailored to the configured providers at startup/reload, so only supported provider-specific fields are exposed. Restart/reload Pi after changing provider config.
93
+
94
+ ## Configuration
95
+
96
+ Resolution order: defaults < environment variables < global config < project config < CLI flags.
97
+
98
+ ### Environment variables
99
+
100
+ ```bash
101
+ PI_WEB_KIT_PROVIDER_SEARCH=exa_mcp|exa|tinyfish|brave|firecrawl
102
+ PI_WEB_KIT_PROVIDER_FETCH=exa_mcp|exa|tinyfish|markdown_new|firecrawl
103
+ EXA_API_KEY=...
104
+ TINYFISH_API_KEY=...
105
+ BRAVE_SEARCH_API_KEY=...
106
+ FIRECRAWL_API_KEY=...
107
+ ```
108
+
109
+ ### Config files
110
+
111
+ Config files, in increasing precedence:
112
+
113
+ | Scope | Path |
114
+ |---|---|
115
+ | Global | `~/.pi/agent/pi-web-kit.json` |
116
+ | Project | `.pi-web-kit.json` |
117
+
118
+ Example:
119
+
120
+ ```json
121
+ {
122
+ "provider_search": "firecrawl",
123
+ "provider_fetch": "markdown_new",
124
+ "apiKeys": {
125
+ "firecrawl": "..."
126
+ },
127
+ "markdownNew": {
128
+ "method": "auto",
129
+ "retainImages": false
130
+ }
131
+ }
132
+ ```
133
+
134
+ Do not commit config files containing secrets. Project `.pi-web-kit.json` is ignored by this repo's `.gitignore`, but other repositories may need their own ignore rule.
135
+
136
+ ### CLI overrides
137
+
138
+ ```bash
139
+ pi -e . --web-provider-search firecrawl --web-provider-fetch markdown_new --print "Search and fetch docs"
140
+ ```
141
+
142
+ Provider CLI flags are temporary for the Pi process. Restart/reload Pi after changing provider config so registered tool schemas match the active provider.
143
+
144
+ ## Tools
145
+
146
+ ### `web_search`
147
+
148
+ Searches with the active search provider and returns compact results grouped by query.
149
+
150
+ | Parameter | Type | Description |
151
+ |---|---|---|
152
+ | `query` | string | Single search query. |
153
+ | `queries` | string[] | Multiple related search queries. Max 5 after de-duplication. |
154
+ | `numResults` | integer | Results per query. Range: 1-20. Default: 10. |
155
+
156
+ Provider-specific parameters are exposed only for the configured provider, such as Exa date/domain filters, TinyFish `page`, Brave locale/freshness options, or Firecrawl scrape/search options.
157
+
158
+ ### `web_fetch`
159
+
160
+ Fetches page content with the active fetch provider. Results are cached in memory by canonical URL plus provider/config/fetch-affecting options.
161
+
162
+ | Parameter | Type | Description |
163
+ |---|---|---|
164
+ | `url` | string | Single URL. Must be `http:` or `https:`. |
165
+ | `urls` | string[] | Multiple URLs. Max 10 after de-duplication. |
166
+ | `offset` | integer | Character offset for cached/ranged reads. Single URL only. |
167
+ | `limit` | integer | Maximum characters to return. Default: 30,000 for one URL, 8,000 for multiple URLs. |
168
+ | `refresh` | boolean | Refetch even if cached. |
169
+
170
+ Provider-specific parameters are exposed only for the configured provider, such as TinyFish `format`, markdown.new `method` / `retainImages`, or Firecrawl `format`, `waitFor`, `mobile`, `location`, and `maxAge`.
171
+
172
+ ## Cache and limits
173
+
174
+ `web_fetch` uses an in-memory cache for the current Pi process.
175
+
176
+ | Limit | Value |
177
+ |---|---:|
178
+ | Cache TTL | 30 minutes |
179
+ | Max cached entries | 100 |
180
+ | Max cached bytes | 20 MiB |
181
+ | Max URLs per call | 10 |
182
+ | Max queries per call | 5 |
183
+ | Max `numResults` | 20 |
184
+ | Max URL length | 2048 characters |
185
+
186
+ Cache keys include the provider, canonical URL, fetch-affecting parameters, relevant provider defaults, and a short API-key/account scope marker. `refresh: true` bypasses and replaces the cached entry.
187
+
188
+ ## Privacy and security
189
+
190
+ `pi-web-kit` sends search queries and fetched URLs to the configured provider. Fetch providers may also receive provider-specific options. API keys are read from environment variables or local config files and are used only for provider requests.
191
+
192
+ The extension rejects non-HTTP(S) URLs and URLs with embedded username/password credentials. Provider responses are not sandboxed; they are returned to Pi as tool output.
193
+
194
+ Report security issues privately. See [SECURITY.md](SECURITY.md).
195
+
196
+ ## Troubleshooting
197
+
198
+ | Symptom | Cause | Fix |
199
+ |---|---|---|
200
+ | `provider requires ... API_KEY` | Selected provider needs an API key. | Set the provider's env var or `apiKeys` config entry. |
201
+ | Provider mismatch / schema error after config change | Pi registered tools for the previous startup provider. | Restart/reload Pi after provider changes. |
202
+ | Invalid URL / scheme / credentials error | URL validation rejected the input. | Use an absolute `http:` or `https:` URL without username/password credentials. |
203
+ | Timeout error | Provider request exceeded its timeout. | Retry, reduce URL count, or switch provider. |
204
+ | No content returned | Provider returned no matching content or a redirected/canonicalized response could not be mapped. | Retry with `refresh: true`, fetch a single URL, or switch provider. |
205
+ | Large page is truncated | Tool output is bounded for context efficiency. | Use `offset` and `limit` to continue reading chunks. |
206
+
207
+ ## Development
208
+
209
+ Requirements:
210
+
211
+ - Node.js >= 20.6.0
212
+ - npm
213
+
214
+ Common commands:
215
+
216
+ ```bash
217
+ npm install
218
+ npm run check
219
+ npm test
220
+ npm audit --omit=dev
221
+ npm run pack:dry-run
222
+ ```
223
+
224
+ This package is source-distributed. Pi loads the TypeScript extension files directly via its extension loader.
225
+
226
+ ## Contributing
227
+
228
+ Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for development workflow and pull request guidelines.
229
+
230
+ ## License
231
+
232
+ MIT. See [LICENSE](LICENSE).
package/SECURITY.md ADDED
@@ -0,0 +1,26 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes are provided for the latest released version of `pi-web-kit`.
6
+
7
+ ## Reporting a vulnerability
8
+
9
+ Please do not open a public issue for suspected security vulnerabilities.
10
+
11
+ Report privately by contacting the repository maintainer through GitHub. Include:
12
+
13
+ - a description of the issue;
14
+ - steps to reproduce;
15
+ - affected versions or commits, if known;
16
+ - any suggested mitigation.
17
+
18
+ The maintainer will acknowledge reports as soon as practical and coordinate disclosure once a fix or mitigation is available.
19
+
20
+ ## Security model
21
+
22
+ `pi-web-kit` is a Pi package. Pi extensions execute with the same permissions as the local user running Pi. Users should review installed Pi packages and only install packages from sources they trust.
23
+
24
+ `pi-web-kit` sends search queries and fetched URLs to the configured third-party provider. Page content returned by providers is cached in memory for the lifetime of the Pi process, subject to TTL and size limits. API keys are read from environment variables or local config files and are used only for provider requests. Do not commit API keys, tokens, or config files containing secrets.
25
+
26
+ The extension validates URLs before fetch calls and only accepts `http:` and `https:` URLs without embedded credentials. This validation reduces accidental misuse but does not sandbox provider responses or the local Pi process.