pi-unsloth-webtools 0.6.0 → 0.6.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/README.md +2 -0
- package/index.ts +19 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ pi install /path/to/pi-unsloth-webtools
|
|
|
20
20
|
|
|
21
21
|
## What it does
|
|
22
22
|
|
|
23
|
+
Both tools display their target in the TUI tool row: `web_search "query"`, `web_search <url>` in url mode, and `web_fetch <url>`.
|
|
24
|
+
|
|
23
25
|
### web_search
|
|
24
26
|
|
|
25
27
|
Mirrors Unsloth Studio's `web_search` tool:
|
package/index.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { defineTool, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { defineTool, type ExtensionAPI, type ExtensionContext, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { collapseWhitespace } from "./html-to-md.ts";
|
|
3
4
|
import { SEARCH_TIMEOUT_MS, webSearch as defaultWebSearch } from "./web-search.ts";
|
|
4
5
|
import { DEFAULT_FETCH_TIMEOUT_MS, fetchPageText as defaultFetchPageText } from "./web-fetch.ts";
|
|
5
6
|
import { loadDefaultFetchSettings, loadDefaultFetchTimeoutMs } from "./settings.ts";
|
|
6
7
|
|
|
8
|
+
function toolCallLine(theme: Theme, name: string, detail: string) {
|
|
9
|
+
const line = theme.fg("toolTitle", theme.bold(name)) + (detail ? ` ${theme.fg("accent", detail)}` : "");
|
|
10
|
+
return { render: () => [line], invalidate: () => {} };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function collapsedArg(value: unknown): string {
|
|
14
|
+
return collapseWhitespace(typeof value === "string" ? value : "");
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
function positiveNumber(value: unknown): number | undefined {
|
|
8
18
|
if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
|
|
9
19
|
const n = Math.floor(value);
|
|
@@ -87,6 +97,11 @@ export function createWebTools(deps: WebToolsDeps = {}) {
|
|
|
87
97
|
'Use web_search with the url parameter (e.g. {"url": "<URL>"}) to read the full text of a page found in search results.',
|
|
88
98
|
],
|
|
89
99
|
parameters: WebSearchParams,
|
|
100
|
+
renderCall(args, theme) {
|
|
101
|
+
const url = collapsedArg(args.url);
|
|
102
|
+
const query = collapsedArg(args.query);
|
|
103
|
+
return toolCallLine(theme, "web_search", url || (query ? `"${query}"` : ""));
|
|
104
|
+
},
|
|
90
105
|
async execute(_toolCallId, params, signal, onUpdate, _ctx) {
|
|
91
106
|
if (params.url?.trim()) {
|
|
92
107
|
const url = params.url.trim();
|
|
@@ -135,6 +150,9 @@ export function createWebTools(deps: WebToolsDeps = {}) {
|
|
|
135
150
|
"webFetch.allowLocalFiles: false in settings. The download size is capped.",
|
|
136
151
|
promptSnippet: "Fetch a web page and return readable text content",
|
|
137
152
|
parameters: WebFetchParams,
|
|
153
|
+
renderCall(args, theme) {
|
|
154
|
+
return toolCallLine(theme, "web_fetch", collapsedArg(args.url));
|
|
155
|
+
},
|
|
138
156
|
async execute(_toolCallId, params, signal, onUpdate, _ctx) {
|
|
139
157
|
onUpdate?.({ content: [{ type: "text", text: `Fetching ${params.url}...` }], details: {} });
|
|
140
158
|
const cwd = (_ctx as ExtensionContext | undefined)?.cwd;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-unsloth-webtools",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pi extension: web_search and web_fetch tools ported from the Unsloth Studio codebase (DuckDuckGo search, SSRF-safe direct fetching, HTML-to-Markdown extraction)",
|
|
6
6
|
"main": "index.ts",
|