@rjshrjndrn/pi-fetch 0.1.2 → 0.1.3
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/extensions/index.ts +32 -0
- package/package.json +3 -2
package/extensions/index.ts
CHANGED
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
DEFAULT_MAX_BYTES,
|
|
5
5
|
DEFAULT_MAX_LINES,
|
|
6
6
|
formatSize,
|
|
7
|
+
keyHint,
|
|
7
8
|
} from "@mariozechner/pi-coding-agent"
|
|
9
|
+
import { Text } from "@mariozechner/pi-tui"
|
|
8
10
|
import { Type } from "@sinclair/typebox"
|
|
9
11
|
import { fetchPage, formatResult } from "../src/fetch.js"
|
|
10
12
|
|
|
@@ -26,6 +28,36 @@ export default function (pi: ExtensionAPI) {
|
|
|
26
28
|
url: Type.String({ description: "URL of the webpage to fetch" }),
|
|
27
29
|
}),
|
|
28
30
|
|
|
31
|
+
renderCall(args, theme, context) {
|
|
32
|
+
const text = (context.lastComponent as Text) ?? new Text("", 0, 0)
|
|
33
|
+
const url = typeof args?.url === "string" ? args.url : "..."
|
|
34
|
+
text.setText(
|
|
35
|
+
`${theme.fg("toolTitle", theme.bold("web_fetch"))} ${theme.fg("accent", url)}`
|
|
36
|
+
)
|
|
37
|
+
return text
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
renderResult(result, options, theme, context) {
|
|
41
|
+
const text = (context.lastComponent as Text) ?? new Text("", 0, 0)
|
|
42
|
+
const output =
|
|
43
|
+
result.content
|
|
44
|
+
?.filter((c: any) => c.type === "text")
|
|
45
|
+
.map((c: any) => c.text || "")
|
|
46
|
+
.join("\n") || ""
|
|
47
|
+
|
|
48
|
+
const lines = output.split("\n")
|
|
49
|
+
const maxLines = options.expanded ? lines.length : 10
|
|
50
|
+
const displayLines = lines.slice(0, maxLines)
|
|
51
|
+
const remaining = lines.length - maxLines
|
|
52
|
+
|
|
53
|
+
let rendered = `\n${displayLines.map((line: string) => theme.fg("toolOutput", line)).join("\n")}`
|
|
54
|
+
if (remaining > 0) {
|
|
55
|
+
rendered += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`
|
|
56
|
+
}
|
|
57
|
+
text.setText(rendered)
|
|
58
|
+
return text
|
|
59
|
+
},
|
|
60
|
+
|
|
29
61
|
async execute(_toolCallId, params, signal, _onUpdate, _ctx) {
|
|
30
62
|
const result = await fetchPage(params.url, signal ?? undefined)
|
|
31
63
|
const output = formatResult(result)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjshrjndrn/pi-fetch",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Web content extraction for pi — fetch any URL as clean Markdown using Defuddle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"jsdom": "^29.0.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@mariozechner/pi-coding-agent": "
|
|
25
|
+
"@mariozechner/pi-coding-agent": "^0.66.1",
|
|
26
|
+
"@mariozechner/pi-tui": "*",
|
|
26
27
|
"@sinclair/typebox": "*"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|