pi-ext
bugabingas pi extensions
owned by admin
fix(web): align fetch output limit
734bbd0ceff17fc2dd7dbf11a0c93d4ac7a9c327
Oliver Jan Krylow <oliver@bugabinga.net> ·
SSH signature · not checked
Browse filesCompare with HEAD
Changed files (4)
extensions/web/README.md
Modified 26 26 optional; `markdown` default, or `text`, `html`, `json`, `raw`.
28 - optional; default/max `20000`, min `100`.
28 + optional; default `20000`, max `100000`, min `100`.
30 30 optional; default `120000` ms, min `5000`, max `600000`.
31 31 Passed to `fetchUrlStream` alongside the Pi/tool abort signal.
42 42 optional; default `20`, min `1`, max `100`.
44 - optional; default `8000`, min `100`, max `100000`.
44 + optional; default `8000`, max `100000`, min `100`.
extensions/web/__tests__/harness.test.ts
Modified 12 12 import { createTestSession, type TestSession }
from "../../../test/harness";
13 -import { DEFAULT_MAX_CHARS, DEFAULT_TIMEOUT_MS }
from "../constants";
13 +import { DEFAULT_TIMEOUT_MS, MAX_VISIBLE_CHARS }
from "../constants";
14 14 import webExtension
from "../index";
15 15 import * as search
from "../search";
87 87 expect(props.format.
description).
toContain(
"raw skips conversion");
88 88 expect(props.linesMatching.
description).
toContain(
"Literal substrings");
89 89 expect(props.contextLines.
description).
toContain(
"max 100");
90 - expect(props.maxChars.
description).
toContain(
91 - `default/max ${DEFAULT_MAX_CHARS}`,
90 + expect(props.maxChars.
description).
toContain(
`max ${MAX_VISIBLE_CHARS}`);
93 91 expect(props.timeout.
description).
toContain(
94 92 `default ${DEFAULT_TIMEOUT_MS}`,
140 - [
"maxChars",
100,
100_000],
138 + [
"maxChars",
100, MAX_VISIBLE_CHARS],
141 139 [
"maxBytes",
1000,
100_000_000],
142 140 [
"contextLines",
0,
100],
143 141 [
"timeout",
5000,
600_000],
166 164 url:
"https://example.com",
167 - maxChars: DEFAULT_MAX_CHARS
+ 1,
165 + maxChars: MAX_VISIBLE_CHARS
+ 1,
169 167 {
action:
"search",
query:
"docs",
format:
"markdown" },
170 168 {
action:
"fetch",
url:
"https://example.com",
count:
5 },
extensions/web/constants.ts
Modified 5 5 export const DEFAULT_TIMEOUT_MS
= 120_000;
6 6 export const DEFAULT_MAX_BYTES
= 50 * 1024 * 1024;
7 7 export const DEFAULT_MAX_CHARS
= 20_000;
8 +export const MAX_VISIBLE_CHARS
= 100_000;
8 9 export const DDG_HTML_URL
= "https://html.duckduckgo.com/html/";
10 11 export const USER_AGENT
= extensions/web/index.ts
Modified 32 32 DEFAULT_TIMEOUT_MS,
34 35 }
from "./constants.js";
35 36 import { lazy }
from "./lazy.js";
799 800 maxChars: Type.
Optional(
801 - description:
`Visible characters (default ${DEFAULT_MAX_CHARS}).`,
802 + description:
`Visible characters (default ${DEFAULT_MAX_CHARS}, max ${MAX_VISIBLE_CHARS}).`,
803 - maximum: DEFAULT_MAX_CHARS,
804 + maximum: MAX_VISIBLE_CHARS,
806 807 maxBytes: Type.
Optional(
1020 1021 const format
= params.format
?? "markdown";
1021 1022 const maxChars
= Math.
min(
1022 1023 params.maxChars
?? DEFAULT_MAX_CHARS,
1023 - DEFAULT_MAX_CHARS,
1024 + MAX_VISIBLE_CHARS,
1026 1027 const setStatus = (msg
: string)
=> ctx?.ui?.
setStatus(
"web", msg);
1184 1185 maxChars: Type.
Optional(
1186 - description:
"Visible characters (default 8000).",
1187 + description:
`Visible characters (default 8000, max ${MAX_VISIBLE_CHARS}).`,
1189 + maximum: MAX_VISIBLE_CHARS,
1475 1476 maxChars: Type.
Optional(
1477 - description:
`Fetch: default/max ${DEFAULT_MAX_CHARS}. Map: default 8000, max 100000.`,
1478 + description:
`Fetch: default ${DEFAULT_MAX_CHARS}, max ${MAX_VISIBLE_CHARS}. Map: default 8000, max ${MAX_VISIBLE_CHARS}.`,
1480 + maximum: MAX_VISIBLE_CHARS,
1491 1492 const { Check, Errors }
= await import(
"typebox/value");
1492 1493 const schema
= {
...handler.parameters, additionalProperties:
false };
1493 1494 if (
!Check(schema, params)) {
1495 - `Invalid web ${action} arguments: ${JSON.stringify([...Errors(schema, params)])}`,
1495 + const details
= [
...Errors(schema, params)]
1497 + const path
= "path" in error
? error.path
: "arguments";
1499 + "value" in error
? JSON.
stringify(error.
value)
: "unknown";
1500 + return `${path} ${error.message} (received ${value})`;
1503 + throw new Error(
`Invalid web ${action} arguments: ${details}`);
1498 1505 return handler.
execute(id, params, signal, onUpdate, ctx);