@far-world-labs/verblets 0.7.3 → 0.7.4

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.
@@ -21,7 +21,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
21
21
  return Oi;
22
22
  },
23
23
  get CONTEXT_KINDS() {
24
- return Ii;
24
+ return ki;
25
25
  },
26
26
  get COST_POSTURE() {
27
27
  return Ci;
@@ -42,10 +42,10 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
42
42
  return Ai;
43
43
  },
44
44
  get DomainEvent() {
45
- return k;
45
+ return A;
46
46
  },
47
47
  get ENVIRONMENT() {
48
- return ki;
48
+ return Ii;
49
49
  },
50
50
  get EmbeddingService() {
51
51
  return Qn;
@@ -60,7 +60,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
60
60
  return cp;
61
61
  },
62
62
  get ListStyle() {
63
- return ue;
63
+ return me;
64
64
  },
65
65
  get ModelService() {
66
66
  return Sn;
@@ -198,7 +198,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
198
198
  return Ni;
199
199
  },
200
200
  get createProgressEmitter() {
201
- return I;
201
+ return k;
202
202
  },
203
203
  get createTraceCollector() {
204
204
  return Vm;
@@ -276,10 +276,10 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
276
276
  return jc;
277
277
  },
278
278
  get embedStepBack() {
279
- return Ic;
279
+ return kc;
280
280
  },
281
281
  get embedSubquestions() {
282
- return kc;
282
+ return Ic;
283
283
  },
284
284
  get embedWarmup() {
285
285
  return vc;
@@ -315,13 +315,13 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
315
315
  return Ba;
316
316
  },
317
317
  get fillMissing() {
318
- return Ia;
318
+ return ka;
319
319
  },
320
320
  get filter() {
321
321
  return Zi;
322
322
  },
323
323
  get filterAmbiguous() {
324
- return ka;
324
+ return Ia;
325
325
  },
326
326
  get filterEach() {
327
327
  return CS;
@@ -345,7 +345,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
345
345
  return mp;
346
346
  },
347
347
  get getOptions() {
348
- return q;
348
+ return F;
349
349
  },
350
350
  get glossary() {
351
351
  return ta;
@@ -408,7 +408,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
408
408
  return Ca;
409
409
  },
410
410
  get nameStep() {
411
- return A;
411
+ return O;
412
412
  },
413
413
  get normalizeInstruction() {
414
414
  return mi;
@@ -435,10 +435,10 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
435
435
  return jo;
436
436
  },
437
437
  get pFilter() {
438
- return IS;
438
+ return kS;
439
439
  },
440
440
  get pFind() {
441
- return kS;
441
+ return IS;
442
442
  },
443
443
  get pGroup() {
444
444
  return OS;
@@ -495,7 +495,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
495
495
  return sa;
496
496
  },
497
497
  get reduce() {
498
- return Ie;
498
+ return ke;
499
499
  },
500
500
  get reduceEach() {
501
501
  return NS;
@@ -543,10 +543,10 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
543
543
  return nc;
544
544
  },
545
545
  get scopePhase() {
546
- return L;
546
+ return B;
547
547
  },
548
548
  get score() {
549
- return ke;
549
+ return Ie;
550
550
  },
551
551
  get scoreChunksByProbes() {
552
552
  return Pc;
@@ -684,7 +684,7 @@ const rl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
684
684
  return oc;
685
685
  },
686
686
  get version() {
687
- return In;
687
+ return kn;
688
688
  },
689
689
  get windowFor() {
690
690
  return Aa;
@@ -800,7 +800,7 @@ const hl = (e) => {
800
800
  number: fl,
801
801
  boolean: hl
802
802
  };
803
- function D(e) {
803
+ function q(e) {
804
804
  const t = fn[e], n = So[t?.type] ?? String, r = $e[`VERBLETS_FORCE_${e}`];
805
805
  if (r !== void 0 && r !== "") {
806
806
  const o = n(r);
@@ -823,7 +823,7 @@ async function gl(e) {
823
823
  const s = await dt.get(e);
824
824
  if (s !== void 0) return n(s);
825
825
  }
826
- return D(e);
826
+ return q(e);
827
827
  }
828
828
  function xo(e) {
829
829
  dt = e;
@@ -831,7 +831,7 @@ function xo(e) {
831
831
  function yl() {
832
832
  return dt;
833
833
  }
834
- const bl = D, wl = D, vl = D;
834
+ const bl = q, wl = q, vl = q;
835
835
  function yn() {
836
836
  const e = [];
837
837
  for (const t of sl)
@@ -848,7 +848,7 @@ function yn() {
848
848
  }
849
849
  const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
850
850
  __proto__: null,
851
- get: D,
851
+ get: q,
852
852
  getAsync: gl,
853
853
  getBoolean: vl,
854
854
  getNumber: wl,
@@ -856,7 +856,7 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
856
856
  getString: bl,
857
857
  setRuntimeProvider: xo,
858
858
  validate: yn
859
- }, Symbol.toStringTag, { value: "Module" })), $o = D("VERBLETS_CACHE_TTL"), xl = D("VERBLETS_DISABLE_CACHE") !== !0, Po = D("VERBLETS_DEBUG_PROMPT"), To = D("VERBLETS_DEBUG_REQUEST_IF_CHANGED"), Eo = D("VERBLETS_DEBUG_RESPONSE"), Io = D("VERBLETS_DEBUG_RESPONSE_IF_CHANGED"), $l = (e) => /^(gpt-5|o[34])/i.test(e), ko = (e) => Array.isArray(e) ? e.map((t) => t.type === "image" ? {
859
+ }, Symbol.toStringTag, { value: "Module" })), $o = q("VERBLETS_CACHE_TTL"), xl = q("VERBLETS_DISABLE_CACHE") !== !0, Po = q("VERBLETS_DEBUG_PROMPT"), To = q("VERBLETS_DEBUG_REQUEST_IF_CHANGED"), Eo = q("VERBLETS_DEBUG_RESPONSE"), ko = q("VERBLETS_DEBUG_RESPONSE_IF_CHANGED"), $l = (e) => /^(gpt-5|o[34])/i.test(e), Io = (e) => Array.isArray(e) ? e.map((t) => t.type === "image" ? {
860
860
  type: "image_url",
861
861
  image_url: {
862
862
  url: `data:${t.mediaType};base64,${t.data}`
@@ -876,7 +876,7 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
876
876
  };
877
877
  d.messages && (d.messages = d.messages.map((y) => ({
878
878
  ...y,
879
- content: ko(y.content)
879
+ content: Io(y.content)
880
880
  }))), o !== void 0 && (d.max_completion_tokens = o), $l(d.model) || (i !== void 0 && (d.temperature = i), a !== void 0 && (d.top_p = a), c !== void 0 && (d.frequency_penalty = c), l !== void 0 && (d.presence_penalty = l));
881
881
  const h = {
882
882
  method: "POST",
@@ -891,12 +891,12 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
891
891
  __proto__: null,
892
892
  buildRequest: Pl,
893
893
  parseResponse: Tl,
894
- translateContentBlocks: ko
895
- }, Symbol.toStringTag, { value: "Module" })), Il = (e) => {
894
+ translateContentBlocks: Io
895
+ }, Symbol.toStringTag, { value: "Module" })), kl = (e) => {
896
896
  const t = e.filter((s) => s.role === "system"), n = e.filter((s) => s.role !== "system");
897
897
  return { instructions: t.map((s) => s.content).join(`
898
898
  `), messages: n };
899
- }, kl = (e) => e ? e.type === "json_schema" ? {
899
+ }, Il = (e) => e ? e.type === "json_schema" ? {
900
900
  text: {
901
901
  format: {
902
902
  type: "json_schema",
@@ -927,21 +927,21 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
927
927
  presence_penalty: y,
928
928
  // eslint-disable-line no-unused-vars
929
929
  ...b
930
- } = r, { instructions: f, messages: g } = Il(o), m = {
930
+ } = r, { instructions: f, messages: g } = kl(o), m = {
931
931
  model: i,
932
932
  input: g,
933
933
  ...b
934
934
  };
935
- f && (m.instructions = f), a && (m.max_output_tokens = a), l && (m.tools = l.map((v) => v.type === "function" ? {
935
+ f && (m.instructions = f), a && (m.max_output_tokens = a), l && (m.tools = l.map((S) => S.type === "function" ? {
936
936
  type: "function",
937
- name: v.function.name,
938
- description: v.function.description,
939
- parameters: v.function.parameters,
940
- strict: v.function.strict
941
- } : v), u && (m.tool_choice = u));
942
- const w = kl(c);
937
+ name: S.function.name,
938
+ description: S.function.description,
939
+ parameters: S.function.parameters,
940
+ strict: S.function.strict
941
+ } : S), u && (m.tool_choice = u));
942
+ const w = Il(c);
943
943
  Object.assign(m, w);
944
- const S = {
944
+ const v = {
945
945
  method: "POST",
946
946
  headers: {
947
947
  Authorization: `Bearer ${t}`,
@@ -949,7 +949,7 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
949
949
  },
950
950
  body: JSON.stringify(m)
951
951
  };
952
- return { url: s, fetchOptions: S };
952
+ return { url: s, fetchOptions: v };
953
953
  }, Ol = (e) => {
954
954
  const t = e.output || [], n = t.find((i) => i.type === "message"), r = t.filter((i) => i.type === "function_call");
955
955
  let s = "";
@@ -1097,14 +1097,14 @@ const Sl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1097
1097
  ...b
1098
1098
  };
1099
1099
  f && (w.system = f), c !== void 0 && (w.temperature = c);
1100
- const S = Dl(u);
1101
- if (S) {
1102
- w.tools = S;
1100
+ const v = Dl(u);
1101
+ if (v) {
1102
+ w.tools = v;
1103
1103
  const x = jl(p);
1104
1104
  x && (w.tool_choice = x);
1105
1105
  }
1106
- const v = Bl(l);
1107
- Object.assign(w, v);
1106
+ const S = Bl(l);
1107
+ Object.assign(w, S);
1108
1108
  const P = {
1109
1109
  method: "POST",
1110
1110
  headers: {
@@ -1240,8 +1240,8 @@ const _o = (e) => {
1240
1240
  { once: !0 }
1241
1241
  ), n.signal;
1242
1242
  };
1243
- let kt;
1244
- const Hl = async () => (kt || (kt = await import("node:crypto")), kt), Ql = (e) => {
1243
+ let It;
1244
+ const Hl = async () => (It || (It = await import("node:crypto")), It), Ql = (e) => {
1245
1245
  if (e !== "sha256")
1246
1246
  throw new Error(`Unsupported algorithm: ${e}`);
1247
1247
  const t = [];
@@ -1360,10 +1360,10 @@ Most prompts will ask for a specific output format, so comply with those details
1360
1360
  requestTimeout: 45e3,
1361
1361
  vision: !0,
1362
1362
  get apiKey() {
1363
- return D("OPENAI_API_KEY");
1363
+ return q("OPENAI_API_KEY");
1364
1364
  },
1365
1365
  get apiUrl() {
1366
- return D("OPENAI_PROXY_URL");
1366
+ return q("OPENAI_PROXY_URL");
1367
1367
  },
1368
1368
  systemPrompt: ae
1369
1369
  },
@@ -1375,10 +1375,10 @@ Most prompts will ask for a specific output format, so comply with those details
1375
1375
  requestTimeout: 45e3,
1376
1376
  vision: !0,
1377
1377
  get apiKey() {
1378
- return D("OPENAI_API_KEY");
1378
+ return q("OPENAI_API_KEY");
1379
1379
  },
1380
1380
  get apiUrl() {
1381
- return D("OPENAI_PROXY_URL");
1381
+ return q("OPENAI_PROXY_URL");
1382
1382
  },
1383
1383
  systemPrompt: ae
1384
1384
  },
@@ -1390,10 +1390,10 @@ Most prompts will ask for a specific output format, so comply with those details
1390
1390
  requestTimeout: 3e4,
1391
1391
  vision: !0,
1392
1392
  get apiKey() {
1393
- return D("OPENAI_API_KEY");
1393
+ return q("OPENAI_API_KEY");
1394
1394
  },
1395
1395
  get apiUrl() {
1396
- return D("OPENAI_PROXY_URL");
1396
+ return q("OPENAI_PROXY_URL");
1397
1397
  },
1398
1398
  systemPrompt: ae
1399
1399
  },
@@ -1406,10 +1406,10 @@ Most prompts will ask for a specific output format, so comply with those details
1406
1406
  requestTimeout: 12e4,
1407
1407
  vision: !0,
1408
1408
  get apiKey() {
1409
- return D("OPENAI_API_KEY");
1409
+ return q("OPENAI_API_KEY");
1410
1410
  },
1411
1411
  get apiUrl() {
1412
- return D("OPENAI_PROXY_URL");
1412
+ return q("OPENAI_PROXY_URL");
1413
1413
  },
1414
1414
  systemPrompt: ae
1415
1415
  },
@@ -1422,7 +1422,7 @@ Most prompts will ask for a specific output format, so comply with those details
1422
1422
  requestTimeout: 9e4,
1423
1423
  vision: !0,
1424
1424
  get apiKey() {
1425
- return D("ANTHROPIC_API_KEY");
1425
+ return q("ANTHROPIC_API_KEY");
1426
1426
  },
1427
1427
  get apiUrl() {
1428
1428
  return "https://api.anthropic.com/";
@@ -1437,7 +1437,7 @@ Most prompts will ask for a specific output format, so comply with those details
1437
1437
  requestTimeout: 45e3,
1438
1438
  vision: !0,
1439
1439
  get apiKey() {
1440
- return D("ANTHROPIC_API_KEY");
1440
+ return q("ANTHROPIC_API_KEY");
1441
1441
  },
1442
1442
  get apiUrl() {
1443
1443
  return "https://api.anthropic.com/";
@@ -1452,7 +1452,7 @@ Most prompts will ask for a specific output format, so comply with those details
1452
1452
  requestTimeout: 12e4,
1453
1453
  vision: !0,
1454
1454
  get apiKey() {
1455
- return D("ANTHROPIC_API_KEY");
1455
+ return q("ANTHROPIC_API_KEY");
1456
1456
  },
1457
1457
  get apiUrl() {
1458
1458
  return "https://api.anthropic.com/";
@@ -1469,11 +1469,11 @@ Most prompts will ask for a specific output format, so comply with those details
1469
1469
  structuredOutput: !1,
1470
1470
  vision: !1,
1471
1471
  get apiUrl() {
1472
- const e = D("OPENWEBUI_API_URL") || "";
1472
+ const e = q("OPENWEBUI_API_URL") || "";
1473
1473
  return e.endsWith("/") ? e : `${e}/`;
1474
1474
  },
1475
1475
  get apiKey() {
1476
- return D("OPENWEBUI_API_KEY");
1476
+ return q("OPENWEBUI_API_KEY");
1477
1477
  },
1478
1478
  systemPrompt: ae
1479
1479
  },
@@ -1486,11 +1486,11 @@ Most prompts will ask for a specific output format, so comply with those details
1486
1486
  structuredOutput: !1,
1487
1487
  vision: !1,
1488
1488
  get apiUrl() {
1489
- const e = D("OPENWEBUI_API_URL") || "";
1489
+ const e = q("OPENWEBUI_API_URL") || "";
1490
1490
  return e.endsWith("/") ? e : `${e}/`;
1491
1491
  },
1492
1492
  get apiKey() {
1493
- return D("OPENWEBUI_API_KEY");
1493
+ return q("OPENWEBUI_API_KEY");
1494
1494
  },
1495
1495
  systemPrompt: ae
1496
1496
  },
@@ -1503,11 +1503,11 @@ Most prompts will ask for a specific output format, so comply with those details
1503
1503
  structuredOutput: !1,
1504
1504
  vision: !1,
1505
1505
  get apiUrl() {
1506
- const e = D("OPENWEBUI_API_URL") || "";
1506
+ const e = q("OPENWEBUI_API_URL") || "";
1507
1507
  return e.endsWith("/") ? e : `${e}/`;
1508
1508
  },
1509
1509
  get apiKey() {
1510
- return D("OPENWEBUI_API_KEY");
1510
+ return q("OPENWEBUI_API_KEY");
1511
1511
  },
1512
1512
  systemPrompt: ae
1513
1513
  },
@@ -1520,11 +1520,11 @@ Most prompts will ask for a specific output format, so comply with those details
1520
1520
  structuredOutput: !1,
1521
1521
  vision: !1,
1522
1522
  get apiUrl() {
1523
- const e = D("OPENWEBUI_API_URL") || "";
1523
+ const e = q("OPENWEBUI_API_URL") || "";
1524
1524
  return e.endsWith("/") ? e : `${e}/`;
1525
1525
  },
1526
1526
  get apiKey() {
1527
- return D("OPENWEBUI_API_KEY");
1527
+ return q("OPENWEBUI_API_KEY");
1528
1528
  },
1529
1529
  systemPrompt: ae
1530
1530
  },
@@ -1537,11 +1537,11 @@ Most prompts will ask for a specific output format, so comply with those details
1537
1537
  structuredOutput: !1,
1538
1538
  vision: !1,
1539
1539
  get apiUrl() {
1540
- const e = D("OPENWEBUI_API_URL") || "";
1540
+ const e = q("OPENWEBUI_API_URL") || "";
1541
1541
  return e.endsWith("/") ? e : `${e}/`;
1542
1542
  },
1543
1543
  get apiKey() {
1544
- return D("OPENWEBUI_API_KEY");
1544
+ return q("OPENWEBUI_API_KEY");
1545
1545
  },
1546
1546
  systemPrompt: ae
1547
1547
  }
@@ -1559,11 +1559,11 @@ Most prompts will ask for a specific output format, so comply with those details
1559
1559
  { use: "gpt-4.1-mini" }
1560
1560
  ];
1561
1561
  function uu() {
1562
- const e = !!D("OPENAI_API_KEY"), t = !!D("ANTHROPIC_API_KEY"), n = !!D("OPENWEBUI_API_KEY");
1562
+ const e = !!q("OPENAI_API_KEY"), t = !!q("ANTHROPIC_API_KEY"), n = !!q("OPENWEBUI_API_KEY");
1563
1563
  let r;
1564
1564
  return e && t ? r = [...lu] : t ? r = [...cu] : e ? r = [...ur] : r = [...ur], n && r.unshift(
1565
- { match: { sensitive: !0, good: !0 }, use: D("VERBLETS_SENSITIVITY_GOOD_MODEL") },
1566
- { match: { sensitive: !0 }, use: D("VERBLETS_SENSITIVITY_MODEL") }
1565
+ { match: { sensitive: !0, good: !0 }, use: q("VERBLETS_SENSITIVITY_GOOD_MODEL") },
1566
+ { match: { sensitive: !0 }, use: q("VERBLETS_SENSITIVITY_MODEL") }
1567
1567
  ), r;
1568
1568
  }
1569
1569
  const vn = uu();
@@ -1571,11 +1571,11 @@ function pu() {
1571
1571
  const e = yn();
1572
1572
  for (const t of e)
1573
1573
  console.warn(`Warning: ${t}`);
1574
- bo.isBrowser && D("OPENAI_API_KEY") && console.warn(
1574
+ bo.isBrowser && q("OPENAI_API_KEY") && console.warn(
1575
1575
  "WARNING: API key detected in browser environment. For security, please use a proxy endpoint instead."
1576
1576
  );
1577
1577
  }
1578
- D("NODE_ENV") !== "test" && pu();
1578
+ q("NODE_ENV") !== "test" && pu();
1579
1579
  const du = (e) => {
1580
1580
  const t = Bo[e];
1581
1581
  if (!t) return;
@@ -1804,7 +1804,7 @@ const hu = /(?:\s*[{[]|[{[]+\s*[{[])/, he = (e) => {
1804
1804
  return a;
1805
1805
  const c = a.match(hu);
1806
1806
  return (c ? a.slice(c.index) : void 0) ?? a;
1807
- }, fu = 'If you are unsure, say "undefined" as your answer.', gu = 'Answer the question either with "true" or "false" as your answer.', yu = "Answer the question with a number that could be parsed by the JS Number constructor. Do not include formatting, units, digit group separators, or spelled-out numbers in your answer.", bu = "Answer the question with a date that can be parsed by the JS Date constructor. ISO format is preferred. Do not include additional text or punctuation.", wu = "Respond with a JSON object or array that parses with JSON.parse, with no wrapping code block, and no wrapping XML.", vu = 'Return a JSON object with an "items" array property.', Su = 'Return a JSON object with a "value" property.', xu = 'Respond with a JSON object that parses with JSON.parse, with no other text and no code block. It should take the form "{ "value": 42, "unit": "<SI or other unit name>" }".', Ee = "Respond with a JSON object or array that parses with JSON.parse, with no other text and no code block.", qo = "Respond with a JSON array that parses with JSON.parse, with no additional text, no punctuation, and no code block.", $u = qo, Xe = `${qo} The array should only contain text. No additional structure.`, Fo = "Return an array of objects — not strings, and not just the objects.", Pu = "Even if the input is not JSON, describe as much as possible in a JSON structure that corresponds to the input.", zo = "You MUST follow the format as described.", Uo = "Provide as much valid data as possible based on available information. Clearly indicate any uncertainties or missing data.", Tu = "Include the line number where each check is performed.", Eu = "Do not fabricate facts. When uncertain, say so rather than guessing.", Wo = "Question:", Iu = "Instructions:", $n = "Details:", Vo = "Fixes:", Jo = "Focus all efforts on this content here:", ku = "Contents to convert to JSON:", Au = "Use this as example output only:", Ou = "Choose only from the following:", _u = "Transform the following object:", Ko = "Create a list of items with the following description:", Pn = "Make sure each item meets the following conditions:", Tn = "Do not use any of the following items:", Go = "The returned object must look like the following, including all the same properties:", En = "Make it conform exactly to the following schema:", Cu = "What is the intent of the following message:", Yo = "Sort the following items by:", ju = "Give me an intent response for the following:", Nu = "The extracted operation must be one of the following:", Ru = "The extracted parameters must be from the following options:", Mu = "Give an explanation followed by a succinct answer. The explanation part should come first, and should be at least 100 words. Next, insert a row of 20 equal signs (=) to create a clear separation.", Lu = "The content below the dividing line should only be valid JSON that can be parsed with JSON.parse.", Bu = "Next insert the succinctly-stated answer should be below the dividing line and work as a primitive datatype in JS. Be as succinct as possible as it will be parsed by a script.", Du = "Think through this step by step.", qu = "First restate the request in your own words, then provide your answer.", Fu = "State any assumptions you are making before answering.", zu = "Explain the reasoning behind your answer.", Uu = "Try to find flaws in your own output. If you find any, address them.", Wu = "Identify any unclear or ambiguous information in your response, and rephrase it for clarity.", Vu = "Rate your confidence in this response on a 0–1 scale. Be candidly critical.", Ju = "Rate on a 0–1 scale how well your output satisfied each point in the original prompt. Be strict.", Ku = "If your confidence is 0.3 or lower, rewrite to address the gaps.", Gu = "Consider both pros and cons before arriving at a conclusion.", Yu = "If there are alternative solutions or perspectives, include them.", Hu = "Provide specific examples to illustrate your point.", Qu = "Use an analogy to make this easier to understand.", Ho = "How would an expert in this field respond?", Xu = "Explain this so a non-expert can understand it.", Zu = "How else could this be interpreted?", ep = "What evidence supports your view?", tp = "What are the limitations of this approach?", np = "What information is still missing?", rp = "How would you evaluate differing views on this?", sp = "What additional input would help you give a better answer?", oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1807
+ }, fu = 'If you are unsure, say "undefined" as your answer.', gu = 'Answer the question either with "true" or "false" as your answer.', yu = "Answer the question with a number that could be parsed by the JS Number constructor. Do not include formatting, units, digit group separators, or spelled-out numbers in your answer.", bu = "Answer the question with a date that can be parsed by the JS Date constructor. ISO format is preferred. Do not include additional text or punctuation.", wu = "Respond with a JSON object or array that parses with JSON.parse, with no wrapping code block, and no wrapping XML.", vu = 'Return a JSON object with an "items" array property.', Su = 'Return a JSON object with a "value" property.', xu = 'Respond with a JSON object that parses with JSON.parse, with no other text and no code block. It should take the form "{ "value": 42, "unit": "<SI or other unit name>" }".', Ee = "Respond with a JSON object or array that parses with JSON.parse, with no other text and no code block.", qo = "Respond with a JSON array that parses with JSON.parse, with no additional text, no punctuation, and no code block.", $u = qo, Xe = `${qo} The array should only contain text. No additional structure.`, Fo = "Return an array of objects — not strings, and not just the objects.", Pu = "Even if the input is not JSON, describe as much as possible in a JSON structure that corresponds to the input.", zo = "You MUST follow the format as described.", Uo = "Provide as much valid data as possible based on available information. Clearly indicate any uncertainties or missing data.", Tu = "Include the line number where each check is performed.", Eu = "Do not fabricate facts. When uncertain, say so rather than guessing.", Wo = "Question:", ku = "Instructions:", $n = "Details:", Vo = "Fixes:", Jo = "Focus all efforts on this content here:", Iu = "Contents to convert to JSON:", Au = "Use this as example output only:", Ou = "Choose only from the following:", _u = "Transform the following object:", Ko = "Create a list of items with the following description:", Pn = "Make sure each item meets the following conditions:", Tn = "Do not use any of the following items:", Go = "The returned object must look like the following, including all the same properties:", En = "Make it conform exactly to the following schema:", Cu = "What is the intent of the following message:", Yo = "Sort the following items by:", ju = "Give me an intent response for the following:", Nu = "The extracted operation must be one of the following:", Ru = "The extracted parameters must be from the following options:", Mu = "Give an explanation followed by a succinct answer. The explanation part should come first, and should be at least 100 words. Next, insert a row of 20 equal signs (=) to create a clear separation.", Lu = "The content below the dividing line should only be valid JSON that can be parsed with JSON.parse.", Bu = "Next insert the succinctly-stated answer should be below the dividing line and work as a primitive datatype in JS. Be as succinct as possible as it will be parsed by a script.", Du = "Think through this step by step.", qu = "First restate the request in your own words, then provide your answer.", Fu = "State any assumptions you are making before answering.", zu = "Explain the reasoning behind your answer.", Uu = "Try to find flaws in your own output. If you find any, address them.", Wu = "Identify any unclear or ambiguous information in your response, and rephrase it for clarity.", Vu = "Rate your confidence in this response on a 0–1 scale. Be candidly critical.", Ju = "Rate on a 0–1 scale how well your output satisfied each point in the original prompt. Be strict.", Ku = "If your confidence is 0.3 or lower, rewrite to address the gaps.", Gu = "Consider both pros and cons before arriving at a conclusion.", Yu = "If there are alternative solutions or perspectives, include them.", Hu = "Provide specific examples to illustrate your point.", Qu = "Use an analogy to make this easier to understand.", Ho = "How would an expert in this field respond?", Xu = "Explain this so a non-expert can understand it.", Zu = "How else could this be interpreted?", ep = "What evidence supports your view?", tp = "What are the limitations of this approach?", np = "What information is still missing?", rp = "How would you evaluate differing views on this?", sp = "What additional input would help you give a better answer?", oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1808
1808
  __proto__: null,
1809
1809
  alternativeInterpretations: Zu,
1810
1810
  alternativeSolutions: Yu,
@@ -1825,7 +1825,7 @@ const hu = /(?:\s*[{[]|[{[]+\s*[{[])/, he = (e) => {
1825
1825
  contentIsExample: Au,
1826
1826
  contentIsExampleObject: Go,
1827
1827
  contentIsFixes: Vo,
1828
- contentIsInstructions: Iu,
1828
+ contentIsInstructions: ku,
1829
1829
  contentIsIntent: ju,
1830
1830
  contentIsMain: Jo,
1831
1831
  contentIsOperationOption: Nu,
@@ -1837,7 +1837,7 @@ const hu = /(?:\s*[{[]|[{[]+\s*[{[])/, he = (e) => {
1837
1837
  contentListCriteria: Ko,
1838
1838
  contentListItemCriteria: Pn,
1839
1839
  contentListToOmit: Tn,
1840
- contentToJSON: ku,
1840
+ contentToJSON: Iu,
1841
1841
  evaluateDifferingViews: rp,
1842
1842
  evidenceSupportsView: ep,
1843
1843
  expertResponse: Ho,
@@ -1884,9 +1884,9 @@ function op(e, { forceHTML: t = !1, name: n, tag: r = "data", title: s, fit: o =
1884
1884
  const i = typeof e == "string" ? e : JSON.stringify(e, null, 2);
1885
1885
  return /\n/.test(i) || t || n ? $(i, { name: n, tag: r, title: s, fit: o }) : Qo(i, { title: s });
1886
1886
  }
1887
- const ip = "0.7.3", ap = {
1887
+ const ip = "0.7.4", ap = {
1888
1888
  version: ip
1889
- }, In = ap.version, fe = Object.freeze({
1889
+ }, kn = ap.version, fe = Object.freeze({
1890
1890
  /** Decisions, phases, meaningful outcomes. Audit-log-shaped. */
1891
1891
  event: "event",
1892
1892
  /** Execution mechanics: lifecycle, batch progress, retries. Progress-bar-shaped. */
@@ -1916,7 +1916,7 @@ const ip = "0.7.3", ap = {
1916
1916
  providerWait: "provider:wait",
1917
1917
  providerRetry: "provider:retry",
1918
1918
  error: "error"
1919
- }), k = Object.freeze({
1919
+ }), A = Object.freeze({
1920
1920
  phase: "phase",
1921
1921
  step: "step",
1922
1922
  tick: "chain:tick",
@@ -2009,10 +2009,10 @@ function dp(e, t) {
2009
2009
  s && e(r);
2010
2010
  };
2011
2011
  }
2012
- function I(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i, eventFilter: a } = {}) {
2012
+ function k(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i, eventFilter: a } = {}) {
2013
2013
  const c = dp(t, a), l = r, u = {};
2014
2014
  s && (u.traceId = s), o && (u.spanId = o), i && (u.parentSpanId = i);
2015
- const d = { step: e, operation: n, ...u, ...{ libraryName: "verblets", libraryVersion: In } }, h = {
2015
+ const d = { step: e, operation: n, ...u, ...{ libraryName: "verblets", libraryVersion: kn } }, h = {
2016
2016
  start() {
2017
2017
  xe(c, { kind: fe.telemetry, ...d, event: De.start });
2018
2018
  },
@@ -2041,7 +2041,7 @@ function I(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i,
2041
2041
  * @param {{ confidence?: number, confidenceInterval?: { low: number, high: number }, unknowns?: string[], [key: string]: * }} data
2042
2042
  */
2043
2043
  uncertainty(y = {}) {
2044
- xe(c, { kind: fe.event, ...d, event: k.uncertainty, ...y });
2044
+ xe(c, { kind: fe.event, ...d, event: A.uncertainty, ...y });
2045
2045
  },
2046
2046
  complete(y = {}) {
2047
2047
  const { durationMs: b, ...f } = y, g = b ?? (l ? Date.now() - l.getTime() : void 0);
@@ -2081,11 +2081,11 @@ function I(e, t, { operation: n, now: r, traceId: s, spanId: o, parentSpanId: i,
2081
2081
  };
2082
2082
  return h;
2083
2083
  }
2084
- function L(e, t) {
2084
+ function B(e, t) {
2085
2085
  if (!(!e || typeof e != "function"))
2086
2086
  return (n) => e({ ...n, phase: n.phase ? `${t}/${n.phase}` : t });
2087
2087
  }
2088
- function A(e, t) {
2088
+ function O(e, t) {
2089
2089
  const n = t.operation, r = n ? `${n}/${e}` : e;
2090
2090
  return {
2091
2091
  ...t,
@@ -2113,7 +2113,7 @@ async function mp(e, t, n) {
2113
2113
  const o = { operation: t.operation }, i = await s(o, { logger: t.logger }), a = i ?? n;
2114
2114
  r.source = ut.policy, r.value = a, r.policyReturned = i;
2115
2115
  } else t[e] !== void 0 ? (r.source = ut.config, r.value = t[e]) : (r.source = ut.fallback, r.value = n);
2116
- return I(e, t.onProgress, t).metrics({
2116
+ return k(e, t.onProgress, t).metrics({
2117
2117
  event: ye.optionResolve,
2118
2118
  source: r.source,
2119
2119
  value: r.value,
@@ -2194,7 +2194,7 @@ const wp = (e, t, n = {}) => {
2194
2194
  }, vp = ({ debugPrompt: e, isCached: t, prompt: n }) => {
2195
2195
  (e || Po || To && !t) && (console.error("+++ DEBUG PROMPT +++"), console.error(n), console.error("+++ DEBUG PROMPT END +++"));
2196
2196
  }, Sp = ({ debugResult: e, isCached: t, resultShaped: n }) => {
2197
- (e || Eo || Io && !t) && (console.error("+++ DEBUG RESULT +++"), console.error(n), console.error("+++ DEBUG RESULT END +++"));
2197
+ (e || Eo || ko && !t) && (console.error("+++ DEBUG RESULT +++"), console.error(n), console.error("+++ DEBUG RESULT END +++"));
2198
2198
  };
2199
2199
  let en;
2200
2200
  const xp = (e) => {
@@ -2225,57 +2225,57 @@ const xp = (e) => {
2225
2225
  unwrapValues: y,
2226
2226
  unwrapCollections: b
2227
2227
  } = t, f = en ? { ...en, ...t.policy } : t.policy, g = f ? { ...t, policy: f } : t, m = await re("forceQuery", g, !1), w = { ...Oo(c) };
2228
- for (const B of $p) {
2229
- const X = await re(B, g, void 0);
2230
- X !== void 0 && (w[B] = X);
2228
+ for (const D of $p) {
2229
+ const X = await re(D, g, void 0);
2230
+ X !== void 0 && (w[D] = X);
2231
2231
  }
2232
- for (const B of Qe) {
2233
- const X = await re(B, g, void 0);
2234
- X !== void 0 && (w[B] = X);
2232
+ for (const D of Qe) {
2233
+ const X = await re(D, g, void 0);
2234
+ X !== void 0 && (w[D] = X);
2235
2235
  }
2236
- const S = Date.now(), v = {};
2236
+ const v = Date.now(), S = {};
2237
2237
  let P = !1;
2238
- w.negotiate && (Object.assign(v, w.negotiate), P = !0);
2239
- for (const B of Qe)
2240
- B in w && (v[B] = w[B], P = !0);
2238
+ w.negotiate && (Object.assign(S, w.negotiate), P = !0);
2239
+ for (const D of Qe)
2240
+ D in w && (S[D] = w[D], P = !0);
2241
2241
  const x = w.modelName;
2242
- let E, O;
2243
- P ? (E = n.negotiateModel(x, v), O = E?.name) : (O = w.modelName, E = n.getModel(O));
2244
- const R = I("llm", t.onProgress, t), j = P ? Ge.negotiated : w.modelName ? Ge.config : Ge.default;
2242
+ let E, I;
2243
+ P ? (E = n.negotiateModel(x, S), I = E?.name) : (I = w.modelName, E = n.getModel(I));
2244
+ const R = k("llm", t.onProgress, t), j = P ? Ge.negotiated : w.modelName ? Ge.config : Ge.default;
2245
2245
  R.metrics({
2246
2246
  event: ye.llmModel,
2247
- model: O,
2247
+ model: I,
2248
2248
  provider: E?.provider || "openai",
2249
2249
  source: j,
2250
- negotiation: P ? v : void 0,
2250
+ negotiation: P ? S : void 0,
2251
2251
  preferred: w.modelName
2252
2252
  });
2253
- const F = Array.isArray(e) ? e.reduce((B, X) => B + (X.type === "text" ? X.text.length : 0), 0) : e.length;
2253
+ const L = Array.isArray(e) ? e.reduce((D, X) => D + (X.type === "text" ? X.text.length : 0), 0) : e.length;
2254
2254
  l?.info && l.info({
2255
2255
  event: "llm:start",
2256
- promptLength: F,
2257
- model: O
2256
+ promptLength: L,
2257
+ model: I
2258
2258
  });
2259
2259
  const V = n.getDefaultModel(), Y = E?.apiUrl || V?.apiUrl, H = E?.apiKey || V?.apiKey, ee = n.getRequestConfig({
2260
2260
  prompt: e,
2261
2261
  ...w,
2262
- modelName: O
2263
- }), pe = E.structuredOutput === !1 && !!ee.responseFormat;
2262
+ modelName: I
2263
+ }), ue = E.structuredOutput === !1 && !!ee.responseFormat;
2264
2264
  let G = ee;
2265
- if (pe) {
2266
- const B = ee.responseFormat?.json_schema?.schema, X = B ? `${Ee} ${En} ${$(JSON.stringify(B), { tag: "json-schema--do-not-output" })}` : Ee, ce = (le) => Array.isArray(le) ? [...le, { type: "text", text: X }] : `${le}
2265
+ if (ue) {
2266
+ const D = ee.responseFormat?.json_schema?.schema, X = D ? `${Ee} ${En} ${$(JSON.stringify(D), { tag: "json-schema--do-not-output" })}` : Ee, ce = (le) => Array.isArray(le) ? [...le, { type: "text", text: X }] : `${le}
2267
2267
 
2268
2268
  ${X}`, ve = ee.messages?.map(
2269
2269
  (le, Ne, Ue) => Ne === Ue.length - 1 && le.role === "user" ? { ...le, content: ce(le.content) } : le
2270
2270
  ) ?? ee.messages, { responseFormat: tr, ...Tt } = ee;
2271
2271
  G = { ...Tt, messages: ve };
2272
2272
  }
2273
- const te = await re("cacheEnabled", t, void 0), ie = te === !1 || te === void 0 && D("VERBLETS_DISABLE_CACHE") === !0, de = await re("cacheTTL", t, void 0);
2273
+ const te = await re("cacheEnabled", t, void 0), ie = te === !1 || te === void 0 && q("VERBLETS_DISABLE_CACHE") === !0, pe = await re("cacheTTL", t, void 0);
2274
2274
  let Z, we;
2275
2275
  if (!ie && r) {
2276
2276
  we = await r();
2277
- const { result: B } = await Ro(we, ee);
2278
- Z = B;
2277
+ const { result: D } = await Ro(we, ee);
2278
+ Z = D;
2279
2279
  }
2280
2280
  p({
2281
2281
  isCached: !!Z,
@@ -2284,53 +2284,53 @@ ${X}`, ve = ee.messages?.map(
2284
2284
  requestConfig: ee
2285
2285
  });
2286
2286
  try {
2287
- let B = Z;
2287
+ let D = Z;
2288
2288
  if (!Z || m) {
2289
- const le = w.requestTimeout || n.getModel(O).requestTimeout, Ne = new Lo(le), Ue = E.provider || "openai", nr = Yl(Ue), { url: Dc, fetchOptions: rr } = nr.buildRequest(
2289
+ const le = w.requestTimeout || n.getModel(I).requestTimeout, Ne = new Lo(le), Ue = E.provider || "openai", nr = Yl(Ue), { url: Dc, fetchOptions: rr } = nr.buildRequest(
2290
2290
  Y,
2291
2291
  H,
2292
2292
  E.endpoint,
2293
2293
  G
2294
2294
  );
2295
2295
  bp(rr, s, Ne);
2296
- const me = await qc(Dc, rr);
2296
+ const de = await qc(Dc, rr);
2297
2297
  Ne.clearTimeout();
2298
- const Et = me.headers.get("content-type") || "";
2298
+ const Et = de.headers.get("content-type") || "";
2299
2299
  if (!Et.includes("application/json") && !Et.includes("text/json")) {
2300
- const It = await me.text().then((Se) => Se.slice(0, 200)), Me = new Error(
2301
- `Completions request [error]: expected JSON response but got ${Et || "unknown content-type"} (status: ${me.status}, body: ${It})`
2300
+ const kt = await de.text().then((Se) => Se.slice(0, 200)), Me = new Error(
2301
+ `Completions request [error]: expected JSON response but got ${Et || "unknown content-type"} (status: ${de.status}, body: ${kt})`
2302
2302
  );
2303
- throw Me.httpStatus = me.status, Me.retryAfterMs = mr(me.headers.get("retry-after")), Me.provider = Ue, Me;
2303
+ throw Me.httpStatus = de.status, Me.retryAfterMs = mr(de.headers.get("retry-after")), Me.provider = Ue, Me;
2304
2304
  }
2305
- const Re = await me.json();
2306
- if (!me.ok) {
2307
- const It = Re?.error?.message || Re?.error?.type || "Unknown error", Me = [`status: ${me?.status}`, `type: ${Re?.error?.type}`].join(", "), Se = new Error(`Completions request [error]: ${It} (${Me})`);
2308
- throw Se.httpStatus = me.status, Se.errorType = Re?.error?.type, Se.errorCode = Re?.error?.code, Se.retryAfterMs = mr(me.headers.get("retry-after")), Se.provider = Ue, Se;
2305
+ const Re = await de.json();
2306
+ if (!de.ok) {
2307
+ const kt = Re?.error?.message || Re?.error?.type || "Unknown error", Me = [`status: ${de?.status}`, `type: ${Re?.error?.type}`].join(", "), Se = new Error(`Completions request [error]: ${kt} (${Me})`);
2308
+ throw Se.httpStatus = de.status, Se.errorType = Re?.error?.type, Se.errorCode = Re?.error?.code, Se.retryAfterMs = mr(de.headers.get("retry-after")), Se.provider = Ue, Se;
2309
2309
  }
2310
- B = nr.parseResponse(Re), !ie && we && await Mo(
2310
+ D = nr.parseResponse(Re), !ie && we && await Mo(
2311
2311
  we,
2312
2312
  ee,
2313
- B,
2314
- ...de !== void 0 ? [de] : []
2313
+ D,
2314
+ ...pe !== void 0 ? [pe] : []
2315
2315
  );
2316
2316
  }
2317
- if (pe && typeof B.choices?.[0]?.message?.content == "string") {
2318
- const le = he(B.choices[0].message.content);
2317
+ if (ue && typeof D.choices?.[0]?.message?.content == "string") {
2318
+ const le = he(D.choices[0].message.content);
2319
2319
  try {
2320
2320
  const Ne = xn(le);
2321
- B = {
2322
- ...B,
2321
+ D = {
2322
+ ...D,
2323
2323
  choices: [
2324
2324
  {
2325
- ...B.choices[0],
2326
- message: { ...B.choices[0].message, content: JSON.stringify(Ne) }
2325
+ ...D.choices[0],
2326
+ message: { ...D.choices[0].message, content: JSON.stringify(Ne) }
2327
2327
  }
2328
2328
  ]
2329
2329
  };
2330
2330
  } catch {
2331
2331
  }
2332
2332
  }
2333
- const X = d(B, ee, {
2333
+ const X = d(D, ee, {
2334
2334
  skipResponseParse: h,
2335
2335
  unwrapValues: y,
2336
2336
  unwrapCollections: b
@@ -2340,16 +2340,16 @@ ${X}`, ve = ee.messages?.map(
2340
2340
  isCached: !!Z,
2341
2341
  prompt: e,
2342
2342
  requestConfig: ee,
2343
- result: B,
2343
+ result: D,
2344
2344
  resultShaped: X
2345
2345
  }), l?.info && l.info({
2346
2346
  event: "llm:end",
2347
- duration: Date.now() - S,
2347
+ duration: Date.now() - v,
2348
2348
  cached: !!Z,
2349
- model: O
2349
+ model: I
2350
2350
  });
2351
2351
  const ce = {
2352
- model: O,
2352
+ model: I,
2353
2353
  provider: E.provider || "openai",
2354
2354
  cached: !!Z
2355
2355
  };
@@ -2358,7 +2358,7 @@ ${X}`, ve = ee.messages?.map(
2358
2358
  status: pr.success,
2359
2359
  ...ce
2360
2360
  });
2361
- const ve = B?.usage, tr = ve?.prompt_tokens ?? 0, Tt = ve?.completion_tokens ?? 0;
2361
+ const ve = D?.usage, tr = ve?.prompt_tokens ?? 0, Tt = ve?.completion_tokens ?? 0;
2362
2362
  return R.measure({
2363
2363
  metric: ge.tokenUsage,
2364
2364
  tokenType: dr.input,
@@ -2371,12 +2371,12 @@ ${X}`, ve = ee.messages?.map(
2371
2371
  ...ce
2372
2372
  }), R.measure({
2373
2373
  metric: ge.llmDuration,
2374
- value: Date.now() - S,
2374
+ value: Date.now() - v,
2375
2375
  ...ce
2376
2376
  }), X;
2377
- } catch (B) {
2377
+ } catch (D) {
2378
2378
  const X = {
2379
- model: O,
2379
+ model: I,
2380
2380
  provider: E.provider || "openai"
2381
2381
  };
2382
2382
  throw R.metrics({
@@ -2384,15 +2384,15 @@ ${X}`, ve = ee.messages?.map(
2384
2384
  status: pr.error,
2385
2385
  ...X,
2386
2386
  error: {
2387
- message: B.message,
2388
- httpStatusCode: B.httpStatus,
2389
- type: B.errorType
2387
+ message: D.message,
2388
+ httpStatusCode: D.httpStatus,
2389
+ type: D.errorType
2390
2390
  }
2391
2391
  }), R.measure({
2392
2392
  metric: ge.llmDuration,
2393
- value: Date.now() - S,
2393
+ value: Date.now() - v,
2394
2394
  ...X
2395
- }), B;
2395
+ }), D;
2396
2396
  }
2397
2397
  };
2398
2398
  function Zo(e, t) {
@@ -2412,7 +2412,7 @@ ${Ee}`, Tp = {
2412
2412
  type: "string"
2413
2413
  }
2414
2414
  }
2415
- }, kn = (e = Tp) => {
2415
+ }, In = (e = Tp) => {
2416
2416
  const t = Object.entries(e.properties).map(([n, r]) => {
2417
2417
  const s = Object.entries(r).filter(
2418
2418
  ([a, c]) => ["format", "description"].includes(a) && !!c
@@ -2421,15 +2421,15 @@ ${Ee}`, Tp = {
2421
2421
  }).join(", ");
2422
2422
  return `${Go} \`{ ${t} }\`. ${Ee}.
2423
2423
  `;
2424
- }, ti = (e) => e ? `Ensure the type is ${e}. ` : "", Ep = "ensure values meant to be numbers are numbers", Ip = "ensure the type is a real schema.org type", kp = "ensure the returned object has @context, name", ni = (e, t, n) => {
2424
+ }, ti = (e) => e ? `Ensure the type is ${e}. ` : "", Ep = "ensure values meant to be numbers are numbers", kp = "ensure the type is a real schema.org type", Ip = "ensure the returned object has @context, name", ni = (e, t, n) => {
2425
2425
  const r = `${ti(t)}`, s = n ? `
2426
2426
  ${En} ${$(JSON.stringify(n), {
2427
2427
  tag: "schema"
2428
2428
  })}` : "";
2429
2429
  return `Give me "${e}" in schema.org JSON format with a full set of properties. ${r ? `${r}.` : ""}
2430
2430
  - ${Ep}
2431
- - ${Ip}
2432
2431
  - ${kp}
2432
+ - ${Ip}
2433
2433
  ${s}
2434
2434
  ${Ee}`;
2435
2435
  }, Ap = (e) => `Use the following information to create a blog post. Don't necessarily use all of the information. Keep your sentences varied, but nothing too long. Focus on writing an interesting, engaging post:
@@ -2446,7 +2446,7 @@ ${e}
2446
2446
  }, _p = (e, { schema: t = Op } = {}) => `Make an array of "${e}" objects.
2447
2447
 
2448
2448
  ${Pn}
2449
- - ${kn(t)}
2449
+ - ${In(t)}
2450
2450
  - ${Uo}
2451
2451
 
2452
2452
  ${Ee} ${Fo}`, Cp = "Please continue building the list.", jp = 10, ri = (e, {
@@ -2628,7 +2628,7 @@ Query: ${e}`, cd = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
2628
2628
  __proto__: null,
2629
2629
  asEnum: ei,
2630
2630
  asJSONSchema: Pp,
2631
- asObjectWithSchema: kn,
2631
+ asObjectWithSchema: In,
2632
2632
  asSchemaOrgText: ni,
2633
2633
  asSchemaOrgType: ti,
2634
2634
  asXML: $,
@@ -2653,8 +2653,8 @@ Query: ${e}`, cd = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
2653
2653
  wrapList: Zp,
2654
2654
  wrapVariable: op
2655
2655
  }, Symbol.toStringTag, { value: "Module" }));
2656
- async function q(e, t) {
2657
- const n = Object.keys(t), r = I("options", e.onProgress, e);
2656
+ async function F(e, t) {
2657
+ const n = Object.keys(t), r = k("options", e.onProgress, e);
2658
2658
  r.progress({ event: W.start, totalItems: n.length });
2659
2659
  const s = await fp(e, t);
2660
2660
  return r.progress({
@@ -2706,8 +2706,8 @@ const ud = {
2706
2706
  async function On(e, t = {}) {
2707
2707
  const { text: n, context: r } = N(e, []), s = r ? `${n}
2708
2708
 
2709
- ${r}` : n, o = A(hr, t), i = I(hr, o.onProgress, o);
2710
- i.start(), i.emit({ event: k.input, value: s });
2709
+ ${r}` : n, o = O(hr, t), i = k(hr, o.onProgress, o);
2710
+ i.start(), i.emit({ event: A.input, value: s });
2711
2711
  const a = `${md} ${hd}
2712
2712
 
2713
2713
  ${pd} ${dd}
@@ -2719,7 +2719,7 @@ The value should be "true", "false", or "undefined".`;
2719
2719
  systemPrompt: a,
2720
2720
  responseFormat: C("boolean_evaluation", ud)
2721
2721
  }), l = c === "true" ? !0 : c === "false" ? !1 : void 0;
2722
- return i.emit({ event: k.output, value: l }), i.complete({ outcome: T.success }), l;
2722
+ return i.emit({ event: A.output, value: l }), i.complete({ outcome: T.success }), l;
2723
2723
  } catch (c) {
2724
2724
  throw i.error(c), c;
2725
2725
  }
@@ -2801,7 +2801,7 @@ async function M(e, t = {}) {
2801
2801
  }
2802
2802
  };
2803
2803
  let p = 0, d = 0, h = new Error("Nothing to run"), y;
2804
- const f = I(n || "retry", c, r);
2804
+ const f = k(n || "retry", c, r);
2805
2805
  c && f.progress({
2806
2806
  event: W.start,
2807
2807
  attemptNumber: 1,
@@ -2809,24 +2809,24 @@ async function M(e, t = {}) {
2809
2809
  retryOnAll: i,
2810
2810
  retryMode: a
2811
2811
  });
2812
- const g = (w) => new Promise((S, v) => {
2812
+ const g = (w) => new Promise((v, S) => {
2813
2813
  if (l?.aborted) {
2814
- v(Ot(l));
2814
+ S(Ot(l));
2815
2815
  return;
2816
2816
  }
2817
- const P = setTimeout(S, w);
2817
+ const P = setTimeout(v, w);
2818
2818
  l?.addEventListener(
2819
2819
  "abort",
2820
2820
  () => {
2821
- clearTimeout(P), v(Ot(l));
2821
+ clearTimeout(P), S(Ot(l));
2822
2822
  },
2823
2823
  { once: !0 }
2824
2824
  );
2825
- }), m = async (w, S) => {
2826
- let v = w;
2827
- for (; v > 0; ) {
2828
- const P = Math.min(v, Sd);
2829
- await g(P), v -= P, v > 0 && f.progress({ ...S, remaining: v, elapsed: w - v });
2825
+ }), m = async (w, v) => {
2826
+ let S = w;
2827
+ for (; S > 0; ) {
2828
+ const P = Math.min(S, Sd);
2829
+ await g(P), S -= P, S > 0 && f.progress({ ...v, remaining: S, elapsed: w - S });
2830
2830
  }
2831
2831
  };
2832
2832
  e: for (; p < s; ) {
@@ -2895,16 +2895,16 @@ async function M(e, t = {}) {
2895
2895
  let x = 0, E = 0;
2896
2896
  for (; ; ) {
2897
2897
  x++;
2898
- const O = u.creditRetryInterval, R = {
2898
+ const I = u.creditRetryInterval, R = {
2899
2899
  event: W.providerWait,
2900
2900
  category: U.creditExhausted,
2901
2901
  provider: h.provider,
2902
- delay: O,
2902
+ delay: I,
2903
2903
  attempt: x,
2904
2904
  elapsed: E,
2905
2905
  error: { message: h.message, httpStatus: h.httpStatus }
2906
2906
  };
2907
- f.progress(R), await m(O, R), E += O, f.progress({
2907
+ f.progress(R), await m(I, R), E += I, f.progress({
2908
2908
  event: W.providerRetry,
2909
2909
  category: U.creditExhausted,
2910
2910
  provider: h.provider,
@@ -2912,7 +2912,7 @@ async function M(e, t = {}) {
2912
2912
  elapsed: E
2913
2913
  }), f.measure({
2914
2914
  metric: ge.providerWait,
2915
- value: O,
2915
+ value: I,
2916
2916
  category: U.creditExhausted,
2917
2917
  provider: h.provider
2918
2918
  });
@@ -2983,8 +2983,8 @@ async function M(e, t = {}) {
2983
2983
  continue e;
2984
2984
  }
2985
2985
  }
2986
- const S = h.httpStatus ?? h.response?.status, v = i || S === 429 || S >= 500 && S < 600, P = !v || p >= s - 1;
2987
- if (v && p < s - 1) {
2986
+ const v = h.httpStatus ?? h.response?.status, S = i || v === 429 || v >= 500 && v < 600, P = !S || p >= s - 1;
2987
+ if (S && p < s - 1) {
2988
2988
  const x = o * p;
2989
2989
  if (c) {
2990
2990
  const E = {
@@ -3082,11 +3082,11 @@ function Ed({
3082
3082
  outputBudget: Math.floor(i * t / (1 + t))
3083
3083
  };
3084
3084
  }
3085
- function Id(e, t, n) {
3085
+ function kd(e, t, n) {
3086
3086
  const r = Math.max(...e.map((s) => bi(s, n)));
3087
3087
  return Math.max(1, Math.floor(t.inputBudget / (r * Td)));
3088
3088
  }
3089
- function kd(e, { targetBatchSize: t, budget: n, model: r }) {
3089
+ function Id(e, { targetBatchSize: t, budget: n, model: r }) {
3090
3090
  const s = [];
3091
3091
  let o = [], i = 0, a = 0;
3092
3092
  for (let c = 0; c < e.length; c++) {
@@ -3101,7 +3101,7 @@ function kd(e, { targetBatchSize: t, budget: n, model: r }) {
3101
3101
  return o.length > 0 && s.push({ items: o, startIndex: a }), s;
3102
3102
  }
3103
3103
  async function Ae(e, t = {}) {
3104
- const { batchSize: n, contextBuffer: r = yi, llm: s } = t, { outputRatio: o, maxTokenBudget: i } = await q(t, {
3104
+ const { batchSize: n, contextBuffer: r = yi, llm: s } = t, { outputRatio: o, maxTokenBudget: i } = await F(t, {
3105
3105
  outputRatio: fi,
3106
3106
  maxTokenBudget: gi
3107
3107
  }), a = t.modelService || Te, c = Do(s) || a.getDefaultModel()?.name, l = a.getModel(c), u = Ed({
@@ -3109,8 +3109,8 @@ async function Ae(e, t = {}) {
3109
3109
  outputRatio: o,
3110
3110
  maxTokenBudget: i,
3111
3111
  contextBuffer: r
3112
- }), p = n || Id(e, u, l);
3113
- return kd(e, { targetBatchSize: p, budget: u, model: l });
3112
+ }), p = n || kd(e, u, l);
3113
+ return Id(e, { targetBatchSize: p, budget: u, model: l });
3114
3114
  }
3115
3115
  const Ad = 3, Od = 1e4, _d = 0.3;
3116
3116
  function Cd(e) {
@@ -3150,12 +3150,12 @@ async function Q(e, t, n = {}) {
3150
3150
  throw c.reason ?? new Error("The operation was aborted.");
3151
3151
  if (a === z.resilient) {
3152
3152
  const w = await Promise.allSettled(
3153
- m.map((S, v) => t(S, g + v))
3153
+ m.map((v, S) => t(v, g + S))
3154
3154
  );
3155
- b.push(...w.map((S, v) => S.status === "fulfilled" ? S.value : m[v]));
3155
+ b.push(...w.map((v, S) => v.status === "fulfilled" ? v.value : m[S]));
3156
3156
  } else {
3157
3157
  const w = await Promise.all(
3158
- m.map((S, v) => t(S, g + v))
3158
+ m.map((v, S) => t(v, g + S))
3159
3159
  );
3160
3160
  b.push(...w);
3161
3161
  }
@@ -3171,15 +3171,15 @@ async function Q(e, t, n = {}) {
3171
3171
  const b = e.slice(y, y + h), f = Date.now();
3172
3172
  let g = 0;
3173
3173
  if (a === z.resilient) {
3174
- const S = await Promise.allSettled(
3175
- b.map((v, P) => t(v, y + P))
3174
+ const v = await Promise.allSettled(
3175
+ b.map((S, P) => t(S, y + P))
3176
3176
  );
3177
- g = S.filter((v) => v.status === "rejected").length, p.push(...S.map((v, P) => v.status === "fulfilled" ? v.value : b[P]));
3177
+ g = v.filter((S) => S.status === "rejected").length, p.push(...v.map((S, P) => S.status === "fulfilled" ? S.value : b[P]));
3178
3178
  } else {
3179
- const S = await Promise.all(
3180
- b.map((v, P) => t(v, y + P))
3179
+ const v = await Promise.all(
3180
+ b.map((S, P) => t(S, y + P))
3181
3181
  );
3182
- p.push(...S);
3182
+ p.push(...v);
3183
3183
  }
3184
3184
  const m = Date.now() - f, w = g / b.length;
3185
3185
  d.record(m, w), h = jd(
@@ -3340,51 +3340,51 @@ async function Kd(e, t, n) {
3340
3340
  async function _n(e, t = {}) {
3341
3341
  const { text: n, context: r } = N(e, []), s = r ? `${n}
3342
3342
 
3343
- ${r}` : n, o = A(yr, t), i = I(yr, o.onProgress, o);
3344
- i.start(), i.emit({ event: k.input, value: s });
3345
- const { maxAttempts: a, validate: c, returnBestEffort: l } = await q(o, {
3343
+ ${r}` : n, o = O(yr, t), i = k(yr, o.onProgress, o);
3344
+ i.start(), i.emit({ event: A.input, value: s });
3345
+ const { maxAttempts: a, validate: c, returnBestEffort: l } = await F(o, {
3346
3346
  rigor: J(zd, ["validate", "maxAttempts", "returnBestEffort"])
3347
3347
  });
3348
3348
  try {
3349
3349
  const u = Wd(s), p = br(s);
3350
3350
  if (!c) {
3351
- const S = await Ct(p, o);
3352
- return i.emit({ event: k.output, value: S }), i.complete({ outcome: T.success }), S;
3351
+ const v = await Ct(p, o);
3352
+ return i.emit({ event: A.output, value: v }), i.complete({ outcome: T.success }), v;
3353
3353
  }
3354
3354
  const [d, h] = await Q(
3355
3355
  [
3356
3356
  () => _(u, {
3357
3357
  ...o,
3358
- onProgress: L(o.onProgress, "expectations"),
3358
+ onProgress: B(o.onProgress, "expectations"),
3359
3359
  responseFormat: C("date_expectations", xd)
3360
3360
  }),
3361
3361
  () => Ct(p, {
3362
3362
  ...o,
3363
- onProgress: L(o.onProgress, "extract")
3363
+ onProgress: B(o.onProgress, "extract")
3364
3364
  })
3365
3365
  ],
3366
- (S) => S(),
3366
+ (v) => v(),
3367
3367
  { maxParallel: 2, abortSignal: o?.abortSignal }
3368
3368
  ), y = d.length > 0 ? d : ["The result is a valid date"];
3369
3369
  if (!h) {
3370
- i.emit({ event: k.output, value: void 0 }), i.complete({ outcome: T.success });
3370
+ i.emit({ event: A.output, value: void 0 }), i.complete({ outcome: T.success });
3371
3371
  return;
3372
3372
  }
3373
3373
  let b = h, f = e, g = 0;
3374
3374
  const m = i.batch(a), w = await M(
3375
3375
  async () => {
3376
3376
  g += 1, i.emit({
3377
- event: k.step,
3377
+ event: A.step,
3378
3378
  stepName: "validation-attempt",
3379
3379
  attempt: g,
3380
3380
  maxAttempts: a,
3381
3381
  currentDate: b?.toISOString()
3382
3382
  });
3383
- const S = await Kd(b, y, o);
3384
- if (m(1), S.passed)
3383
+ const v = await Kd(b, y, o);
3384
+ if (m(1), v.passed)
3385
3385
  return b;
3386
- f = `${s} The previous answer (${b.toISOString()}) failed to satisfy: "${S.failedCheck}". Try again.`;
3387
- const v = br(f), P = await Ct(v, o);
3386
+ f = `${s} The previous answer (${b.toISOString()}) failed to satisfy: "${v.failedCheck}". Try again.`;
3387
+ const S = br(f), P = await Ct(S, o);
3388
3388
  if (!P || (b = P, g >= a))
3389
3389
  return l ? b : void 0;
3390
3390
  throw new Error("Retrying after validation failure");
@@ -3396,7 +3396,7 @@ ${r}` : n, o = A(yr, t), i = I(yr, o.onProgress, o);
3396
3396
  retryOnAll: !0
3397
3397
  }
3398
3398
  );
3399
- return i.emit({ event: k.output, value: w }), i.complete({ outcome: T.success }), w;
3399
+ return i.emit({ event: A.output, value: w }), i.complete({ outcome: T.success }), w;
3400
3400
  } catch (u) {
3401
3401
  throw i.error(u), u;
3402
3402
  }
@@ -3415,7 +3415,7 @@ const Gd = (e) => ({
3415
3415
  additionalProperties: !1
3416
3416
  }), { asUndefinedByDefault: Yd, contentIsQuestion: Hd, explainAndSeparate: Qd } = oe, wr = "enum";
3417
3417
  async function xi(e, t, n = {}) {
3418
- const { text: r, context: s } = N(e, []), o = A(wr, n), i = I(wr, o.onProgress, o);
3418
+ const { text: r, context: s } = N(e, []), o = O(wr, n), i = k(wr, o.onProgress, o);
3419
3419
  i.start();
3420
3420
  const a = [
3421
3421
  `${Hd} ${$(r, { tag: "text" })}
@@ -3464,7 +3464,7 @@ const Xd = {
3464
3464
  explainAndSeparatePrimitive: rm
3465
3465
  } = oe, vr = "number";
3466
3466
  async function Cn(e, t = {}) {
3467
- const { text: n, context: r } = N(e, []), s = A(vr, t), o = I(vr, s.onProgress, s);
3467
+ const { text: n, context: r } = N(e, []), s = O(vr, t), o = k(vr, s.onProgress, s);
3468
3468
  o.start();
3469
3469
  const i = [
3470
3470
  `${tm} ${$(n, { tag: "text" })}
@@ -3525,7 +3525,7 @@ const sm = "Bad datatype returned for number query.", om = "Value is not a numbe
3525
3525
  additionalProperties: um
3526
3526
  }, { asNumberWithUnits: dm, contentIsQuestion: mm, explainAndSeparate: hm, explainAndSeparateJSON: fm } = oe, Sr = "number-with-units", gm = C("number_with_units_result", pm);
3527
3527
  async function Nn(e, t = {}) {
3528
- const { text: n, context: r } = N(e, []), s = A(Sr, t), o = I(Sr, s.onProgress, s);
3528
+ const { text: n, context: r } = N(e, []), s = O(Sr, t), o = k(Sr, s.onProgress, s);
3529
3529
  o.start();
3530
3530
  const i = [
3531
3531
  `${mm} ${$(n, { tag: "text" })}
@@ -3585,7 +3585,7 @@ function xm({ spec: e, text: t, ...n }) {
3585
3585
  };
3586
3586
  }
3587
3587
  async function Rn(e, t = {}) {
3588
- const n = A("scale:spec", t), r = I("scale:spec", n.onProgress, n);
3588
+ const n = O("scale:spec", t), r = k("scale:spec", n.onProgress, n);
3589
3589
  r.start();
3590
3590
  try {
3591
3591
  const s = "You are a scale specification generator. Analyze the scaling instructions and produce a clear, comprehensive specification.", o = `Analyze these scaling instructions and generate a scale specification.
@@ -3617,7 +3617,7 @@ IMPORTANT: Each property must be a simple string value, not a nested object or a
3617
3617
  }
3618
3618
  }
3619
3619
  async function $m(e, t, n = {}) {
3620
- const r = A("scale:apply", n), s = `Apply the scale specification to transform this item.
3620
+ const r = O("scale:apply", n), s = `Apply the scale specification to transform this item.
3621
3621
 
3622
3622
  ${$(t, { tag: "scale-specification" })}
3623
3623
 
@@ -3638,20 +3638,20 @@ Return a JSON object with a "value" property containing the scaled result.`;
3638
3638
  }
3639
3639
  async function Pi(e, t, n) {
3640
3640
  [t, n] = K(t, n, ["spec"]);
3641
- const { text: r, known: s, context: o } = N(t, ["spec"]), i = A($r, n), a = I($r, i.onProgress, i);
3641
+ const { text: r, known: s, context: o } = N(t, ["spec"]), i = O($r, n), a = k($r, i.onProgress, i);
3642
3642
  a.start();
3643
3643
  try {
3644
- a.emit({ event: k.step, stepName: "generating-specification" });
3644
+ a.emit({ event: A.step, stepName: "generating-specification" });
3645
3645
  const c = s.spec || await Rn(o ? `${r}
3646
3646
 
3647
3647
  ${o}` : r, {
3648
3648
  ...i,
3649
- onProgress: L(i.onProgress, "scale:spec")
3649
+ onProgress: B(i.onProgress, "scale:spec")
3650
3650
  });
3651
- a.emit({ event: k.step, stepName: "applying-scale", specification: c });
3651
+ a.emit({ event: A.step, stepName: "applying-scale", specification: c });
3652
3652
  const l = await $m(e, c, {
3653
3653
  ...i,
3654
- onProgress: L(i.onProgress, "scale:apply")
3654
+ onProgress: B(i.onProgress, "scale:apply")
3655
3655
  });
3656
3656
  return a.complete({ outcome: T.success }), l;
3657
3657
  } catch (c) {
@@ -3684,11 +3684,11 @@ const Pr = {
3684
3684
  required: ["corpusProfile", "classificationCriteria", "salienceCriteria", "categoryNotes"],
3685
3685
  additionalProperties: !1
3686
3686
  }
3687
- }, Pm = "object", Tm = { severity: { type: "string", enum: ["none", "low", "medium", "high", "critical"], description: "Absolute risk level of this item" }, salience: { type: "string", enum: ["routine", "notable", "significant", "exceptional"], description: "How notable this item is relative to the corpus baseline" }, categories: { type: "object", description: "Per-category breakdown with severity and salience", additionalProperties: { type: "object", properties: { severity: { type: "string", enum: ["none", "low", "medium", "high", "critical"] }, salience: { type: "string", enum: ["routine", "notable", "significant", "exceptional"] } }, required: ["severity", "salience"], additionalProperties: !1 } }, summary: { type: "string", description: "Brief explanation of the classification" } }, Em = ["severity", "salience", "categories", "summary"], Im = !1, km = {
3687
+ }, Pm = "object", Tm = { severity: { type: "string", enum: ["none", "low", "medium", "high", "critical"], description: "Absolute risk level of this item" }, salience: { type: "string", enum: ["routine", "notable", "significant", "exceptional"], description: "How notable this item is relative to the corpus baseline" }, categories: { type: "object", description: "Per-category breakdown with severity and salience", additionalProperties: { type: "object", properties: { severity: { type: "string", enum: ["none", "low", "medium", "high", "critical"] }, salience: { type: "string", enum: ["routine", "notable", "significant", "exceptional"] } }, required: ["severity", "salience"], additionalProperties: !1 } }, summary: { type: "string", description: "Brief explanation of the classification" } }, Em = ["severity", "salience", "categories", "summary"], km = !1, Im = {
3688
3688
  type: Pm,
3689
3689
  properties: Tm,
3690
3690
  required: Em,
3691
- additionalProperties: Im
3691
+ additionalProperties: km
3692
3692
  }, Tr = "calibrate", Am = (e) => {
3693
3693
  if (e !== void 0 && (e === "low" || e === "med" || e === "high"))
3694
3694
  return e;
@@ -3717,9 +3717,9 @@ function Om(e) {
3717
3717
  };
3718
3718
  }
3719
3719
  async function Ti(e, t = {}) {
3720
- const n = A("calibrate:spec", t), r = I("calibrate:spec", n.onProgress, n);
3720
+ const n = O("calibrate:spec", t), r = k("calibrate:spec", n.onProgress, n);
3721
3721
  r.start();
3722
- const { thresholdStrategy: s, sensitivity: o } = await q(n, {
3722
+ const { thresholdStrategy: s, sensitivity: o } = await F(n, {
3723
3723
  thresholdStrategy: "statistical",
3724
3724
  sensitivity: J(Am)
3725
3725
  }), { instructions: i } = n, a = Om(e), c = "You are a calibration specification generator. Analyze the corpus scan statistics and produce a calibrated classification specification. The specification should enable consistent severity and salience classification of individual items relative to this corpus.", l = i ? `
@@ -3774,7 +3774,7 @@ IMPORTANT: Each property must be a simple string value, not a nested object or a
3774
3774
  }
3775
3775
  }
3776
3776
  async function _m(e, t, n = {}) {
3777
- const r = A("calibrate:apply", n), s = I("calibrate:apply", r.onProgress, r);
3777
+ const r = O("calibrate:apply", n), s = k("calibrate:apply", r.onProgress, r);
3778
3778
  s.start();
3779
3779
  const o = `Classify this scan result against the calibration specification.
3780
3780
 
@@ -3792,7 +3792,7 @@ Return a JSON object with:
3792
3792
  const i = await M(
3793
3793
  () => _(o, {
3794
3794
  ...r,
3795
- responseFormat: C("calibrate_result", km)
3795
+ responseFormat: C("calibrate_result", Im)
3796
3796
  }),
3797
3797
  {
3798
3798
  label: "calibrate classify",
@@ -3815,11 +3815,11 @@ async function Ei(e, t, n) {
3815
3815
  [t, n] = K(t, n, ["spec"]);
3816
3816
  const { text: r, known: s, context: o } = N(t, ["spec"]), i = o ? `${r}
3817
3817
 
3818
- ${o}` : r, a = A(Tr, n), c = I(Tr, a.onProgress, a);
3818
+ ${o}` : r, a = O(Tr, n), c = k(Tr, a.onProgress, a);
3819
3819
  c.start();
3820
3820
  try {
3821
3821
  const l = s.spec || await Ti([e], { ...a, instructions: i });
3822
- c.emit({ event: k.phase, phase: "applying-calibrate", specification: l });
3822
+ c.emit({ event: A.phase, phase: "applying-calibrate", specification: l });
3823
3823
  const u = await _m(e, l, a);
3824
3824
  return c.complete({ outcome: T.success }), u;
3825
3825
  } catch (l) {
@@ -3827,7 +3827,7 @@ ${o}` : r, a = A(Tr, n), c = I(Tr, a.onProgress, a);
3827
3827
  }
3828
3828
  }
3829
3829
  Ei.knownTexts = ["spec"];
3830
- const Ii = Object.freeze(["application", "providers", "request", "content"]), ki = Object.freeze({
3830
+ const ki = Object.freeze(["application", "providers", "request", "content"]), Ii = Object.freeze({
3831
3831
  PRODUCTION: "production",
3832
3832
  DEVELOPMENT: "development",
3833
3833
  TEST: "test"
@@ -3855,10 +3855,10 @@ const Ii = Object.freeze(["application", "providers", "request", "content"]), ki
3855
3855
  }), jm = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3856
3856
  __proto__: null,
3857
3857
  COMPLIANCE: Oi,
3858
- CONTEXT_KINDS: Ii,
3858
+ CONTEXT_KINDS: ki,
3859
3859
  COST_POSTURE: Ci,
3860
3860
  DOMAIN: Ai,
3861
- ENVIRONMENT: ki,
3861
+ ENVIRONMENT: Ii,
3862
3862
  QUALITY_INTENT: _i
3863
3863
  }, Symbol.toStringTag, { value: "Module" }));
3864
3864
  function ji(e) {
@@ -3899,7 +3899,7 @@ function tn(e, t, n) {
3899
3899
  a[c] = Array.isArray(l) ? [...l] : l;
3900
3900
  r[o] = a;
3901
3901
  }
3902
- return I("context-builder", t, n).emit({ event: k.output, kinds: Object.keys(r) }), ji(r);
3902
+ return k("context-builder", t, n).emit({ event: A.output, kinds: Object.keys(r) }), ji(r);
3903
3903
  }
3904
3904
  };
3905
3905
  }
@@ -3920,12 +3920,12 @@ function Ni({
3920
3920
  function Ri() {
3921
3921
  return {
3922
3922
  key: "default",
3923
- environment: D("NODE_ENV") || "development",
3924
- version: In
3923
+ environment: q("NODE_ENV") || "development",
3924
+ version: kn
3925
3925
  };
3926
3926
  }
3927
3927
  function Mi() {
3928
- const e = !!D("OPENAI_API_KEY"), t = !!D("ANTHROPIC_API_KEY"), n = !!D("OPENWEBUI_API_KEY"), r = n, s = !!D("REDIS_HOST");
3928
+ const e = !!q("OPENAI_API_KEY"), t = !!q("ANTHROPIC_API_KEY"), n = !!q("OPENWEBUI_API_KEY"), r = n, s = !!q("REDIS_HOST");
3929
3929
  return {
3930
3930
  key: "default",
3931
3931
  openai: e,
@@ -4011,9 +4011,9 @@ ${t}` : ""}`, Bm = (e, t) => {
4011
4011
  return { floorIdx: s, candidates: o, selection: i, mayResults: r };
4012
4012
  };
4013
4013
  async function Dm(e, t, n, r) {
4014
- const s = A(ht, r), o = I(ht, s.onProgress, s);
4014
+ const s = O(ht, r), o = k(ht, s.onProgress, s);
4015
4015
  o.start();
4016
- const { instruction: i, constraints: a } = await q(s, {
4016
+ const { instruction: i, constraints: a } = await F(s, {
4017
4017
  instruction: void 0,
4018
4018
  constraints: void 0
4019
4019
  });
@@ -4038,25 +4038,25 @@ async function Dm(e, t, n, r) {
4038
4038
  const g = () => {
4039
4039
  const m = {};
4040
4040
  for (const w of n) {
4041
- const S = l.get(w.name);
4042
- m[w.name] = S.selection ?? S.candidates[0];
4041
+ const v = l.get(w.name);
4042
+ m[w.name] = v.selection ?? v.candidates[0];
4043
4043
  }
4044
4044
  return m;
4045
4045
  };
4046
4046
  for (const m of a) {
4047
- const w = g(), S = m.enforce(w);
4048
- if (S)
4049
- for (const [v, P] of Object.entries(S)) {
4050
- const x = n.find((F) => F.name === v);
4047
+ const w = g(), v = m.enforce(w);
4048
+ if (v)
4049
+ for (const [S, P] of Object.entries(v)) {
4050
+ const x = n.find((L) => L.name === S);
4051
4051
  if (!x) continue;
4052
4052
  const E = x.values.indexOf(P);
4053
4053
  if (E < 0) continue;
4054
- const O = l.get(v);
4055
- if (E <= O.floorIdx) continue;
4054
+ const I = l.get(S);
4055
+ if (E <= I.floorIdx) continue;
4056
4056
  const R = x.values.slice(E);
4057
4057
  let j;
4058
- R.length <= 1 ? j = R[0] ?? x.values[x.values.length - 1] : O.selection !== void 0 && R.includes(O.selection) ? j = O.selection : j = P, l.set(v, {
4059
- ...O,
4058
+ R.length <= 1 ? j = R[0] ?? x.values[x.values.length - 1] : I.selection !== void 0 && R.includes(I.selection) ? j = I.selection : j = P, l.set(S, {
4059
+ ...I,
4060
4060
  floorIdx: E,
4061
4061
  candidates: R,
4062
4062
  selection: j
@@ -4071,7 +4071,7 @@ async function Dm(e, t, n, r) {
4071
4071
  if (u.length === 0)
4072
4072
  return o.complete({ outcome: T.success, dimensions: n.length }), n.map((g) => l.get(g.name).selection);
4073
4073
  const p = u.map((g) => {
4074
- const m = l.get(g.name), w = m.mayResults.filter((S) => m.candidates.includes(S.resolved));
4074
+ const m = l.get(g.name), w = m.mayResults.filter((v) => m.candidates.includes(v.resolved));
4075
4075
  return { dim: g, candidates: m.candidates, viableMays: w };
4076
4076
  }), d = Lm(p, i), h = {}, y = {};
4077
4077
  for (const { dim: g, candidates: m } of p)
@@ -4093,10 +4093,10 @@ async function Dm(e, t, n, r) {
4093
4093
  { label: "value-arbitrate", config: s }
4094
4094
  );
4095
4095
  for (const g of u) {
4096
- const m = l.get(g.name), w = f?.[g.name], S = y[g.name]?.[w];
4096
+ const m = l.get(g.name), w = f?.[g.name], v = y[g.name]?.[w];
4097
4097
  l.set(g.name, {
4098
4098
  ...m,
4099
- selection: S !== void 0 ? S : m.candidates[0]
4099
+ selection: v !== void 0 ? v : m.candidates[0]
4100
4100
  });
4101
4101
  }
4102
4102
  return o.complete({
@@ -4113,9 +4113,9 @@ async function Bi(e, t, n, r = {}) {
4113
4113
  if (!n?.length) throw new Error("valueArbitrate requires at least one value");
4114
4114
  if (Rm(n))
4115
4115
  return Dm(e, t, n, r);
4116
- const s = A(ht, r), o = I(ht, s.onProgress, s);
4116
+ const s = O(ht, r), o = k(ht, s.onProgress, s);
4117
4117
  o.start();
4118
- const { instruction: i } = await q(s, {
4118
+ const { instruction: i } = await F(s, {
4119
4119
  instruction: void 0
4120
4120
  });
4121
4121
  try {
@@ -4565,7 +4565,7 @@ const wt = ["in", "startsWith", "endsWith", "contains", "lessThan", "greaterThan
4565
4565
  }, Ln = (e, t) => e.clauses.every((n) => Fi(n, t)), th = (e, t) => {
4566
4566
  const n = e.find((r) => Ln(r, t));
4567
4567
  return n ? { option: n.option, value: n.value } : void 0;
4568
- }, nh = (e, t) => e.filter((n) => Ln(n, t)).map((n) => ({ option: n.option, value: n.value })), Ir = "suggest-targeting-rules", rh = (e, t) => {
4568
+ }, nh = (e, t) => e.filter((n) => Ln(n, t)).map((n) => ({ option: n.option, value: n.value })), kr = "suggest-targeting-rules", rh = (e, t) => {
4569
4569
  const n = e.map(
4570
4570
  (r, s) => `${s + 1}. option="${r.option}" operation="${r.operation}" source="${r.source}" value="${r.value}"${r.policyReturned !== void 0 ? ` policyReturned="${r.policyReturned}"` : ""}${r.error ? ` error="${r.error}"` : ""}`
4571
4571
  ).join(`
@@ -4590,7 +4590,7 @@ async function zi(e, t, n) {
4590
4590
  [t, n] = K(t, n);
4591
4591
  const { text: r, context: s } = N(t, []), o = s ? `${r}
4592
4592
 
4593
- ${s}` : r, i = A(Ir, n), a = I(Ir, i.onProgress, i);
4593
+ ${s}` : r, i = O(kr, n), a = k(kr, i.onProgress, i);
4594
4594
  if (a.start(), !e || e.length === 0)
4595
4595
  return a.complete({ outcome: T.success }), [];
4596
4596
  try {
@@ -4604,7 +4604,7 @@ ${s}` : r, i = A(Ir, n), a = I(Ir, i.onProgress, i);
4604
4604
  }
4605
4605
  }
4606
4606
  zi.knownTexts = [];
4607
- const sh = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"), ue = {
4607
+ const sh = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"), me = {
4608
4608
  NEWLINE: "newline",
4609
4609
  XML: "xml",
4610
4610
  AUTO: "auto"
@@ -4617,11 +4617,11 @@ function oh(e, t = 1e3) {
4617
4617
  });
4618
4618
  }
4619
4619
  function je(e, t, n) {
4620
- const r = e || ue.AUTO;
4621
- return r === ue.AUTO ? oh(t, n) ? ue.XML : ue.NEWLINE : r;
4620
+ const r = e || me.AUTO;
4621
+ return r === me.AUTO ? oh(t, n) ? me.XML : me.NEWLINE : r;
4622
4622
  }
4623
4623
  function ih(e, t) {
4624
- return t === ue.NEWLINE ? e.map((r) => String(r)).join(`
4624
+ return t === me.NEWLINE ? e.map((r) => String(r)).join(`
4625
4625
  `) : `<list>
4626
4626
  ${e.map((r) => ` <item>${sh(String(r))}</item>`).join(`
4627
4627
  `)}
@@ -4645,7 +4645,7 @@ ${o}`;
4645
4645
  },
4646
4646
  required: ["items"],
4647
4647
  additionalProperties: !1
4648
- }, kr = "list-batch";
4648
+ }, Ir = "list-batch";
4649
4649
  async function be(e, t, n) {
4650
4650
  [t, n] = K(t, n);
4651
4651
  let r;
@@ -4657,10 +4657,10 @@ async function be(e, t, n) {
4657
4657
 
4658
4658
  ${y}` : h;
4659
4659
  }
4660
- const s = A(kr, n), o = I(kr, s.onProgress, s);
4660
+ const s = O(Ir, n), o = k(Ir, s.onProgress, s);
4661
4661
  o.start();
4662
4662
  const {
4663
- listStyle: i = ue.AUTO,
4663
+ listStyle: i = me.AUTO,
4664
4664
  autoModeThreshold: a = 1e3,
4665
4665
  maxTokens: c,
4666
4666
  responseFormat: l,
@@ -4716,10 +4716,11 @@ ${y}` : h;
4716
4716
  }
4717
4717
  be.knownTexts = [];
4718
4718
  const Ar = "map", rn = Symbol("unprocessed");
4719
- function lh(e, t, n, r, s) {
4720
- const o = r ? `
4719
+ function lh(e, t, n, r) {
4720
+ const s = r ? `
4721
4721
 
4722
- ${r}` : "", i = `Transform each item in the list according to the instructions below. Apply the transformation consistently to every item.
4722
+ ${r}` : "";
4723
+ return `Transform each item in the list according to the instructions below. Apply the transformation consistently to every item.
4723
4724
 
4724
4725
  ${$(e, { tag: "transformation-instructions" })}
4725
4726
 
@@ -4727,23 +4728,10 @@ IMPORTANT:
4727
4728
  - Transform each item independently
4728
4729
  - Apply the same transformation logic to all items
4729
4730
  - Preserve the order of items from the input list
4730
- - Output one transformed result per input item${o}`;
4731
- return s ? `${i}
4731
+ - Output one transformed result per input item${s}
4732
4732
 
4733
4733
  The input list contains exactly ${t.length} item${t.length === 1 ? "" : "s"}.
4734
- Return exactly ${t.length} result${t.length === 1 ? "" : "s"} in the items array, one per input item.` : n === ue.NEWLINE ? `${i}
4735
-
4736
- The input list contains exactly ${t.length} item${t.length === 1 ? "" : "s"}, separated by newlines.
4737
- Return exactly ${t.length} line${t.length === 1 ? "" : "s"} of output, one transformed item per line. Do not number the lines.` : `${i}
4738
-
4739
- Return the transformed items as an XML list with exactly ${t.length} items:
4740
- <list>
4741
- <item>transformed content 1</item>
4742
- <item>transformed content 2</item>
4743
- ...
4744
- </list>
4745
-
4746
- Preserve all formatting and newlines within each <item> element.`;
4734
+ Return exactly ${t.length} result${t.length === 1 ? "" : "s"} in the items array, one per input item.`;
4747
4735
  }
4748
4736
  const Or = async function(e, t, n = {}) {
4749
4737
  const { maxParallel: r = 3, errorPosture: s, onProgress: o, _batchDone: i, _context: a } = n, c = new Array(e.length).fill(rn), l = await Ae(e, n), u = i ?? (() => {
@@ -4751,17 +4739,11 @@ const Or = async function(e, t, n = {}) {
4751
4739
  return await Q(
4752
4740
  l,
4753
4741
  async ({ items: p, startIndex: d }) => {
4754
- const h = je(n.listStyle, p, n.autoModeThreshold), y = lh(
4755
- t,
4756
- p,
4757
- h,
4758
- a,
4759
- n.responseFormat
4760
- );
4742
+ const h = je(n.listStyle, p, n.autoModeThreshold), y = lh(t, p, h, a);
4761
4743
  try {
4762
4744
  const b = {
4763
4745
  ...n,
4764
- onProgress: L(o, "map:list-batch"),
4746
+ onProgress: B(o, "map:list-batch"),
4765
4747
  listStyle: h
4766
4748
  }, f = await M(() => be(p, y, b), {
4767
4749
  label: "map:batch",
@@ -4786,10 +4768,10 @@ const Or = async function(e, t, n = {}) {
4786
4768
  ), c;
4787
4769
  }, Oe = async function(e, t, n) {
4788
4770
  [t, n] = K(t, n);
4789
- const { text: r, context: s } = N(t, []), o = A(Ar, n), i = I(Ar, o.onProgress, o);
4790
- i.start(), i.emit({ event: k.input, value: e });
4771
+ const { text: r, context: s } = N(t, []), o = O(Ar, n), i = k(Ar, o.onProgress, o);
4772
+ i.start(), i.emit({ event: A.input, value: e });
4791
4773
  try {
4792
- const { maxAttempts: a, maxParallel: c, errorPosture: l } = await q(o, {
4774
+ const { maxAttempts: a, maxParallel: c, errorPosture: l } = await F(o, {
4793
4775
  maxAttempts: 3,
4794
4776
  maxParallel: 3,
4795
4777
  errorPosture: z.resilient
@@ -4803,16 +4785,16 @@ const Or = async function(e, t, n = {}) {
4803
4785
  });
4804
4786
  for (let b = 1; b < a; b += 1) {
4805
4787
  const f = [], g = [];
4806
- if (p.forEach((w, S) => {
4807
- w === rn && (f.push(S), g.push(e[S]));
4788
+ if (p.forEach((w, v) => {
4789
+ w === rn && (f.push(v), g.push(e[v]));
4808
4790
  }), g.length === 0) break;
4809
4791
  (await Or(g, r, {
4810
4792
  ...o,
4811
4793
  maxAttempts: a,
4812
4794
  maxParallel: c,
4813
4795
  _context: s
4814
- })).forEach((w, S) => {
4815
- p[f[S]] = w;
4796
+ })).forEach((w, v) => {
4797
+ p[f[v]] = w;
4816
4798
  });
4817
4799
  }
4818
4800
  let d = 0;
@@ -4828,7 +4810,7 @@ const Or = async function(e, t, n = {}) {
4828
4810
  failedItems: d,
4829
4811
  outcome: h
4830
4812
  };
4831
- return i.emit({ event: k.output, value: p }), i.complete(y), p;
4813
+ return i.emit({ event: A.output, value: p }), i.complete(y), p;
4832
4814
  } catch (a) {
4833
4815
  throw i.error(a), a;
4834
4816
  }
@@ -4891,8 +4873,8 @@ function bh(e = "central_tendency_result", t = void 0) {
4891
4873
  return C(e, t || fh);
4892
4874
  }
4893
4875
  async function Wi(e, t, n = {}) {
4894
- const r = A(_r, n), s = I(_r, r.onProgress, r);
4895
- s.start(), s.emit({ event: k.input, value: e });
4876
+ const r = O(_r, n), s = k(_r, r.onProgress, r);
4877
+ s.start(), s.emit({ event: A.input, value: e });
4896
4878
  try {
4897
4879
  const { text: o, context: i } = N(e, []);
4898
4880
  if (!o || typeof o != "string")
@@ -4905,7 +4887,7 @@ ${i}` : "", p = bh("central_tendency_result"), d = await _(`${l}${u}`, {
4905
4887
  ...r,
4906
4888
  responseFormat: p
4907
4889
  });
4908
- return s.emit({ event: k.output, value: d }), s.complete({ outcome: T.success }), d;
4890
+ return s.emit({ event: A.output, value: d }), s.complete({ outcome: T.success }), d;
4909
4891
  } catch (o) {
4910
4892
  throw s.error(o), o;
4911
4893
  }
@@ -4971,9 +4953,9 @@ async function Vi(e, t, n = {}) {
4971
4953
  return [];
4972
4954
  if (!Array.isArray(t) || t.length === 0)
4973
4955
  throw new Error("seedItems must be a non-empty array");
4974
- const r = A(jr, n), s = I(jr, r.onProgress, r);
4975
- s.start(), s.emit({ event: k.input, value: e });
4976
- const { batchSize: o } = await q(r, {
4956
+ const r = O(jr, n), s = k(jr, r.onProgress, r);
4957
+ s.start(), s.emit({ event: A.input, value: e });
4958
+ const { batchSize: o } = await F(r, {
4977
4959
  batchSize: 5
4978
4960
  });
4979
4961
  try {
@@ -4981,13 +4963,13 @@ async function Vi(e, t, n = {}) {
4981
4963
  ...r,
4982
4964
  batchSize: o,
4983
4965
  responseFormat: wh,
4984
- onProgress: L(r.onProgress, "map:evaluation")
4966
+ onProgress: B(r.onProgress, "map:evaluation")
4985
4967
  }), c = (p) => p && typeof p == "object" && typeof p.score == "number", l = a.filter(c).length, u = {
4986
4968
  totalItems: a.length,
4987
4969
  successCount: l,
4988
4970
  failureCount: a.length - l
4989
4971
  };
4990
- return s.emit({ event: k.output, value: a }), s.complete({ outcome: T.success, ...u }), a;
4972
+ return s.emit({ event: A.output, value: a }), s.complete({ outcome: T.success, ...u }), a;
4991
4973
  } catch (i) {
4992
4974
  throw s.error(i), i;
4993
4975
  }
@@ -5009,12 +4991,12 @@ const Nr = {
5009
4991
  }, Rr = "reduce", Sh = C(
5010
4992
  Nr.name,
5011
4993
  Nr.schema
5012
- ), Ie = async function(t, n, r) {
4994
+ ), ke = async function(t, n, r) {
5013
4995
  [n, r] = K(n, r);
5014
- const { text: s, context: o } = N(n, []), i = A(Rr, r), a = I(Rr, i.onProgress, i);
5015
- a.start(), a.emit({ event: k.input, value: t });
4996
+ const { text: s, context: o } = N(n, []), i = O(Rr, r), a = k(Rr, i.onProgress, i);
4997
+ a.start(), a.emit({ event: A.input, value: t });
5016
4998
  try {
5017
- const { accumulatorMode: c } = await q(i, {
4999
+ const { accumulatorMode: c } = await F(i, {
5018
5000
  accumulatorMode: "auto"
5019
5001
  });
5020
5002
  let l = i.initial;
@@ -5028,7 +5010,7 @@ const Nr = {
5028
5010
  for (const { items: b, skip: f } of p) {
5029
5011
  if (f) continue;
5030
5012
  const g = je(i.listStyle, b, i.autoModeThreshold), m = ({ style: x, count: E }) => {
5031
- const O = x === ue.XML ? "XML" : "", R = o ? `
5013
+ const I = x === me.XML ? "XML" : "", R = o ? `
5032
5014
 
5033
5015
  ${o}` : "";
5034
5016
  return `Start with the given accumulator. Apply the transformation instructions to each item in the list sequentially, using the result as the new accumulator each time. Return only the final accumulator.
@@ -5046,15 +5028,15 @@ ${$(l !== void 0 ? l : "No initial value - use first item as starting point", {
5046
5028
  tag: "accumulator"
5047
5029
  })}
5048
5030
 
5049
- Process exactly ${E} items from the ${O} list below and return the final accumulator value.${R}`;
5050
- }, w = i.responseFormat || Sh, S = m({ style: g, count: b.length }), v = {
5031
+ Process exactly ${E} items from the ${I} list below and return the final accumulator value.${R}`;
5032
+ }, w = i.responseFormat || Sh, v = m({ style: g, count: b.length }), S = {
5051
5033
  ...i,
5052
5034
  listStyle: g,
5053
5035
  responseFormat: w
5054
- }, P = await M(() => be(b, S, v), {
5036
+ }, P = await M(() => be(b, v, S), {
5055
5037
  label: "reduce:batch",
5056
5038
  config: i,
5057
- onProgress: L(i.onProgress, "batch")
5039
+ onProgress: B(i.onProgress, "batch")
5058
5040
  });
5059
5041
  !i.responseFormat && P?.accumulator !== void 0 ? l = P.accumulator : l = P, d(b.length);
5060
5042
  }
@@ -5068,12 +5050,12 @@ Process exactly ${E} items from the ${O} list below and return the final accumul
5068
5050
  totalBatches: h.length,
5069
5051
  outcome: T.success
5070
5052
  };
5071
- return a.emit({ event: k.output, value: l }), a.complete(y), l;
5053
+ return a.emit({ event: A.output, value: l }), a.complete(y), l;
5072
5054
  } catch (c) {
5073
5055
  throw a.error(c), c;
5074
5056
  }
5075
5057
  };
5076
- Ie.knownTexts = [];
5058
+ ke.knownTexts = [];
5077
5059
  const Mr = {
5078
5060
  name: "pattern_candidates",
5079
5061
  schema: {
@@ -5127,9 +5109,9 @@ function sn(e, t = 50, n = 10) {
5127
5109
  return r;
5128
5110
  }
5129
5111
  async function Ji(e, t = {}) {
5130
- const n = A(Lr, t), r = I(Lr, n.onProgress, n);
5131
- r.start(), r.emit({ event: k.input, value: e });
5132
- const { maxStringLength: s, maxArrayLength: o, topN: i, capacity: a } = await q(n, {
5112
+ const n = O(Lr, t), r = k(Lr, n.onProgress, n);
5113
+ r.start(), r.emit({ event: A.input, value: e });
5114
+ const { maxStringLength: s, maxArrayLength: o, topN: i, capacity: a } = await F(n, {
5133
5115
  thoroughness: J(xh, ["topN", "capacity"]),
5134
5116
  maxStringLength: 50,
5135
5117
  maxArrayLength: 10
@@ -5162,28 +5144,28 @@ async function Ji(e, t = {}) {
5162
5144
  Return all candidates. If the input list is empty, return an empty array.
5163
5145
  `;
5164
5146
  try {
5165
- const p = r.batch(l.length), d = await Ie(l, u, {
5147
+ const p = r.batch(l.length), d = await ke(l, u, {
5166
5148
  ...n,
5167
5149
  initial: [],
5168
5150
  responseFormat: $h,
5169
- onProgress: L(n.onProgress, "reduce:accumulate")
5151
+ onProgress: B(n.onProgress, "reduce:accumulate")
5170
5152
  });
5171
5153
  if (p(l.length), !Array.isArray(d))
5172
5154
  return r.complete({ outcome: T.success }), [];
5173
5155
  const h = d.filter((y) => y.type === "pattern" && y.count >= 2).toSorted((y, b) => b.count - y.count).map((y) => y.template).slice(0, i);
5174
- return r.emit({ event: k.output, value: h }), r.complete({ outcome: T.success }), h;
5156
+ return r.emit({ event: A.output, value: h }), r.complete({ outcome: T.success }), h;
5175
5157
  } catch (p) {
5176
5158
  throw r.error(p), p;
5177
5159
  }
5178
5160
  }
5179
5161
  Ji.knownTexts = [];
5180
- const Ph = () => !!D("VERBLETS_DEBUG"), ne = (...e) => {
5162
+ const Ph = () => !!q("VERBLETS_DEBUG"), ne = (...e) => {
5181
5163
  Ph() && console.error(...e);
5182
- }, Th = "http://json-schema.org/draft-07/schema#", Eh = "object", Ih = ["thresholdCandidates"], kh = { thresholdCandidates: { type: "array", items: { type: "object", required: ["value", "rationale", "percentilePosition", "riskProfile", "falsePositiveRate", "falseNegativeRate", "confidence"], properties: { value: { type: "number", description: "The recommended threshold value" }, rationale: { type: "string", description: "Human-readable explanation of why this threshold was selected" }, percentilePosition: { type: "number", minimum: 0, maximum: 100, description: "Where this threshold falls in the distribution (0-100)" }, riskProfile: { type: "string", enum: ["conservative", "balanced", "aggressive"], description: "The risk stance this threshold represents" }, falsePositiveRate: { type: "number", minimum: 0, maximum: 1, description: "Estimated rate of false positives with this threshold" }, falseNegativeRate: { type: "number", minimum: 0, maximum: 1, description: "Estimated rate of false negatives with this threshold" }, confidence: { type: "number", minimum: 0, maximum: 1, description: "Model's confidence in this threshold recommendation (0-1)" }, coverageAbove: { type: "number", minimum: 0, maximum: 1, description: "Proportion of data points above this threshold" }, coverageBelow: { type: "number", minimum: 0, maximum: 1, description: "Proportion of data points below this threshold" }, distributionInsight: { type: "string", description: "Key insight about the distribution at this threshold (e.g., 'natural break in bimodal distribution')" } }, additionalProperties: !1 } }, distributionAnalysis: { type: "object", properties: { mean: { type: "number" }, median: { type: "number" }, standardDeviation: { type: "number" }, skewness: { type: "string", enum: ["left", "right", "normal"], description: "Direction of distribution skew" }, outlierPresence: { type: "string", enum: ["none", "low", "moderate", "high"], description: "Presence of outliers in the distribution" }, distributionType: { type: "string", enum: ["normal", "bimodal", "multimodal", "uniform", "exponential", "long-tail"], description: "Identified distribution pattern" } }, additionalProperties: !1 } }, Ah = !1, Oh = {
5164
+ }, Th = "http://json-schema.org/draft-07/schema#", Eh = "object", kh = ["thresholdCandidates"], Ih = { thresholdCandidates: { type: "array", items: { type: "object", required: ["value", "rationale", "percentilePosition", "riskProfile", "falsePositiveRate", "falseNegativeRate", "confidence"], properties: { value: { type: "number", description: "The recommended threshold value" }, rationale: { type: "string", description: "Human-readable explanation of why this threshold was selected" }, percentilePosition: { type: "number", minimum: 0, maximum: 100, description: "Where this threshold falls in the distribution (0-100)" }, riskProfile: { type: "string", enum: ["conservative", "balanced", "aggressive"], description: "The risk stance this threshold represents" }, falsePositiveRate: { type: "number", minimum: 0, maximum: 1, description: "Estimated rate of false positives with this threshold" }, falseNegativeRate: { type: "number", minimum: 0, maximum: 1, description: "Estimated rate of false negatives with this threshold" }, confidence: { type: "number", minimum: 0, maximum: 1, description: "Model's confidence in this threshold recommendation (0-1)" }, coverageAbove: { type: "number", minimum: 0, maximum: 1, description: "Proportion of data points above this threshold" }, coverageBelow: { type: "number", minimum: 0, maximum: 1, description: "Proportion of data points below this threshold" }, distributionInsight: { type: "string", description: "Key insight about the distribution at this threshold (e.g., 'natural break in bimodal distribution')" } }, additionalProperties: !1 } }, distributionAnalysis: { type: "object", properties: { mean: { type: "number" }, median: { type: "number" }, standardDeviation: { type: "number" }, skewness: { type: "string", enum: ["left", "right", "normal"], description: "Direction of distribution skew" }, outlierPresence: { type: "string", enum: ["none", "low", "moderate", "high"], description: "Presence of outliers in the distribution" }, distributionType: { type: "string", enum: ["normal", "bimodal", "multimodal", "uniform", "exponential", "long-tail"], description: "Identified distribution pattern" } }, additionalProperties: !1 } }, Ah = !1, Oh = {
5183
5165
  $schema: Th,
5184
5166
  type: Eh,
5185
- required: Ih,
5186
- properties: kh,
5167
+ required: kh,
5168
+ properties: Ih,
5187
5169
  additionalProperties: Ah
5188
5170
  }, Br = "detect-threshold";
5189
5171
  function Ki(e, t) {
@@ -5212,9 +5194,9 @@ function Ki(e, t) {
5212
5194
  }
5213
5195
  async function Gi(e, t, n, r) {
5214
5196
  [n, r] = K(n, r);
5215
- const { text: s, context: o } = N(n, []), i = A(Br, { llm: { good: !0 }, ...r }), a = I(Br, i.onProgress, i);
5197
+ const { text: s, context: o } = N(n, []), i = O(Br, { llm: { good: !0 }, ...r }), a = k(Br, i.onProgress, i);
5216
5198
  a.start();
5217
- const { batchSize: c } = await q(i, {
5199
+ const { batchSize: c } = await F(i, {
5218
5200
  batchSize: 50
5219
5201
  });
5220
5202
  if (!e || !Array.isArray(e) || e.length === 0)
@@ -5225,7 +5207,7 @@ async function Gi(e, t, n, r) {
5225
5207
  throw new Error("Goal must be specified to determine appropriate thresholds");
5226
5208
  try {
5227
5209
  const l = r.stats ?? Ki(e, t);
5228
- a.emit({ event: k.phase, phase: "statistics", stats: l });
5210
+ a.emit({ event: A.phase, phase: "statistics", stats: l });
5229
5211
  const u = e.map((P) => ({
5230
5212
  value: P[t],
5231
5213
  percentileRank: Math.round(
@@ -5293,14 +5275,14 @@ Return the updated accumulator as valid JSON.`, o].filter(Boolean).join(`
5293
5275
  const x = u.slice(P, P + b);
5294
5276
  f.push(JSON.stringify(x));
5295
5277
  }
5296
- a.emit({ event: k.phase, phase: "enriched", enrichedData: u });
5297
- const m = await Ie(f, y, {
5278
+ a.emit({ event: A.phase, phase: "enriched", enrichedData: u });
5279
+ const m = await ke(f, y, {
5298
5280
  ...i,
5299
5281
  initial: JSON.stringify(d),
5300
5282
  batchSize: c,
5301
5283
  responseFormat: C("analysis_accumulator", p),
5302
- onProgress: L(i.onProgress, "reduce:analysis")
5303
- }), S = [`Based on the following analysis of ${l.count} data points for property "${t}", generate threshold recommendations.
5284
+ onProgress: B(i.onProgress, "reduce:analysis")
5285
+ }), v = [`Based on the following analysis of ${l.count} data points for property "${t}", generate threshold recommendations.
5304
5286
 
5305
5287
  ${$(s, { tag: "goal" })}
5306
5288
 
@@ -5333,8 +5315,8 @@ Generate specific threshold recommendations that:
5333
5315
 
5334
5316
  Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
5335
5317
 
5336
- `), v = await M(
5337
- () => _(S, {
5318
+ `), S = await M(
5319
+ () => _(v, {
5338
5320
  ...i,
5339
5321
  responseFormat: C("threshold_result", Oh)
5340
5322
  }),
@@ -5343,9 +5325,9 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
5343
5325
  config: i
5344
5326
  }
5345
5327
  );
5346
- return v.thresholdCandidates && (v.thresholdCandidates = v.thresholdCandidates.filter((P) => P.value < l.min || P.value > l.max ? (ne(
5328
+ return S.thresholdCandidates && (S.thresholdCandidates = S.thresholdCandidates.filter((P) => P.value < l.min || P.value > l.max ? (ne(
5347
5329
  `Threshold value ${P.value} is outside data range [${l.min}, ${l.max}]`
5348
- ), !1) : !0)), v.distributionAnalysis = {
5330
+ ), !1) : !0)), S.distributionAnalysis = {
5349
5331
  mean: l.mean,
5350
5332
  median: l.median,
5351
5333
  standardDeviation: l.stdDev,
@@ -5353,7 +5335,7 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
5353
5335
  max: l.max,
5354
5336
  percentiles: l.percentiles,
5355
5337
  dataPoints: l.count
5356
- }, a.complete({ outcome: T.success }), v;
5338
+ }, a.complete({ outcome: T.success }), S;
5357
5339
  } catch (l) {
5358
5340
  throw a.error(l), l;
5359
5341
  }
@@ -5374,7 +5356,7 @@ function Lh({ spec: e, text: t, ...n }) {
5374
5356
  };
5375
5357
  }
5376
5358
  async function Yi(e, t = {}) {
5377
- const n = A("entities:spec", t), r = "You are an entity specification generator. Create a clear, concise specification for entity extraction.", s = `Analyze these entity extraction instructions and generate a specification.
5359
+ const n = O("entities:spec", t), r = "You are an entity specification generator. Create a clear, concise specification for entity extraction.", s = `Analyze these entity extraction instructions and generate a specification.
5378
5360
 
5379
5361
  ${$(e, { tag: "entity-instructions" })}
5380
5362
 
@@ -5396,7 +5378,7 @@ Keep it simple and actionable.`;
5396
5378
  );
5397
5379
  }
5398
5380
  async function Bh(e, t, n = {}) {
5399
- const r = A("entities:apply", n), s = `Apply the entity specification to extract entities from this text.
5381
+ const r = O("entities:apply", n), s = `Apply the entity specification to extract entities from this text.
5400
5382
 
5401
5383
  ${$(t, { tag: "entity-specification" })}
5402
5384
 
@@ -5420,11 +5402,11 @@ Include every entity that matches the specification. Do not add properties beyon
5420
5402
  }
5421
5403
  async function Hi(e, t, n) {
5422
5404
  [t, n] = K(t, n, ["spec"]);
5423
- const { text: r, known: s, context: o } = N(t, ["spec"]), i = A(Dr, n), a = I(Dr, i.onProgress, i);
5405
+ const { text: r, known: s, context: o } = N(t, ["spec"]), i = O(Dr, n), a = k(Dr, i.onProgress, i);
5424
5406
  a.start();
5425
5407
  try {
5426
5408
  a.emit({
5427
- event: k.step,
5409
+ event: A.step,
5428
5410
  stepName: "generating-specification",
5429
5411
  instructions: r
5430
5412
  });
@@ -5432,12 +5414,12 @@ async function Hi(e, t, n) {
5432
5414
 
5433
5415
  ${o}` : r, {
5434
5416
  ...i,
5435
- onProgress: L(i.onProgress, "spec")
5417
+ onProgress: B(i.onProgress, "spec")
5436
5418
  });
5437
- a.emit({ event: k.step, stepName: "extracting-entities", specification: c });
5419
+ a.emit({ event: A.step, stepName: "extracting-entities", specification: c });
5438
5420
  const l = await Bh(e, c, {
5439
5421
  ...i,
5440
- onProgress: L(i.onProgress, "apply")
5422
+ onProgress: B(i.onProgress, "apply")
5441
5423
  });
5442
5424
  return a.complete({ outcome: T.success }), l;
5443
5425
  } catch (c) {
@@ -5507,9 +5489,9 @@ async function Xi(e, t, n) {
5507
5489
  [t, n] = K(t, n);
5508
5490
  const { text: r, context: s } = N(t, []), o = s ? `${r}
5509
5491
 
5510
- ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5511
- a.start(), a.emit({ event: k.input, value: e });
5512
- const { maxParallel: c, windowSize: l, overlapSize: u, maxAttempts: p, retryMode: d, retryOnAll: h } = await q(i, {
5492
+ ${s}` : r, i = O(qr, n), a = k(qr, i.onProgress, i);
5493
+ a.start(), a.emit({ event: A.input, value: e });
5494
+ const { maxParallel: c, windowSize: l, overlapSize: u, maxAttempts: p, retryMode: d, retryOnAll: h } = await F(i, {
5513
5495
  precision: J(qh, ["windowSize", "overlapSize"]),
5514
5496
  maxParallel: 3,
5515
5497
  maxAttempts: void 0,
@@ -5524,7 +5506,7 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5524
5506
  for (let x = 0; x < b; x += l - u)
5525
5507
  f.push(x);
5526
5508
  a.emit({
5527
- event: k.phase,
5509
+ event: A.phase,
5528
5510
  phase: "windowing",
5529
5511
  totalLines: b,
5530
5512
  windowCount: f.length,
@@ -5537,17 +5519,17 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5537
5519
  totalItems: f.length,
5538
5520
  totalBatches: f.length,
5539
5521
  maxParallel: c
5540
- }), a.emit({ event: k.phase, phase: "extraction" });
5522
+ }), a.emit({ event: A.phase, phase: "extraction" });
5541
5523
  const m = await Q(
5542
5524
  f,
5543
5525
  async (x) => {
5544
- const E = Math.min(x + l, b), O = y.slice(x, E), R = zh(O, x, o), j = await M(
5526
+ const E = Math.min(x + l, b), I = y.slice(x, E), R = zh(I, x, o), j = await M(
5545
5527
  async () => {
5546
- const F = await _(R, {
5528
+ const L = await _(R, {
5547
5529
  ...i,
5548
5530
  responseFormat: Qi
5549
5531
  });
5550
- return Fh(F);
5532
+ return Fh(L);
5551
5533
  },
5552
5534
  {
5553
5535
  label: "extract-blocks:window",
@@ -5555,7 +5537,7 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5555
5537
  maxAttempts: p,
5556
5538
  retryMode: d,
5557
5539
  retryOnAll: h,
5558
- onProgress: L(i.onProgress, "window")
5540
+ onProgress: B(i.onProgress, "window")
5559
5541
  }
5560
5542
  );
5561
5543
  return g(1), j;
@@ -5567,26 +5549,26 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5567
5549
  }
5568
5550
  );
5569
5551
  a.emit({
5570
- event: k.phase,
5552
+ event: A.phase,
5571
5553
  phase: "merging",
5572
5554
  rawBlocks: m.flat().length
5573
5555
  });
5574
- const w = m.flat().filter((x) => x && x.startLine !== void 0 && x.endLine !== void 0).toSorted((x, E) => x.startLine - E.startLine || E.endLine - x.endLine), S = [];
5556
+ const w = m.flat().filter((x) => x && x.startLine !== void 0 && x.endLine !== void 0).toSorted((x, E) => x.startLine - E.startLine || E.endLine - x.endLine), v = [];
5575
5557
  for (const x of w) {
5576
- const E = S[S.length - 1];
5577
- !E || x.startLine > E.endLine ? S.push({ ...x }) : x.endLine > E.endLine && (E.endLine = x.endLine);
5558
+ const E = v[v.length - 1];
5559
+ !E || x.startLine > E.endLine ? v.push({ ...x }) : x.endLine > E.endLine && (E.endLine = x.endLine);
5578
5560
  }
5579
- const v = S.map(
5561
+ const S = v.map(
5580
5562
  ({ startLine: x, endLine: E }) => y.slice(x, E + 1)
5581
5563
  );
5582
5564
  a.progress({
5583
5565
  event: W.complete,
5584
5566
  totalItems: f.length,
5585
5567
  processedItems: g.count,
5586
- blocksExtracted: v.length
5568
+ blocksExtracted: S.length
5587
5569
  });
5588
- const P = { blocksExtracted: v.length, outcome: T.success };
5589
- return a.emit({ event: k.output, value: v }), a.complete(P), v;
5570
+ const P = { blocksExtracted: S.length, outcome: T.success };
5571
+ return a.emit({ event: A.output, value: S }), a.complete(P), S;
5590
5572
  } catch (y) {
5591
5573
  throw a.error(y), y;
5592
5574
  }
@@ -5625,13 +5607,13 @@ const zr = {
5625
5607
  zr.schema
5626
5608
  ), Zi = async function(t, n, r) {
5627
5609
  [n, r] = K(n, r, ["guidance"]);
5628
- const { text: s, known: o, context: i } = N(n, ["guidance"]), a = A(Ur, r), c = I(Ur, a.onProgress, a);
5629
- c.start(), c.emit({ event: k.input, value: t });
5610
+ const { text: s, known: o, context: i } = N(n, ["guidance"]), a = O(Ur, r), c = k(Ur, a.onProgress, a);
5611
+ c.start(), c.emit({ event: A.input, value: t });
5630
5612
  const {
5631
5613
  guidance: l,
5632
5614
  errorPosture: u,
5633
5615
  maxParallel: p = 3
5634
- } = await q(a, {
5616
+ } = await F(a, {
5635
5617
  strictness: J(Uh, ["guidance", "errorPosture"])
5636
5618
  }), d = o.guidance ?? l, h = new Array(t.length), y = await Ae(t, a), b = c.batch(t.length);
5637
5619
  c.progress({
@@ -5639,7 +5621,7 @@ const zr = {
5639
5621
  totalItems: t.length,
5640
5622
  totalBatches: y.length
5641
5623
  });
5642
- const f = ({ style: S, count: v }) => {
5624
+ const f = ({ style: v, count: S }) => {
5643
5625
  const P = d ? `
5644
5626
 
5645
5627
  ${$(d, { tag: "borderline-handling" })}` : "", x = i ? `
@@ -5653,34 +5635,42 @@ IMPORTANT:
5653
5635
  - Consider all aspects of the filtering criteria
5654
5636
  - Return only "yes" or "no" for each item
5655
5637
  - Maintain the exact order of the input list${x}`;
5656
- return S === ue.NEWLINE ? `${E}
5638
+ return v === me.NEWLINE ? `${E}
5657
5639
 
5658
- Process exactly ${v} items from the list below and return ${v} yes/no decisions.` : `${E}
5640
+ Process exactly ${S} items from the list below and return ${S} yes/no decisions.` : `${E}
5659
5641
 
5660
- Process exactly ${v} items from the XML list below and return ${v} yes/no decisions.`;
5642
+ Process exactly ${S} items from the XML list below and return ${S} yes/no decisions.`;
5661
5643
  };
5662
5644
  await Q(
5663
5645
  y,
5664
- async ({ items: S, startIndex: v }) => {
5665
- const P = je(a.listStyle, S, a.autoModeThreshold), x = f({ style: P, count: S.length }), E = {
5646
+ async ({ items: v, startIndex: S }) => {
5647
+ const P = je(a.listStyle, v, a.autoModeThreshold), x = f({ style: P, count: v.length }), E = {
5666
5648
  ...a,
5667
5649
  listStyle: P,
5668
5650
  responseFormat: a.responseFormat ?? Wh
5669
5651
  };
5670
5652
  try {
5671
- const O = await M(() => be(S, x, E), {
5653
+ const I = await M(() => be(v, x, E), {
5672
5654
  label: "filter:batch",
5673
5655
  config: a,
5674
- onProgress: L(a.onProgress, "batch")
5656
+ onProgress: B(a.onProgress, "batch")
5675
5657
  });
5676
- S.forEach((R, j) => {
5677
- h[v + j] = O[j]?.toLowerCase().trim() === "yes";
5678
- }), b(S.length);
5679
- } catch (O) {
5680
- if (O.name === "AbortError" || a?.abortSignal?.aborted || u === z.strict) throw O;
5681
- c.error(O, { startIndex: v, itemCount: S.length });
5682
- for (let R = 0; R < S.length; R++)
5683
- h[v + R] = !1;
5658
+ if (!Array.isArray(I) || I.length !== v.length) {
5659
+ const R = Array.isArray(I) ? I : [], j = Math.min(R.length, v.length);
5660
+ for (let L = 0; L < j; L++)
5661
+ h[S + L] = R[L]?.toLowerCase().trim() === "yes";
5662
+ for (let L = j; L < v.length; L++)
5663
+ h[S + L] = !1;
5664
+ } else
5665
+ for (let R = 0; R < v.length; R++)
5666
+ h[S + R] = I[R]?.toLowerCase().trim() === "yes";
5667
+ b(v.length);
5668
+ } catch (I) {
5669
+ if (I.name === "AbortError" || a?.abortSignal?.aborted || u === z.strict) throw I;
5670
+ c.error(I, { startIndex: S, itemCount: v.length });
5671
+ for (let R = 0; R < v.length; R++)
5672
+ h[S + R] = !1;
5673
+ b(v.length);
5684
5674
  }
5685
5675
  },
5686
5676
  {
@@ -5689,14 +5679,14 @@ Process exactly ${v} items from the XML list below and return ${v} yes/no decisi
5689
5679
  abortSignal: a.abortSignal
5690
5680
  }
5691
5681
  );
5692
- const g = t.filter((S, v) => h[v]);
5682
+ const g = t.filter((v, S) => h[S]);
5693
5683
  c.progress({
5694
5684
  event: W.complete,
5695
5685
  totalItems: t.length,
5696
5686
  processedItems: b.count
5697
5687
  });
5698
- const m = h.some((S) => S === void 0) ? T.partial : T.success, w = { inputCount: t.length, outputCount: g.length, outcome: m };
5699
- return c.emit({ event: k.output, value: g }), c.complete(w), g;
5688
+ const m = h.some((v) => v === void 0) ? T.partial : T.success, w = { inputCount: t.length, outputCount: g.length, outcome: m };
5689
+ return c.emit({ event: A.output, value: g }), c.complete(w), g;
5700
5690
  };
5701
5691
  Zi.knownTexts = ["guidance"];
5702
5692
  const Wr = {
@@ -5719,15 +5709,15 @@ const Wr = {
5719
5709
  }
5720
5710
  }, Vr = "find", Vh = C(Wr.name, Wr.schema), ea = async function(t, n, r) {
5721
5711
  [n, r] = K(n, r);
5722
- const { text: s, context: o } = N(n, []), i = A(Vr, r), a = I(Vr, i.onProgress, i);
5723
- a.start(), a.emit({ event: k.input, value: t });
5724
- const { maxParallel: c, errorPosture: l } = await q(i, {
5712
+ const { text: s, context: o } = N(n, []), i = O(Vr, r), a = k(Vr, i.onProgress, i);
5713
+ a.start(), a.emit({ event: A.input, value: t });
5714
+ const { maxParallel: c, errorPosture: l } = await F(i, {
5725
5715
  maxParallel: 3,
5726
5716
  errorPosture: z.resilient
5727
5717
  }), u = ({ style: g, count: m }) => {
5728
5718
  const w = o ? `
5729
5719
 
5730
- ${o}` : "", S = `From the list below, identify and return the SINGLE item that BEST matches the search criteria.
5720
+ ${o}` : "", v = `From the list below, identify and return the SINGLE item that BEST matches the search criteria.
5731
5721
 
5732
5722
  ${$(s, { tag: "search-criteria" })}
5733
5723
 
@@ -5737,9 +5727,9 @@ IMPORTANT:
5737
5727
  - Return the complete original item text, unchanged
5738
5728
  - If NO items match the criteria, return an empty string
5739
5729
  - Return ONLY ONE item, even if multiple items match${w}`;
5740
- return g === ue.NEWLINE ? `${S}
5730
+ return g === me.NEWLINE ? `${v}
5741
5731
 
5742
- Process exactly ${m} items from the list below and return the single best match.` : `${S}
5732
+ Process exactly ${m} items from the list below and return the single best match.` : `${v}
5743
5733
 
5744
5734
  Process exactly ${m} items from the XML list below and return the single best match.`;
5745
5735
  }, p = [];
@@ -5754,29 +5744,29 @@ Process exactly ${m} items from the XML list below and return the single best ma
5754
5744
  const m = b.slice(g, g + c);
5755
5745
  await Q(
5756
5746
  m,
5757
- async ({ items: w, startIndex: S }) => {
5758
- const v = je(i.listStyle, w, i.autoModeThreshold);
5747
+ async ({ items: w, startIndex: v }) => {
5748
+ const S = je(i.listStyle, w, i.autoModeThreshold);
5759
5749
  try {
5760
5750
  const P = await M(
5761
- () => be(w, u({ style: v, count: w.length }), {
5751
+ () => be(w, u({ style: S, count: w.length }), {
5762
5752
  ...i,
5763
- listStyle: v,
5753
+ listStyle: S,
5764
5754
  responseFormat: i.responseFormat || Vh
5765
5755
  }),
5766
5756
  {
5767
5757
  label: "find:batch",
5768
5758
  config: i,
5769
- onProgress: L(i.onProgress, "batch")
5759
+ onProgress: B(i.onProgress, "batch")
5770
5760
  }
5771
5761
  ), x = Array.isArray(P) && P[0];
5772
5762
  if (x) {
5773
- const E = t.findIndex((R) => R === x), O = E !== -1 ? E : S;
5774
- p.push({ result: x, index: O });
5763
+ const E = t.findIndex((R) => R === x), I = E !== -1 ? E : v;
5764
+ p.push({ result: x, index: I });
5775
5765
  }
5776
5766
  y(w.length);
5777
5767
  } catch (P) {
5778
- if (a.error(P, { startIndex: S, itemCount: w.length }), l === z.strict) throw P;
5779
- ne(`find batch at index ${S} failed: ${P.message}`);
5768
+ if (a.error(P, { startIndex: v, itemCount: w.length }), l === z.strict) throw P;
5769
+ ne(`find batch at index ${v} failed: ${P.message}`);
5780
5770
  }
5781
5771
  },
5782
5772
  {
@@ -5793,12 +5783,12 @@ Process exactly ${m} items from the XML list below and return the single best ma
5793
5783
  found: p.length > 0
5794
5784
  }), p.length > 0) {
5795
5785
  const g = p.reduce(
5796
- (w, S) => S.index < w.index ? S : w
5786
+ (w, v) => v.index < w.index ? v : w
5797
5787
  ), m = { found: !0, totalItems: t.length, outcome: T.success };
5798
- return a.emit({ event: k.output, value: g.result }), a.complete(m), g.result;
5788
+ return a.emit({ event: A.output, value: g.result }), a.complete(m), g.result;
5799
5789
  }
5800
5790
  const f = { found: !1, totalItems: t.length, outcome: T.success };
5801
- return a.emit({ event: k.output, value: "" }), a.complete(f), "";
5791
+ return a.emit({ event: A.output, value: "" }), a.complete(f), "";
5802
5792
  };
5803
5793
  ea.knownTexts = [];
5804
5794
  const Jh = "http://json-schema.org/draft-07/schema#", Kh = "object", Gh = { items: { type: "array", description: "Array of sorted items", items: { type: "string", description: "A sorted item" } } }, Yh = ["items"], Hh = !1, Qh = {
@@ -5815,9 +5805,9 @@ const Jh = "http://json-schema.org/draft-07/schema#", Kh = "object", Gh = { item
5815
5805
  let ef = si;
5816
5806
  const tf = 10, nf = (e) => [...new Set(e.filter((t) => t.trim() !== ""))], Bn = async (e, t, n) => {
5817
5807
  [t, n] = K(t, n);
5818
- const { text: r, context: s } = N(t, []), o = A(Jr, n), i = I(Jr, o.onProgress, o);
5808
+ const { text: r, context: s } = N(t, []), o = O(Jr, n), i = k(Jr, o.onProgress, o);
5819
5809
  i.start();
5820
- const { batchSize: a, extremeK: c, iterations: l, selectBottom: u } = await q(o, {
5810
+ const { batchSize: a, extremeK: c, iterations: l, selectBottom: u } = await F(o, {
5821
5811
  effort: J(Xh, ["extremeK", "iterations", "selectBottom"]),
5822
5812
  batchSize: tf
5823
5813
  }), p = nf(e);
@@ -5830,8 +5820,8 @@ const tf = 10, nf = (e) => [...new Set(e.filter((t) => t.trim() !== ""))], Bn =
5830
5820
  iterations: l,
5831
5821
  criteria: t
5832
5822
  });
5833
- const d = async (v) => {
5834
- const P = ef({ description: r }, v);
5823
+ const d = async (S) => {
5824
+ const P = ef({ description: r }, S);
5835
5825
  if (Array.isArray(P))
5836
5826
  return P;
5837
5827
  const x = s ? `${P}
@@ -5842,67 +5832,67 @@ ${s}` : P, E = await M(
5842
5832
  label: "sort-batch",
5843
5833
  config: o
5844
5834
  }
5845
- ), O = E?.items || E;
5846
- return Array.isArray(O) ? O.filter(Boolean) : [];
5847
- }, h = async (v, P) => {
5848
- const x = Ce(a)(v);
5849
- let E = [], O = [], R = 0;
5835
+ ), I = E?.items || E;
5836
+ return Array.isArray(I) ? I.filter(Boolean) : [];
5837
+ }, h = async (S, P) => {
5838
+ const x = Ce(a)(S);
5839
+ let E = [], I = [], R = 0;
5850
5840
  const j = i.batch(x.length);
5851
- for (const F of x) {
5841
+ for (const L of x) {
5852
5842
  i.emit({
5853
- event: k.step,
5843
+ event: A.step,
5854
5844
  stepName: "sorting-chunk",
5855
5845
  iteration: P,
5856
5846
  chunkNumber: R + 1,
5857
5847
  totalChunks: x.length,
5858
- batchSize: F.length
5848
+ batchSize: L.length
5859
5849
  });
5860
- const V = [...F, ...E, ...u ? O : []];
5850
+ const V = [...L, ...E, ...u ? I : []];
5861
5851
  let Y = await d(V);
5862
5852
  const H = new Set(V), ee = new Set(Y);
5863
5853
  if (Y.length !== V.length || ee.size !== H.size) {
5864
- const pe = V.filter((te) => !ee.has(te));
5854
+ const ue = V.filter((te) => !ee.has(te));
5865
5855
  Y = [...Y.filter(
5866
- (te, ie, de) => H.has(te) && de.indexOf(te) === ie
5867
- ), ...pe], Y.length !== V.length && ne(`Sort mismatch: sent ${V.length}, got ${Y.length}`);
5856
+ (te, ie, pe) => H.has(te) && pe.indexOf(te) === ie
5857
+ ), ...ue], Y.length !== V.length && ne(`Sort mismatch: sent ${V.length}, got ${Y.length}`);
5868
5858
  }
5869
5859
  if (E = Y.slice(0, Math.min(c, Y.length)), u) {
5870
- const pe = Math.max(0, Y.length - E.length), G = Math.min(c, pe);
5871
- O = G > 0 ? Y.slice(-G) : [];
5860
+ const ue = Math.max(0, Y.length - E.length), G = Math.min(c, ue);
5861
+ I = G > 0 ? Y.slice(-G) : [];
5872
5862
  }
5873
5863
  R++, j(1);
5874
5864
  }
5875
5865
  return {
5876
5866
  top: E,
5877
- bottom: u ? O : [],
5878
- selected: /* @__PURE__ */ new Set([...E, ...u ? O : []])
5867
+ bottom: u ? I : [],
5868
+ selected: /* @__PURE__ */ new Set([...E, ...u ? I : []])
5879
5869
  };
5880
5870
  }, y = [], b = [];
5881
5871
  let f = p;
5882
- for (let v = 0; v < l && f.length > 0; v++) {
5872
+ for (let S = 0; S < l && f.length > 0; S++) {
5883
5873
  i.emit({
5884
- event: k.step,
5874
+ event: A.step,
5885
5875
  stepName: "extracting-extremes",
5886
- iteration: v + 1,
5876
+ iteration: S + 1,
5887
5877
  totalIterations: l,
5888
5878
  remainingItems: f.length
5889
5879
  });
5890
- const { top: P, bottom: x, selected: E } = await h(f, v + 1);
5891
- y.push(...P), u && b.unshift(...x), f = f.filter((O) => !E.has(O)), i.emit({
5892
- event: k.step,
5880
+ const { top: P, bottom: x, selected: E } = await h(f, S + 1);
5881
+ y.push(...P), u && b.unshift(...x), f = f.filter((I) => !E.has(I)), i.emit({
5882
+ event: A.step,
5893
5883
  stepName: "iteration-complete",
5894
- iteration: v + 1,
5884
+ iteration: S + 1,
5895
5885
  totalIterations: l,
5896
5886
  topCount: y.length,
5897
5887
  bottomCount: b.length,
5898
5888
  remainingItems: f.length
5899
5889
  });
5900
5890
  }
5901
- const g = u ? [...y, ...f, ...b] : [...y, ...f], m = new Set(p), w = /* @__PURE__ */ new Set(), S = [];
5902
- for (const v of g)
5903
- m.has(v) && !w.has(v) && (w.add(v), S.push(v));
5904
- for (const v of p)
5905
- w.has(v) || S.push(v);
5891
+ const g = u ? [...y, ...f, ...b] : [...y, ...f], m = new Set(p), w = /* @__PURE__ */ new Set(), v = [];
5892
+ for (const S of g)
5893
+ m.has(S) && !w.has(S) && (w.add(S), v.push(S));
5894
+ for (const S of p)
5895
+ w.has(S) || v.push(S);
5906
5896
  return i.progress({
5907
5897
  event: W.complete,
5908
5898
  totalItems: p.length,
@@ -5910,7 +5900,7 @@ ${s}` : P, E = await M(
5910
5900
  topItems: y.length,
5911
5901
  bottomItems: b.length,
5912
5902
  remainingItems: f.length
5913
- }), i.complete({ outcome: T.success, totalItems: p.length }), S;
5903
+ }), i.complete({ outcome: T.success, totalItems: p.length }), v;
5914
5904
  } catch (d) {
5915
5905
  throw i.error(d), d;
5916
5906
  }
@@ -5950,9 +5940,9 @@ const Kr = {
5950
5940
  Kr.schema
5951
5941
  );
5952
5942
  async function ta(e, t = {}) {
5953
- const { text: n, known: r, context: s } = N(e, ["terms"]), o = A(Gr, t), i = I(Gr, o.onProgress, o);
5943
+ const { text: n, known: r, context: s } = N(e, ["terms"]), o = O(Gr, t), i = k(Gr, o.onProgress, o);
5954
5944
  i.start();
5955
- const { maxTerms: a, sortBy: c, sentencesPerBatch: l, overlap: u } = await q(o, {
5945
+ const { maxTerms: a, sortBy: c, sentencesPerBatch: l, overlap: u } = await F(o, {
5956
5946
  maxTerms: 10,
5957
5947
  sortBy: "importance for understanding the content",
5958
5948
  sentencesPerBatch: 3,
@@ -5977,25 +5967,25 @@ async function ta(e, t = {}) {
5977
5967
 
5978
5968
  Return a "terms" object containing an array of the extracted terms.${s ? `
5979
5969
 
5980
- ${s}` : ""}`, S = await Oe(f, w, {
5970
+ ${s}` : ""}`, v = await Oe(f, w, {
5981
5971
  ...o,
5982
5972
  batchSize: o.batchSize ?? 1,
5983
5973
  responseFormat: rf,
5984
- onProgress: L(o.onProgress, "glossary:extract")
5974
+ onProgress: B(o.onProgress, "glossary:extract")
5985
5975
  });
5986
5976
  g(f.length);
5987
- const v = /* @__PURE__ */ new Set();
5988
- S.forEach((P) => {
5977
+ const S = /* @__PURE__ */ new Set();
5978
+ v.forEach((P) => {
5989
5979
  P && P.terms && Array.isArray(P.terms) && P.terms.forEach((x) => {
5990
- x && typeof x == "string" && v.add(x);
5980
+ x && typeof x == "string" && S.add(x);
5991
5981
  });
5992
- }), p = Array.from(v);
5982
+ }), p = Array.from(S);
5993
5983
  }
5994
- if (i.emit({ event: k.phase, phase: "extracted", terms: p }), p.length === 0)
5984
+ if (i.emit({ event: A.phase, phase: "extracted", terms: p }), p.length === 0)
5995
5985
  return i.complete({ outcome: T.success, terms: 0 }), [];
5996
5986
  const h = (await Bn(p, c, {
5997
5987
  ...o,
5998
- onProgress: L(o.onProgress, "glossary:sort")
5988
+ onProgress: B(o.onProgress, "glossary:sort")
5999
5989
  })).slice(0, a);
6000
5990
  return i.complete({ outcome: T.success, terms: h.length }), h;
6001
5991
  } catch (p) {
@@ -6034,17 +6024,13 @@ PROCESS:
6034
6024
 
6035
6025
  OUTPUT FORMAT:
6036
6026
  The accumulator should contain a comma-separated list of the current best category names.`;
6037
- }, af = (e) => ({ style: t, count: n }) => {
6038
- const r = e.join(", "), s = `Assign each item in the list below to one of these categories:
6027
+ }, af = (e) => ({ count: t }) => {
6028
+ const n = e.join(", ");
6029
+ return `Assign each item in the list below to one of these categories:
6039
6030
 
6040
- ${$(r, { tag: "categories" })}
6031
+ ${$(n, { tag: "categories" })}
6041
6032
 
6042
- Return exactly ${n} category names, one per line, in the same order as the input items.`;
6043
- return t === ue.NEWLINE ? `${s}
6044
-
6045
- Process exactly ${n} items from the list below.` : `${s}
6046
-
6047
- Process exactly ${n} items from the XML list below.`;
6033
+ Return exactly ${t} category names in the items array, one per input item, in the same order as the input list.`;
6048
6034
  }, Hr = (e) => e.split(/[,\n]/).map((t) => t.trim()).filter(Boolean), cf = (e) => {
6049
6035
  const t = {};
6050
6036
  for (const { items: n, labels: r } of e)
@@ -6059,14 +6045,14 @@ Process exactly ${n} items from the XML list below.`;
6059
6045
  };
6060
6046
  async function na(e, t, n) {
6061
6047
  [t, n] = K(t, n, ["categories"]);
6062
- const { text: r, known: s, context: o } = N(t, ["categories"]), i = A(Yr, n), a = I(Yr, i.onProgress, i);
6048
+ const { text: r, known: s, context: o } = N(t, ["categories"]), i = O(Yr, n), a = k(Yr, i.onProgress, i);
6063
6049
  a.start();
6064
6050
  const {
6065
6051
  guidance: c,
6066
6052
  maxParallel: l,
6067
6053
  errorPosture: u,
6068
6054
  topN: p
6069
- } = await q(i, {
6055
+ } = await F(i, {
6070
6056
  granularity: J(sf, ["guidance", "topN"]),
6071
6057
  maxParallel: 3,
6072
6058
  errorPosture: z.resilient
@@ -6076,7 +6062,7 @@ async function na(e, t, n) {
6076
6062
  f = Hr(s.categories);
6077
6063
  else {
6078
6064
  a.emit({
6079
- event: k.phase,
6065
+ event: A.phase,
6080
6066
  phase: "category-discovery",
6081
6067
  description: "Discovering categories from items"
6082
6068
  });
@@ -6084,16 +6070,16 @@ async function na(e, t, n) {
6084
6070
  r,
6085
6071
  d,
6086
6072
  c
6087
- ), F = await Ie(e, j, {
6073
+ ), L = await ke(e, j, {
6088
6074
  ...i,
6089
6075
  initial: "",
6090
6076
  now: b,
6091
- onProgress: L(i.onProgress, "reduce:category-discovery")
6077
+ onProgress: B(i.onProgress, "reduce:category-discovery")
6092
6078
  });
6093
- f = Hr(F);
6079
+ f = Hr(L);
6094
6080
  }
6095
6081
  f.length === 0 && f.push("other"), a.emit({
6096
- event: k.phase,
6082
+ event: A.phase,
6097
6083
  phase: "assignment",
6098
6084
  description: "Assigning items to categories",
6099
6085
  categories: f,
@@ -6101,35 +6087,31 @@ async function na(e, t, n) {
6101
6087
  });
6102
6088
  const g = [], m = af(f), w = o ? (j) => `${m(j)}
6103
6089
 
6104
- ${o}` : m, v = await Ae(e, i), P = a.batch(e.length);
6090
+ ${o}` : m, S = await Ae(e, i), P = a.batch(e.length);
6105
6091
  await Q(
6106
- v,
6107
- async ({ items: j, startIndex: F }) => {
6092
+ S,
6093
+ async ({ items: j, startIndex: L }) => {
6108
6094
  const V = je(h, j, y);
6109
6095
  try {
6110
6096
  const Y = {
6111
6097
  ...i,
6112
6098
  listStyle: V
6113
6099
  }, H = await M(
6114
- () => be(
6115
- j,
6116
- w({ style: V, count: j.length }),
6117
- Y
6118
- ),
6100
+ () => be(j, w({ count: j.length }), Y),
6119
6101
  {
6120
6102
  label: "group:batch",
6121
6103
  config: i,
6122
- onProgress: L(i.onProgress, "assign")
6104
+ onProgress: B(i.onProgress, "assign")
6123
6105
  }
6124
6106
  );
6125
6107
  if (!Array.isArray(H) || H.length !== j.length) {
6126
6108
  const ee = new Array(j.length).fill("other");
6127
- g.push({ items: j, labels: ee, startIndex: F });
6109
+ g.push({ items: j, labels: ee, startIndex: L });
6128
6110
  } else
6129
- g.push({ items: j, labels: H, startIndex: F });
6111
+ g.push({ items: j, labels: H, startIndex: L });
6130
6112
  P(j.length);
6131
6113
  } catch (Y) {
6132
- throw a.error(Y, { startIndex: F, itemCount: j.length }), Y;
6114
+ throw a.error(Y, { startIndex: L, itemCount: j.length }), Y;
6133
6115
  }
6134
6116
  },
6135
6117
  {
@@ -6138,8 +6120,8 @@ ${o}` : m, v = await Ae(e, i), P = a.batch(e.length);
6138
6120
  abortSignal: i.abortSignal
6139
6121
  }
6140
6122
  );
6141
- const x = g.toSorted((j, F) => j.startIndex - F.startIndex), E = cf(x), O = p ? lf(E, p) : E, R = Object.keys(O).length;
6142
- return a.complete({ groupCount: R, outcome: T.success }), O;
6123
+ const x = g.toSorted((j, L) => j.startIndex - L.startIndex), E = cf(x), I = p ? lf(E, p) : E, R = Object.keys(I).length;
6124
+ return a.complete({ groupCount: R, outcome: T.success }), I;
6143
6125
  }
6144
6126
  na.knownTexts = ["categories"];
6145
6127
  const uf = "http://json-schema.org/draft-07/schema#", pf = "object", df = { items: { type: "array", description: "Array of common features, instances, or relational links shared by all items", items: { type: "string", description: "A common feature, instance, or relational link" } } }, mf = ["items"], hf = !1, ff = {
@@ -6174,7 +6156,7 @@ ${yf}`,
6174
6156
  };
6175
6157
  async function Dn(e, t, n) {
6176
6158
  [t, n] = K(t, n);
6177
- const { text: r, context: s } = N(t, []), o = A(Qr, n), i = I(Qr, o.onProgress, o);
6159
+ const { text: r, context: s } = N(t, []), o = O(Qr, n), i = k(Qr, o.onProgress, o);
6178
6160
  if (i.start(), !Array.isArray(e) || e.length === 0)
6179
6161
  return i.complete({ outcome: T.success }), [];
6180
6162
  if (e.length < 2)
@@ -6225,13 +6207,13 @@ const Sf = {
6225
6207
  },
6226
6208
  required: ["items"],
6227
6209
  additionalProperties: !1
6228
- }, xf = "http://json-schema.org/draft-07/schema#", $f = "object", Pf = "Intersection results between categories", Tf = { intersections: { type: "object", description: "Map of intersection results keyed by combination identifier", additionalProperties: { type: "object", properties: { combination: { type: "array", items: { type: "string" }, description: "Array of category names that form this intersection" }, description: { type: "string", description: "Clear explanation of what this intersection represents" }, elements: { type: "array", items: { type: "string" }, description: "Specific examples that belong to ALL categories in the combination" } }, required: ["combination", "description", "elements"], additionalProperties: !1 } } }, Ef = ["intersections"], If = !1, kf = {
6210
+ }, xf = "http://json-schema.org/draft-07/schema#", $f = "object", Pf = "Intersection results between categories", Tf = { intersections: { type: "object", description: "Map of intersection results keyed by combination identifier", additionalProperties: { type: "object", properties: { combination: { type: "array", items: { type: "string" }, description: "Array of category names that form this intersection" }, description: { type: "string", description: "Clear explanation of what this intersection represents" }, elements: { type: "array", items: { type: "string" }, description: "Specific examples that belong to ALL categories in the combination" } }, required: ["combination", "description", "elements"], additionalProperties: !1 } } }, Ef = ["intersections"], kf = !1, If = {
6229
6211
  $schema: xf,
6230
6212
  type: $f,
6231
6213
  description: Pf,
6232
6214
  properties: Tf,
6233
6215
  required: Ef,
6234
- additionalProperties: If
6216
+ additionalProperties: kf
6235
6217
  }, Xr = "intersections", { strictFormat: Af, contentIsQuestion: Of } = oe, _f = (e, t, n) => {
6236
6218
  const r = e.join(", "), s = `${Of} Find specific examples, instances, or elements that belong to all of the given categories.
6237
6219
 
@@ -6276,9 +6258,9 @@ ${$(t, { tag: "additional-context" })}` : "";
6276
6258
  async function oa(e, t, n) {
6277
6259
  if ([t, n] = K(t, n), !Array.isArray(e) || e.length < 2)
6278
6260
  return {};
6279
- const { text: r, context: s } = N(t, []), o = A(Xr, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), i = I(Xr, o.onProgress, o);
6261
+ const { text: r, context: s } = N(t, []), o = O(Xr, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), i = k(Xr, o.onProgress, o);
6280
6262
  i.start();
6281
- const { useSchemaValidation: a } = await q(o, {
6263
+ const { useSchemaValidation: a } = await F(o, {
6282
6264
  useSchemaValidation: !1
6283
6265
  }), { minSize: c = 2, maxSize: l = e.length, batchSize: u = 10 } = o;
6284
6266
  try {
@@ -6290,7 +6272,7 @@ async function oa(e, t, n) {
6290
6272
  async (b) => {
6291
6273
  const f = await jf(b, r, s, {
6292
6274
  ...o,
6293
- onProgress: L(o.onProgress, "combo")
6275
+ onProgress: B(o.onProgress, "combo")
6294
6276
  });
6295
6277
  return h(1), f;
6296
6278
  },
@@ -6314,7 +6296,7 @@ async function oa(e, t, n) {
6314
6296
  }
6315
6297
  function Nf(e = "intersection_result") {
6316
6298
  return {
6317
- responseFormat: C(e, kf)
6299
+ responseFormat: C(e, If)
6318
6300
  };
6319
6301
  }
6320
6302
  async function Rf(e, t = {}) {
@@ -6358,12 +6340,12 @@ function aa() {
6358
6340
  }
6359
6341
  const Vf = (e, t) => `${Wf} ${e}
6360
6342
 
6361
- ${kn(t)}
6343
+ ${In(t)}
6362
6344
 
6363
6345
  ${Uf}`, Jf = ({ result: e, resultsAll: t } = {}) => t.includes(e), Kf = ({ queryCount: e, startTime: t, queryLimit: n, timeoutMs: r } = {}) => e > n || /* @__PURE__ */ new Date() - t > r, Gf = async function* (t, n = {}) {
6364
6346
  const { text: r, context: s } = N(t, []), o = s ? `${r}
6365
6347
 
6366
- ${s}` : r, i = A("list:generate", {
6348
+ ${s}` : r, i = O("list:generate", {
6367
6349
  llm: { fast: !0, good: !0, cheap: !0 },
6368
6350
  ...n
6369
6351
  }), a = [], c = {};
@@ -6377,28 +6359,28 @@ ${s}` : r, i = A("list:generate", {
6377
6359
  });
6378
6360
  let g = [];
6379
6361
  try {
6380
- const S = await M(
6362
+ const v = await M(
6381
6363
  () => _(f, { ...i, ...aa() }),
6382
6364
  {
6383
6365
  label: "list-generate",
6384
6366
  config: i
6385
6367
  }
6386
- ), v = S?.items || S;
6387
- g = Array.isArray(v) ? v.filter(Boolean) : [];
6388
- } catch (S) {
6389
- if (S.name === "AbortError")
6390
- throw S;
6368
+ ), S = v?.items || v;
6369
+ g = Array.isArray(S) ? S.filter(Boolean) : [];
6370
+ } catch (v) {
6371
+ if (v.name === "AbortError")
6372
+ throw v;
6391
6373
  ne(
6392
- `Generate list [error]: ${S.message} ${f.slice(0, 100).replace(`
6374
+ `Generate list [error]: ${v.message} ${f.slice(0, 100).replace(`
6393
6375
  `, "\\n")}`
6394
6376
  ), l = !0;
6395
6377
  break;
6396
6378
  }
6397
- const m = g.filter((S) => !(S in c));
6379
+ const m = g.filter((v) => !(v in c));
6398
6380
  b += 1;
6399
- for (const S of m) {
6400
- const v = {
6401
- result: S,
6381
+ for (const v of m) {
6382
+ const S = {
6383
+ result: v,
6402
6384
  resultsAll: a,
6403
6385
  resultsNew: g,
6404
6386
  queryCount: b,
@@ -6406,11 +6388,11 @@ ${s}` : r, i = A("list:generate", {
6406
6388
  queryLimit: d,
6407
6389
  timeoutMs: h
6408
6390
  };
6409
- if (await p(v)) {
6391
+ if (await p(S)) {
6410
6392
  l = !0;
6411
6393
  break;
6412
6394
  }
6413
- await u(v) || (c[S] = !0, a.push(S), yield S);
6395
+ await u(S) || (c[v] = !0, a.push(v), yield v);
6414
6396
  }
6415
6397
  await p({
6416
6398
  result: void 0,
@@ -6424,7 +6406,7 @@ ${s}` : r, i = A("list:generate", {
6424
6406
  }
6425
6407
  };
6426
6408
  async function Ze(e, t = {}) {
6427
- const { text: n, context: r } = N(e, ia), s = A(Zr, t), o = I(Zr, s.onProgress, s);
6409
+ const { text: n, context: r } = N(e, ia), s = O(Zr, t), o = k(Zr, s.onProgress, s);
6428
6410
  o.start();
6429
6411
  try {
6430
6412
  const { schema: i } = s, a = r ? `${n}
@@ -6437,7 +6419,7 @@ ${r}` : n, c = await M(
6437
6419
  }
6438
6420
  ), l = c?.items || c, u = Array.isArray(l) ? l : [];
6439
6421
  if (i && u.length > 0) {
6440
- o.emit({ event: k.step, stepName: "transform", itemCount: u.length });
6422
+ o.emit({ event: A.step, stepName: "transform", itemCount: u.length });
6441
6423
  const p = o.batch(u.length), d = [];
6442
6424
  for (const h of u) {
6443
6425
  const y = Vf(h, i), b = await M(() => _(y, s), {
@@ -6479,15 +6461,15 @@ const Yf = "http://json-schema.org/draft-07/schema#", Hf = "object", Qf = { item
6479
6461
  `);
6480
6462
  async function ca(e, t, n) {
6481
6463
  typeof t == "number" && (n = { ...n, count: t }, t = void 0), [t, n] = K(t, n);
6482
- const r = A(es, n), s = I(es, r.onProgress, r);
6483
- s.start(), s.emit({ event: k.input, value: e });
6464
+ const r = O(es, n), s = k(es, r.onProgress, r);
6465
+ s.start(), s.emit({ event: A.input, value: e });
6484
6466
  const { text: o, context: i } = N(t, []), a = await re("count", r, e.length * 2);
6485
6467
  try {
6486
6468
  const c = await _(ng(e, a, o, i), {
6487
6469
  ...r,
6488
6470
  responseFormat: tg
6489
6471
  }), l = c?.items || c;
6490
- return Array.isArray(l) ? (s.emit({ event: k.output, value: l }), s.complete({ outcome: T.success }), l) : (ne(`Expected items array, got: ${typeof l}`), s.complete({ outcome: T.success }), []);
6472
+ return Array.isArray(l) ? (s.emit({ event: A.output, value: l }), s.complete({ outcome: T.success }), l) : (ne(`Expected items array, got: ${typeof l}`), s.complete({ outcome: T.success }), []);
6491
6473
  } catch (c) {
6492
6474
  throw s.error(c), c;
6493
6475
  }
@@ -6536,7 +6518,7 @@ function ns(e, t) {
6536
6518
  }
6537
6519
  const qn = Rn;
6538
6520
  async function mg(e, t, n = {}) {
6539
- const r = A("score:item", n), s = `Apply the score specification to evaluate this item.
6521
+ const r = O("score:item", n), s = `Apply the score specification to evaluate this item.
6540
6522
 
6541
6523
  ${$(t, { tag: "score-specification" })}
6542
6524
 
@@ -6560,7 +6542,7 @@ ${o}` : r, a = s.spec || await qn(i, n);
6560
6542
  return mg(e, a, n);
6561
6543
  }
6562
6544
  async function rs(e, t, n, r) {
6563
- const { maxParallel: s, errorPosture: o, onProgress: i, logger: a, anchoring: c, _providedAnchors: l } = r, p = await Ae(e, n), d = new Array(e.length).fill(void 0), h = I("score", i, r), y = h.batch(e.length);
6545
+ const { maxParallel: s, errorPosture: o, onProgress: i, logger: a, anchoring: c, _providedAnchors: l } = r, p = await Ae(e, n), d = new Array(e.length).fill(void 0), h = k("score", i, r), y = h.batch(e.length);
6564
6546
  h.progress({
6565
6547
  event: W.start,
6566
6548
  totalItems: e.length,
@@ -6574,12 +6556,12 @@ async function rs(e, t, n, r) {
6574
6556
  const g = await M(() => be(f.items, t, n), {
6575
6557
  label: "score:batch",
6576
6558
  config: r,
6577
- onProgress: L(i, "batch")
6559
+ onProgress: B(i, "batch")
6578
6560
  });
6579
6561
  ns(g, f.items.length).forEach((m, w) => {
6580
6562
  d[f.startIndex + w] = m;
6581
6563
  }), b = dg(f.items, g, c), h.emit({
6582
- event: k.phase,
6564
+ event: A.phase,
6583
6565
  phase: "anchors-established",
6584
6566
  anchors: b
6585
6567
  });
@@ -6602,10 +6584,10 @@ ${b}` : t;
6602
6584
  const w = await M(() => be(g, f, n), {
6603
6585
  label: "score:batch",
6604
6586
  config: r,
6605
- onProgress: L(i, "batch")
6587
+ onProgress: B(i, "batch")
6606
6588
  });
6607
- ns(w, g.length).forEach((S, v) => {
6608
- d[m + v] = S;
6589
+ ns(w, g.length).forEach((v, S) => {
6590
+ d[m + S] = v;
6609
6591
  });
6610
6592
  } catch (w) {
6611
6593
  if (h.error(w, { itemCount: g.length }), o === z.strict) throw w;
@@ -6625,11 +6607,11 @@ ${b}` : t;
6625
6607
  processedItems: y.count
6626
6608
  }), d;
6627
6609
  }
6628
- async function ke(e, t, n) {
6610
+ async function Ie(e, t, n) {
6629
6611
  [t, n] = K(t, n, ["spec", "anchors"]);
6630
- const { text: r, known: s, context: o } = N(t, ["spec", "anchors"]), { now: i } = n, a = A(ts, n), c = I(ts, a.onProgress, a);
6631
- c.start(), c.emit({ event: k.input, value: e });
6632
- const { maxParallel: l, maxAttempts: u, temperature: p, errorPosture: d, anchoring: h } = await q(
6612
+ const { text: r, known: s, context: o } = N(t, ["spec", "anchors"]), { now: i } = n, a = O(ts, n), c = k(ts, a.onProgress, a);
6613
+ c.start(), c.emit({ event: A.input, value: e });
6614
+ const { maxParallel: l, maxAttempts: u, temperature: p, errorPosture: d, anchoring: h } = await F(
6633
6615
  a,
6634
6616
  {
6635
6617
  maxParallel: 3,
@@ -6639,11 +6621,11 @@ async function ke(e, t, n) {
6639
6621
  anchoring: J(lg)
6640
6622
  }
6641
6623
  );
6642
- c.emit({ event: k.phase, phase: "generating-specification" });
6624
+ c.emit({ event: A.phase, phase: "generating-specification" });
6643
6625
  const y = o ? `${r}
6644
6626
 
6645
6627
  ${o}` : r, b = s.spec || await qn(y, a);
6646
- c.emit({ event: k.phase, phase: "scoring-items", specification: b });
6628
+ c.emit({ event: A.phase, phase: "scoring-items", specification: b });
6647
6629
  const f = fg(
6648
6630
  b,
6649
6631
  "Return ONLY the numeric score for each item according to the specification range."
@@ -6661,19 +6643,19 @@ ${o}` : r, b = s.spec || await qn(y, a);
6661
6643
  _providedAnchors: s.anchors
6662
6644
  }, w = await rs(e, f, g, m);
6663
6645
  for (let x = 1; x < u; x += 1) {
6664
- const E = [], O = [];
6665
- if (w.forEach((j, F) => {
6666
- j == null && (E.push(F), O.push(e[F]));
6667
- }), O.length === 0) break;
6668
- (await rs(O, f, g, {
6646
+ const E = [], I = [];
6647
+ if (w.forEach((j, L) => {
6648
+ j == null && (E.push(L), I.push(e[L]));
6649
+ }), I.length === 0) break;
6650
+ (await rs(I, f, g, {
6669
6651
  ...m,
6670
6652
  now: /* @__PURE__ */ new Date()
6671
- })).forEach((j, F) => {
6672
- j !== void 0 && (w[E[F]] = j);
6653
+ })).forEach((j, L) => {
6654
+ j !== void 0 && (w[E[L]] = j);
6673
6655
  });
6674
6656
  }
6675
- const S = w.filter((x) => x !== void 0).length, v = w.length - S, P = v > 0 ? T.partial : T.success;
6676
- return c.complete({ totalItems: w.length, successCount: S, failedItems: v, outcome: P }), w;
6657
+ const v = w.filter((x) => x !== void 0).length, S = w.length - v, P = S > 0 ? T.partial : T.success;
6658
+ return c.complete({ totalItems: w.length, successCount: v, failedItems: S, outcome: P }), w;
6677
6659
  }
6678
6660
  function fg(e, t = "") {
6679
6661
  const n = `Apply this score specification to evaluate each item:
@@ -6691,7 +6673,7 @@ function gg({ spec: e, anchors: t, text: n, ...r }) {
6691
6673
  ...r
6692
6674
  };
6693
6675
  }
6694
- ke.knownTexts = ["spec", "anchors"];
6676
+ Ie.knownTexts = ["spec", "anchors"];
6695
6677
  const yg = "object", bg = { matrix: { type: "array", items: { type: "array", items: { type: "object", properties: { score: { type: "number" }, rationale: { type: "string", minLength: 1 } }, required: ["score", "rationale"], additionalProperties: !1 } } }, scale: { type: "object", properties: { min: { type: "number" }, max: { type: "number" } }, required: ["min", "max"], additionalProperties: !1 } }, wg = ["matrix", "scale"], vg = !1, rt = {
6696
6678
  type: yg,
6697
6679
  properties: bg,
@@ -6786,7 +6768,7 @@ ${s}` : os(e, t, n, r), a = xg(e.length, t.length), c = C("score_matrix_result",
6786
6768
  return Pg(l?.matrix, e.length, t.length);
6787
6769
  }
6788
6770
  async function as(e, t, n, r, s, o) {
6789
- const { maxParallel: i, errorPosture: a, onProgress: c, anchoring: l, _providedAnchors: u } = o, p = await Ae(e, { ...s, outputRatio: 4 }), d = Array.from({ length: e.length }), h = I("score-matrix", c, o), y = h.batch(e.length);
6771
+ const { maxParallel: i, errorPosture: a, onProgress: c, anchoring: l, _providedAnchors: u } = o, p = await Ae(e, { ...s, outputRatio: 4 }), d = Array.from({ length: e.length }), h = k("score-matrix", c, o), y = h.batch(e.length);
6790
6772
  h.progress({
6791
6773
  event: W.start,
6792
6774
  totalItems: e.length,
@@ -6799,11 +6781,11 @@ async function as(e, t, n, r, s, o) {
6799
6781
  try {
6800
6782
  const m = await M(
6801
6783
  () => is(g.items, t, n, r, "", s),
6802
- { label: "score-matrix:batch", config: o, onProgress: L(c, "batch") }
6784
+ { label: "score-matrix:batch", config: o, onProgress: B(c, "batch") }
6803
6785
  );
6804
- m.forEach((w, S) => {
6805
- d[g.startIndex + S] = w;
6806
- }), b = $g(g.items, m, t, l), h.emit({ event: k.phase, phase: "anchors-established" });
6786
+ m.forEach((w, v) => {
6787
+ d[g.startIndex + v] = w;
6788
+ }), b = $g(g.items, m, t, l), h.emit({ event: A.phase, phase: "anchors-established" });
6807
6789
  } catch (m) {
6808
6790
  if (h.error(m, { batchIndex: 0, itemCount: g.items.length }), a === z.strict) throw m;
6809
6791
  }
@@ -6818,10 +6800,10 @@ async function as(e, t, n, r, s, o) {
6818
6800
  {
6819
6801
  label: "score-matrix:batch",
6820
6802
  config: o,
6821
- onProgress: L(c, "batch")
6803
+ onProgress: B(c, "batch")
6822
6804
  }
6823
- )).forEach((S, v) => {
6824
- d[m + v] = S;
6805
+ )).forEach((v, S) => {
6806
+ d[m + S] = v;
6825
6807
  });
6826
6808
  } catch (w) {
6827
6809
  if (h.error(w, { itemCount: g.length }), a === z.strict) throw w;
@@ -6847,10 +6829,10 @@ async function ua(e, t, n, r) {
6847
6829
  [n, r] = K(n, r, ["anchors"]);
6848
6830
  const { text: s, known: o, context: i } = N(n, ["anchors"]), a = i ? `${s}
6849
6831
 
6850
- ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
6851
- if (u.start({ dimensions: c.length }), u.emit({ event: k.input, value: e }), e.length === 0)
6832
+ ${i}` : s, c = la(t), l = O(ss, r), u = k(ss, l.onProgress, l);
6833
+ if (u.start({ dimensions: c.length }), u.emit({ event: A.input, value: e }), e.length === 0)
6852
6834
  return u.complete({ rows: 0, columns: c.length, outcome: T.success }), { matrix: [], dimensions: c.map((x) => x.dimension), scale: Ve };
6853
- const { maxParallel: p, maxAttempts: d, temperature: h, errorPosture: y, anchoring: b } = await q(
6835
+ const { maxParallel: p, maxAttempts: d, temperature: h, errorPosture: y, anchoring: b } = await F(
6854
6836
  l,
6855
6837
  {
6856
6838
  maxParallel: 3,
@@ -6867,7 +6849,7 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
6867
6849
  anchoring: b,
6868
6850
  _providedAnchors: o.anchors
6869
6851
  };
6870
- u.emit({ event: k.phase, phase: "scoring-matrix" });
6852
+ u.emit({ event: A.phase, phase: "scoring-matrix" });
6871
6853
  const m = await as(
6872
6854
  e,
6873
6855
  c,
@@ -6877,43 +6859,43 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
6877
6859
  g
6878
6860
  );
6879
6861
  for (let x = 1; x < d; x += 1) {
6880
- const E = [], O = [];
6881
- if (m.forEach((j, F) => {
6882
- j == null && (E.push(F), O.push(e[F]));
6883
- }), O.length === 0) break;
6862
+ const E = [], I = [];
6863
+ if (m.forEach((j, L) => {
6864
+ j == null && (E.push(L), I.push(e[L]));
6865
+ }), I.length === 0) break;
6884
6866
  u.emit({
6885
- event: k.phase,
6867
+ event: A.phase,
6886
6868
  phase: "retrying-missing",
6887
- count: O.length,
6869
+ count: I.length,
6888
6870
  attempt: x
6889
6871
  }), (await as(
6890
- O,
6872
+ I,
6891
6873
  c,
6892
6874
  a,
6893
6875
  Ve,
6894
6876
  f,
6895
6877
  { ...g, now: /* @__PURE__ */ new Date() }
6896
- )).forEach((j, F) => {
6897
- j !== void 0 && (m[E[F]] = j);
6878
+ )).forEach((j, L) => {
6879
+ j !== void 0 && (m[E[L]] = j);
6898
6880
  });
6899
6881
  }
6900
6882
  const w = m.map(
6901
6883
  (x) => x ?? c.map(() => ({ score: Ve.min, rationale: "scoring failed" }))
6902
- ), S = m.filter((x) => x !== void 0).length, v = m.length - S, P = v > 0 ? T.partial : T.success;
6884
+ ), v = m.filter((x) => x !== void 0).length, S = m.length - v, P = S > 0 ? T.partial : T.success;
6903
6885
  return u.emit({
6904
- event: k.output,
6886
+ event: A.output,
6905
6887
  value: { rows: w.length, columns: c.length }
6906
- }), u.complete({ totalItems: e.length, successCount: S, failedItems: v, outcome: P }), {
6888
+ }), u.complete({ totalItems: e.length, successCount: v, failedItems: S, outcome: P }), {
6907
6889
  matrix: w,
6908
6890
  dimensions: c.map((x) => x.dimension),
6909
6891
  scale: Ve
6910
6892
  };
6911
6893
  }
6912
6894
  ua.knownTexts = ["anchors"];
6913
- const Eg = "http://json-schema.org/draft-07/schema#", Ig = "object", kg = { items: { type: "array", description: "Array of tag IDs assigned to the item. Each ID must exactly match an id from the provided vocabulary", items: { type: "string", description: "Tag identifier that must exactly match an id from the provided tag vocabulary" } } }, Ag = ["items"], Og = !1, _g = {
6895
+ const Eg = "http://json-schema.org/draft-07/schema#", kg = "object", Ig = { items: { type: "array", description: "Array of tag IDs assigned to the item. Each ID must exactly match an id from the provided vocabulary", items: { type: "string", description: "Tag identifier that must exactly match an id from the provided tag vocabulary" } } }, Ag = ["items"], Og = !1, _g = {
6914
6896
  $schema: Eg,
6915
- type: Ig,
6916
- properties: kg,
6897
+ type: kg,
6898
+ properties: Ig,
6917
6899
  required: Ag,
6918
6900
  additionalProperties: Og
6919
6901
  }, cs = "tags", Cg = {
@@ -6936,7 +6918,7 @@ const Eg = "http://json-schema.org/draft-07/schema#", Ig = "object", kg = { item
6936
6918
  additionalProperties: !1
6937
6919
  };
6938
6920
  async function Fn(e, t = {}) {
6939
- const n = A("tags:spec", t), r = I("tags:spec", n.onProgress, n);
6921
+ const n = O("tags:spec", t), r = k("tags:spec", n.onProgress, n);
6940
6922
  r.start();
6941
6923
  try {
6942
6924
  const s = "You are a tag specification generator. Create clear, actionable tagging criteria.", o = `Analyze these tagging instructions and generate a specification.
@@ -6965,10 +6947,10 @@ Keep it concise and actionable.`, i = await M(
6965
6947
  }
6966
6948
  }
6967
6949
  async function jg(e, t, n, r = {}) {
6968
- const s = A(`${cs}:apply`, r), o = I(`${cs}:apply`, s.onProgress, s);
6950
+ const s = O(`${cs}:apply`, r), o = k(`${cs}:apply`, s.onProgress, s);
6969
6951
  o.start();
6970
6952
  try {
6971
- const { vocabularyMode: i } = await q(s, {
6953
+ const { vocabularyMode: i } = await F(s, {
6972
6954
  vocabularyMode: "strict"
6973
6955
  }), a = i === "open" ? `Available tags (prefer these, but you MAY suggest new tag IDs for items that don't fit any existing tag):
6974
6956
  ${$(JSON.stringify(n.tags), { tag: "available-tags" })}` : `Available tags (you MUST use only the "id" field from these tags):
@@ -7008,13 +6990,13 @@ ${o}` : r, c = s.spec || await Fn(a, n);
7008
6990
  }
7009
6991
  async function da(e, t, n) {
7010
6992
  [t, n] = K(t, n, Fe);
7011
- const r = A("tags:map", n), s = I("tags:map", r.onProgress, r);
6993
+ const r = O("tags:map", n), s = k("tags:map", r.onProgress, r);
7012
6994
  s.start();
7013
6995
  try {
7014
- const { text: o, known: i, context: a } = N(t, Fe), c = i.vocabulary, l = i.vocabularyMode ?? (await q(r, { vocabularyMode: "strict" })).vocabularyMode, u = a ? `${o}
6996
+ const { text: o, known: i, context: a } = N(t, Fe), c = i.vocabulary, l = i.vocabularyMode ?? (await F(r, { vocabularyMode: "strict" })).vocabularyMode, u = a ? `${o}
7015
6997
 
7016
6998
  ${a}` : o, p = i.spec || await Fn(u, r);
7017
- s.emit({ event: k.phase, phase: "applying-tags", specification: p });
6999
+ s.emit({ event: A.phase, phase: "applying-tags", specification: p });
7018
7000
  const d = Ng(
7019
7001
  p,
7020
7002
  c,
@@ -7027,7 +7009,7 @@ Return empty array when no tags apply.`,
7027
7009
  ), y = s.batch(h.length), b = {
7028
7010
  ...r,
7029
7011
  responseFormat: C("tags_map_result", Cg),
7030
- onProgress: L(r.onProgress, "tags:map")
7012
+ onProgress: B(r.onProgress, "tags:map")
7031
7013
  }, f = await Oe(h, d, b);
7032
7014
  return y(h.length), s.complete({ outcome: T.success }), f;
7033
7015
  } catch (o) {
@@ -7102,9 +7084,9 @@ function ma(e, { context: t = "", diversity: n } = {}) {
7102
7084
  async function ha(e, t = {}) {
7103
7085
  if (!e || typeof e != "string")
7104
7086
  throw new Error("categoryName must be a non-empty string");
7105
- const n = A(ls, { llm: { fast: !0, good: !0, cheap: !0 }, ...t }), r = I(ls, n.onProgress, n);
7087
+ const n = O(ls, { llm: { fast: !0, good: !0, cheap: !0 }, ...t }), r = k(ls, n.onProgress, n);
7106
7088
  r.start();
7107
- const { text: s, context: o } = N(e, []), { diversity: i, count: a } = await q(n, {
7089
+ const { text: s, context: o } = N(e, []), { diversity: i, count: a } = await F(n, {
7108
7090
  diversity: J(Mg, ["diversity", "count"])
7109
7091
  }), { context: c = "" } = n, l = [o, c].filter(Boolean).join(`
7110
7092
 
@@ -7115,7 +7097,7 @@ async function ha(e, t = {}) {
7115
7097
  }), d = await Ze(p, {
7116
7098
  ...n,
7117
7099
  shouldStop: ({ resultsAll: h }) => h.length >= a,
7118
- onProgress: L(n.onProgress, "list:sampling")
7100
+ onProgress: B(n.onProgress, "list:sampling")
7119
7101
  });
7120
7102
  if (!d || d.length === 0)
7121
7103
  throw new Error(`No sample items generated for category: ${e}`);
@@ -7140,9 +7122,9 @@ const us = "collect-terms", Bg = (e, t) => {
7140
7122
  return s && r.push(s.trim()), r;
7141
7123
  };
7142
7124
  async function zn(e, t = {}) {
7143
- const { text: n, known: r, context: s } = N(e, ["uniqueTerms"]), o = A(us, t), i = I(us, o.onProgress, o);
7125
+ const { text: n, known: r, context: s } = N(e, ["uniqueTerms"]), o = O(us, t), i = k(us, o.onProgress, o);
7144
7126
  i.start();
7145
- const { topN: a, chunkLen: c } = await q(o, {
7127
+ const { topN: a, chunkLen: c } = await F(o, {
7146
7128
  topN: 20,
7147
7129
  chunkLen: 1e3
7148
7130
  });
@@ -7158,7 +7140,7 @@ async function zn(e, t = {}) {
7158
7140
 
7159
7141
  ${s}` : "", w = await Ze(
7160
7142
  `key words and phrases that would help find documents about: ${g}${m}`,
7161
- { ...o, onProgress: L(o.onProgress, "list:extract") }
7143
+ { ...o, onProgress: B(o.onProgress, "list:extract") }
7162
7144
  );
7163
7145
  return y(1), w;
7164
7146
  },
@@ -7171,14 +7153,14 @@ ${s}` : "", w = await Ze(
7171
7153
  )).filter(Array.isArray).flat();
7172
7154
  l = Array.from(new Set(f.map((g) => g.trim()))).filter(Boolean);
7173
7155
  }
7174
- if (i.emit({ event: k.phase, phase: "extracted", uniqueTerms: l }), l.length <= a)
7156
+ if (i.emit({ event: A.phase, phase: "extracted", uniqueTerms: l }), l.length <= a)
7175
7157
  return i.complete({ outcome: T.success }), l;
7176
- const u = await ke(
7158
+ const u = await Ie(
7177
7159
  l,
7178
7160
  "relevance as a search term for finding information (1-10, higher is more important)",
7179
- { ...o, onProgress: L(o.onProgress, "score:rank") }
7161
+ { ...o, onProgress: B(o.onProgress, "score:rank") }
7180
7162
  ), d = l.map((h, y) => ({ term: h, score: u[y] ?? 0 })).toSorted((h, y) => y.score - h.score);
7181
- return i.emit({ event: k.phase, phase: "scored", termsWithScores: d }), i.complete({ outcome: T.success }), d.slice(0, a).map((h) => h.term);
7163
+ return i.emit({ event: A.phase, phase: "scored", termsWithScores: d }), i.complete({ outcome: T.success }), d.slice(0, a).map((h) => h.term);
7182
7164
  } catch (l) {
7183
7165
  throw i.error(l), l;
7184
7166
  }
@@ -7201,25 +7183,25 @@ async function Un({
7201
7183
  throw new Error("At least one speaker is required");
7202
7184
  if (!a)
7203
7185
  throw new Error("Topic is required");
7204
- const u = A(ps, i), p = I(ps, u.onProgress, u);
7205
- p.start(), p.emit({ event: k.input, value: { speakers: e, topic: a } });
7186
+ const u = O(ps, i), p = k(ps, u.onProgress, u);
7187
+ p.start(), p.emit({ event: A.input, value: { speakers: e, topic: a } });
7206
7188
  try {
7207
- const d = r.length > 0 ? r.map((S) => `${S.time} ${S.name} (${S.id}): ${S.comment}`).join(`
7189
+ const d = r.length > 0 ? r.map((v) => `${v.time} ${v.name} (${v.id}): ${v.comment}`).join(`
7208
7190
  `) : "", y = [
7209
7191
  o.customPrompt || "",
7210
7192
  d ? $(d, { tag: "conversation-history" }) : "",
7211
7193
  a ? $(a, { tag: "topic" }) : ""
7212
7194
  ].filter(Boolean).join(`
7213
7195
 
7214
- `), b = e.map((S, v) => {
7215
- const x = [S.name || `Speaker ${v + 1}`];
7216
- S.bio && x.push(`Bio: ${S.bio}`), S.agenda && x.push(`Agenda: ${S.agenda}`);
7217
- const E = s.get?.(S.id) ?? [];
7196
+ `), b = e.map((v, S) => {
7197
+ const x = [v.name || `Speaker ${S + 1}`];
7198
+ v.bio && x.push(`Bio: ${v.bio}`), v.agenda && x.push(`Agenda: ${v.agenda}`);
7199
+ const E = s.get?.(v.id) ?? [];
7218
7200
  if (E.length > 0) {
7219
- const O = E.map((R) => `[${R.time}] ${R.comment}`).join(`
7201
+ const I = E.map((R) => `[${R.time}] ${R.comment}`).join(`
7220
7202
  `);
7221
7203
  x.push(`Prior statements:
7222
- ${O}`);
7204
+ ${I}`);
7223
7205
  }
7224
7206
  return x.join(`
7225
7207
  `);
@@ -7232,9 +7214,9 @@ ${O}`);
7232
7214
 
7233
7215
  `), m = p.batch(e.length), w = await Oe(b, g, {
7234
7216
  ...u,
7235
- onProgress: L(u.onProgress, "conversation-turn-reduce:map")
7217
+ onProgress: B(u.onProgress, "conversation-turn-reduce:map")
7236
7218
  });
7237
- return m(e.length), p.emit({ event: k.output, value: w }), p.complete({ outcome: T.success, speakers: e.length }), w;
7219
+ return m(e.length), p.emit({ event: A.output, value: w }), p.complete({ outcome: T.success, speakers: e.length }), w;
7238
7220
  } catch (d) {
7239
7221
  throw p.error(d), d;
7240
7222
  }
@@ -7292,9 +7274,9 @@ class vt {
7292
7274
  throw new Error("Duplicate speaker id");
7293
7275
  s.add(p.id);
7294
7276
  });
7295
- const { text: o, context: i } = N(t, []), a = A(st, r), c = I(st, a.onProgress, a);
7296
- c.start(), c.emit({ event: k.input, value: { topic: o, speakers: n } });
7297
- const { depth: l, maxParallel: u } = await q(a, {
7277
+ const { text: o, context: i } = N(t, []), a = O(st, r), c = k(st, a.onProgress, a);
7278
+ c.start(), c.emit({ event: A.input, value: { topic: o, speakers: n } });
7279
+ const { depth: l, maxParallel: u } = await F(a, {
7298
7280
  depth: J(Fg),
7299
7281
  maxParallel: J(zg)
7300
7282
  });
@@ -7308,7 +7290,7 @@ class vt {
7308
7290
  constructor(t, n, r = {}, s = {}) {
7309
7291
  const o = r.emitter && r.config;
7310
7292
  this.emitter = o ? r.emitter : void 0, this.bundleContext = o ? r.bundleContext ?? "" : "";
7311
- const i = o ? r.config : A(st, r), {
7293
+ const i = o ? r.config : O(st, r), {
7312
7294
  rules: a = {},
7313
7295
  speakFn: c,
7314
7296
  bulkSpeakFn: l,
@@ -7329,7 +7311,7 @@ class vt {
7329
7311
  turnPolicy: a.turnPolicy || ds(this.speakers)
7330
7312
  },
7331
7313
  a
7332
- ), this.speakFn = c, this.bulkSpeakFn = l, this.maxParallel = s.maxParallel ?? 3, !this.speakFn && !this.bulkSpeakFn && (this.bulkSpeakFn = Un), this.llm = u, this.clock = p || (() => /* @__PURE__ */ new Date()), this.emitter || (this.emitter = I(st, i.onProgress, i)), this.onProgress = i.onProgress, this.runConfig = i, this.otherOptions = b, this.messages = [], this.speakerMemory = /* @__PURE__ */ new Map();
7314
+ ), this.speakFn = c, this.bulkSpeakFn = l, this.maxParallel = s.maxParallel ?? 3, !this.speakFn && !this.bulkSpeakFn && (this.bulkSpeakFn = Un), this.llm = u, this.clock = p || (() => /* @__PURE__ */ new Date()), this.emitter || (this.emitter = k(st, i.onProgress, i)), this.onProgress = i.onProgress, this.runConfig = i, this.otherOptions = b, this.messages = [], this.speakerMemory = /* @__PURE__ */ new Map();
7333
7315
  }
7334
7316
  _push(t, n) {
7335
7317
  const r = (n ?? "").trim();
@@ -7357,7 +7339,7 @@ class vt {
7357
7339
  speakerMemory: o,
7358
7340
  rules: this.rules,
7359
7341
  llm: this.llm,
7360
- onProgress: L(this.runConfig.onProgress, `round-${t}`)
7342
+ onProgress: B(this.runConfig.onProgress, `round-${t}`)
7361
7343
  })).forEach((a, c) => {
7362
7344
  this._push(s[c].id, a);
7363
7345
  }) : this.speakFn && (await Q(
@@ -7374,7 +7356,7 @@ class vt {
7374
7356
  speakerMemory: o,
7375
7357
  rules: this.rules,
7376
7358
  llm: this.llm,
7377
- onProgress: L(this.runConfig.onProgress, `round-${t}`)
7359
+ onProgress: B(this.runConfig.onProgress, `round-${t}`)
7378
7360
  });
7379
7361
  return { speaker: a, comment: c };
7380
7362
  } catch (c) {
@@ -7390,7 +7372,7 @@ class vt {
7390
7372
  c && this._push(a.id, c);
7391
7373
  }), t += 1, n(1);
7392
7374
  }
7393
- return this.emitter.emit({ event: k.output, value: this.messages }), this.emitter.complete({ outcome: T.success }), this.messages;
7375
+ return this.emitter.emit({ event: A.output, value: this.messages }), this.emitter.complete({ outcome: T.success }), this.messages;
7394
7376
  } catch (t) {
7395
7377
  throw this.emitter.error(t), t;
7396
7378
  }
@@ -7408,7 +7390,7 @@ const Ug = "http://json-schema.org/draft-07/schema#", Wg = "object", Vg = { mean
7408
7390
  Gg
7409
7391
  ), Hg = (e) => `List all distinct dictionary meanings or common uses of ${$(e, { tag: "term" })}.
7410
7392
  Return a JSON object with a "meanings" array containing the distinct meanings.`, fa = async (e, t = {}) => {
7411
- const n = A("disambiguate:meanings", {
7393
+ const n = O("disambiguate:meanings", {
7412
7394
  llm: { fast: !0, good: !0, cheap: !0 },
7413
7395
  ...t
7414
7396
  }), r = Hg(e), s = await M(
@@ -7427,27 +7409,27 @@ async function ga(e, t, n) {
7427
7409
  [t, n] = K(t, n);
7428
7410
  const { text: r, context: s } = N(t, []), o = s ? `${r}
7429
7411
 
7430
- ${s}` : r, i = A(ms, n), a = I(ms, i.onProgress, i);
7412
+ ${s}` : r, i = O(ms, n), a = k(ms, i.onProgress, i);
7431
7413
  a.start();
7432
7414
  try {
7433
- a.emit({ event: k.step, stepName: "extracting-meanings", term: e });
7415
+ a.emit({ event: A.step, stepName: "extracting-meanings", term: e });
7434
7416
  const c = await fa(e, {
7435
7417
  ...i,
7436
- onProgress: L(i.onProgress, "meanings")
7418
+ onProgress: B(i.onProgress, "meanings")
7437
7419
  });
7438
7420
  a.emit({
7439
- event: k.step,
7421
+ event: A.step,
7440
7422
  stepName: "scoring-meanings",
7441
7423
  term: e,
7442
7424
  meanings: c,
7443
7425
  meaningCount: c.length
7444
7426
  });
7445
- const l = await ke(
7427
+ const l = await Ie(
7446
7428
  c,
7447
7429
  `how well this meaning of ${$(e, { tag: "term" })} matches the context: ${$(o, { tag: "context" })}`,
7448
7430
  {
7449
7431
  ...i,
7450
- onProgress: L(i.onProgress, "score:relevance")
7432
+ onProgress: B(i.onProgress, "score:relevance")
7451
7433
  }
7452
7434
  );
7453
7435
  let u = 0, p = -1 / 0;
@@ -7732,10 +7714,10 @@ class et {
7732
7714
  static async create(t, n = {}) {
7733
7715
  const { text: r, context: s } = N(t, []), o = [n.bundleContext, s].filter(Boolean).join(`
7734
7716
 
7735
- `), i = A(r, n), a = I(r, i.onProgress, i);
7717
+ `), i = O(r, n), a = k(r, i.onProgress, i);
7736
7718
  a.start();
7737
7719
  try {
7738
- const { temperature: c, variety: l } = await q(i, {
7720
+ const { temperature: c, variety: l } = await F(i, {
7739
7721
  temperature: void 0,
7740
7722
  variety: J(gs)
7741
7723
  }), u = new et(r, n, i, {
@@ -7784,17 +7766,17 @@ class et {
7784
7766
  }
7785
7767
  }
7786
7768
  const va = async (e, t = {}) => {
7787
- const { text: n, context: r } = N(e, []), s = A(fs, t), o = I(fs, s.onProgress, s);
7788
- o.start(), o.emit({ event: k.input, value: n });
7769
+ const { text: n, context: r } = N(e, []), s = O(fs, t), o = k(fs, s.onProgress, s);
7770
+ o.start(), o.emit({ event: A.input, value: n });
7789
7771
  try {
7790
7772
  const i = o.batch(1);
7791
- o.emit({ event: k.phase, phase: "tree-construction" });
7773
+ o.emit({ event: A.phase, phase: "tree-construction" });
7792
7774
  const a = await et.create(n, {
7793
7775
  ...s,
7794
7776
  bundleContext: r,
7795
- onProgress: L(s.onProgress, "tree-construction")
7777
+ onProgress: B(s.onProgress, "tree-construction")
7796
7778
  });
7797
- return i(1), o.emit({ event: k.output, value: a }), o.complete({ outcome: T.success }), a;
7779
+ return i(1), o.emit({ event: A.output, value: a }), o.complete({ outcome: T.success }), a;
7798
7780
  } catch (i) {
7799
7781
  throw o.error(i), i;
7800
7782
  }
@@ -8016,7 +7998,7 @@ function Ey(e, t, n, r, s = St) {
8016
7998
  avgChunkSize: a
8017
7999
  };
8018
8000
  }
8019
- function Iy(e, t, n) {
8001
+ function ky(e, t, n) {
8020
8002
  const r = e.length, s = Ta(n, r), o = Py(t, s, r), i = [];
8021
8003
  for (let a = 0; a < r; a += o)
8022
8004
  i.push({
@@ -8027,7 +8009,7 @@ function Iy(e, t, n) {
8027
8009
  });
8028
8010
  return i;
8029
8011
  }
8030
- async function ky(e, t, n = {}) {
8012
+ async function Iy(e, t, n = {}) {
8031
8013
  if (t < an)
8032
8014
  return { expansions: [e], tokensUsed: 0 };
8033
8015
  try {
@@ -8035,7 +8017,7 @@ async function ky(e, t, n = {}) {
8035
8017
  ...n,
8036
8018
  topN: 5,
8037
8019
  chunkLen: 500,
8038
- onProgress: L(n.onProgress, "collect-terms:query-expansion")
8020
+ onProgress: B(n.onProgress, "collect-terms:query-expansion")
8039
8021
  });
8040
8022
  return {
8041
8023
  expansions: [e, ...r],
@@ -8071,13 +8053,13 @@ async function _y(e, t, n, r = {}) {
8071
8053
  const o = e.slice(0, n), i = o.map((l) => {
8072
8054
  const u = l.text.replace(/\s+/g, " ").trim();
8073
8055
  return (u.match(/^[^.!?]{1,300}[.!?]/)?.[0] || u.slice(0, 300)).trim();
8074
- }), a = await ke(
8056
+ }), a = await Ie(
8075
8057
  i,
8076
8058
  `relevance to query: ${$(t, { tag: "query" })} (0=unrelated, 5=partially related, 10=directly answers)`,
8077
8059
  {
8078
8060
  ...r,
8079
8061
  batchSize: yy,
8080
- onProgress: L(r.onProgress, "score:edge-ranking")
8062
+ onProgress: B(r.onProgress, "score:edge-ranking")
8081
8063
  }
8082
8064
  );
8083
8065
  return {
@@ -8105,7 +8087,7 @@ async function Cy(e, t, n, r, s, o = {}) {
8105
8087
  {
8106
8088
  ...o,
8107
8089
  batchSize: 10,
8108
- onProgress: L(o.onProgress, "map:compression")
8090
+ onProgress: B(o.onProgress, "map:compression")
8109
8091
  }
8110
8092
  ), d = [];
8111
8093
  let h = 0;
@@ -8178,7 +8160,7 @@ async function Ea(e, t, n) {
8178
8160
  [t, n] = K(t, n, ["expansions"]);
8179
8161
  const { text: r, known: s, context: o } = N(t, ["expansions"]), i = o ? `${r}
8180
8162
 
8181
- ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8163
+ ${o}` : r, a = O(bs, n), c = k(bs, a.onProgress, a);
8182
8164
  c.start();
8183
8165
  const {
8184
8166
  targetSize: l,
@@ -8190,7 +8172,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8190
8172
  llmScoring: b,
8191
8173
  llmCompression: f,
8192
8174
  scoringTokenRatio: g
8193
- } = await q(a, {
8175
+ } = await F(a, {
8194
8176
  targetSize: _e.targetSize,
8195
8177
  tokenBudget: _e.tokenBudget,
8196
8178
  gapFillerBudgetRatio: _e.gapFillerBudgetRatio,
@@ -8226,62 +8208,62 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8226
8208
  try {
8227
8209
  m.targetSize <= 0 && (m.targetSize = _e.targetSize), m.chunkSize <= 0 && (m.chunkSize = _e.chunkSize), m.tokenBudget <= 0 && (m.tokenBudget = _e.tokenBudget);
8228
8210
  let w = m.tokenBudget;
8229
- c.emit({ event: k.phase, phase: "chunking" });
8230
- const S = Iy(e, m.chunkSize, m.targetSize), v = Ey(
8231
- S,
8211
+ c.emit({ event: A.phase, phase: "chunking" });
8212
+ const v = ky(e, m.chunkSize, m.targetSize), S = Ey(
8213
+ v,
8232
8214
  m.targetSize,
8233
8215
  w,
8234
8216
  e.length,
8235
8217
  g
8236
8218
  );
8237
- !b && !f && (v.tfIdfBudget = m.targetSize, v.reservedSpace = 0), c.emit({ event: k.phase, phase: "query-expansion" });
8219
+ !b && !f && (S.tfIdfBudget = m.targetSize, S.reservedSpace = 0), c.emit({ event: A.phase, phase: "query-expansion" });
8238
8220
  const P = a;
8239
8221
  let x, E = 0;
8240
8222
  if (s.expansions)
8241
- x = s.expansions.split(",").map((B) => B.trim()).filter(Boolean), x.unshift(i);
8223
+ x = s.expansions.split(",").map((D) => D.trim()).filter(Boolean), x.unshift(i);
8242
8224
  else if (y) {
8243
- const B = await ky(i, w, P);
8244
- x = B.expansions, E = B.tokensUsed;
8225
+ const D = await Iy(i, w, P);
8226
+ x = D.expansions, E = D.tokensUsed;
8245
8227
  } else
8246
8228
  x = [i];
8247
- w -= E, c.emit({ event: k.phase, phase: "tfidf-scoring", expansions: x });
8248
- const O = Ay(S, x), { selected: R, candidates: j, sizeUsed: F } = Oy(
8249
- O,
8250
- v.tfIdfBudget
8229
+ w -= E, c.emit({ event: A.phase, phase: "tfidf-scoring", expansions: x });
8230
+ const I = Ay(v, x), { selected: R, candidates: j, sizeUsed: L } = Oy(
8231
+ I,
8232
+ S.tfIdfBudget
8251
8233
  );
8252
- c.emit({ event: k.phase, phase: "edge-scoring" });
8253
- const { scored: V, tokensUsed: Y } = b ? await _y(j, i, v.chunksWeCanScore, {
8234
+ c.emit({ event: A.phase, phase: "edge-scoring" });
8235
+ const { scored: V, tokensUsed: Y } = b ? await _y(j, i, S.chunksWeCanScore, {
8254
8236
  ...P,
8255
8237
  llmWeight: h
8256
8238
  }) : { scored: [], tokensUsed: 0 };
8257
8239
  w -= Y;
8258
- let H = vs(R, F, V, m.targetSize);
8259
- c.emit({ event: k.phase, phase: "compression" });
8240
+ let H = vs(R, L, V, m.targetSize);
8241
+ c.emit({ event: A.phase, phase: "compression" });
8260
8242
  const ee = m.targetSize - H.size;
8261
- let pe = 0;
8262
- const G = Math.min(v.avgChunkSize * 0.5, 200);
8263
- if (f && ee > G && v.chunksWeCanCompress > 0) {
8264
- const B = jy(O, H.chunks), { compressed: X, tokensUsed: ce } = await Cy(
8265
- B,
8243
+ let ue = 0;
8244
+ const G = Math.min(S.avgChunkSize * 0.5, 200);
8245
+ if (f && ee > G && S.chunksWeCanCompress > 0) {
8246
+ const D = jy(I, H.chunks), { compressed: X, tokensUsed: ce } = await Cy(
8247
+ D,
8266
8248
  i,
8267
- v.chunksWeCanCompress,
8249
+ S.chunksWeCanCompress,
8268
8250
  ee,
8269
- v,
8251
+ S,
8270
8252
  { ...P, compressionRatio: d }
8271
8253
  );
8272
- pe = ce, w -= ce, H = vs(H.chunks, H.size, X, m.targetSize);
8254
+ ue = ce, w -= ce, H = vs(H.chunks, H.size, X, m.targetSize);
8273
8255
  }
8274
- c.emit({ event: k.phase, phase: "assembly" });
8256
+ c.emit({ event: A.phase, phase: "assembly" });
8275
8257
  let te = H.chunks, ie = 0;
8276
8258
  if (m.gapFillerBudgetRatio > 0) {
8277
- const B = Math.floor(m.targetSize * m.gapFillerBudgetRatio), X = m.targetSize - H.size, ce = Math.min(B, X);
8259
+ const D = Math.floor(m.targetSize * m.gapFillerBudgetRatio), X = m.targetSize - H.size, ce = Math.min(D, X);
8278
8260
  if (ce > 0) {
8279
- const ve = Ly(O, te, ce);
8261
+ const ve = Ly(I, te, ce);
8280
8262
  ve.length > 0 && (te = [...te, ...ve], ie = ve.length);
8281
8263
  }
8282
8264
  }
8283
- const de = Ny(te);
8284
- let Z = Ry(de);
8265
+ const pe = Ny(te);
8266
+ let Z = Ry(pe);
8285
8267
  Z.length > m.targetSize * 3 && (Z = Pa(Z.slice(0, m.targetSize * 2)));
8286
8268
  const we = {
8287
8269
  content: Z,
@@ -8290,15 +8272,15 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8290
8272
  finalSize: Z.length,
8291
8273
  reductionRatio: (1 - Z.length / e.length).toFixed(2),
8292
8274
  allocation: {
8293
- tfIdfBudget: v.tfIdfBudget,
8294
- reservedForLLM: v.reservedSpace,
8295
- actualLLMSpace: te.filter((B) => B.llmScore).reduce((B, X) => B + X.size, 0)
8275
+ tfIdfBudget: S.tfIdfBudget,
8276
+ reservedForLLM: S.reservedSpace,
8277
+ actualLLMSpace: te.filter((D) => D.llmScore).reduce((D, X) => D + X.size, 0)
8296
8278
  },
8297
8279
  chunks: {
8298
- total: S.length,
8280
+ total: v.length,
8299
8281
  tfIdfSelected: R.length,
8300
- llmSelected: te.filter((B) => B.llmScore && !B.compressed).length,
8301
- compressed: te.filter((B) => B.compressed).length,
8282
+ llmSelected: te.filter((D) => D.llmScore && !D.compressed).length,
8283
+ compressed: te.filter((D) => D.compressed).length,
8302
8284
  gapFillers: ie
8303
8285
  },
8304
8286
  tokens: {
@@ -8307,7 +8289,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8307
8289
  breakdown: {
8308
8290
  expansion: E,
8309
8291
  scoring: Y || 0,
8310
- compression: pe || 0
8292
+ compression: ue || 0
8311
8293
  }
8312
8294
  }
8313
8295
  }
@@ -8336,10 +8318,10 @@ const By = "http://json-schema.org/draft-07/schema#", Dy = "object", qy = !1, Fy
8336
8318
  Return JSON with "template" and "variables" where each variable has "original", "candidate", and "confidence".${t ? `
8337
8319
 
8338
8320
  ${t}` : ""}`;
8339
- async function Ia(e, t = {}) {
8321
+ async function ka(e, t = {}) {
8340
8322
  const { text: n, context: r } = N(e, []), s = r ? `${n}
8341
8323
 
8342
- ${r}` : n, o = A(Ss, t), i = I(Ss, o.onProgress, o);
8324
+ ${r}` : n, o = O(Ss, t), i = k(Ss, o.onProgress, o);
8343
8325
  i.start();
8344
8326
  try {
8345
8327
  const a = Ky(o.creativity), c = Gy(s, { creativityGuidance: a }), l = await _(c, {
@@ -8351,12 +8333,12 @@ ${r}` : n, o = A(Ss, t), i = I(Ss, o.onProgress, o);
8351
8333
  throw i.error(a), a;
8352
8334
  }
8353
8335
  }
8354
- Ia.knownTexts = [];
8336
+ ka.knownTexts = [];
8355
8337
  const xs = "filter-ambiguous";
8356
- async function ka(e, t = {}) {
8357
- const { text: n, known: r, context: s } = N(e, ["rankedSentences"]), o = A(xs, t), i = I(xs, o.onProgress, o);
8338
+ async function Ia(e, t = {}) {
8339
+ const { text: n, known: r, context: s } = N(e, ["rankedSentences"]), o = O(xs, t), i = k(xs, o.onProgress, o);
8358
8340
  i.start();
8359
- const { topN: a } = await q(o, {
8341
+ const { topN: a } = await F(o, {
8360
8342
  topN: 10
8361
8343
  });
8362
8344
  try {
@@ -8372,17 +8354,17 @@ async function ka(e, t = {}) {
8372
8354
  return i.complete({ outcome: T.success }), [];
8373
8355
  const f = s ? `
8374
8356
 
8375
- ${s}` : "", g = await ke(
8357
+ ${s}` : "", g = await Ie(
8376
8358
  b,
8377
8359
  `How ambiguous or easily misinterpreted is this sentence?${f}`,
8378
8360
  {
8379
8361
  ...o,
8380
- onProgress: L(o.onProgress, "score:sentence-ambiguity")
8362
+ onProgress: B(o.onProgress, "score:sentence-ambiguity")
8381
8363
  }
8382
8364
  );
8383
8365
  c = b.map((m, w) => ({ sentence: m, score: g[w] ?? 0 })).toSorted((m, w) => w.score - m.score).slice(0, a);
8384
8366
  }
8385
- i.emit({ event: k.phase, phase: "ranked", rankedSentences: c });
8367
+ i.emit({ event: A.phase, phase: "ranked", rankedSentences: c });
8386
8368
  const l = i.batch(c.length), p = (await Q(
8387
8369
  c,
8388
8370
  async ({ sentence: b }) => {
@@ -8390,7 +8372,7 @@ ${s}` : "", g = await ke(
8390
8372
  ...o,
8391
8373
  attachments: { text: b },
8392
8374
  targetNewItemsCount: 5,
8393
- onProgress: L(o.onProgress, "list:extract")
8375
+ onProgress: B(o.onProgress, "list:extract")
8394
8376
  });
8395
8377
  return l(1), f.map((g) => ({ term: g, sentence: b }));
8396
8378
  },
@@ -8403,12 +8385,12 @@ ${s}` : "", g = await ke(
8403
8385
  )).filter(Array.isArray).flat();
8404
8386
  if (p.length === 0)
8405
8387
  return i.complete({ outcome: T.success }), [];
8406
- const d = await ke(
8388
+ const d = await Ie(
8407
8389
  p.map((b) => `${b.term} | ${b.sentence}`),
8408
8390
  "Score how ambiguous the term is within the sentence.",
8409
8391
  {
8410
8392
  ...o,
8411
- onProgress: L(o.onProgress, "score:term-ambiguity")
8393
+ onProgress: B(o.onProgress, "score:term-ambiguity")
8412
8394
  }
8413
8395
  ), y = p.map((b, f) => ({ ...b, score: d[f] ?? 0 })).toSorted((b, f) => (f.score || 0) - (b.score || 0));
8414
8396
  return i.complete({ outcome: T.success }), y.slice(0, a);
@@ -8416,7 +8398,7 @@ ${s}` : "", g = await ke(
8416
8398
  throw i.error(c), c;
8417
8399
  }
8418
8400
  }
8419
- ka.knownTexts = ["rankedSentences"];
8401
+ Ia.knownTexts = ["rankedSentences"];
8420
8402
  function Aa(e, t = 5, n = 50) {
8421
8403
  if (e.length === 0) return [];
8422
8404
  const r = [], s = Math.max(1, Math.floor(t * (1 - n / 100)));
@@ -8440,9 +8422,9 @@ async function Oa(e, t, n) {
8440
8422
  if (e.length === 1) return e[0];
8441
8423
  const { text: r, context: s } = N(t, []), o = s ? `${r}
8442
8424
 
8443
- ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
8425
+ ${s}` : r, i = O($s, n), a = k($s, i.onProgress, i);
8444
8426
  a.start();
8445
- const { styleHint: c, windowSize: l, overlapPercent: u } = await q(i, {
8427
+ const { styleHint: c, windowSize: l, overlapPercent: u } = await F(i, {
8446
8428
  fidelity: J(Yy, ["windowSize", "overlapPercent"]),
8447
8429
  styleHint: ""
8448
8430
  });
@@ -8451,7 +8433,7 @@ ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
8451
8433
  p,
8452
8434
  async (f, g) => {
8453
8435
  a.emit({
8454
- event: k.step,
8436
+ event: A.step,
8455
8437
  stepName: "processing-window",
8456
8438
  windowNumber: g + 1,
8457
8439
  totalWindows: p.length
@@ -8459,19 +8441,19 @@ ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
8459
8441
  const m = f.fragments.map((P, x) => `${x + 1}. ${P}`).join(`
8460
8442
  `), w = c ? `
8461
8443
 
8462
- ${$(c, { tag: "style-guidance" })}` : "", S = `${o}${w}
8444
+ ${$(c, { tag: "style-guidance" })}` : "", v = `${o}${w}
8463
8445
 
8464
8446
  Window ${g + 1} of ${p.length} - Join these fragments:
8465
8447
 
8466
8448
  ${$(m, { tag: "fragments" })}
8467
8449
 
8468
- Important: This is part of a larger sequence. Join these fragments while being mindful that this result will be combined with other processed windows. Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the joined result for this window.`, v = await M(() => _(S, i), {
8450
+ Important: This is part of a larger sequence. Join these fragments while being mindful that this result will be combined with other processed windows. Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the joined result for this window.`, S = await M(() => _(v, i), {
8469
8451
  label: `join-window-${g + 1}`,
8470
8452
  config: i,
8471
- onProgress: L(i.onProgress, "window")
8453
+ onProgress: B(i.onProgress, "window")
8472
8454
  });
8473
8455
  return d(1), {
8474
- content: v || f.fragments.join(" "),
8456
+ content: S || f.fragments.join(" "),
8475
8457
  window: f
8476
8458
  };
8477
8459
  },
@@ -8484,16 +8466,16 @@ Important: This is part of a larger sequence. Join these fragments while being m
8484
8466
  let b = y[0].content;
8485
8467
  for (let f = 1; f < y.length; f++) {
8486
8468
  a.emit({
8487
- event: k.step,
8469
+ event: A.step,
8488
8470
  stepName: "stitching",
8489
8471
  stitchNumber: f,
8490
8472
  totalStitches: y.length - 1
8491
8473
  });
8492
- const g = y[f], m = y[f - 1].window, w = g.window, S = Math.max(m.startIndex, w.startIndex), v = Math.min(m.endIndex, w.endIndex);
8493
- if (S <= v) {
8494
- const P = e.slice(S, v + 1), x = c ? `
8474
+ const g = y[f], m = y[f - 1].window, w = g.window, v = Math.max(m.startIndex, w.startIndex), S = Math.min(m.endIndex, w.endIndex);
8475
+ if (v <= S) {
8476
+ const P = e.slice(v, S + 1), x = c ? `
8495
8477
 
8496
- ${$(c, { tag: "style-guidance" })}` : "", E = P.join(" | "), O = `${o}${x}
8478
+ ${$(c, { tag: "style-guidance" })}` : "", E = P.join(" | "), I = `${o}${x}
8497
8479
 
8498
8480
  Stitch these two sections by resolving their overlapping region:
8499
8481
 
@@ -8506,7 +8488,7 @@ ${$(E, { tag: "overlapping-fragments" })}
8506
8488
  The terminal ends of both sections should be preserved. Only resolve the overlapping middle region where these fragments appear.
8507
8489
 
8508
8490
  Add necessary connecting words, prepositions, conjunctions, or other filler text to create a coherent, grammatically correct, and semantically meaningful result. Output only the final stitched result with terminals preserved.`;
8509
- b = await M(() => _(O, i), {
8491
+ b = await M(() => _(I, i), {
8510
8492
  label: `join-stitch-${f}`,
8511
8493
  config: i
8512
8494
  }) || b;
@@ -8546,7 +8528,7 @@ const Hy = {
8546
8528
  additionalProperties: !1
8547
8529
  }, { asUndefinedByDefault: Qy, contentIsQuestion: Xy } = oe, Ps = "name";
8548
8530
  async function _a(e, t = {}) {
8549
- const { text: n, context: r } = N(e, []), s = A(Ps, t), o = I(Ps, s.onProgress, s);
8531
+ const { text: n, context: r } = N(e, []), s = O(Ps, t), o = k(Ps, s.onProgress, s);
8550
8532
  o.start();
8551
8533
  const i = [
8552
8534
  `${Xy} Suggest a concise, memorable name for the <subject>.
@@ -8596,7 +8578,7 @@ ${r}
8596
8578
  The value should be the generated name.`;
8597
8579
  };
8598
8580
  async function Ca(e, t = [], n = {}) {
8599
- const { text: r, context: s } = N(e, []), o = A(Ts, n), i = I(Ts, o.onProgress, o);
8581
+ const { text: r, context: s } = N(e, []), o = O(Ts, n), i = k(Ts, o.onProgress, o);
8600
8582
  i.start();
8601
8583
  try {
8602
8584
  const a = eb(r, t), c = s ? `${a}
@@ -8652,9 +8634,9 @@ const Es = {
8652
8634
  required: ["people"],
8653
8635
  additionalProperties: !1
8654
8636
  }
8655
- }, Is = "people";
8637
+ }, ks = "people";
8656
8638
  async function ja(e, t = 3, n = {}) {
8657
- const r = A(Is, n), s = I(Is, r.onProgress, r);
8639
+ const r = O(ks, n), s = k(ks, r.onProgress, r);
8658
8640
  s.start();
8659
8641
  try {
8660
8642
  const { text: o, context: i } = N(e, []), a = i ? `
@@ -8682,12 +8664,12 @@ const tb = "object", nb = { references: { type: "array", items: { type: "object"
8682
8664
  properties: nb,
8683
8665
  required: rb,
8684
8666
  additionalProperties: sb
8685
- }, ks = "pop-reference", ib = C("pop_reference_result", ob);
8667
+ }, Is = "pop-reference", ib = C("pop_reference_result", ob);
8686
8668
  async function Na(e, t, n) {
8687
8669
  [t, n] = K(t, n);
8688
- const { text: r, context: s } = N(t, []), o = A(ks, n), i = I(ks, o.onProgress, o);
8670
+ const { text: r, context: s } = N(t, []), o = O(Is, n), i = k(Is, o.onProgress, o);
8689
8671
  i.start();
8690
- const { referenceContext: a, referencesPerSource: c } = await q(o, {
8672
+ const { referenceContext: a, referencesPerSource: c } = await F(o, {
8691
8673
  referenceContext: !1,
8692
8674
  referencesPerSource: 2
8693
8675
  }), { include: l = [] } = o;
@@ -8792,9 +8774,9 @@ One question per string.`;
8792
8774
  }, gb = async function* (t, n = {}) {
8793
8775
  const { text: r, context: s } = N(t, []), o = s ? `${r}
8794
8776
 
8795
- ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
8777
+ ${s}` : r, i = O(As, n), a = k(As, i.onProgress, i);
8796
8778
  a.start();
8797
- const { exploration: c } = await q(i, {
8779
+ const { exploration: c } = await F(i, {
8798
8780
  exploration: J(lb)
8799
8781
  }), l = [], u = {}, p = [];
8800
8782
  let d = !1, h = o;
@@ -8803,7 +8785,7 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
8803
8785
  try {
8804
8786
  for (; !d; ) {
8805
8787
  if (a.emit({
8806
- event: k.step,
8788
+ event: A.step,
8807
8789
  stepName: "generating-round",
8808
8790
  attempt: g + 1,
8809
8791
  questionsFound: l.length
@@ -8828,18 +8810,18 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
8828
8810
  ...i,
8829
8811
  temperature: f,
8830
8812
  responseFormat: C("questions_list", ab)
8831
- }, S = await M(() => _(m, w), {
8813
+ }, v = await M(() => _(m, w), {
8832
8814
  label: "questions-generate",
8833
8815
  config: i
8834
- }), v = pb(S, c);
8816
+ }), S = pb(v, c);
8835
8817
  if (c < 0.5) {
8836
- const x = Math.floor(Math.random() * v.length);
8837
- h = v[x];
8818
+ const x = Math.floor(Math.random() * S.length);
8819
+ h = S[x];
8838
8820
  }
8839
- const P = v.filter((x) => !(x in u));
8821
+ const P = S.filter((x) => !(x in u));
8840
8822
  g += 1;
8841
8823
  for (const x of P) {
8842
- if (await b(x, l, v, g)) {
8824
+ if (await b(x, l, S, g)) {
8843
8825
  d = !0;
8844
8826
  break;
8845
8827
  }
@@ -8909,7 +8891,7 @@ function un(e) {
8909
8891
  }));
8910
8892
  }
8911
8893
  async function La(e, t = {}) {
8912
- const n = A("relations:spec", t), { canonicalization: r } = await q(n, {
8894
+ const n = O("relations:spec", t), { canonicalization: r } = await F(n, {
8913
8895
  canonicalization: J(Ma)
8914
8896
  }), s = "You are a relation specification generator. Create a clear, concise specification for relation extraction.";
8915
8897
  let o, i, a;
@@ -8954,7 +8936,7 @@ Use natural language, not symbolic identifiers or linked data formats.`, await M
8954
8936
  );
8955
8937
  }
8956
8938
  async function Pb(e, t, n = {}) {
8957
- const r = A("relations:apply", n), { canonicalization: s } = await q(r, {
8939
+ const r = O("relations:apply", n), { canonicalization: s } = await F(r, {
8958
8940
  canonicalization: J(Ma)
8959
8941
  }), { entities: o } = r;
8960
8942
  let i = `Apply the relation specification to extract relations from this text.
@@ -9002,13 +8984,13 @@ Canonicalization: LOOSE — preserve original entity forms from the text. Only m
9002
8984
  }
9003
8985
  async function Ba(e, t, n) {
9004
8986
  [t, n] = K(t, n, ["spec"]);
9005
- const { text: r, known: s, context: o } = N(t, ["spec"]), i = A(Os, n), a = I(Os, i.onProgress, i);
8987
+ const { text: r, known: s, context: o } = N(t, ["spec"]), i = O(Os, n), a = k(Os, i.onProgress, i);
9006
8988
  a.start();
9007
8989
  try {
9008
8990
  const c = o ? `${r}
9009
8991
 
9010
8992
  ${o}` : r, l = s.spec || await La(c, i);
9011
- a.emit({ event: k.phase, phase: "applying-relations", specification: l });
8993
+ a.emit({ event: A.phase, phase: "applying-relations", specification: l });
9012
8994
  const p = (await Pb(e, l, i)).items || [];
9013
8995
  return a.complete({ outcome: T.success }), p;
9014
8996
  } catch (c) {
@@ -9016,11 +8998,11 @@ ${o}` : r, l = s.spec || await La(c, i);
9016
8998
  }
9017
8999
  }
9018
9000
  Ba.knownTexts = ["spec"];
9019
- const Tb = "http://json-schema.org/draft-07/schema#", Eb = "http://example.com/schemas/intent-schema.json", Ib = "object", kb = { queryText: { type: "string", description: "The user's query text." }, intent: { type: "object", properties: { operation: { type: "string", description: "The operation associated with the intent." }, displayName: { type: "string", description: "The display name of the intent." } }, required: ["operation", "displayName"], description: "Information about the intent." }, parameters: { type: "object", additionalProperties: !0, description: "Parameters associated with the intent." }, optionalParameters: { type: "object", additionalProperties: !0, description: "Optional parameters associated with the intent." } }, Ab = ["queryText", "intent"], Ob = "Schema for an intent response.", Da = {
9001
+ const Tb = "http://json-schema.org/draft-07/schema#", Eb = "http://example.com/schemas/intent-schema.json", kb = "object", Ib = { queryText: { type: "string", description: "The user's query text." }, intent: { type: "object", properties: { operation: { type: "string", description: "The operation associated with the intent." }, displayName: { type: "string", description: "The display name of the intent." } }, required: ["operation", "displayName"], description: "Information about the intent." }, parameters: { type: "object", additionalProperties: !0, description: "Parameters associated with the intent." }, optionalParameters: { type: "object", additionalProperties: !0, description: "Optional parameters associated with the intent." } }, Ab = ["queryText", "intent"], Ob = "Schema for an intent response.", Da = {
9020
9002
  $schema: Tb,
9021
9003
  $id: Eb,
9022
- type: Ib,
9023
- properties: kb,
9004
+ type: kb,
9005
+ properties: Ib,
9024
9006
  required: Ab,
9025
9007
  description: Ob
9026
9008
  }, _b = "http://json-schema.org/draft-07/schema#", Cb = "object", jb = { passed: { type: "boolean", description: "Whether the architecture test passed" }, reason: { type: "string", description: "Explanation of the test result" } }, Nb = ["passed", "reason"], Rb = !1, qa = {
@@ -9172,7 +9154,7 @@ const Tb = "http://json-schema.org/draft-07/schema#", Eb = "http://example.com/s
9172
9154
  async function Va(e, t, n = {}) {
9173
9155
  const { text: r, context: s } = N(e, []), o = s ? `${r}
9174
9156
 
9175
- ${s}` : r, i = A(_s, n), a = I(_s, i.onProgress, i);
9157
+ ${s}` : r, i = O(_s, n), a = k(_s, i.onProgress, i);
9176
9158
  a.start();
9177
9159
  try {
9178
9160
  const c = t ? pw(t) : void 0, l = c ? C(`schema_org_${t.toLowerCase()}`, c) : { type: "json_object" }, u = await _(ni(o, t, c), {
@@ -9252,7 +9234,7 @@ A: ${p.answer}`).join(`
9252
9234
  {
9253
9235
  label: "socratic-ask",
9254
9236
  config: o,
9255
- onProgress: L(o?.onProgress, "ask")
9237
+ onProgress: B(o?.onProgress, "ask")
9256
9238
  }
9257
9239
  );
9258
9240
  }, Sw = async ({
@@ -9279,15 +9261,15 @@ A: ${p.answer}`).join(`
9279
9261
  {
9280
9262
  label: "socratic-answer",
9281
9263
  config: o,
9282
- onProgress: L(o?.onProgress, "answer")
9264
+ onProgress: B(o?.onProgress, "answer")
9283
9265
  }
9284
9266
  );
9285
9267
  };
9286
9268
  class tt {
9287
9269
  static async create(t, n = {}) {
9288
- const { text: r, context: s } = N(t, []), o = A(it, n), i = I(it, o.onProgress, o);
9289
- i.start(), i.emit({ event: k.input, value: r });
9290
- const { challenge: a, temperature: c } = await q(o, {
9270
+ const { text: r, context: s } = N(t, []), o = O(it, n), i = k(it, o.onProgress, o);
9271
+ i.start(), i.emit({ event: A.input, value: r });
9272
+ const { challenge: a, temperature: c } = await F(o, {
9291
9273
  challenge: J(Cs, ["challenge", "temperature"])
9292
9274
  });
9293
9275
  return new tt(
@@ -9304,8 +9286,8 @@ class tt {
9304
9286
  this.emitter = s ? n.emitter : void 0, this.bundleContext = s ? n.bundleContext ?? "" : "";
9305
9287
  const o = s ? n.config : n, { ask: i = vw, answer: a = Sw, llm: c, abortSignal: l } = o;
9306
9288
  if (this.statement = t, this.ask = i, this.answer = a, this.llm = c, this.config = o, this.history = [], this.challenge = r.challenge ?? (o.challenge !== void 0 ? Cs(o.challenge).challenge : void 0), this.temperature = r.temperature ?? o.temperature ?? 0.7, !this.emitter) {
9307
- const u = A(it, o);
9308
- this.config = u, this.emitter = I(it, u.onProgress, u);
9289
+ const u = O(it, o);
9290
+ this.config = u, this.emitter = k(it, u.onProgress, u);
9309
9291
  }
9310
9292
  this.abortSignal = l;
9311
9293
  }
@@ -9315,7 +9297,7 @@ class tt {
9315
9297
  async step() {
9316
9298
  const t = this.history.length + 1;
9317
9299
  this.emitter.emit({
9318
- event: k.step,
9300
+ event: A.step,
9319
9301
  stepName: "asking-question",
9320
9302
  turnNumber: t,
9321
9303
  topic: this.statement
@@ -9330,7 +9312,7 @@ class tt {
9330
9312
  bundleContext: this.bundleContext
9331
9313
  });
9332
9314
  this.emitter.emit({
9333
- event: k.step,
9315
+ event: A.step,
9334
9316
  stepName: "answering-question",
9335
9317
  turnNumber: t,
9336
9318
  question: n
@@ -9351,12 +9333,12 @@ class tt {
9351
9333
  const n = this.emitter.batch(t);
9352
9334
  for (let r = 0; r < t; r += 1)
9353
9335
  this.emitter.emit({
9354
- event: k.phase,
9336
+ event: A.phase,
9355
9337
  phase: `round-${r + 1}`,
9356
9338
  round: r + 1,
9357
9339
  totalRounds: t
9358
9340
  }), await this.step(), n(1);
9359
- return this.emitter.emit({ event: k.output, value: this.history }), this.emitter.complete({ outcome: T.success, turns: this.history.length }), this.history;
9341
+ return this.emitter.emit({ event: A.output, value: this.history }), this.emitter.complete({ outcome: T.success, turns: this.history.length }), this.history;
9360
9342
  } catch (n) {
9361
9343
  throw this.emitter.error(n), n;
9362
9344
  }
@@ -9414,17 +9396,17 @@ const Ns = "split", zt = { short: 0.5, long: 0.1 }, Pw = (e) => e === void 0 ? z
9414
9396
  - Each section should be substantively different from adjacent sections
9415
9397
  - Preserve ALL original text exactly - only add delimiters
9416
9398
  - For topic changes: Look for shifts in subject matter, not just related themes
9417
- - Be selective - fewer, more meaningful splits are better than many weak ones${t}`, Iw = (e, t) => `IMPORTANT RULES:
9399
+ - Be selective - fewer, more meaningful splits are better than many weak ones${t}`, kw = (e, t) => `IMPORTANT RULES:
9418
9400
  - Only insert "${e}" at semantic boundaries - where the meaning, topic, or argument shifts
9419
9401
  - Ignore structural markers like paragraph breaks, headings, or bullet lists unless they coincide with a genuine meaning shift
9420
9402
  - A new example or anecdote supporting the SAME point is NOT a split boundary
9421
9403
  - Split when the author moves to a different claim, a different subject, or a different phase of reasoning
9422
9404
  - Preserve ALL original text exactly - only add delimiters
9423
- - Be selective - fewer, more meaningful splits are better than many weak ones${t}`, kw = (e, t, n, r = {}) => {
9405
+ - Be selective - fewer, more meaningful splits are better than many weak ones${t}`, Iw = (e, t, n, r = {}) => {
9424
9406
  const { previousContent: s = "", targetSplitCount: o = void 0, mode: i = "structural" } = r, a = o ? `
9425
9407
  - Aim for approximately ${o} sections in this chunk` : "", c = s ? `
9426
9408
 
9427
- ${$(s.slice(-200), { tag: "previous-context" })}` : "", l = i === "semantic" ? Iw(n, a) : Ew(n, a);
9409
+ ${$(s.slice(-200), { tag: "previous-context" })}` : "", l = i === "semantic" ? kw(n, a) : Ew(n, a);
9428
9410
  return `You are marking split points in text with "${n}".
9429
9411
 
9430
9412
  ${$(t, { tag: "instructions" })}
@@ -9437,7 +9419,7 @@ async function Ja(e, t, n) {
9437
9419
  [t, n] = K(t, n);
9438
9420
  const { text: r, context: s } = N(t, []), o = s ? `${r}
9439
9421
 
9440
- ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns, i.onProgress, i);
9422
+ ${s}` : r, i = O(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = k(Ns, i.onProgress, i);
9441
9423
  a.start();
9442
9424
  const {
9443
9425
  chunkLen: c,
@@ -9445,7 +9427,7 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
9445
9427
  temperature: u,
9446
9428
  preservation: p,
9447
9429
  mode: d
9448
- } = await q(i, {
9430
+ } = await F(i, {
9449
9431
  chunkLen: 4e3,
9450
9432
  targetSplitsPerChunk: void 0,
9451
9433
  temperature: 0.1,
@@ -9459,28 +9441,28 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
9459
9441
  try {
9460
9442
  const f = Kn(e, c), g = a.batch(f.length), m = await Q(
9461
9443
  f,
9462
- async (v, P) => {
9463
- const E = kw(v, o, h, {
9444
+ async (S, P) => {
9445
+ const E = Iw(S, o, h, {
9464
9446
  targetSplitCount: l,
9465
9447
  mode: d
9466
- }), O = {
9448
+ }), I = {
9467
9449
  ...i,
9468
9450
  temperature: u
9469
9451
  };
9470
9452
  try {
9471
- const R = await M(() => _(E, O), {
9453
+ const R = await M(() => _(E, I), {
9472
9454
  label: "split",
9473
9455
  config: i,
9474
- onProgress: L(i.onProgress, "chunk")
9456
+ onProgress: B(i.onProgress, "chunk")
9475
9457
  }), j = R.replace(
9476
9458
  new RegExp(h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
9477
9459
  ""
9478
- ), F = v.trim(), V = F.length < 100 ? y : b;
9479
- return Math.abs(j.length - F.length) > F.length * V ? (i.logger?.warn && i.logger.warn(
9460
+ ), L = S.trim(), V = L.length < 100 ? y : b;
9461
+ return Math.abs(j.length - L.length) > L.length * V ? (i.logger?.warn && i.logger.warn(
9480
9462
  `Split output differs significantly from input for chunk ${P + 1}, using original chunk`
9481
- ), g(1), v) : (g(1), R);
9463
+ ), g(1), S) : (g(1), R);
9482
9464
  } catch (R) {
9483
- return i.logger?.warn && i.logger.warn(`Split failed for chunk ${P + 1}:`, R.message), g(1), v;
9465
+ return i.logger?.warn && i.logger.warn(`Split failed for chunk ${P + 1}:`, R.message), g(1), S;
9484
9466
  }
9485
9467
  },
9486
9468
  {
@@ -9489,12 +9471,12 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
9489
9471
  abortSignal: i.abortSignal,
9490
9472
  label: "split chunks"
9491
9473
  }
9492
- ), w = h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), S = m.join("").split(new RegExp(w)).map((v) => v.trim()).filter(Boolean);
9474
+ ), w = h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), v = m.join("").split(new RegExp(w)).map((S) => S.trim()).filter(Boolean);
9493
9475
  return a.complete({
9494
9476
  outcome: T.success,
9495
9477
  chunks: f.length,
9496
- segments: S.length
9497
- }), S;
9478
+ segments: v.length
9479
+ }), v;
9498
9480
  } catch (f) {
9499
9481
  throw a.error(f), f;
9500
9482
  }
@@ -9547,7 +9529,7 @@ class Ka extends Map {
9547
9529
  targetTokensTotalRatio: a = jw(i),
9548
9530
  ...c
9549
9531
  }) {
9550
- if (super(), this.cache = /* @__PURE__ */ new Map(), this.data = /* @__PURE__ */ new Map(), this.isCacheValid = !1, this.maxTokensPerValue = t ?? n.maxOutputTokens, this.llmOptions = { modelName: n.name, ...r }, this.runConfig = A(Ms, c), o)
9532
+ if (super(), this.cache = /* @__PURE__ */ new Map(), this.data = /* @__PURE__ */ new Map(), this.isCacheValid = !1, this.maxTokensPerValue = t ?? n.maxOutputTokens, this.llmOptions = { modelName: n.name, ...r }, this.runConfig = O(Ms, c), o)
9551
9533
  this.targetTokens = o;
9552
9534
  else if (s && n) {
9553
9535
  this.promptTokens = n.toTokens(s).length;
@@ -9565,7 +9547,7 @@ class Ka extends Map {
9565
9547
  return { totalSizeWeight: t, budgets: r };
9566
9548
  }
9567
9549
  async myFillCache() {
9568
- const t = I(Ms, this.runConfig.onProgress, this.runConfig);
9550
+ const t = k(Ms, this.runConfig.onProgress, this.runConfig);
9569
9551
  t.start();
9570
9552
  try {
9571
9553
  const { budgets: n } = this.calculateBudgets(), r = t.batch(n.length);
@@ -9596,7 +9578,7 @@ class Ka extends Map {
9596
9578
  }
9597
9579
  const y = c.toTokens(h).length;
9598
9580
  t.emit({
9599
- event: k.step,
9581
+ event: A.step,
9600
9582
  stepName: "context-trim",
9601
9583
  key: s,
9602
9584
  originalTokens: l,
@@ -9686,7 +9668,7 @@ function Gn(e, t, n = {}) {
9686
9668
  });
9687
9669
  });
9688
9670
  const a = Object.entries(i).map(([m, w]) => ({
9689
- tag: e.tags.find((S) => S.id === m),
9671
+ tag: e.tags.find((v) => v.id === m),
9690
9672
  count: w
9691
9673
  })).toSorted((m, w) => w.count - m.count), c = a.slice(0, r), l = a.slice(-s), u = t.filter((m) => m && m.length > 0).length, p = t.reduce((m, w) => m + (w ? w.length : 0), 0), d = t.length > 0 ? p / t.length : 0, h = {
9692
9674
  totalItems: t.length,
@@ -9722,7 +9704,7 @@ function Gn(e, t, n = {}) {
9722
9704
  };
9723
9705
  }
9724
9706
  async function Dw(e, t, n = {}) {
9725
- const r = A("tag-vocabulary:generate", n), s = `Generate a comprehensive tag vocabulary for categorizing items.
9707
+ const r = O("tag-vocabulary:generate", n), s = `Generate a comprehensive tag vocabulary for categorizing items.
9726
9708
 
9727
9709
  ${$(e, { tag: "tag-system-specification" })}
9728
9710
 
@@ -9750,7 +9732,7 @@ The vocabulary should be complete enough to categorize diverse items along the i
9750
9732
  );
9751
9733
  }
9752
9734
  async function qw(e, t, n, r = {}) {
9753
- const s = A("tag-vocabulary:refine", r), { topN: o = 3, bottomN: i = 3 } = s, a = Gn(e, t, { topN: o, bottomN: i }), c = `Refine this tag vocabulary based on usage analysis.
9735
+ const s = O("tag-vocabulary:refine", r), { topN: o = 3, bottomN: i = 3 } = s, a = Gn(e, t, { topN: o, bottomN: i }), c = `Refine this tag vocabulary based on usage analysis.
9754
9736
 
9755
9737
  ${$(n, { tag: "original-specification" })}
9756
9738
 
@@ -9788,7 +9770,7 @@ Return an improved vocabulary that provides better coverage and clearer distinct
9788
9770
  async function Ya(e, t, n = {}) {
9789
9771
  const { text: r, known: s, context: o } = N(e, ["initialVocab"]), i = o ? `${r}
9790
9772
 
9791
- ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
9773
+ ${o}` : r, a = O(Ls, n), c = k(Ls, a.onProgress, a);
9792
9774
  c.start();
9793
9775
  try {
9794
9776
  const { tagger: l, sampleSize: u = 50 } = a;
@@ -9800,19 +9782,19 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
9800
9782
  else {
9801
9783
  const b = t.slice(0, Math.min(u, t.length));
9802
9784
  c.emit({
9803
- event: k.step,
9785
+ event: A.step,
9804
9786
  stepName: "generate-initial-vocabulary",
9805
9787
  sampleCount: b.length
9806
9788
  }), p = await Dw(i, b, a);
9807
9789
  }
9808
9790
  c.emit({
9809
- event: k.step,
9791
+ event: A.step,
9810
9792
  stepName: "apply-tags",
9811
9793
  itemCount: t.length,
9812
9794
  initialVocab: p
9813
9795
  });
9814
9796
  const d = await l(t, p), h = Gn(p, d);
9815
- c.emit({ event: k.step, stepName: "refine-vocabulary", statistics: h });
9797
+ c.emit({ event: A.step, stepName: "refine-vocabulary", statistics: h });
9816
9798
  const y = await qw(p, d, i, a);
9817
9799
  return c.complete({ outcome: T.success }), y;
9818
9800
  } catch (l) {
@@ -9822,9 +9804,9 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
9822
9804
  Ya.knownTexts = ["initialVocab"];
9823
9805
  const Bs = "themes", Fw = (e) => e.split(/\n{2,}/).map((t) => t.trim()).filter(Boolean);
9824
9806
  async function Ha(e, t = {}) {
9825
- const { text: n, known: r, context: s } = N(e, ["rawThemes"]), o = A(Bs, t), i = I(Bs, o.onProgress, o);
9807
+ const { text: n, known: r, context: s } = N(e, ["rawThemes"]), o = O(Bs, t), i = k(Bs, o.onProgress, o);
9826
9808
  i.start();
9827
- const { topN: a } = await q(o, {
9809
+ const { topN: a } = await F(o, {
9828
9810
  topN: void 0
9829
9811
  });
9830
9812
  try {
@@ -9834,25 +9816,25 @@ async function Ha(e, t = {}) {
9834
9816
  else {
9835
9817
  const h = Fw(n);
9836
9818
  i.emit({
9837
- event: k.phase,
9819
+ event: A.phase,
9838
9820
  phase: "extraction"
9839
9821
  });
9840
9822
  const b = `Update the accumulator with short themes from this text. Avoid duplicates. Return ONLY a comma-separated list of themes with no explanation or additional text.${s ? `
9841
9823
 
9842
9824
  ${s}` : ""}`, f = Wn(h);
9843
- c = (await Ie(f, b, {
9825
+ c = (await ke(f, b, {
9844
9826
  ...o,
9845
- onProgress: L(o.onProgress, "themes:extract")
9827
+ onProgress: B(o.onProgress, "themes:extract")
9846
9828
  })).split(",").map((m) => m.trim()).filter(Boolean);
9847
9829
  }
9848
9830
  i.emit({
9849
- event: k.phase,
9831
+ event: A.phase,
9850
9832
  phase: "refinement",
9851
9833
  rawThemes: c
9852
9834
  });
9853
- const u = `Refine the accumulator by merging similar themes. ${a ? `Limit to the top ${a} themes.` : "Return all meaningful themes."} Return ONLY a comma-separated list with no explanation or additional text.`, d = (await Ie(c, u, {
9835
+ const u = `Refine the accumulator by merging similar themes. ${a ? `Limit to the top ${a} themes.` : "Return all meaningful themes."} Return ONLY a comma-separated list with no explanation or additional text.`, d = (await ke(c, u, {
9854
9836
  ...o,
9855
- onProgress: L(o.onProgress, "themes:refine")
9837
+ onProgress: B(o.onProgress, "themes:refine")
9856
9838
  })).split(",").map((h) => h.trim()).filter(Boolean);
9857
9839
  return i.complete({ outcome: T.success, themes: d.length }), d;
9858
9840
  } catch (c) {
@@ -9923,9 +9905,9 @@ async function Vw(e, t = {}) {
9923
9905
  }
9924
9906
  async function Qa(e, t, n) {
9925
9907
  [t, n] = K(t, n, ["knowledge"]);
9926
- const { text: r, known: s, context: o } = N(t, ["knowledge"]), i = A(Ds, n), a = [Uw, r, o].filter(Boolean).join(`
9908
+ const { text: r, known: s, context: o } = N(t, ["knowledge"]), i = O(Ds, n), a = [Uw, r, o].filter(Boolean).join(`
9927
9909
 
9928
- `), c = I(Ds, i.onProgress, i);
9910
+ `), c = k(Ds, i.onProgress, i);
9929
9911
  c.start();
9930
9912
  const {
9931
9913
  chunkSize: l,
@@ -9935,7 +9917,7 @@ async function Qa(e, t, n) {
9935
9917
  llmDedup: h,
9936
9918
  knowledgeBase: y,
9937
9919
  enrichMap: b
9938
- } = await q(i, {
9920
+ } = await F(i, {
9939
9921
  enrichment: J(zw, ["llmDedup", "knowledgeBase", "enrichMap"]),
9940
9922
  chunkSize: 2e3,
9941
9923
  overlap: 200,
@@ -9943,26 +9925,26 @@ async function Qa(e, t, n) {
9943
9925
  errorPosture: z.resilient
9944
9926
  }), f = s.knowledge, { onProgress: g, batchSize: m, now: w } = i;
9945
9927
  try {
9946
- const S = 1 + (h ? 1 : 0) + (y ? 2 : 0), v = c.batch(S), P = Kn(e, l, { overlap: u }), x = [];
9928
+ const v = 1 + (h ? 1 : 0) + (y ? 2 : 0), S = c.batch(v), P = Kn(e, l, { overlap: u }), x = [];
9947
9929
  let E = 0;
9948
9930
  await Q(
9949
9931
  P,
9950
- async (j, F) => {
9932
+ async (j, L) => {
9951
9933
  try {
9952
9934
  const V = await M(
9953
9935
  () => Vw(j, { ...i, now: w, systemPrompt: a }),
9954
9936
  {
9955
- label: `timeline chunk ${F + 1}`,
9937
+ label: `timeline chunk ${L + 1}`,
9956
9938
  config: i
9957
9939
  }
9958
9940
  );
9959
- x.push(...V), g?.(F + 1, P.length);
9941
+ x.push(...V), g?.(L + 1, P.length);
9960
9942
  } catch (V) {
9961
9943
  if (E++, d === z.strict) throw V;
9962
9944
  i.logger?.warn && i.logger.warn(
9963
- `Timeline extraction failed for chunk ${F + 1}:`,
9945
+ `Timeline extraction failed for chunk ${L + 1}:`,
9964
9946
  V.message
9965
- ), g?.(F + 1, P.length);
9947
+ ), g?.(L + 1, P.length);
9966
9948
  }
9967
9949
  },
9968
9950
  {
@@ -9971,20 +9953,20 @@ async function Qa(e, t, n) {
9971
9953
  label: "timeline chunks",
9972
9954
  abortSignal: i.abortSignal
9973
9955
  }
9974
- ), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`), v(1);
9975
- let O = Ww([x]);
9976
- if (h && O.length > 0) {
9977
- const j = O.map((H) => `- ${H.timestamp}: ${H.name}`).join(`
9978
- `), F = `Consolidate these timeline events by merging duplicates that refer to the same occurrence. Keep the most descriptive version of each event and preserve ALL unique events.
9956
+ ), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`), S(1);
9957
+ let I = Ww([x]);
9958
+ if (h && I.length > 0) {
9959
+ const j = I.map((H) => `- ${H.timestamp}: ${H.name}`).join(`
9960
+ `), L = `Consolidate these timeline events by merging duplicates that refer to the same occurrence. Keep the most descriptive version of each event and preserve ALL unique events.
9979
9961
 
9980
- ${$(j, { tag: "events" })}`, V = await _(F, {
9962
+ ${$(j, { tag: "events" })}`, V = await _(L, {
9981
9963
  ...i,
9982
9964
  systemPrompt: "You are a timeline deduplication engine. Return all unique events, merging only true duplicates.",
9983
9965
  responseFormat: C(Le.name, Le.schema)
9984
9966
  }), Y = V?.events || V;
9985
- Array.isArray(Y) && Y.length > 0 && (O = Ke(Y)), v(1);
9967
+ Array.isArray(Y) && Y.length > 0 && (I = Ke(Y)), S(1);
9986
9968
  }
9987
- if ((y || f) && O.length > 0) {
9969
+ if ((y || f) && I.length > 0) {
9988
9970
  let j = [];
9989
9971
  if (f)
9990
9972
  try {
@@ -10003,24 +9985,24 @@ Given the current knowledge base and a new event, return an updated knowledge ba
10003
9985
  4. Adds important related events that fall within the timeline scope (between first and last events)
10004
9986
  5. Include events that provide crucial context or fill important gaps
10005
9987
 
10006
- Return as JSON with the same event format, maintaining chronological order.`, ie = O.map((Z) => `${Z.timestamp}: ${Z.name}`), de = await Ie(ie, te, {
9988
+ Return as JSON with the same event format, maintaining chronological order.`, ie = I.map((Z) => `${Z.timestamp}: ${Z.name}`), pe = await ke(ie, te, {
10007
9989
  ...i,
10008
9990
  initial: JSON.stringify({ events: [] }),
10009
9991
  responseFormat: C(Le.name, Le.schema),
10010
9992
  ...m !== void 0 && { batchSize: m },
10011
- onProgress: L(i.onProgress, "reduce:knowledge-base")
9993
+ onProgress: B(i.onProgress, "reduce:knowledge-base")
10012
9994
  });
10013
9995
  try {
10014
- j = Ke(de.events || []);
9996
+ j = Ke(pe.events || []);
10015
9997
  } catch (Z) {
10016
9998
  ne("Failed to parse knowledge base:", Z.message);
10017
9999
  }
10018
10000
  }
10019
- c.emit({ event: k.phase, phase: "enrichment", knowledgeBase: j }), v(1);
10020
- const F = j.map((G) => `- ${G.timestamp}: ${G.name}`).join(`
10001
+ c.emit({ event: A.phase, phase: "enrichment", knowledgeBase: j }), S(1);
10002
+ const L = j.map((G) => `- ${G.timestamp}: ${G.name}`).join(`
10021
10003
  `), V = `Given an extracted event, enrich it using this knowledge base:
10022
10004
 
10023
- ${$(F, { tag: "knowledge-base" })}
10005
+ ${$(L, { tag: "knowledge-base" })}
10024
10006
 
10025
10007
  Rules:
10026
10008
  1. If the knowledge base has a more accurate date for this event, use it
@@ -10029,33 +10011,33 @@ Rules:
10029
10011
  4. Keep the original if the knowledge base doesn't have better information
10030
10012
 
10031
10013
  Return the enriched event as: "YYYY-MM-DD: Event name" or with the appropriate timestamp format.`, H = (await Oe(
10032
- O.map((G) => `${G.timestamp}: ${G.name}`),
10014
+ I.map((G) => `${G.timestamp}: ${G.name}`),
10033
10015
  V,
10034
10016
  {
10035
10017
  ...i,
10036
10018
  ...m !== void 0 && { batchSize: m },
10037
10019
  maxParallel: p,
10038
- onProgress: L(i.onProgress, "map:enrichment")
10020
+ onProgress: B(i.onProgress, "map:enrichment")
10039
10021
  }
10040
10022
  )).map((G, te) => {
10041
- if (!G) return O[te];
10023
+ if (!G) return I[te];
10042
10024
  const ie = G.indexOf(":");
10043
10025
  if (ie > 0) {
10044
- const de = G.substring(0, ie).trim(), Z = G.substring(ie + 1).trim(), we = de !== O[te].timestamp;
10026
+ const pe = G.substring(0, ie).trim(), Z = G.substring(ie + 1).trim(), we = pe !== I[te].timestamp;
10045
10027
  return {
10046
- timestamp: de,
10028
+ timestamp: pe,
10047
10029
  name: Z,
10048
10030
  ...we && { enriched: !0 }
10049
10031
  };
10050
10032
  }
10051
- return O[te];
10052
- }), ee = new Set(H.map((G) => G.name.toLowerCase())), pe = j.filter((G) => !ee.has(G.name.toLowerCase()));
10053
- O = Ke([...H, ...pe]), v(1);
10033
+ return I[te];
10034
+ }), ee = new Set(H.map((G) => G.name.toLowerCase())), ue = j.filter((G) => !ee.has(G.name.toLowerCase()));
10035
+ I = Ke([...H, ...ue]), S(1);
10054
10036
  }
10055
10037
  const R = E > 0 ? T.partial : T.success;
10056
- return c.complete({ outcome: R }), O;
10057
- } catch (S) {
10058
- throw c.error(S), S;
10038
+ return c.complete({ outcome: R }), I;
10039
+ } catch (v) {
10040
+ throw c.error(v), v;
10059
10041
  }
10060
10042
  }
10061
10043
  Qa.knownTexts = ["knowledge"];
@@ -10114,7 +10096,7 @@ ${r}
10114
10096
  </error>`));
10115
10097
  }
10116
10098
  async function ec(e, t, n = {}) {
10117
- const r = A(qs, { llm: { fast: !0, good: !0 }, ...n }), s = I(qs, r.onProgress, r);
10099
+ const r = O(qs, { llm: { fast: !0, good: !0 }, ...n }), s = k(qs, r.onProgress, r);
10118
10100
  s.start();
10119
10101
  let o;
10120
10102
  try {
@@ -10171,9 +10153,9 @@ function Zw(e, t) {
10171
10153
  }
10172
10154
  async function tc(e, t, n) {
10173
10155
  [t, n] = K(t, n);
10174
- const { text: r, context: s } = N(t, []), o = A(zs, n), i = I(zs, o.onProgress, o);
10156
+ const { text: r, context: s } = N(t, []), o = O(zs, n), i = k(zs, o.onProgress, o);
10175
10157
  i.start();
10176
- const { chunkSize: a, strictness: c } = await q(o, {
10158
+ const { chunkSize: a, strictness: c } = await F(o, {
10177
10159
  chunkSize: 1e3,
10178
10160
  strictness: J(Xw)
10179
10161
  });
@@ -10185,9 +10167,9 @@ ${s}` : "", h = `${$(r, { tag: "removal_criteria" })}
10185
10167
  NOTE: These text blocks are in REVERSE order (from end to beginning of document).
10186
10168
  Score how important THE ENTIRE TEXT BLOCK is to KEEP in the document (0 = should be removed, 10 = must keep).
10187
10169
  Each item in the list is ONE complete text block - evaluate it as a whole unit.
10188
- Consider the removal criteria above when scoring.${d}`, b = (await ke(p, h, {
10170
+ Consider the removal criteria above when scoring.${d}`, b = (await Ie(p, h, {
10189
10171
  ...o,
10190
- onProgress: L(o.onProgress, "score:relevance")
10172
+ onProgress: B(o.onProgress, "score:relevance")
10191
10173
  // Don't use stopOnThreshold - we need all scores to find high ones
10192
10174
  })).findIndex((g) => (g ?? 1 / 0) < c);
10193
10175
  let f;
@@ -10248,9 +10230,9 @@ ${$(e, { tag: "intent" })}`, Yn = ["scientific", "causal", "softCover"], nv = {
10248
10230
  }[e] ?? Kt, oc = async (e, t = {}) => {
10249
10231
  const { text: n, context: r } = N(e, []), s = r ? `
10250
10232
 
10251
- ${r}` : "", o = A(Us, { llm: { sensitive: !0 }, ...t }), i = I(Us, o.onProgress, o);
10233
+ ${r}` : "", o = O(Us, { llm: { sensitive: !0 }, ...t }), i = k(Us, o.onProgress, o);
10252
10234
  i.start();
10253
- const { strategies: a, variantCount: c } = await q(o, {
10235
+ const { strategies: a, variantCount: c } = await F(o, {
10254
10236
  coverage: J(rv, ["strategies", "variantCount"])
10255
10237
  }), l = a.map(
10256
10238
  (u) => `${nv[u](n, c)}${s}`
@@ -10262,7 +10244,7 @@ ${r}` : "", o = A(Us, { llm: { sensitive: !0 }, ...t }), i = I(Us, o.onProgress,
10262
10244
  const h = await M(() => _(d, { ...o, responseFormat: tv }), {
10263
10245
  label: "veiled-variants",
10264
10246
  config: o,
10265
- onProgress: L(o.onProgress, "strategy")
10247
+ onProgress: B(o.onProgress, "strategy")
10266
10248
  });
10267
10249
  return u(1), h;
10268
10250
  },
@@ -10368,22 +10350,22 @@ async function pv(e, { columns: t = 2, tileHeight: n = 300, gutter: r = 4, quali
10368
10350
  w: f.info.width,
10369
10351
  h: f.info.height
10370
10352
  })), l = Math.ceil(e.length / t), u = Array.from({ length: t }, (f, g) => {
10371
- const m = c.filter((w, S) => S % t === g);
10353
+ const m = c.filter((w, v) => v % t === g);
10372
10354
  return m.length > 0 ? Math.max(...m.map((w) => w.w)) : 0;
10373
10355
  }), p = u.reduce((f, g) => f + g, 0) + r * (t - 1), d = l * n + r * (l - 1), h = [];
10374
10356
  for (let f = 0; f < c.length; f++) {
10375
- const g = f % t, m = Math.floor(f / t), w = u.slice(0, g).reduce((v, P) => v + P, 0) + r * g, S = m * (n + r);
10376
- if (c[f].x = w, c[f].y = S, h.push({ input: a[f].data, left: w, top: S }), c[f].label) {
10377
- const v = Math.min(24, c[f].h), P = Math.min(14, v - 2), x = c[f].label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), E = Buffer.from(
10378
- `<svg width="${c[f].w}" height="${v}">
10379
- <rect x="0" y="0" width="${c[f].w}" height="${v}" fill="rgba(0,0,0,0.6)"/>
10380
- <text x="4" y="${v - 3}" font-family="sans-serif" font-size="${P}" fill="white">${x}</text>
10357
+ const g = f % t, m = Math.floor(f / t), w = u.slice(0, g).reduce((S, P) => S + P, 0) + r * g, v = m * (n + r);
10358
+ if (c[f].x = w, c[f].y = v, h.push({ input: a[f].data, left: w, top: v }), c[f].label) {
10359
+ const S = Math.min(24, c[f].h), P = Math.min(14, S - 2), x = c[f].label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), E = Buffer.from(
10360
+ `<svg width="${c[f].w}" height="${S}">
10361
+ <rect x="0" y="0" width="${c[f].w}" height="${S}" fill="rgba(0,0,0,0.6)"/>
10362
+ <text x="4" y="${S - 3}" font-family="sans-serif" font-size="${P}" fill="white">${x}</text>
10381
10363
  </svg>`
10382
10364
  );
10383
10365
  h.push({
10384
10366
  input: E,
10385
10367
  left: w,
10386
- top: S + c[f].h - v
10368
+ top: v + c[f].h - S
10387
10369
  });
10388
10370
  }
10389
10371
  }
@@ -10422,16 +10404,16 @@ const Vs = "analyze-image", dv = C("analysis", {
10422
10404
  [t, n] = K(t, n);
10423
10405
  const { text: r, context: s } = N(t, []), o = s ? `${r}
10424
10406
 
10425
- ${s}` : r, i = A(Vs, n), a = I(Vs, i.onProgress, i);
10407
+ ${s}` : r, i = O(Vs, n), a = k(Vs, i.onProgress, i);
10426
10408
  a.start();
10427
10409
  const c = hv(e), l = c.length;
10428
10410
  try {
10429
- const { tile: u } = await q(i, {
10411
+ const { tile: u } = await F(i, {
10430
10412
  tile: !1
10431
10413
  }), p = u && c.length > 1;
10432
10414
  let d;
10433
10415
  if (p) {
10434
- const f = c.map((S) => S.path), g = c.map((S) => S.label).filter(Boolean), m = await pv(f, {
10416
+ const f = c.map((v) => v.path), g = c.map((v) => v.label).filter(Boolean), m = await pv(f, {
10435
10417
  labels: g.length > 0 ? g : void 0
10436
10418
  });
10437
10419
  a.emit({
@@ -10450,7 +10432,7 @@ ${s}` : r, i = A(Vs, n), a = I(Vs, i.onProgress, i);
10450
10432
  const h = Zo(o, d), y = i.responseFormat ? i : { ...i, responseFormat: dv }, b = await M(() => _(h, y), {
10451
10433
  label: "analyze-image:llm",
10452
10434
  config: i,
10453
- onProgress: L(i.onProgress, "llm")
10435
+ onProgress: B(i.onProgress, "llm")
10454
10436
  });
10455
10437
  return a.complete({ outcome: T.success, imageCount: l, tiled: p }), b;
10456
10438
  } catch (u) {
@@ -10462,9 +10444,9 @@ const Js = "auto";
10462
10444
  async function uc(e, t = {}) {
10463
10445
  const { text: n, context: r } = N(e, []), s = r ? `${n}
10464
10446
 
10465
- ${r}` : n, o = A(Js, t), i = I(Js, o.onProgress, o);
10447
+ ${r}` : n, o = O(Js, t), i = k(Js, o.onProgress, o);
10466
10448
  i.start();
10467
- const { schemas: a, defaultFunction: c, defaultArguments: l } = await q(o, {
10449
+ const { schemas: a, defaultFunction: c, defaultArguments: l } = await F(o, {
10468
10450
  schemas: Ua,
10469
10451
  defaultFunction: void 0,
10470
10452
  defaultArguments: {}
@@ -10552,8 +10534,8 @@ async function wv({
10552
10534
  onProgress: a,
10553
10535
  operation: c
10554
10536
  }) {
10555
- const l = A(Ks, { onProgress: a, operation: c }), u = I(Ks, l.onProgress, l);
10556
- u.start(), u.emit({ event: k.input, value: e });
10537
+ const l = O(Ks, { onProgress: a, operation: c }), u = k(Ks, l.onProgress, l);
10538
+ u.start(), u.emit({ event: A.input, value: e });
10557
10539
  let p;
10558
10540
  try {
10559
10541
  if (t === void 0 && !n)
@@ -10567,7 +10549,7 @@ async function wv({
10567
10549
  let y;
10568
10550
  throw typeof o == "function" ? y = o({ actual: e, equals: t, constraint: n }) : y = o, y || (y = t !== void 0 ? "LLM assertion failed: Does the actual value strictly equal the expected value?" : `LLM assertion failed: ${n}`), new Error(y);
10569
10551
  }
10570
- u.emit({ event: k.output, value: p }), u.complete({ outcome: T.success });
10552
+ u.emit({ event: A.output, value: p }), u.complete({ outcome: T.success });
10571
10553
  } catch (d) {
10572
10554
  throw u.error(d), d;
10573
10555
  }
@@ -10659,7 +10641,7 @@ ${o}`), t === "error")
10659
10641
  return e;
10660
10642
  }
10661
10643
  async function $v(e, t, n, r = {}) {
10662
- const s = A("expect", r), { mode: o } = await q(s, {
10644
+ const s = O("expect", r), { mode: o } = await F(s, {
10663
10645
  mode: $e.VERBLETS_LLM_EXPECT_MODE || "none"
10664
10646
  });
10665
10647
  if (t === void 0 && !n)
@@ -10691,7 +10673,7 @@ const Gs = "intent", Pv = (e) => {
10691
10673
  }[e] : e;
10692
10674
  }, Tv = C("intent_result", yt);
10693
10675
  async function dc(e, t, n = {}) {
10694
- const { text: r, context: s } = N(e, []), o = A(Gs, n), i = I(Gs, o.onProgress, o);
10676
+ const { text: r, context: s } = N(e, []), o = O(Gs, n), i = k(Gs, o.onProgress, o);
10695
10677
  i.start();
10696
10678
  try {
10697
10679
  if (!Array.isArray(t) || t.length === 0)
@@ -10753,10 +10735,10 @@ class Ev {
10753
10735
  return this;
10754
10736
  }
10755
10737
  }
10756
- function Iv(e, t = void 0) {
10738
+ function kv(e, t = void 0) {
10757
10739
  return new Ev(e, t);
10758
10740
  }
10759
- function kv(e) {
10741
+ function Iv(e) {
10760
10742
  const n = new Error().stack.split(`
10761
10743
  `);
10762
10744
  if (e === void 0) {
@@ -10785,7 +10767,7 @@ function Av(e) {
10785
10767
  } : { file: "unknown", line: 0 };
10786
10768
  }
10787
10769
  function Ov(e = 0) {
10788
- const t = kv(4 + e);
10770
+ const t = Iv(4 + e);
10789
10771
  return {
10790
10772
  filePath: t.file,
10791
10773
  line: t.line
@@ -10840,18 +10822,18 @@ function Hs(e) {
10840
10822
  }
10841
10823
  const Qs = "llm-logger";
10842
10824
  function mc(e = {}) {
10843
- const t = A(Qs, e), n = I(Qs, t.onProgress, t);
10825
+ const t = O(Qs, e), n = k(Qs, t.onProgress, t);
10844
10826
  n.start();
10845
10827
  try {
10846
- let g = function(m, w = "log", S = 0) {
10847
- const v = Ov(S), P = {
10828
+ let g = function(m, w = "log", v = 0) {
10829
+ const S = Ov(v), P = {
10848
10830
  id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
10849
10831
  ts: /* @__PURE__ */ new Date(),
10850
10832
  raw: m,
10851
10833
  // Store original data as-is (any structure)
10852
10834
  meta: /* @__PURE__ */ new Map([
10853
10835
  ["level", w],
10854
- ["fileContext", v]
10836
+ ["fileContext", S]
10855
10837
  ]),
10856
10838
  attachments: {},
10857
10839
  // AI enrichments to merge
@@ -10884,8 +10866,8 @@ function mc(e = {}) {
10884
10866
  ...m.ts ? {} : { ts: P.ts },
10885
10867
  ...m.level ? {} : { level: w },
10886
10868
  // Add file context
10887
- ...m.file ? {} : { file: v.filePath },
10888
- ...m.line ? {} : { line: v.line }
10869
+ ...m.file ? {} : { file: S.filePath },
10870
+ ...m.line ? {} : { line: S.line }
10889
10871
  } : E = {
10890
10872
  data: m,
10891
10873
  id: P.id,
@@ -10929,17 +10911,17 @@ function mc(e = {}) {
10929
10911
  hostLogger: c = void 0
10930
10912
  } = e, l = new Mn(r), u = [], p = c ? Hs(c) : void 0, d = /* @__PURE__ */ new Map();
10931
10913
  s.forEach((m) => {
10932
- Iv(m.laneId !== void 0, "Each lane must have an laneId property").toBe(!0), d.set(m.laneId, []);
10914
+ kv(m.laneId !== void 0, "Each lane must have an laneId property").toBe(!0), d.set(m.laneId, []);
10933
10915
  });
10934
10916
  const h = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
10935
10917
  let b = !1;
10936
10918
  o.forEach((m) => {
10937
10919
  const w = l.registerReader();
10938
10920
  y.set(m.processorId, w), h.set(m.processorId, -1);
10939
- const S = m.batchSize || 10, v = async () => {
10921
+ const v = m.batchSize || 10, S = async () => {
10940
10922
  if (!b)
10941
10923
  try {
10942
- const P = await l.readBatch(w, S, m.batchTimeout), x = Cv(P.data), O = `# Log Processing Context
10924
+ const P = await l.readBatch(w, v, m.batchTimeout), x = Cv(P.data), I = `# Log Processing Context
10943
10925
  # Processor: ${m.processorId} (${m.description || "No description"})
10944
10926
  # Batch size: ${P.data.length} logs
10945
10927
  # Task: Analyze the following NDJSON log entries and return bulk adjustments
@@ -10960,32 +10942,32 @@ function mc(e = {}) {
10960
10942
  # ]
10961
10943
  #
10962
10944
  # NDJSON Log Data:
10963
- ` + x, R = await m.process(O);
10945
+ ` + x, R = await m.process(I);
10964
10946
  if (Array.isArray(R))
10965
10947
  for (const j of R) {
10966
- const F = u.findIndex((V) => V.id === j.logId);
10967
- if (F !== -1) {
10968
- const V = u[F];
10948
+ const L = u.findIndex((V) => V.id === j.logId);
10949
+ if (L !== -1) {
10950
+ const V = u[L];
10969
10951
  if (j.adjustments)
10970
10952
  for (const [Y, H] of Object.entries(j.adjustments))
10971
10953
  Ys(V.attachments, Y, H);
10972
10954
  j.aiMeta && (V.aiMeta || (V.aiMeta = {}), Object.assign(V.aiMeta, j.aiMeta));
10973
10955
  }
10974
10956
  }
10975
- h.set(m.processorId, P.lastOffset), b || setTimeout(v, 0);
10957
+ h.set(m.processorId, P.lastOffset), b || setTimeout(S, 0);
10976
10958
  } catch (P) {
10977
- p && p.error(`Processor ${m.processorId} error: ${P.message}`), b || setTimeout(v, 1e3);
10959
+ p && p.error(`Processor ${m.processorId} error: ${P.message}`), b || setTimeout(S, 1e3);
10978
10960
  }
10979
10961
  };
10980
- v();
10962
+ S();
10981
10963
  });
10982
10964
  const f = () => {
10983
10965
  for (const [m, w] of d)
10984
10966
  if (w.length > 0) {
10985
- const S = s.find((v) => v.laneId === m);
10986
- if (S) {
10987
- const v = w.filter((P) => !P.aiMeta?.skip);
10988
- v.length > 0 && S.writer(v), w.length = 0;
10967
+ const v = s.find((S) => S.laneId === m);
10968
+ if (v) {
10969
+ const S = w.filter((P) => !P.aiMeta?.skip);
10970
+ S.length > 0 && v.writer(S), w.length = 0;
10989
10971
  }
10990
10972
  }
10991
10973
  };
@@ -11008,17 +10990,17 @@ function mc(e = {}) {
11008
10990
  trace: (m, w = 0) => g(m, "trace", w),
11009
10991
  fatal: (m, w = 0) => g(m, "fatal", w),
11010
10992
  // Enhanced attachment API
11011
- attachToLog: (m, w, S) => {
11012
- const v = u.findIndex((P) => P.id === m);
11013
- return v !== -1 ? (Ys(u[v].attachments, w, S), !0) : !1;
10993
+ attachToLog: (m, w, v) => {
10994
+ const S = u.findIndex((P) => P.id === m);
10995
+ return S !== -1 ? (Ys(u[S].attachments, w, v), !0) : !1;
11014
10996
  },
11015
10997
  getLogAttachment: (m, w) => {
11016
- const S = u.find((v) => v.id === m);
11017
- return S ? _v(S.attachments, w) : void 0;
10998
+ const v = u.find((S) => S.id === m);
10999
+ return v ? _v(v.attachments, w) : void 0;
11018
11000
  },
11019
11001
  markLogSkippable: (m, w = !0) => {
11020
- const S = u.findIndex((v) => v.id === m);
11021
- return S !== -1 ? (u[S].aiMeta.skip = w, !0) : !1;
11002
+ const v = u.findIndex((S) => S.id === m);
11003
+ return v !== -1 ? (u[v].aiMeta.skip = w, !0) : !1;
11022
11004
  },
11023
11005
  // Ring buffer access - legacy API compatibility
11024
11006
  ringBuffer: {
@@ -11066,15 +11048,15 @@ function mc(e = {}) {
11066
11048
  }),
11067
11049
  // Wait for all processors to catch up to current write position
11068
11050
  waitForProcessing: async (m = 3e4) => {
11069
- const w = Date.now(), v = l.getStats().writeOffset;
11070
- if (v === 0)
11051
+ const w = Date.now(), S = l.getStats().writeOffset;
11052
+ if (S === 0)
11071
11053
  return;
11072
11054
  f();
11073
- const P = (x, E) => E + 1 < v;
11055
+ const P = (x, E) => E + 1 < S;
11074
11056
  for (; Date.now() - w < m; ) {
11075
11057
  let x = !0;
11076
- for (const [E, O] of h)
11077
- if (P(E, O)) {
11058
+ for (const [E, I] of h)
11059
+ if (P(E, I)) {
11078
11060
  x = !1;
11079
11061
  break;
11080
11062
  }
@@ -11086,9 +11068,9 @@ function mc(e = {}) {
11086
11068
  }
11087
11069
  if (p) {
11088
11070
  const x = [];
11089
- for (const [E, O] of h)
11090
- if (P(E, O)) {
11091
- const R = v - O - 1;
11071
+ for (const [E, I] of h)
11072
+ if (P(E, I)) {
11073
+ const R = S - I - 1;
11092
11074
  x.push(`${E} (${R} logs pending)`);
11093
11075
  }
11094
11076
  p.warn(
@@ -11221,7 +11203,7 @@ Provide:
11221
11203
  additionalProperties: !1
11222
11204
  };
11223
11205
  async function pn(e, t = {}) {
11224
- const { text: n, context: r } = N(e, []), s = A(Xs, t), o = I(Xs, s.onProgress, s);
11206
+ const { text: n, context: r } = N(e, []), s = O(Xs, t), o = k(Xs, s.onProgress, s);
11225
11207
  o.start();
11226
11208
  try {
11227
11209
  const {
@@ -11277,7 +11259,7 @@ const Lv = {
11277
11259
  additionalProperties: !1
11278
11260
  }, Zs = "sentiment";
11279
11261
  async function hc(e, t = {}) {
11280
- const { text: n, context: r } = N(e, []), s = A(Zs, t), o = I(Zs, s.onProgress, s);
11262
+ const { text: n, context: r } = N(e, []), s = O(Zs, t), o = k(Zs, s.onProgress, s);
11281
11263
  o.start();
11282
11264
  const i = [
11283
11265
  `Identify the overall sentiment of the following text as "positive", "negative", or "neutral".
@@ -11368,21 +11350,21 @@ function gc({
11368
11350
  llm: o,
11369
11351
  ...i
11370
11352
  } = {}) {
11371
- const { text: a, context: c } = N(e, []), l = A(eo, { llm: o, ...i }), u = I(eo, l.onProgress, l);
11372
- u.start(), u.emit({ event: k.input, value: a });
11353
+ const { text: a, context: c } = N(e, []), l = O(eo, { llm: o, ...i }), u = k(eo, l.onProgress, l);
11354
+ u.start(), u.emit({ event: A.input, value: a });
11373
11355
  const p = l.now ?? /* @__PURE__ */ new Date(), d = u.batch();
11374
11356
  let h, y = 0, b = 0, f = r;
11375
11357
  const g = [];
11376
11358
  let m = !0, w;
11377
- const S = async () => {
11359
+ const v = async () => {
11378
11360
  if (!m) return;
11379
- w || (w = await q(l, {
11361
+ w || (w = await F(l, {
11380
11362
  tolerance: J(Wv)
11381
11363
  }));
11382
11364
  const { tolerance: P } = w;
11383
11365
  try {
11384
11366
  u.emit({
11385
- event: k.step,
11367
+ event: A.step,
11386
11368
  stepName: "tick",
11387
11369
  tickNumber: y + 1
11388
11370
  }), f = await t({
@@ -11390,7 +11372,7 @@ function gc({
11390
11372
  lastInvocationResult: f,
11391
11373
  initial: r
11392
11374
  });
11393
- const x = fc(a, f), O = [
11375
+ const x = fc(a, f), I = [
11394
11376
  `${Bv} ${x}`,
11395
11377
  `${Dv} ${qv}`,
11396
11378
  'Your response should be an ISO date or a short duration like "10 minutes".',
@@ -11402,7 +11384,7 @@ function gc({
11402
11384
  ].filter(Boolean).join(`
11403
11385
 
11404
11386
  `), R = await M(
11405
- () => _(O, {
11387
+ () => _(I, {
11406
11388
  ...l,
11407
11389
  responseFormat: zv
11408
11390
  }),
@@ -11414,21 +11396,21 @@ function gc({
11414
11396
  g.push(R), g.length > n && g.shift();
11415
11397
  const j = await Uv(R, l);
11416
11398
  if (s) {
11417
- const F = new Date(Date.now() + j);
11399
+ const L = new Date(Date.now() + j);
11418
11400
  await s({
11419
11401
  timingString: R,
11420
11402
  data: f,
11421
- nextDate: F
11403
+ nextDate: L
11422
11404
  });
11423
11405
  }
11424
11406
  u.measure({
11425
11407
  metric: ge.tickDuration,
11426
11408
  value: Date.now() - p.getTime(),
11427
11409
  tickNumber: y + 1
11428
- }), b = 0, y += 1, d(1), m && (h = setTimeout(S, j));
11410
+ }), b = 0, y += 1, d(1), m && (h = setTimeout(v, j));
11429
11411
  } catch (x) {
11430
11412
  if (ne(`Error in setInterval step: ${x.message}`), b += 1, u.emit({
11431
- event: k.step,
11413
+ event: A.step,
11432
11414
  stepName: "tick-error",
11433
11415
  tickNumber: y + 1,
11434
11416
  error: x.message,
@@ -11443,10 +11425,10 @@ function gc({
11443
11425
  m = !1, clearTimeout(h), u.error(x);
11444
11426
  return;
11445
11427
  }
11446
- m && (h = setTimeout(S, 1e3));
11428
+ m && (h = setTimeout(v, 1e3));
11447
11429
  }
11448
11430
  };
11449
- return h = setTimeout(S, 0), () => {
11431
+ return h = setTimeout(v, 0), () => {
11450
11432
  m = !1, clearTimeout(h), u.complete({ outcome: T.success, ticks: y });
11451
11433
  };
11452
11434
  }
@@ -11461,7 +11443,7 @@ function xt(e, t = {}) {
11461
11443
  return r = r.replace(/[^\S\n]+/g, " "), r.trim();
11462
11444
  }
11463
11445
  function Vv() {
11464
- const e = D("VERBLETS_EMBED_MODEL");
11446
+ const e = q("VERBLETS_EMBED_MODEL");
11465
11447
  return {
11466
11448
  [e]: {
11467
11449
  name: e,
@@ -11492,7 +11474,7 @@ function Vv() {
11492
11474
  };
11493
11475
  }
11494
11476
  function Jv() {
11495
- const e = D("VERBLETS_EMBED_MODEL");
11477
+ const e = q("VERBLETS_EMBED_MODEL");
11496
11478
  return [
11497
11479
  { match: { good: !0, multi: !1 }, use: e },
11498
11480
  { use: "Xenova/clip-vit-base-patch16" }
@@ -11541,16 +11523,16 @@ async function Yv(e) {
11541
11523
  const { batchSize: y = r, abortSignal: b } = h, f = dn(d, y), g = [];
11542
11524
  for (const m of f) {
11543
11525
  b?.throwIfAborted();
11544
- const w = i(m, { padding: !0, truncation: !0 }), v = (await a(w)).text_embeds, P = v.dims[1];
11526
+ const w = i(m, { padding: !0, truncation: !0 }), S = (await a(w)).text_embeds, P = S.dims[1];
11545
11527
  for (let x = 0; x < m.length; x++)
11546
- g.push(no(new Float32Array(v.data.slice(x * P, (x + 1) * P))));
11528
+ g.push(no(new Float32Array(S.data.slice(x * P, (x + 1) * P))));
11547
11529
  }
11548
11530
  return g;
11549
11531
  }, embedImages: async (d, h = {}) => {
11550
11532
  const { batchSize: y = s, abortSignal: b } = h, f = dn(d, y), g = [];
11551
11533
  for (const m of f) {
11552
11534
  b?.throwIfAborted();
11553
- const w = await Promise.all(m.map((E) => Zc.read(E))), S = await c(w), P = (await l(S)).image_embeds, x = P.dims[1];
11535
+ const w = await Promise.all(m.map((E) => Zc.read(E))), v = await c(w), P = (await l(v)).image_embeds, x = P.dims[1];
11554
11536
  for (let E = 0; E < m.length; E++)
11555
11537
  g.push(no(new Float32Array(P.data.slice(E * x, (E + 1) * x))));
11556
11538
  }
@@ -11756,7 +11738,7 @@ const Zv = {
11756
11738
  additionalProperties: !1
11757
11739
  }, ro = "embed-rewrite-query";
11758
11740
  async function Tc(e, t = {}) {
11759
- const { text: n, context: r } = N(e, []), s = A(ro, t), o = I(ro, s.onProgress, s);
11741
+ const { text: n, context: r } = N(e, []), s = O(ro, t), o = k(ro, s.onProgress, s);
11760
11742
  o.start();
11761
11743
  try {
11762
11744
  const i = li(n), a = r ? `${i}
@@ -11791,10 +11773,10 @@ const eS = {
11791
11773
  }[e] : e;
11792
11774
  };
11793
11775
  async function Ec(e, t = {}) {
11794
- const { text: n, context: r } = N(e, []), s = A(so, t), o = I(so, s.onProgress, s);
11776
+ const { text: n, context: r } = N(e, []), s = O(so, t), o = k(so, s.onProgress, s);
11795
11777
  o.start();
11796
11778
  try {
11797
- const { divergence: i, count: a } = await q(s, {
11779
+ const { divergence: i, count: a } = await F(s, {
11798
11780
  divergence: J(tS),
11799
11781
  count: 3
11800
11782
  }), c = ui(n, a, { divergenceGuidance: i }), l = r ? `${c}
@@ -11828,11 +11810,11 @@ const nS = {
11828
11810
  high: "Step back to foundational principles and theories. Generate questions about the underlying mechanisms, first principles, or cross-domain analogies that explain why the specific topic works the way it does. Prefer theoretical depth over topical proximity."
11829
11811
  }[e] : e;
11830
11812
  };
11831
- async function Ic(e, t = {}) {
11832
- const { text: n, context: r } = N(e, []), s = A(oo, t), o = I(oo, s.onProgress, s);
11813
+ async function kc(e, t = {}) {
11814
+ const { text: n, context: r } = N(e, []), s = O(oo, t), o = k(oo, s.onProgress, s);
11833
11815
  o.start();
11834
11816
  try {
11835
- const { abstraction: i, count: a } = await q(s, {
11817
+ const { abstraction: i, count: a } = await F(s, {
11836
11818
  abstraction: J(rS),
11837
11819
  count: 3
11838
11820
  }), c = pi(n, a, { abstractionGuidance: i }), l = r ? `${c}
@@ -11846,7 +11828,7 @@ ${r}` : c, u = await _(l, {
11846
11828
  throw o.error(i), i;
11847
11829
  }
11848
11830
  }
11849
- Ic.knownTexts = [];
11831
+ kc.knownTexts = [];
11850
11832
  const sS = {
11851
11833
  type: "object",
11852
11834
  properties: {
@@ -11866,11 +11848,11 @@ const sS = {
11866
11848
  high: "Decompose into many fine-grained sub-questions. Each sub-question should target a single specific fact, entity, or data point needed to fully answer the original query. Be thorough — prefer many narrow, precise questions over fewer broad ones."
11867
11849
  }[e] : e;
11868
11850
  };
11869
- async function kc(e, t = {}) {
11870
- const { text: n, context: r } = N(e, []), s = A(io, t), o = I(io, s.onProgress, s);
11851
+ async function Ic(e, t = {}) {
11852
+ const { text: n, context: r } = N(e, []), s = O(io, t), o = k(io, s.onProgress, s);
11871
11853
  o.start();
11872
11854
  try {
11873
- const { granularity: i } = await q(s, {
11855
+ const { granularity: i } = await F(s, {
11874
11856
  granularity: J(oS)
11875
11857
  }), a = di(n, { granularityGuidance: i }), c = r ? `${a}
11876
11858
 
@@ -11883,7 +11865,7 @@ ${r}` : a, l = await _(c, {
11883
11865
  throw o.error(i), i;
11884
11866
  }
11885
11867
  }
11886
- kc.knownTexts = [];
11868
+ Ic.knownTexts = [];
11887
11869
  const iS = {
11888
11870
  type: "object",
11889
11871
  properties: {
@@ -11896,7 +11878,7 @@ const iS = {
11896
11878
  additionalProperties: !1
11897
11879
  }, ao = "embed-rewrite-to-output-doc";
11898
11880
  async function Ac(e, t = {}) {
11899
- const { text: n, context: r } = N(e, []), s = A(ao, t), o = I(ao, s.onProgress, s);
11881
+ const { text: n, context: r } = N(e, []), s = O(ao, t), o = k(ao, s.onProgress, s);
11900
11882
  o.start();
11901
11883
  try {
11902
11884
  const i = ad(n), a = r ? `${i}
@@ -12069,9 +12051,9 @@ const vS = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
12069
12051
  openai: vS
12070
12052
  };
12071
12053
  async function xS(e, t = {}) {
12072
- const n = A("agent", t), r = I("agent", n.onProgress, n);
12054
+ const n = O("agent", t), r = k("agent", n.onProgress, n);
12073
12055
  r.start({ instruction: e.slice(0, 200) });
12074
- const s = await q(n, {
12056
+ const s = await F(n, {
12075
12057
  maxTurns: void 0,
12076
12058
  cwd: void 0,
12077
12059
  systemPrompt: void 0,
@@ -12153,7 +12135,7 @@ async function ES(e, t, n = {}) {
12153
12135
  label: a = "pMap"
12154
12136
  } = n;
12155
12137
  if (!t || t.length === 0) return [];
12156
- const c = I(a, i);
12138
+ const c = k(a, i);
12157
12139
  c.start();
12158
12140
  const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
12159
12141
  let d = 0;
@@ -12177,7 +12159,7 @@ async function ES(e, t, n = {}) {
12177
12159
  throw c.error(h), h;
12178
12160
  }
12179
12161
  }
12180
- async function IS(e, t, n = {}) {
12162
+ async function kS(e, t, n = {}) {
12181
12163
  const {
12182
12164
  maxParallel: r = 3,
12183
12165
  errorPosture: s = z.resilient,
@@ -12186,7 +12168,7 @@ async function IS(e, t, n = {}) {
12186
12168
  label: a = "pFilter"
12187
12169
  } = n;
12188
12170
  if (!t || t.length === 0) return [];
12189
- const c = I(a, i);
12171
+ const c = k(a, i);
12190
12172
  c.start();
12191
12173
  const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
12192
12174
  let d = 0;
@@ -12211,7 +12193,7 @@ async function IS(e, t, n = {}) {
12211
12193
  throw c.error(h), h;
12212
12194
  }
12213
12195
  }
12214
- async function kS(e, t, n = {}) {
12196
+ async function IS(e, t, n = {}) {
12215
12197
  const {
12216
12198
  maxParallel: r = 3,
12217
12199
  errorPosture: s = z.resilient,
@@ -12220,7 +12202,7 @@ async function kS(e, t, n = {}) {
12220
12202
  label: a = "pFind"
12221
12203
  } = n;
12222
12204
  if (!t || t.length === 0) return;
12223
- const c = I(a, i);
12205
+ const c = k(a, i);
12224
12206
  c.start();
12225
12207
  const l = c.batch(t.length), u = Ce(r)(t);
12226
12208
  let p = 0;
@@ -12249,7 +12231,7 @@ async function kS(e, t, n = {}) {
12249
12231
  }
12250
12232
  }
12251
12233
  async function AS(e, t, n, r = {}) {
12252
- const { abortSignal: s, onProgress: o, label: i = "pReduce" } = r, a = I(i, o);
12234
+ const { abortSignal: s, onProgress: o, label: i = "pReduce" } = r, a = k(i, o);
12253
12235
  a.start();
12254
12236
  const c = a.batch(t.length);
12255
12237
  let l = n;
@@ -12272,7 +12254,7 @@ async function OS(e, t, n = {}) {
12272
12254
  label: a = "pGroup"
12273
12255
  } = n;
12274
12256
  if (!t || t.length === 0) return {};
12275
- const c = I(a, i);
12257
+ const c = k(a, i);
12276
12258
  c.start();
12277
12259
  const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
12278
12260
  let d = 0;
@@ -12307,7 +12289,7 @@ async function OS(e, t, n = {}) {
12307
12289
  async function _S(e, t, n = {}) {
12308
12290
  const { abortSignal: r, onProgress: s, label: o = "mapEach" } = n;
12309
12291
  if (!t || t.length === 0) return [];
12310
- const i = I(o, s);
12292
+ const i = k(o, s);
12311
12293
  i.start();
12312
12294
  const a = i.batch(t.length), c = new Array(t.length);
12313
12295
  try {
@@ -12323,7 +12305,7 @@ async function _S(e, t, n = {}) {
12323
12305
  async function CS(e, t, n = {}) {
12324
12306
  const { abortSignal: r, onProgress: s, label: o = "filterEach" } = n;
12325
12307
  if (!t || t.length === 0) return [];
12326
- const i = I(o, s);
12308
+ const i = k(o, s);
12327
12309
  i.start();
12328
12310
  const a = i.batch(t.length), c = [];
12329
12311
  try {
@@ -12339,7 +12321,7 @@ async function CS(e, t, n = {}) {
12339
12321
  async function jS(e, t, n = {}) {
12340
12322
  const { abortSignal: r, onProgress: s, label: o = "findEach" } = n;
12341
12323
  if (!t || t.length === 0) return;
12342
- const i = I(o, s);
12324
+ const i = k(o, s);
12343
12325
  i.start();
12344
12326
  const a = i.batch(t.length);
12345
12327
  try {
@@ -12356,7 +12338,7 @@ async function jS(e, t, n = {}) {
12356
12338
  }
12357
12339
  }
12358
12340
  async function NS(e, t, n, r = {}) {
12359
- const { abortSignal: s, onProgress: o, label: i = "reduceEach" } = r, a = I(i, o);
12341
+ const { abortSignal: s, onProgress: o, label: i = "reduceEach" } = r, a = k(i, o);
12360
12342
  a.start();
12361
12343
  const c = a.batch(t.length);
12362
12344
  let l = n;
@@ -12373,7 +12355,7 @@ async function NS(e, t, n, r = {}) {
12373
12355
  async function RS(e, t, n = {}) {
12374
12356
  const { abortSignal: r, onProgress: s, label: o = "groupEach" } = n;
12375
12357
  if (!t || t.length === 0) return {};
12376
- const i = I(o, s);
12358
+ const i = k(o, s);
12377
12359
  i.start();
12378
12360
  const a = i.batch(t.length), c = {};
12379
12361
  try {
@@ -12633,8 +12615,8 @@ const US = {
12633
12615
  }).join(`
12634
12616
  `), QS = (e, t, n, r) => {
12635
12617
  const s = async (o, i = {}) => {
12636
- const { untrusted: a = !1 } = i, c = A(e, { maxAttempts: 3, ...i }), l = typeof n == "function" ? n(o, c) : n, u = typeof t == "function" ? t(o, c) : t, p = I(e, c.onProgress, c);
12637
- p.start(), p.emit({ event: k.step, stepName: "analyzing" });
12618
+ const { untrusted: a = !1 } = i, c = O(e, { maxAttempts: 3, ...i }), l = typeof n == "function" ? n(o, c) : n, u = typeof t == "function" ? t(o, c) : t, p = k(e, c.onProgress, c);
12619
+ p.start(), p.emit({ event: A.step, stepName: "analyzing" });
12638
12620
  const d = r(o, c), h = a ? u + ai : u, y = a ? [ci, ...d] : d, b = await M(
12639
12621
  () => _(y.join(`
12640
12622
 
@@ -12749,7 +12731,7 @@ ${n.join(", ")}
12749
12731
  `);
12750
12732
  }
12751
12733
  async function lx({ exampleTexts: e, projectionNames: t, propertyNames: n }, r = {}) {
12752
- const s = A(uo, r), o = I(uo, s.onProgress, s);
12734
+ const s = O(uo, r), o = k(uo, s.onProgress, s);
12753
12735
  o.start();
12754
12736
  try {
12755
12737
  const i = cx({ exampleTexts: e, projectionNames: t, propertyNames: n }), a = await M(
@@ -12833,27 +12815,27 @@ async function bx(e, t, n) {
12833
12815
  });
12834
12816
  }
12835
12817
  async function wx({ sourceTexts: e, schema: t }, n = {}) {
12836
- const r = A(po, n), s = I(po, r.onProgress, r);
12818
+ const r = O(po, n), s = k(po, r.onProgress, r);
12837
12819
  s.start();
12838
12820
  try {
12839
12821
  const {
12840
12822
  maxParallel: o,
12841
12823
  batchSize: i,
12842
12824
  errorPosture: a
12843
- } = await q(r, {
12825
+ } = await F(r, {
12844
12826
  maxParallel: 3,
12845
12827
  batchSize: 5,
12846
12828
  errorPosture: z.resilient
12847
12829
  }), c = [];
12848
12830
  for (let d = 0; d < e.length; d += i)
12849
12831
  c.push(e.slice(d, d + i));
12850
- s.emit({ event: k.phase, phase: "fragmenting", totalBatches: c.length });
12832
+ s.emit({ event: A.phase, phase: "fragmenting", totalBatches: c.length });
12851
12833
  const l = s.batch(e.length), p = (await Q(
12852
12834
  c,
12853
12835
  async (d) => {
12854
12836
  const h = await bx(d, t, {
12855
12837
  ...r,
12856
- onProgress: L(r.onProgress, "batch")
12838
+ onProgress: B(r.onProgress, "batch")
12857
12839
  });
12858
12840
  return l(d.length), h;
12859
12841
  },
@@ -12904,7 +12886,7 @@ function Tx(e, t) {
12904
12886
  `);
12905
12887
  }
12906
12888
  async function Ex({ schema: e, studySet: t }, n = {}) {
12907
- const r = A(mo, n), s = I(mo, r.onProgress, r);
12889
+ const r = O(mo, n), s = k(mo, r.onProgress, r);
12908
12890
  s.start();
12909
12891
  try {
12910
12892
  const o = Tx(e, t), i = await M(
@@ -12942,10 +12924,10 @@ function ft(e) {
12942
12924
  for (let s = 0; s < e.length; s++) n[s] = e[s] * r;
12943
12925
  return n;
12944
12926
  }
12945
- function Ix(e, t, n) {
12927
+ function kx(e, t, n) {
12946
12928
  return Pe(e, n) - Pe(e, t);
12947
12929
  }
12948
- function kx(e, t) {
12930
+ function Ix(e, t) {
12949
12931
  const n = new Float32Array(e.length);
12950
12932
  for (let r = 0; r < e.length; r++) n[r] = e[r] * t;
12951
12933
  return n;
@@ -12977,22 +12959,22 @@ async function _x({ fragmentSets: e, schema: t }, n = {}) {
12977
12959
  const o = e.flatMap((g) => g.fragments).some((g) => g.image) ? { ...n, embedding: { multi: !0 } } : n, i = [], a = /* @__PURE__ */ new Map(), c = [], l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
12978
12960
  for (const g of e)
12979
12961
  for (const m of g.fragments) {
12980
- const w = !!m.image, S = w ? `img:${m.image}` : `txt:${m.text}`;
12962
+ const w = !!m.image, v = w ? `img:${m.image}` : `txt:${m.text}`;
12981
12963
  w && !l.has(m.image) && (l.set(m.image, c.length), c.push(m.image)), !w && !a.has(m.text) && (a.set(m.text, i.length), i.push(m.text));
12982
- const v = m.sourceIds?.[0] ?? g.fragmentSetId;
12983
- u.has(v) || u.set(v, /* @__PURE__ */ new Map());
12984
- const P = u.get(v);
12985
- P.has(m.projectionName) || P.set(m.projectionName, []), P.get(m.projectionName).push(S);
12964
+ const S = m.sourceIds?.[0] ?? g.fragmentSetId;
12965
+ u.has(S) || u.set(S, /* @__PURE__ */ new Map());
12966
+ const P = u.get(S);
12967
+ P.has(m.projectionName) || P.set(m.projectionName, []), P.get(m.projectionName).push(v);
12986
12968
  }
12987
12969
  const p = i.length > 0 ? await nt(i, o) : [], d = c.length > 0 ? await er(c, o) : [], h = (g) => g.startsWith("img:") ? d[l.get(g.slice(4))] : p[a.get(g.slice(4))], y = [];
12988
12970
  for (const [g, m] of u) {
12989
- const w = {}, S = [];
12971
+ const w = {}, v = [];
12990
12972
  for (const [P, x] of m) {
12991
- const E = x.map(h), O = mn(E);
12992
- O && (w[P] = ft(O), S.push(...E));
12973
+ const E = x.map(h), I = mn(E);
12974
+ I && (w[P] = ft(I), v.push(...E));
12993
12975
  }
12994
- const v = S.length > 0 ? ft(mn(S)) : void 0;
12995
- y.push({ stateId: g, vectorsByProjectionName: w, baseVector: v });
12976
+ const S = v.length > 0 ? ft(mn(v)) : void 0;
12977
+ y.push({ stateId: g, vectorsByProjectionName: w, baseVector: S });
12996
12978
  }
12997
12979
  const b = await Ox(t, o), f = b !== t._poles ? { ...t, _poles: b } : t;
12998
12980
  return { states: y, schema: f };
@@ -13002,7 +12984,7 @@ function Cx({ states: e, editsByProjectionName: t }) {
13002
12984
  const r = {};
13003
12985
  for (const [s, o] of Object.entries(n.vectorsByProjectionName)) {
13004
12986
  const i = t[s];
13005
- r[s] = i !== void 0 ? kx(o, 1 + i) : new Float32Array(o);
12987
+ r[s] = i !== void 0 ? Ix(o, 1 + i) : new Float32Array(o);
13006
12988
  }
13007
12989
  return {
13008
12990
  stateId: n.stateId,
@@ -13039,9 +13021,9 @@ function Lc(e, t, n, r) {
13039
13021
  }
13040
13022
  let u = 0, p = 0, d = 0;
13041
13023
  for (const [m, w] of Object.entries(c.projectionWeights)) {
13042
- const S = e.vectorsByProjectionName[m];
13043
- if (!S) continue;
13044
- const v = n[m] ?? 1, P = w * v, x = Ix(S, l.low, l.high);
13024
+ const v = e.vectorsByProjectionName[m];
13025
+ if (!v) continue;
13026
+ const S = n[m] ?? 1, P = w * S, x = kx(v, l.low, l.high);
13045
13027
  u += x * P, p += P, d += 1;
13046
13028
  }
13047
13029
  if (p === 0) {
@@ -13081,12 +13063,12 @@ async function Lx({ leftStates: e, rightStates: t, intent: n }, r = {}) {
13081
13063
  for (const [f, g] of l) {
13082
13064
  const m = p.vectorsByProjectionName[f], w = d.vectorsByProjectionName[f];
13083
13065
  if (m && w) {
13084
- let S = Pe(m, w);
13066
+ let v = Pe(m, w);
13085
13067
  if (c) {
13086
- const v = Pe(c, m), P = Pe(c, w);
13087
- S = S * 0.6 + (v + P) * 0.2;
13068
+ const S = Pe(c, m), P = Pe(c, w);
13069
+ v = v * 0.6 + (S + P) * 0.2;
13088
13070
  }
13089
- h += S * g, y += g;
13071
+ h += v * g, y += g;
13090
13072
  }
13091
13073
  }
13092
13074
  const b = y > 0 ? h / y : 0;
@@ -13122,7 +13104,7 @@ const Bx = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13122
13104
  debugPromptGlobally: Po,
13123
13105
  debugPromptGloballyIfChanged: To,
13124
13106
  debugResultGlobally: Eo,
13125
- debugResultGloballyIfChanged: Io,
13107
+ debugResultGloballyIfChanged: ko,
13126
13108
  defaultRules: vn,
13127
13109
  findRule: mu,
13128
13110
  systemPrompt: ae
@@ -13217,19 +13199,19 @@ function zx(e = {}) {
13217
13199
  "eventToTrace",
13218
13200
  "scopePhase",
13219
13201
  "nameStep"
13220
- ]), S = /* @__PURE__ */ new Set(["embedObject"]), v = {};
13202
+ ]), v = /* @__PURE__ */ new Set(["embedObject"]), S = {};
13221
13203
  for (const [P, x] of Object.entries(rl))
13222
13204
  if (!w.has(P)) {
13223
- if (S.has(P) && typeof x == "object" && x !== null) {
13224
- v[P] = Object.fromEntries(
13225
- Object.entries(x).map(([E, O]) => [E, hn(m, O)])
13205
+ if (v.has(P) && typeof x == "object" && x !== null) {
13206
+ S[P] = Object.fromEntries(
13207
+ Object.entries(x).map(([E, I]) => [E, hn(m, I)])
13226
13208
  );
13227
13209
  continue;
13228
13210
  }
13229
- v[P] = hn(m, x);
13211
+ S[P] = hn(m, x);
13230
13212
  }
13231
13213
  return {
13232
- ...v,
13214
+ ...S,
13233
13215
  config: m,
13234
13216
  modelService: y,
13235
13217
  embeddingService: b,
@@ -13247,13 +13229,13 @@ export {
13247
13229
  Pi as A,
13248
13230
  Rn as B,
13249
13231
  xm as C,
13250
- k as D,
13232
+ A as D,
13251
13233
  z as E,
13252
13234
  Ei as F,
13253
13235
  Ti as G,
13254
13236
  Cm as H,
13255
- Ii as I,
13256
- ki as J,
13237
+ ki as I,
13238
+ Ii as J,
13257
13239
  Ai as K,
13258
13240
  Oi as L,
13259
13241
  Ci as M,
@@ -13298,8 +13280,8 @@ export {
13298
13280
  va as aM,
13299
13281
  wa as aN,
13300
13282
  Ea as aO,
13301
- Ia as aP,
13302
- ka as aQ,
13283
+ ka as aP,
13284
+ Ia as aQ,
13303
13285
  Oa as aR,
13304
13286
  _a as aS,
13305
13287
  Ca as aT,
@@ -13323,11 +13305,11 @@ export {
13323
13305
  Ze as ak,
13324
13306
  Gf as al,
13325
13307
  be as am,
13326
- ue as an,
13308
+ me as an,
13327
13309
  je as ao,
13328
13310
  ca as ap,
13329
13311
  Oe as aq,
13330
- ke as ar,
13312
+ Ie as ar,
13331
13313
  qn as as,
13332
13314
  hg as at,
13333
13315
  gg as au,
@@ -13349,8 +13331,8 @@ export {
13349
13331
  Qa as b8,
13350
13332
  ec as b9,
13351
13333
  Ec as bA,
13352
- Ic as bB,
13353
- kc as bC,
13334
+ kc as bB,
13335
+ Ic as bC,
13354
13336
  Ac as bD,
13355
13337
  xt as bE,
13356
13338
  aS as bF,
@@ -13401,7 +13383,7 @@ export {
13401
13383
  er as bx,
13402
13384
  Pc as by,
13403
13385
  Tc as bz,
13404
- I as c,
13386
+ k as c,
13405
13387
  ye as c0,
13406
13388
  fe as c1,
13407
13389
  cp as c2,
@@ -13411,7 +13393,7 @@ export {
13411
13393
  U as c6,
13412
13394
  qe as c7,
13413
13395
  ES as c8,
13414
- IS as c9,
13396
+ kS as c9,
13415
13397
  nu as cA,
13416
13398
  eu as cB,
13417
13399
  ru as cC,
@@ -13431,7 +13413,7 @@ export {
13431
13413
  zx as cQ,
13432
13414
  Sl as cR,
13433
13415
  il as cS,
13434
- kS as ca,
13416
+ IS as ca,
13435
13417
  AS as cb,
13436
13418
  OS as cc,
13437
13419
  _S as cd,
@@ -13439,7 +13421,7 @@ export {
13439
13421
  jS as cf,
13440
13422
  NS as cg,
13441
13423
  RS as ch,
13442
- In as ci,
13424
+ kn as ci,
13443
13425
  Aa as cj,
13444
13426
  MS as ck,
13445
13427
  xn as cl,
@@ -13459,20 +13441,20 @@ export {
13459
13441
  Zl as cz,
13460
13442
  $ as d,
13461
13443
  W as e,
13462
- Ie as f,
13463
- q as g,
13444
+ ke as f,
13445
+ F as g,
13464
13446
  K as h,
13465
13447
  o0 as i,
13466
13448
  C as j,
13467
13449
  N as k,
13468
13450
  M as l,
13469
13451
  cv as m,
13470
- A as n,
13452
+ O as n,
13471
13453
  ac as o,
13472
13454
  Q as p,
13473
13455
  ov as q,
13474
13456
  _ as r,
13475
- L as s,
13457
+ B as s,
13476
13458
  Ux as t,
13477
13459
  On as u,
13478
13460
  _n as v,