donsetch 2.2.1 → 2.2.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/pi-extension.ts +59 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "donsetch",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Web fetch, search and crawl for AI agents. Zero API keys. Chrome-true TLS.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Bishesh Bhandari",
package/pi-extension.ts CHANGED
@@ -32,8 +32,11 @@ const CALL_TIMEOUT_MS = 120_000;
32
32
  const SHUTDOWN_GRACE_MS = 2_000;
33
33
 
34
34
  // ── Color palette — DonSeTch amber theme ──
35
+ // Note: avoid green for success — pi's TUI highlights successful tool
36
+ // calls with green, and using green here causes a visual clash where
37
+ // ANSI codes bleed into pi's highlight. Amber for success, red for
38
+ // errors. Clean separation from pi's own colors.
35
39
  const C_AMBER = "\x1b[38;2;255;178;0m";
36
- const C_GREEN = "\x1b[38;2;100;200;100m";
37
40
  const C_RED = "\x1b[38;2;229;115;115m";
38
41
  const C_DIM = "\x1b[38;2;130;130;140m";
39
42
  const C_CREAM = "\x1b[38;2;240;230;210m";
@@ -286,6 +289,45 @@ function shortUrl(url: string): string {
286
289
  }
287
290
  }
288
291
 
292
+ /**
293
+ * Extract the search provider from structuredContent.
294
+ * Returns "local" when provider is null/undefined (local keyless
295
+ * engine), or the provider name ("exa", "tavily", "serper",
296
+ * "tinyfish") for BYOK.
297
+ */
298
+ function getSearchProvider(sc: any): string {
299
+ if (!sc) return "local";
300
+ const provider = sc.provider;
301
+ if (!provider || provider === "null") return "local";
302
+ return String(provider);
303
+ }
304
+
305
+ /**
306
+ * Extract the fetch source label from structuredContent.
307
+ * Returns "cache" when tier is "1(warm)" (warm cookies, not a
308
+ * fresh fetch), "ghost" when tier starts with "2" (browser
309
+ * escalation), or "" for a normal tier-1 fetch.
310
+ */
311
+ function getFetchSource(sc: any): string {
312
+ if (!sc) return "";
313
+ const tier = String(sc.tier || "");
314
+ if (tier.includes("warm")) return "cache";
315
+ if (tier.startsWith("2")) return "ghost";
316
+ return "";
317
+ }
318
+
319
+ /**
320
+ * Extract the fetch verdict/content status from structuredContent.
321
+ * Returns "blocked" when content_ok is false or verdict is not
322
+ * ContentOk, "" otherwise.
323
+ */
324
+ function getFetchStatus(sc: any): string {
325
+ if (!sc) return "";
326
+ if (sc.content_ok === false) return "blocked";
327
+ if (sc.thin === true) return "thin";
328
+ return "";
329
+ }
330
+
289
331
  // ── Extension ──
290
332
 
291
333
  export default function (pi: ExtensionAPI) {
@@ -342,6 +384,7 @@ export default function (pi: ExtensionAPI) {
342
384
  const result = await callMcpTool(toolName, params);
343
385
  const text = result?.content?.[0]?.text ?? "";
344
386
  const isErr = result?.isError ?? false;
387
+ const sc = result?.structuredContent ?? null;
345
388
 
346
389
  // Build details for TUI rendering
347
390
  const details: any = {
@@ -353,6 +396,10 @@ export default function (pi: ExtensionAPI) {
353
396
  if (toolName === "web_search") {
354
397
  details.results = countSearchResults(text);
355
398
  details.topResult = getFirstResultTitle(text);
399
+ details.provider = getSearchProvider(sc);
400
+ } else if (toolName === "web_fetch") {
401
+ details.source = getFetchSource(sc);
402
+ details.status = getFetchStatus(sc);
356
403
  } else if (toolName === "web_crawl") {
357
404
  details.pages = countCrawlPages(text);
358
405
  }
@@ -399,16 +446,22 @@ export default function (pi: ExtensionAPI) {
399
446
  const isErr = result?.isError || result?.details?.isError;
400
447
  const d = result?.details ?? {};
401
448
  const glyph = isErr ? "\u2717" : "\u2713";
402
- const color = isErr ? C_RED : C_GREEN;
449
+ const glyphColor = isErr ? C_RED : C_AMBER;
403
450
 
404
451
  // Build metadata string per tool
405
452
  let meta = "";
406
453
  if (toolName === "web_fetch") {
407
- const chars = d.chars ?? 0;
408
- meta = `${chars.toLocaleString()} chars`;
454
+ const parts: string[] = [];
455
+ parts.push(`${(d.chars ?? 0).toLocaleString()} chars`);
456
+ if (d.source === "cache") parts.push("via cache");
457
+ else if (d.source === "ghost") parts.push("via ghost");
458
+ if (d.status === "blocked") parts.push("blocked");
459
+ else if (d.status === "thin") parts.push("thin");
460
+ meta = parts.join(" \u00B7 ");
409
461
  } else if (toolName === "web_search") {
410
462
  const count = d.results ?? 0;
411
- meta = `${count} result${count !== 1 ? "s" : ""}`;
463
+ const provider = d.provider ?? "local";
464
+ meta = `${count} result${count !== 1 ? "s" : ""} \u00B7 via ${provider}`;
412
465
  } else if (toolName === "web_crawl") {
413
466
  const pages = d.pages ?? 0;
414
467
  meta = `${pages} page${pages !== 1 ? "s" : ""}`;
@@ -424,7 +477,7 @@ export default function (pi: ExtensionAPI) {
424
477
  line2 = d.preview;
425
478
  }
426
479
 
427
- const line1 = `${color}${glyph}${RESET} ${C_CREAM}${toolName}${RESET} ${C_DIM}\u00B7 ${meta}${RESET}`;
480
+ const line1 = `${glyphColor}${glyph}${RESET} ${C_CREAM}${toolName}${RESET} ${C_DIM}\u00B7 ${meta}${RESET}`;
428
481
  const output = line2
429
482
  ? `${line1}\n ${C_DIM}${line2}${RESET}`
430
483
  : line1;