@crewhaus/tool-web 0.5.8 → 0.6.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/dist/index.d.ts CHANGED
@@ -17,6 +17,14 @@ export type WebFetchConfigInput = {
17
17
  readonly allowedDomains?: readonly string[];
18
18
  };
19
19
  export declare function registerWebFetchConfig(input: WebFetchConfigInput): void;
20
+ /**
21
+ * 0.6.0 §4.4 — the config ONE call runs under: the serving candidate's
22
+ * `tool_config.webFetch` block when its profile declares one
23
+ * (`ToolExecuteContext.toolConfig`, REPLACING the registered block for this
24
+ * call exactly as `registerWebFetchConfig` replaces it at boot), else the
25
+ * process-global registration. A non-object override is ignored.
26
+ */
27
+ export declare function resolveWebFetchConfig(override: unknown): WebFetchConfig;
20
28
  export declare function getWebFetchConfig(): WebFetchConfig;
21
29
  export declare function _resetWebFetchConfig(): void;
22
30
  /**
package/dist/index.js CHANGED
@@ -51,8 +51,24 @@ export class WebFetchPermissionError extends CrewhausError {
51
51
  }
52
52
  let webFetchConfig = { allowedDomains: [] };
53
53
  export function registerWebFetchConfig(input) {
54
+ webFetchConfig = buildWebFetchConfig(input);
55
+ }
56
+ function buildWebFetchConfig(input) {
54
57
  const raw = input.allowedDomains ?? input.allowed_domains ?? [];
55
- webFetchConfig = { allowedDomains: raw.map((d) => d.toLowerCase()) };
58
+ return { allowedDomains: raw.map((d) => d.toLowerCase()) };
59
+ }
60
+ /**
61
+ * 0.6.0 §4.4 — the config ONE call runs under: the serving candidate's
62
+ * `tool_config.webFetch` block when its profile declares one
63
+ * (`ToolExecuteContext.toolConfig`, REPLACING the registered block for this
64
+ * call exactly as `registerWebFetchConfig` replaces it at boot), else the
65
+ * process-global registration. A non-object override is ignored.
66
+ */
67
+ export function resolveWebFetchConfig(override) {
68
+ if (typeof override === "object" && override !== null && !Array.isArray(override)) {
69
+ return buildWebFetchConfig(override);
70
+ }
71
+ return webFetchConfig;
56
72
  }
57
73
  export function getWebFetchConfig() {
58
74
  return webFetchConfig;
@@ -60,11 +76,11 @@ export function getWebFetchConfig() {
60
76
  export function _resetWebFetchConfig() {
61
77
  webFetchConfig = { allowedDomains: [] };
62
78
  }
63
- function isHostAllowed(host) {
64
- if (webFetchConfig.allowedDomains.length === 0)
79
+ function isHostAllowed(host, cfg) {
80
+ if (cfg.allowedDomains.length === 0)
65
81
  return true;
66
82
  const lower = host.toLowerCase();
67
- return webFetchConfig.allowedDomains.some((entry) => lower === entry || lower.endsWith(`.${entry}`));
83
+ return cfg.allowedDomains.some((entry) => lower === entry || lower.endsWith(`.${entry}`));
68
84
  }
69
85
  // Production default — a single named function shared by both the initial
70
86
  // binding and the `_setDnsLookup(undefined)` reset path, so there is one
@@ -299,7 +315,7 @@ async function readBodyCapped(res) {
299
315
  }
300
316
  return new TextDecoder("utf-8", { fatal: false }).decode(merged);
301
317
  }
302
- async function performWebFetch(initialUrl, signal) {
318
+ async function performWebFetch(initialUrl, signal, cfg) {
303
319
  let currentUrl = initialUrl;
304
320
  for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
305
321
  if (currentUrl.protocol !== "http:" && currentUrl.protocol !== "https:") {
@@ -309,7 +325,7 @@ async function performWebFetch(initialUrl, signal) {
309
325
  // The returned IP pins the socket so a rebinding resolver can't swap in a
310
326
  // private address between this check and connect.
311
327
  const pinnedIp = await assertNotSsrf(currentUrl.hostname);
312
- if (!isHostAllowed(currentUrl.hostname)) {
328
+ if (!isHostAllowed(currentUrl.hostname, cfg)) {
313
329
  throw new WebFetchPermissionError(`WebFetch denied: host "${currentUrl.hostname}" is not in allowed_domains`);
314
330
  }
315
331
  const res = await rawFetch(new Request(currentUrl.toString(), {
@@ -394,7 +410,7 @@ export const webFetch = buildTool({
394
410
  }
395
411
  let res;
396
412
  try {
397
- res = await performWebFetch(url, ctrl.signal);
413
+ res = await performWebFetch(url, ctrl.signal, resolveWebFetchConfig(ctx?.toolConfig));
398
414
  }
399
415
  finally {
400
416
  clearTimeout(timer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/tool-web",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "WebFetch (URL → markdown via cheerio + turndown) and WebSearch (provider dispatch)",
6
6
  "main": "dist/index.js",
@@ -15,9 +15,9 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/errors": "0.5.8",
19
- "@crewhaus/tool-builder": "0.5.8",
20
- "@crewhaus/tool-catalog": "0.5.8",
18
+ "@crewhaus/errors": "0.6.0",
19
+ "@crewhaus/tool-builder": "0.6.0",
20
+ "@crewhaus/tool-catalog": "0.6.0",
21
21
  "cheerio": "^1.0.0",
22
22
  "turndown": "^7.2.0",
23
23
  "zod": "^3.23.8"