@parcha/agentrun-web 0.1.0-beta.78 → 0.1.0-beta.80

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/web.d.ts CHANGED
@@ -67,8 +67,10 @@ export type WebConfig = {
67
67
  holds?: readonly Hold[];
68
68
  /** Given each limit a breaker reads that leaves it holding (Hold): the tool's, or its key's. */
69
69
  onHold?: (hold: Hold) => void;
70
- /** Sifts each search's results and judges each fetched part; none: nothing is sifted, as before the step. */
71
- decider?: WebDecider;
70
+ /** Sifts each search's results and judges each fetched part; none: nothing is sifted, as before the step. A function is
71
+ * asked at each call for the decider that call uses, or none (that call is not sifted, as with no decider): a host
72
+ * whose decider can run only once something arrives later (a run's own key) keeps one Web, its pages and holds. */
73
+ decider?: WebDecider | (() => WebDecider | undefined);
72
74
  /** How a search's results reach the model once the decider has scored them ("drop" by default); checked when the
73
75
  * web is made. */
74
76
  policy?: DecidePolicy;
package/dist/web.js CHANGED
@@ -73,8 +73,17 @@ export function createWeb(config) {
73
73
  throw new TypeError(`pageGuard must be true or false (it was ${kindOf(config.pageGuard)})`);
74
74
  if (config.pageGuard && !config.decider)
75
75
  throw new TypeError("pageGuard needs a decider: the page guard asks the run's decider about each page");
76
- // The decider as this Web asks it: held for the Web's life once it refuses its key or its account.
77
- const held = config.decider ? heldOnRefusal(config.decider) : undefined;
76
+ // The decider as this Web asks it now: each one held for the Web's life once it refuses its key or its account.
77
+ const watchedDeciders = new WeakMap();
78
+ const deciderNow = () => {
79
+ const decider = typeof config.decider === "function" ? config.decider() : config.decider;
80
+ if (!decider)
81
+ return undefined;
82
+ let held = watchedDeciders.get(decider);
83
+ if (!held)
84
+ watchedDeciders.set(decider, (held = heldOnRefusal(decider)));
85
+ return held;
86
+ };
78
87
  /** The page guard's verdict on each read the run's pages hold, kept with the read: it goes when the page is evicted,
79
88
  * and a page read again is asked about again, as is one whose guard failed. */
80
89
  const pageVerdicts = new WeakMap();
@@ -95,7 +104,7 @@ export function createWeb(config) {
95
104
  return shared.wait(step.signal);
96
105
  };
97
106
  /** A receipt's `unsifted`, only in a run with a classifier. */
98
- const unsifted = (text) => (config.decider ? { unsifted: text() } : {});
107
+ const unsifted = (text) => (deciderNow() ? { unsifted: text() } : {});
99
108
  const runBreakers = breakers(now);
100
109
  const fetchBreakers = breakers(now);
101
110
  // Each provider's own across both tools: a quota of the whole key holds web_search and web_fetch alike.
@@ -214,6 +223,7 @@ export function createWeb(config) {
214
223
  : !order.length ? { error: "web_search has no provider to ask" }
215
224
  : await feesOfCall.run(lines, () => searchInTurn(order.map((id) => ({ name: id, ask: (deadline) => runOf(id).search(ask, deadline, signal, bounds, session ? { session } : undefined) })), breakerOf, signal, searchMs, tries));
216
225
  // Sifted before it is fitted, so the fit sees only the kept results; fitSearch keeps every other field.
226
+ const held = deciderNow();
217
227
  const sifted = held ? await siftSearch(held, found, { task, signal, ms: config.bounds?.decideMs, pay: decisionPay(config.pay ?? unmetered, lines), policy }) : { answer: found, classifier: "off" };
218
228
  const answer = fitSearch(sifted.answer);
219
229
  const { classifier } = sifted;
@@ -237,6 +247,7 @@ export function createWeb(config) {
237
247
  const problem = partProblem({ offset, maxChars });
238
248
  if (problem) {
239
249
  const refused = { ok: false, url: named, status: 0, title: "", text: "", links: [], error: problem };
250
+ const held = deciderNow();
240
251
  const classifier = held ? (await judgePart(held, asked, refused, {})).classifier : "off";
241
252
  return { answer: refused, receipt: { op: "fetch", asked: named, provider: null, tries, classifier, ...unjudged, out: outOf(webFetchText(refused)), cost: { usd: 0, lines }, ...unsifted(() => webFetchText(refused)) } };
242
253
  }
@@ -256,7 +267,7 @@ export function createWeb(config) {
256
267
  }));
257
268
  const part = webPart(whole, { ...(offset === undefined ? {} : { offset }), ...(maxChars === undefined ? {} : { maxChars }) });
258
269
  const provider = part.ok && part.via !== "stopped" && part.via !== "none" ? part.via : null;
259
- const decider = held;
270
+ const decider = deciderNow();
260
271
  const guard = config.pageGuard && decider && whole.ok ? (options) => guardOf(decider, asked, whole, options) : undefined;
261
272
  const decided = await decideFetch(decider, asked, whole, part, { task, objective: typeof objective === "string" && objective.trim() ? objective : lookingFor, ...(offset === undefined ? {} : { offset }), ...(maxChars === undefined ? {} : { maxChars }), signal, ms: config.bounds?.decideMs, pay: config.pay ?? unmetered, lines, guard });
262
273
  // What the objective found names each provider asked ahead that gave no page, as the part does.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-web",
3
- "version": "0.1.0-beta.78",
3
+ "version": "0.1.0-beta.80",
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.14.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@parcha/pi-browser": "0.1.0-beta.78"
49
+ "@parcha/pi-browser": "0.1.0-beta.80"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",