@parcha/agentrun-web 0.1.0-beta.59 → 0.1.0-beta.61

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.
@@ -1,5 +1,6 @@
1
1
  // The search step: a search's results sifted under a policy.
2
2
  import { clip } from "../page.js";
3
+ import { kindOf } from "../providers/keyed.js";
3
4
  import { QUERY_MAX } from "../search.js";
4
5
  import { bounded, byScore, droppedOf, drops, failed, ran, relevanceOf, since, skipped } from "./record.js";
5
6
  /** Under label or rerank+label, the score at least one result must reach for the search not to be called a miss. */
@@ -8,7 +9,7 @@ const POLICIES = ["drop", "label", "rerank+label"];
8
9
  /** `policy`, "drop" when none is given; any other value throws. */
9
10
  export function policyOf(policy = "drop") {
10
11
  if (!POLICIES.includes(policy))
11
- throw new RangeError(`the classifier's policy must be "drop", "label" or "rerank+label" (it was ${JSON.stringify(policy)})`);
12
+ throw new RangeError(`the classifier's policy must be "drop", "label" or "rerank+label" (it was ${kindOf(policy)})`);
12
13
  return policy;
13
14
  }
14
15
  /** A search's results sifted by `decider` under `options.policy` (DecidePolicy), and `sift` telling the model what was
@@ -39,6 +39,8 @@ export declare const wholeIn: (min: number, max: number) => Check;
39
39
  export declare const yesNo: Check;
40
40
  export declare const matching: (pattern: RegExp, must: string) => Check;
41
41
  export declare const domains: (max: number) => Check;
42
+ /** A refused value's kind in words, for a problem line that names it without echoing it. */
43
+ export declare const kindOf: (value: unknown) => string;
42
44
  /** What is wrong with `settings` for `who` by `checks`, one line each: not an object, a setting it does not take, or a
43
- * value its check refuses. */
45
+ * value its check refuses, named by its kind and never echoed (a key pasted into the wrong setting stays out of it). */
44
46
  export declare function settingsProblems(who: string, settings: unknown, checks: Readonly<Record<string, Check>>): string[];
@@ -120,17 +120,20 @@ export const wholeIn = (min, max) => [(value) => Number.isInteger(value) && valu
120
120
  export const yesNo = [(value) => typeof value === "boolean", "true or false"];
121
121
  export const matching = (pattern, must) => [(value) => typeof value === "string" && pattern.test(value), must];
122
122
  export const domains = (max) => [(value) => Array.isArray(value) && value.length <= max && value.every((one) => typeof one === "string" && one.trim() !== "" && one.length <= 253), `a list of at most ${max} domains`];
123
+ /** A refused value's kind in words, for a problem line that names it without echoing it. */
124
+ export const kindOf = (value) => value === null ? "null" : Array.isArray(value) ? "a list" : typeof value === "object" ? "an object" : `a ${typeof value}`;
123
125
  /** What is wrong with `settings` for `who` by `checks`, one line each: not an object, a setting it does not take, or a
124
- * value its check refuses. */
126
+ * value its check refuses, named by its kind and never echoed (a key pasted into the wrong setting stays out of it). */
125
127
  export function settingsProblems(who, settings, checks) {
126
128
  if (typeof settings !== "object" || settings === null || Array.isArray(settings))
127
129
  return [`${who}'s settings must be an object`];
128
130
  return Object.entries(settings).flatMap(([name, value]) => {
129
- const check = checks[name];
131
+ // Its own checks alone: a setting named constructor or __proto__ is not Object's member.
132
+ const check = Object.hasOwn(checks, name) ? checks[name] : undefined;
130
133
  if (!check)
131
134
  return [`${who} takes no setting ${JSON.stringify(name)} (it takes ${Object.keys(checks).join(", ")})`];
132
135
  if (value === undefined || check[0](value))
133
136
  return [];
134
- return [`${who}'s ${name} must be ${check[1]} (it was ${String(JSON.stringify(value)).slice(0, 60)})`];
137
+ return [`${who}'s ${name} must be ${check[1]} (it was ${kindOf(value)})`];
135
138
  });
136
139
  }
package/dist/web.js CHANGED
@@ -9,6 +9,7 @@ import { missesOf, webFetchText, webPart, webRead } from "./fetch.js";
9
9
  import { unmetered } from "./fees.js";
10
10
  import { askedUrl, partProblem } from "./page.js";
11
11
  import { holdingWords, readerOf } from "./provider.js";
12
+ import { kindOf } from "./providers/keyed.js";
12
13
  import { providerOf, settingsProblemsOf } from "./providers/registry.js";
13
14
  import { breakers, fitSearch, withKeyBreaker, searchArgs, searchInTurn, searchText } from "./search.js";
14
15
  /** One tool's destinations in words: each id, how it is reached, and what holds it ("none" for an empty order). */
@@ -53,7 +54,7 @@ export function createWeb(config) {
53
54
  const now = config.now ?? Date.now;
54
55
  const policy = policyOf(config.policy);
55
56
  if (config.pageGuard !== undefined && typeof config.pageGuard !== "boolean")
56
- throw new TypeError(`pageGuard must be true or false (it was ${JSON.stringify(config.pageGuard)})`);
57
+ throw new TypeError(`pageGuard must be true or false (it was ${kindOf(config.pageGuard)})`);
57
58
  if (config.pageGuard && !config.decider)
58
59
  throw new TypeError("pageGuard needs a decider: the page guard asks the run's decider about each page");
59
60
  // The decider as this Web asks it: held for the Web's life once it refuses its key or its account.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-web",
3
- "version": "0.1.0-beta.59",
3
+ "version": "0.1.0-beta.61",
4
4
  "description": "Web search and web fetch for agents: providers asked in an order given as data, a breaker per provider, a per-run page cache read in parts, and a direct fetch through an injected public-host guard.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -46,7 +46,7 @@
46
46
  "undici": "^8.12.2"
47
47
  },
48
48
  "devDependencies": {
49
- "@parcha/pi-browser": "0.1.0-beta.59"
49
+ "@parcha/pi-browser": "0.1.0-beta.61"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",