@far-world-labs/verblets 0.7.2 → 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.2", 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.2", 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",
@@ -4769,9 +4751,10 @@ const Or = async function(e, t, n = {}) {
4769
4751
  });
4770
4752
  if (!Array.isArray(f))
4771
4753
  throw new Error(`Expected array from listBatch, got: ${typeof f}`);
4772
- f.forEach((g, m) => {
4773
- c[d + m] = g;
4774
- }), u(p.length);
4754
+ const g = Math.min(f.length, p.length);
4755
+ for (let m = 0; m < g; m++)
4756
+ c[d + m] = f[m];
4757
+ u(p.length);
4775
4758
  } catch (b) {
4776
4759
  if (b.name === "AbortError" || n?.abortSignal?.aborted || s === z.strict) throw b;
4777
4760
  u(p.length);
@@ -4785,10 +4768,10 @@ const Or = async function(e, t, n = {}) {
4785
4768
  ), c;
4786
4769
  }, Oe = async function(e, t, n) {
4787
4770
  [t, n] = K(t, n);
4788
- const { text: r, context: s } = N(t, []), o = A(Ar, n), i = I(Ar, o.onProgress, o);
4789
- 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 });
4790
4773
  try {
4791
- const { maxAttempts: a, maxParallel: c, errorPosture: l } = await q(o, {
4774
+ const { maxAttempts: a, maxParallel: c, errorPosture: l } = await F(o, {
4792
4775
  maxAttempts: 3,
4793
4776
  maxParallel: 3,
4794
4777
  errorPosture: z.resilient
@@ -4802,16 +4785,16 @@ const Or = async function(e, t, n = {}) {
4802
4785
  });
4803
4786
  for (let b = 1; b < a; b += 1) {
4804
4787
  const f = [], g = [];
4805
- if (p.forEach((w, S) => {
4806
- 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]));
4807
4790
  }), g.length === 0) break;
4808
4791
  (await Or(g, r, {
4809
4792
  ...o,
4810
4793
  maxAttempts: a,
4811
4794
  maxParallel: c,
4812
4795
  _context: s
4813
- })).forEach((w, S) => {
4814
- p[f[S]] = w;
4796
+ })).forEach((w, v) => {
4797
+ p[f[v]] = w;
4815
4798
  });
4816
4799
  }
4817
4800
  let d = 0;
@@ -4827,7 +4810,7 @@ const Or = async function(e, t, n = {}) {
4827
4810
  failedItems: d,
4828
4811
  outcome: h
4829
4812
  };
4830
- 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;
4831
4814
  } catch (a) {
4832
4815
  throw i.error(a), a;
4833
4816
  }
@@ -4890,8 +4873,8 @@ function bh(e = "central_tendency_result", t = void 0) {
4890
4873
  return C(e, t || fh);
4891
4874
  }
4892
4875
  async function Wi(e, t, n = {}) {
4893
- const r = A(_r, n), s = I(_r, r.onProgress, r);
4894
- 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 });
4895
4878
  try {
4896
4879
  const { text: o, context: i } = N(e, []);
4897
4880
  if (!o || typeof o != "string")
@@ -4904,7 +4887,7 @@ ${i}` : "", p = bh("central_tendency_result"), d = await _(`${l}${u}`, {
4904
4887
  ...r,
4905
4888
  responseFormat: p
4906
4889
  });
4907
- 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;
4908
4891
  } catch (o) {
4909
4892
  throw s.error(o), o;
4910
4893
  }
@@ -4970,9 +4953,9 @@ async function Vi(e, t, n = {}) {
4970
4953
  return [];
4971
4954
  if (!Array.isArray(t) || t.length === 0)
4972
4955
  throw new Error("seedItems must be a non-empty array");
4973
- const r = A(jr, n), s = I(jr, r.onProgress, r);
4974
- s.start(), s.emit({ event: k.input, value: e });
4975
- 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, {
4976
4959
  batchSize: 5
4977
4960
  });
4978
4961
  try {
@@ -4980,13 +4963,13 @@ async function Vi(e, t, n = {}) {
4980
4963
  ...r,
4981
4964
  batchSize: o,
4982
4965
  responseFormat: wh,
4983
- onProgress: L(r.onProgress, "map:evaluation")
4966
+ onProgress: B(r.onProgress, "map:evaluation")
4984
4967
  }), c = (p) => p && typeof p == "object" && typeof p.score == "number", l = a.filter(c).length, u = {
4985
4968
  totalItems: a.length,
4986
4969
  successCount: l,
4987
4970
  failureCount: a.length - l
4988
4971
  };
4989
- 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;
4990
4973
  } catch (i) {
4991
4974
  throw s.error(i), i;
4992
4975
  }
@@ -5008,12 +4991,12 @@ const Nr = {
5008
4991
  }, Rr = "reduce", Sh = C(
5009
4992
  Nr.name,
5010
4993
  Nr.schema
5011
- ), Ie = async function(t, n, r) {
4994
+ ), ke = async function(t, n, r) {
5012
4995
  [n, r] = K(n, r);
5013
- const { text: s, context: o } = N(n, []), i = A(Rr, r), a = I(Rr, i.onProgress, i);
5014
- 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 });
5015
4998
  try {
5016
- const { accumulatorMode: c } = await q(i, {
4999
+ const { accumulatorMode: c } = await F(i, {
5017
5000
  accumulatorMode: "auto"
5018
5001
  });
5019
5002
  let l = i.initial;
@@ -5027,7 +5010,7 @@ const Nr = {
5027
5010
  for (const { items: b, skip: f } of p) {
5028
5011
  if (f) continue;
5029
5012
  const g = je(i.listStyle, b, i.autoModeThreshold), m = ({ style: x, count: E }) => {
5030
- const O = x === ue.XML ? "XML" : "", R = o ? `
5013
+ const I = x === me.XML ? "XML" : "", R = o ? `
5031
5014
 
5032
5015
  ${o}` : "";
5033
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.
@@ -5045,15 +5028,15 @@ ${$(l !== void 0 ? l : "No initial value - use first item as starting point", {
5045
5028
  tag: "accumulator"
5046
5029
  })}
5047
5030
 
5048
- Process exactly ${E} items from the ${O} list below and return the final accumulator value.${R}`;
5049
- }, 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 = {
5050
5033
  ...i,
5051
5034
  listStyle: g,
5052
5035
  responseFormat: w
5053
- }, P = await M(() => be(b, S, v), {
5036
+ }, P = await M(() => be(b, v, S), {
5054
5037
  label: "reduce:batch",
5055
5038
  config: i,
5056
- onProgress: L(i.onProgress, "batch")
5039
+ onProgress: B(i.onProgress, "batch")
5057
5040
  });
5058
5041
  !i.responseFormat && P?.accumulator !== void 0 ? l = P.accumulator : l = P, d(b.length);
5059
5042
  }
@@ -5067,12 +5050,12 @@ Process exactly ${E} items from the ${O} list below and return the final accumul
5067
5050
  totalBatches: h.length,
5068
5051
  outcome: T.success
5069
5052
  };
5070
- 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;
5071
5054
  } catch (c) {
5072
5055
  throw a.error(c), c;
5073
5056
  }
5074
5057
  };
5075
- Ie.knownTexts = [];
5058
+ ke.knownTexts = [];
5076
5059
  const Mr = {
5077
5060
  name: "pattern_candidates",
5078
5061
  schema: {
@@ -5126,9 +5109,9 @@ function sn(e, t = 50, n = 10) {
5126
5109
  return r;
5127
5110
  }
5128
5111
  async function Ji(e, t = {}) {
5129
- const n = A(Lr, t), r = I(Lr, n.onProgress, n);
5130
- r.start(), r.emit({ event: k.input, value: e });
5131
- 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, {
5132
5115
  thoroughness: J(xh, ["topN", "capacity"]),
5133
5116
  maxStringLength: 50,
5134
5117
  maxArrayLength: 10
@@ -5161,28 +5144,28 @@ async function Ji(e, t = {}) {
5161
5144
  Return all candidates. If the input list is empty, return an empty array.
5162
5145
  `;
5163
5146
  try {
5164
- const p = r.batch(l.length), d = await Ie(l, u, {
5147
+ const p = r.batch(l.length), d = await ke(l, u, {
5165
5148
  ...n,
5166
5149
  initial: [],
5167
5150
  responseFormat: $h,
5168
- onProgress: L(n.onProgress, "reduce:accumulate")
5151
+ onProgress: B(n.onProgress, "reduce:accumulate")
5169
5152
  });
5170
5153
  if (p(l.length), !Array.isArray(d))
5171
5154
  return r.complete({ outcome: T.success }), [];
5172
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);
5173
- 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;
5174
5157
  } catch (p) {
5175
5158
  throw r.error(p), p;
5176
5159
  }
5177
5160
  }
5178
5161
  Ji.knownTexts = [];
5179
- const Ph = () => !!D("VERBLETS_DEBUG"), ne = (...e) => {
5162
+ const Ph = () => !!q("VERBLETS_DEBUG"), ne = (...e) => {
5180
5163
  Ph() && console.error(...e);
5181
- }, 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 = {
5182
5165
  $schema: Th,
5183
5166
  type: Eh,
5184
- required: Ih,
5185
- properties: kh,
5167
+ required: kh,
5168
+ properties: Ih,
5186
5169
  additionalProperties: Ah
5187
5170
  }, Br = "detect-threshold";
5188
5171
  function Ki(e, t) {
@@ -5211,9 +5194,9 @@ function Ki(e, t) {
5211
5194
  }
5212
5195
  async function Gi(e, t, n, r) {
5213
5196
  [n, r] = K(n, r);
5214
- 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);
5215
5198
  a.start();
5216
- const { batchSize: c } = await q(i, {
5199
+ const { batchSize: c } = await F(i, {
5217
5200
  batchSize: 50
5218
5201
  });
5219
5202
  if (!e || !Array.isArray(e) || e.length === 0)
@@ -5224,7 +5207,7 @@ async function Gi(e, t, n, r) {
5224
5207
  throw new Error("Goal must be specified to determine appropriate thresholds");
5225
5208
  try {
5226
5209
  const l = r.stats ?? Ki(e, t);
5227
- a.emit({ event: k.phase, phase: "statistics", stats: l });
5210
+ a.emit({ event: A.phase, phase: "statistics", stats: l });
5228
5211
  const u = e.map((P) => ({
5229
5212
  value: P[t],
5230
5213
  percentileRank: Math.round(
@@ -5292,14 +5275,14 @@ Return the updated accumulator as valid JSON.`, o].filter(Boolean).join(`
5292
5275
  const x = u.slice(P, P + b);
5293
5276
  f.push(JSON.stringify(x));
5294
5277
  }
5295
- a.emit({ event: k.phase, phase: "enriched", enrichedData: u });
5296
- const m = await Ie(f, y, {
5278
+ a.emit({ event: A.phase, phase: "enriched", enrichedData: u });
5279
+ const m = await ke(f, y, {
5297
5280
  ...i,
5298
5281
  initial: JSON.stringify(d),
5299
5282
  batchSize: c,
5300
5283
  responseFormat: C("analysis_accumulator", p),
5301
- onProgress: L(i.onProgress, "reduce:analysis")
5302
- }), 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.
5303
5286
 
5304
5287
  ${$(s, { tag: "goal" })}
5305
5288
 
@@ -5332,8 +5315,8 @@ Generate specific threshold recommendations that:
5332
5315
 
5333
5316
  Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
5334
5317
 
5335
- `), v = await M(
5336
- () => _(S, {
5318
+ `), S = await M(
5319
+ () => _(v, {
5337
5320
  ...i,
5338
5321
  responseFormat: C("threshold_result", Oh)
5339
5322
  }),
@@ -5342,9 +5325,9 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
5342
5325
  config: i
5343
5326
  }
5344
5327
  );
5345
- 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(
5346
5329
  `Threshold value ${P.value} is outside data range [${l.min}, ${l.max}]`
5347
- ), !1) : !0)), v.distributionAnalysis = {
5330
+ ), !1) : !0)), S.distributionAnalysis = {
5348
5331
  mean: l.mean,
5349
5332
  median: l.median,
5350
5333
  standardDeviation: l.stdDev,
@@ -5352,7 +5335,7 @@ Return threshold candidates with their rationales.`, o].filter(Boolean).join(`
5352
5335
  max: l.max,
5353
5336
  percentiles: l.percentiles,
5354
5337
  dataPoints: l.count
5355
- }, a.complete({ outcome: T.success }), v;
5338
+ }, a.complete({ outcome: T.success }), S;
5356
5339
  } catch (l) {
5357
5340
  throw a.error(l), l;
5358
5341
  }
@@ -5373,7 +5356,7 @@ function Lh({ spec: e, text: t, ...n }) {
5373
5356
  };
5374
5357
  }
5375
5358
  async function Yi(e, t = {}) {
5376
- 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.
5377
5360
 
5378
5361
  ${$(e, { tag: "entity-instructions" })}
5379
5362
 
@@ -5395,7 +5378,7 @@ Keep it simple and actionable.`;
5395
5378
  );
5396
5379
  }
5397
5380
  async function Bh(e, t, n = {}) {
5398
- 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.
5399
5382
 
5400
5383
  ${$(t, { tag: "entity-specification" })}
5401
5384
 
@@ -5419,11 +5402,11 @@ Include every entity that matches the specification. Do not add properties beyon
5419
5402
  }
5420
5403
  async function Hi(e, t, n) {
5421
5404
  [t, n] = K(t, n, ["spec"]);
5422
- 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);
5423
5406
  a.start();
5424
5407
  try {
5425
5408
  a.emit({
5426
- event: k.step,
5409
+ event: A.step,
5427
5410
  stepName: "generating-specification",
5428
5411
  instructions: r
5429
5412
  });
@@ -5431,12 +5414,12 @@ async function Hi(e, t, n) {
5431
5414
 
5432
5415
  ${o}` : r, {
5433
5416
  ...i,
5434
- onProgress: L(i.onProgress, "spec")
5417
+ onProgress: B(i.onProgress, "spec")
5435
5418
  });
5436
- a.emit({ event: k.step, stepName: "extracting-entities", specification: c });
5419
+ a.emit({ event: A.step, stepName: "extracting-entities", specification: c });
5437
5420
  const l = await Bh(e, c, {
5438
5421
  ...i,
5439
- onProgress: L(i.onProgress, "apply")
5422
+ onProgress: B(i.onProgress, "apply")
5440
5423
  });
5441
5424
  return a.complete({ outcome: T.success }), l;
5442
5425
  } catch (c) {
@@ -5506,9 +5489,9 @@ async function Xi(e, t, n) {
5506
5489
  [t, n] = K(t, n);
5507
5490
  const { text: r, context: s } = N(t, []), o = s ? `${r}
5508
5491
 
5509
- ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5510
- a.start(), a.emit({ event: k.input, value: e });
5511
- 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, {
5512
5495
  precision: J(qh, ["windowSize", "overlapSize"]),
5513
5496
  maxParallel: 3,
5514
5497
  maxAttempts: void 0,
@@ -5523,7 +5506,7 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5523
5506
  for (let x = 0; x < b; x += l - u)
5524
5507
  f.push(x);
5525
5508
  a.emit({
5526
- event: k.phase,
5509
+ event: A.phase,
5527
5510
  phase: "windowing",
5528
5511
  totalLines: b,
5529
5512
  windowCount: f.length,
@@ -5536,17 +5519,17 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5536
5519
  totalItems: f.length,
5537
5520
  totalBatches: f.length,
5538
5521
  maxParallel: c
5539
- }), a.emit({ event: k.phase, phase: "extraction" });
5522
+ }), a.emit({ event: A.phase, phase: "extraction" });
5540
5523
  const m = await Q(
5541
5524
  f,
5542
5525
  async (x) => {
5543
- 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(
5544
5527
  async () => {
5545
- const F = await _(R, {
5528
+ const L = await _(R, {
5546
5529
  ...i,
5547
5530
  responseFormat: Qi
5548
5531
  });
5549
- return Fh(F);
5532
+ return Fh(L);
5550
5533
  },
5551
5534
  {
5552
5535
  label: "extract-blocks:window",
@@ -5554,7 +5537,7 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5554
5537
  maxAttempts: p,
5555
5538
  retryMode: d,
5556
5539
  retryOnAll: h,
5557
- onProgress: L(i.onProgress, "window")
5540
+ onProgress: B(i.onProgress, "window")
5558
5541
  }
5559
5542
  );
5560
5543
  return g(1), j;
@@ -5566,26 +5549,26 @@ ${s}` : r, i = A(qr, n), a = I(qr, i.onProgress, i);
5566
5549
  }
5567
5550
  );
5568
5551
  a.emit({
5569
- event: k.phase,
5552
+ event: A.phase,
5570
5553
  phase: "merging",
5571
5554
  rawBlocks: m.flat().length
5572
5555
  });
5573
- 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 = [];
5574
5557
  for (const x of w) {
5575
- const E = S[S.length - 1];
5576
- !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);
5577
5560
  }
5578
- const v = S.map(
5561
+ const S = v.map(
5579
5562
  ({ startLine: x, endLine: E }) => y.slice(x, E + 1)
5580
5563
  );
5581
5564
  a.progress({
5582
5565
  event: W.complete,
5583
5566
  totalItems: f.length,
5584
5567
  processedItems: g.count,
5585
- blocksExtracted: v.length
5568
+ blocksExtracted: S.length
5586
5569
  });
5587
- const P = { blocksExtracted: v.length, outcome: T.success };
5588
- 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;
5589
5572
  } catch (y) {
5590
5573
  throw a.error(y), y;
5591
5574
  }
@@ -5624,13 +5607,13 @@ const zr = {
5624
5607
  zr.schema
5625
5608
  ), Zi = async function(t, n, r) {
5626
5609
  [n, r] = K(n, r, ["guidance"]);
5627
- const { text: s, known: o, context: i } = N(n, ["guidance"]), a = A(Ur, r), c = I(Ur, a.onProgress, a);
5628
- 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 });
5629
5612
  const {
5630
5613
  guidance: l,
5631
5614
  errorPosture: u,
5632
5615
  maxParallel: p = 3
5633
- } = await q(a, {
5616
+ } = await F(a, {
5634
5617
  strictness: J(Uh, ["guidance", "errorPosture"])
5635
5618
  }), d = o.guidance ?? l, h = new Array(t.length), y = await Ae(t, a), b = c.batch(t.length);
5636
5619
  c.progress({
@@ -5638,7 +5621,7 @@ const zr = {
5638
5621
  totalItems: t.length,
5639
5622
  totalBatches: y.length
5640
5623
  });
5641
- const f = ({ style: S, count: v }) => {
5624
+ const f = ({ style: v, count: S }) => {
5642
5625
  const P = d ? `
5643
5626
 
5644
5627
  ${$(d, { tag: "borderline-handling" })}` : "", x = i ? `
@@ -5652,34 +5635,42 @@ IMPORTANT:
5652
5635
  - Consider all aspects of the filtering criteria
5653
5636
  - Return only "yes" or "no" for each item
5654
5637
  - Maintain the exact order of the input list${x}`;
5655
- return S === ue.NEWLINE ? `${E}
5638
+ return v === me.NEWLINE ? `${E}
5656
5639
 
5657
- 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}
5658
5641
 
5659
- 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.`;
5660
5643
  };
5661
5644
  await Q(
5662
5645
  y,
5663
- async ({ items: S, startIndex: v }) => {
5664
- 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 = {
5665
5648
  ...a,
5666
5649
  listStyle: P,
5667
5650
  responseFormat: a.responseFormat ?? Wh
5668
5651
  };
5669
5652
  try {
5670
- const O = await M(() => be(S, x, E), {
5653
+ const I = await M(() => be(v, x, E), {
5671
5654
  label: "filter:batch",
5672
5655
  config: a,
5673
- onProgress: L(a.onProgress, "batch")
5656
+ onProgress: B(a.onProgress, "batch")
5674
5657
  });
5675
- S.forEach((R, j) => {
5676
- h[v + j] = O[j]?.toLowerCase().trim() === "yes";
5677
- }), b(S.length);
5678
- } catch (O) {
5679
- if (O.name === "AbortError" || a?.abortSignal?.aborted || u === z.strict) throw O;
5680
- c.error(O, { startIndex: v, itemCount: S.length });
5681
- for (let R = 0; R < S.length; R++)
5682
- 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);
5683
5674
  }
5684
5675
  },
5685
5676
  {
@@ -5688,14 +5679,14 @@ Process exactly ${v} items from the XML list below and return ${v} yes/no decisi
5688
5679
  abortSignal: a.abortSignal
5689
5680
  }
5690
5681
  );
5691
- const g = t.filter((S, v) => h[v]);
5682
+ const g = t.filter((v, S) => h[S]);
5692
5683
  c.progress({
5693
5684
  event: W.complete,
5694
5685
  totalItems: t.length,
5695
5686
  processedItems: b.count
5696
5687
  });
5697
- const m = h.some((S) => S === void 0) ? T.partial : T.success, w = { inputCount: t.length, outputCount: g.length, outcome: m };
5698
- 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;
5699
5690
  };
5700
5691
  Zi.knownTexts = ["guidance"];
5701
5692
  const Wr = {
@@ -5718,15 +5709,15 @@ const Wr = {
5718
5709
  }
5719
5710
  }, Vr = "find", Vh = C(Wr.name, Wr.schema), ea = async function(t, n, r) {
5720
5711
  [n, r] = K(n, r);
5721
- const { text: s, context: o } = N(n, []), i = A(Vr, r), a = I(Vr, i.onProgress, i);
5722
- a.start(), a.emit({ event: k.input, value: t });
5723
- 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, {
5724
5715
  maxParallel: 3,
5725
5716
  errorPosture: z.resilient
5726
5717
  }), u = ({ style: g, count: m }) => {
5727
5718
  const w = o ? `
5728
5719
 
5729
- ${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.
5730
5721
 
5731
5722
  ${$(s, { tag: "search-criteria" })}
5732
5723
 
@@ -5736,9 +5727,9 @@ IMPORTANT:
5736
5727
  - Return the complete original item text, unchanged
5737
5728
  - If NO items match the criteria, return an empty string
5738
5729
  - Return ONLY ONE item, even if multiple items match${w}`;
5739
- return g === ue.NEWLINE ? `${S}
5730
+ return g === me.NEWLINE ? `${v}
5740
5731
 
5741
- 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}
5742
5733
 
5743
5734
  Process exactly ${m} items from the XML list below and return the single best match.`;
5744
5735
  }, p = [];
@@ -5753,29 +5744,29 @@ Process exactly ${m} items from the XML list below and return the single best ma
5753
5744
  const m = b.slice(g, g + c);
5754
5745
  await Q(
5755
5746
  m,
5756
- async ({ items: w, startIndex: S }) => {
5757
- const v = je(i.listStyle, w, i.autoModeThreshold);
5747
+ async ({ items: w, startIndex: v }) => {
5748
+ const S = je(i.listStyle, w, i.autoModeThreshold);
5758
5749
  try {
5759
5750
  const P = await M(
5760
- () => be(w, u({ style: v, count: w.length }), {
5751
+ () => be(w, u({ style: S, count: w.length }), {
5761
5752
  ...i,
5762
- listStyle: v,
5753
+ listStyle: S,
5763
5754
  responseFormat: i.responseFormat || Vh
5764
5755
  }),
5765
5756
  {
5766
5757
  label: "find:batch",
5767
5758
  config: i,
5768
- onProgress: L(i.onProgress, "batch")
5759
+ onProgress: B(i.onProgress, "batch")
5769
5760
  }
5770
5761
  ), x = Array.isArray(P) && P[0];
5771
5762
  if (x) {
5772
- const E = t.findIndex((R) => R === x), O = E !== -1 ? E : S;
5773
- 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 });
5774
5765
  }
5775
5766
  y(w.length);
5776
5767
  } catch (P) {
5777
- if (a.error(P, { startIndex: S, itemCount: w.length }), l === z.strict) throw P;
5778
- 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}`);
5779
5770
  }
5780
5771
  },
5781
5772
  {
@@ -5792,12 +5783,12 @@ Process exactly ${m} items from the XML list below and return the single best ma
5792
5783
  found: p.length > 0
5793
5784
  }), p.length > 0) {
5794
5785
  const g = p.reduce(
5795
- (w, S) => S.index < w.index ? S : w
5786
+ (w, v) => v.index < w.index ? v : w
5796
5787
  ), m = { found: !0, totalItems: t.length, outcome: T.success };
5797
- 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;
5798
5789
  }
5799
5790
  const f = { found: !1, totalItems: t.length, outcome: T.success };
5800
- return a.emit({ event: k.output, value: "" }), a.complete(f), "";
5791
+ return a.emit({ event: A.output, value: "" }), a.complete(f), "";
5801
5792
  };
5802
5793
  ea.knownTexts = [];
5803
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 = {
@@ -5814,9 +5805,9 @@ const Jh = "http://json-schema.org/draft-07/schema#", Kh = "object", Gh = { item
5814
5805
  let ef = si;
5815
5806
  const tf = 10, nf = (e) => [...new Set(e.filter((t) => t.trim() !== ""))], Bn = async (e, t, n) => {
5816
5807
  [t, n] = K(t, n);
5817
- 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);
5818
5809
  i.start();
5819
- 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, {
5820
5811
  effort: J(Xh, ["extremeK", "iterations", "selectBottom"]),
5821
5812
  batchSize: tf
5822
5813
  }), p = nf(e);
@@ -5829,8 +5820,8 @@ const tf = 10, nf = (e) => [...new Set(e.filter((t) => t.trim() !== ""))], Bn =
5829
5820
  iterations: l,
5830
5821
  criteria: t
5831
5822
  });
5832
- const d = async (v) => {
5833
- const P = ef({ description: r }, v);
5823
+ const d = async (S) => {
5824
+ const P = ef({ description: r }, S);
5834
5825
  if (Array.isArray(P))
5835
5826
  return P;
5836
5827
  const x = s ? `${P}
@@ -5841,67 +5832,67 @@ ${s}` : P, E = await M(
5841
5832
  label: "sort-batch",
5842
5833
  config: o
5843
5834
  }
5844
- ), O = E?.items || E;
5845
- return Array.isArray(O) ? O.filter(Boolean) : [];
5846
- }, h = async (v, P) => {
5847
- const x = Ce(a)(v);
5848
- 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;
5849
5840
  const j = i.batch(x.length);
5850
- for (const F of x) {
5841
+ for (const L of x) {
5851
5842
  i.emit({
5852
- event: k.step,
5843
+ event: A.step,
5853
5844
  stepName: "sorting-chunk",
5854
5845
  iteration: P,
5855
5846
  chunkNumber: R + 1,
5856
5847
  totalChunks: x.length,
5857
- batchSize: F.length
5848
+ batchSize: L.length
5858
5849
  });
5859
- const V = [...F, ...E, ...u ? O : []];
5850
+ const V = [...L, ...E, ...u ? I : []];
5860
5851
  let Y = await d(V);
5861
5852
  const H = new Set(V), ee = new Set(Y);
5862
5853
  if (Y.length !== V.length || ee.size !== H.size) {
5863
- const pe = V.filter((te) => !ee.has(te));
5854
+ const ue = V.filter((te) => !ee.has(te));
5864
5855
  Y = [...Y.filter(
5865
- (te, ie, de) => H.has(te) && de.indexOf(te) === ie
5866
- ), ...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}`);
5867
5858
  }
5868
5859
  if (E = Y.slice(0, Math.min(c, Y.length)), u) {
5869
- const pe = Math.max(0, Y.length - E.length), G = Math.min(c, pe);
5870
- 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) : [];
5871
5862
  }
5872
5863
  R++, j(1);
5873
5864
  }
5874
5865
  return {
5875
5866
  top: E,
5876
- bottom: u ? O : [],
5877
- selected: /* @__PURE__ */ new Set([...E, ...u ? O : []])
5867
+ bottom: u ? I : [],
5868
+ selected: /* @__PURE__ */ new Set([...E, ...u ? I : []])
5878
5869
  };
5879
5870
  }, y = [], b = [];
5880
5871
  let f = p;
5881
- for (let v = 0; v < l && f.length > 0; v++) {
5872
+ for (let S = 0; S < l && f.length > 0; S++) {
5882
5873
  i.emit({
5883
- event: k.step,
5874
+ event: A.step,
5884
5875
  stepName: "extracting-extremes",
5885
- iteration: v + 1,
5876
+ iteration: S + 1,
5886
5877
  totalIterations: l,
5887
5878
  remainingItems: f.length
5888
5879
  });
5889
- const { top: P, bottom: x, selected: E } = await h(f, v + 1);
5890
- y.push(...P), u && b.unshift(...x), f = f.filter((O) => !E.has(O)), i.emit({
5891
- 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,
5892
5883
  stepName: "iteration-complete",
5893
- iteration: v + 1,
5884
+ iteration: S + 1,
5894
5885
  totalIterations: l,
5895
5886
  topCount: y.length,
5896
5887
  bottomCount: b.length,
5897
5888
  remainingItems: f.length
5898
5889
  });
5899
5890
  }
5900
- const g = u ? [...y, ...f, ...b] : [...y, ...f], m = new Set(p), w = /* @__PURE__ */ new Set(), S = [];
5901
- for (const v of g)
5902
- m.has(v) && !w.has(v) && (w.add(v), S.push(v));
5903
- for (const v of p)
5904
- 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);
5905
5896
  return i.progress({
5906
5897
  event: W.complete,
5907
5898
  totalItems: p.length,
@@ -5909,7 +5900,7 @@ ${s}` : P, E = await M(
5909
5900
  topItems: y.length,
5910
5901
  bottomItems: b.length,
5911
5902
  remainingItems: f.length
5912
- }), i.complete({ outcome: T.success, totalItems: p.length }), S;
5903
+ }), i.complete({ outcome: T.success, totalItems: p.length }), v;
5913
5904
  } catch (d) {
5914
5905
  throw i.error(d), d;
5915
5906
  }
@@ -5949,9 +5940,9 @@ const Kr = {
5949
5940
  Kr.schema
5950
5941
  );
5951
5942
  async function ta(e, t = {}) {
5952
- 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);
5953
5944
  i.start();
5954
- 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, {
5955
5946
  maxTerms: 10,
5956
5947
  sortBy: "importance for understanding the content",
5957
5948
  sentencesPerBatch: 3,
@@ -5976,25 +5967,25 @@ async function ta(e, t = {}) {
5976
5967
 
5977
5968
  Return a "terms" object containing an array of the extracted terms.${s ? `
5978
5969
 
5979
- ${s}` : ""}`, S = await Oe(f, w, {
5970
+ ${s}` : ""}`, v = await Oe(f, w, {
5980
5971
  ...o,
5981
5972
  batchSize: o.batchSize ?? 1,
5982
5973
  responseFormat: rf,
5983
- onProgress: L(o.onProgress, "glossary:extract")
5974
+ onProgress: B(o.onProgress, "glossary:extract")
5984
5975
  });
5985
5976
  g(f.length);
5986
- const v = /* @__PURE__ */ new Set();
5987
- S.forEach((P) => {
5977
+ const S = /* @__PURE__ */ new Set();
5978
+ v.forEach((P) => {
5988
5979
  P && P.terms && Array.isArray(P.terms) && P.terms.forEach((x) => {
5989
- x && typeof x == "string" && v.add(x);
5980
+ x && typeof x == "string" && S.add(x);
5990
5981
  });
5991
- }), p = Array.from(v);
5982
+ }), p = Array.from(S);
5992
5983
  }
5993
- 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)
5994
5985
  return i.complete({ outcome: T.success, terms: 0 }), [];
5995
5986
  const h = (await Bn(p, c, {
5996
5987
  ...o,
5997
- onProgress: L(o.onProgress, "glossary:sort")
5988
+ onProgress: B(o.onProgress, "glossary:sort")
5998
5989
  })).slice(0, a);
5999
5990
  return i.complete({ outcome: T.success, terms: h.length }), h;
6000
5991
  } catch (p) {
@@ -6033,17 +6024,13 @@ PROCESS:
6033
6024
 
6034
6025
  OUTPUT FORMAT:
6035
6026
  The accumulator should contain a comma-separated list of the current best category names.`;
6036
- }, af = (e) => ({ style: t, count: n }) => {
6037
- const r = e.join(", "), s = `Assign each item in the list below to one of these categories:
6038
-
6039
- ${$(r, { tag: "categories" })}
6040
-
6041
- Return exactly ${n} category names, one per line, in the same order as the input items.`;
6042
- return t === ue.NEWLINE ? `${s}
6027
+ }, af = (e) => ({ count: t }) => {
6028
+ const n = e.join(", ");
6029
+ return `Assign each item in the list below to one of these categories:
6043
6030
 
6044
- Process exactly ${n} items from the list below.` : `${s}
6031
+ ${$(n, { tag: "categories" })}
6045
6032
 
6046
- 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.`;
6047
6034
  }, Hr = (e) => e.split(/[,\n]/).map((t) => t.trim()).filter(Boolean), cf = (e) => {
6048
6035
  const t = {};
6049
6036
  for (const { items: n, labels: r } of e)
@@ -6058,14 +6045,14 @@ Process exactly ${n} items from the XML list below.`;
6058
6045
  };
6059
6046
  async function na(e, t, n) {
6060
6047
  [t, n] = K(t, n, ["categories"]);
6061
- 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);
6062
6049
  a.start();
6063
6050
  const {
6064
6051
  guidance: c,
6065
6052
  maxParallel: l,
6066
6053
  errorPosture: u,
6067
6054
  topN: p
6068
- } = await q(i, {
6055
+ } = await F(i, {
6069
6056
  granularity: J(sf, ["guidance", "topN"]),
6070
6057
  maxParallel: 3,
6071
6058
  errorPosture: z.resilient
@@ -6075,7 +6062,7 @@ async function na(e, t, n) {
6075
6062
  f = Hr(s.categories);
6076
6063
  else {
6077
6064
  a.emit({
6078
- event: k.phase,
6065
+ event: A.phase,
6079
6066
  phase: "category-discovery",
6080
6067
  description: "Discovering categories from items"
6081
6068
  });
@@ -6083,16 +6070,16 @@ async function na(e, t, n) {
6083
6070
  r,
6084
6071
  d,
6085
6072
  c
6086
- ), F = await Ie(e, j, {
6073
+ ), L = await ke(e, j, {
6087
6074
  ...i,
6088
6075
  initial: "",
6089
6076
  now: b,
6090
- onProgress: L(i.onProgress, "reduce:category-discovery")
6077
+ onProgress: B(i.onProgress, "reduce:category-discovery")
6091
6078
  });
6092
- f = Hr(F);
6079
+ f = Hr(L);
6093
6080
  }
6094
6081
  f.length === 0 && f.push("other"), a.emit({
6095
- event: k.phase,
6082
+ event: A.phase,
6096
6083
  phase: "assignment",
6097
6084
  description: "Assigning items to categories",
6098
6085
  categories: f,
@@ -6100,35 +6087,31 @@ async function na(e, t, n) {
6100
6087
  });
6101
6088
  const g = [], m = af(f), w = o ? (j) => `${m(j)}
6102
6089
 
6103
- ${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);
6104
6091
  await Q(
6105
- v,
6106
- async ({ items: j, startIndex: F }) => {
6092
+ S,
6093
+ async ({ items: j, startIndex: L }) => {
6107
6094
  const V = je(h, j, y);
6108
6095
  try {
6109
6096
  const Y = {
6110
6097
  ...i,
6111
6098
  listStyle: V
6112
6099
  }, H = await M(
6113
- () => be(
6114
- j,
6115
- w({ style: V, count: j.length }),
6116
- Y
6117
- ),
6100
+ () => be(j, w({ count: j.length }), Y),
6118
6101
  {
6119
6102
  label: "group:batch",
6120
6103
  config: i,
6121
- onProgress: L(i.onProgress, "assign")
6104
+ onProgress: B(i.onProgress, "assign")
6122
6105
  }
6123
6106
  );
6124
6107
  if (!Array.isArray(H) || H.length !== j.length) {
6125
6108
  const ee = new Array(j.length).fill("other");
6126
- g.push({ items: j, labels: ee, startIndex: F });
6109
+ g.push({ items: j, labels: ee, startIndex: L });
6127
6110
  } else
6128
- g.push({ items: j, labels: H, startIndex: F });
6111
+ g.push({ items: j, labels: H, startIndex: L });
6129
6112
  P(j.length);
6130
6113
  } catch (Y) {
6131
- throw a.error(Y, { startIndex: F, itemCount: j.length }), Y;
6114
+ throw a.error(Y, { startIndex: L, itemCount: j.length }), Y;
6132
6115
  }
6133
6116
  },
6134
6117
  {
@@ -6137,8 +6120,8 @@ ${o}` : m, v = await Ae(e, i), P = a.batch(e.length);
6137
6120
  abortSignal: i.abortSignal
6138
6121
  }
6139
6122
  );
6140
- const x = g.toSorted((j, F) => j.startIndex - F.startIndex), E = cf(x), O = p ? lf(E, p) : E, R = Object.keys(O).length;
6141
- 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;
6142
6125
  }
6143
6126
  na.knownTexts = ["categories"];
6144
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 = {
@@ -6173,7 +6156,7 @@ ${yf}`,
6173
6156
  };
6174
6157
  async function Dn(e, t, n) {
6175
6158
  [t, n] = K(t, n);
6176
- 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);
6177
6160
  if (i.start(), !Array.isArray(e) || e.length === 0)
6178
6161
  return i.complete({ outcome: T.success }), [];
6179
6162
  if (e.length < 2)
@@ -6224,13 +6207,13 @@ const Sf = {
6224
6207
  },
6225
6208
  required: ["items"],
6226
6209
  additionalProperties: !1
6227
- }, 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 = {
6228
6211
  $schema: xf,
6229
6212
  type: $f,
6230
6213
  description: Pf,
6231
6214
  properties: Tf,
6232
6215
  required: Ef,
6233
- additionalProperties: If
6216
+ additionalProperties: kf
6234
6217
  }, Xr = "intersections", { strictFormat: Af, contentIsQuestion: Of } = oe, _f = (e, t, n) => {
6235
6218
  const r = e.join(", "), s = `${Of} Find specific examples, instances, or elements that belong to all of the given categories.
6236
6219
 
@@ -6275,9 +6258,9 @@ ${$(t, { tag: "additional-context" })}` : "";
6275
6258
  async function oa(e, t, n) {
6276
6259
  if ([t, n] = K(t, n), !Array.isArray(e) || e.length < 2)
6277
6260
  return {};
6278
- 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);
6279
6262
  i.start();
6280
- const { useSchemaValidation: a } = await q(o, {
6263
+ const { useSchemaValidation: a } = await F(o, {
6281
6264
  useSchemaValidation: !1
6282
6265
  }), { minSize: c = 2, maxSize: l = e.length, batchSize: u = 10 } = o;
6283
6266
  try {
@@ -6289,7 +6272,7 @@ async function oa(e, t, n) {
6289
6272
  async (b) => {
6290
6273
  const f = await jf(b, r, s, {
6291
6274
  ...o,
6292
- onProgress: L(o.onProgress, "combo")
6275
+ onProgress: B(o.onProgress, "combo")
6293
6276
  });
6294
6277
  return h(1), f;
6295
6278
  },
@@ -6313,7 +6296,7 @@ async function oa(e, t, n) {
6313
6296
  }
6314
6297
  function Nf(e = "intersection_result") {
6315
6298
  return {
6316
- responseFormat: C(e, kf)
6299
+ responseFormat: C(e, If)
6317
6300
  };
6318
6301
  }
6319
6302
  async function Rf(e, t = {}) {
@@ -6357,12 +6340,12 @@ function aa() {
6357
6340
  }
6358
6341
  const Vf = (e, t) => `${Wf} ${e}
6359
6342
 
6360
- ${kn(t)}
6343
+ ${In(t)}
6361
6344
 
6362
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 = {}) {
6363
6346
  const { text: r, context: s } = N(t, []), o = s ? `${r}
6364
6347
 
6365
- ${s}` : r, i = A("list:generate", {
6348
+ ${s}` : r, i = O("list:generate", {
6366
6349
  llm: { fast: !0, good: !0, cheap: !0 },
6367
6350
  ...n
6368
6351
  }), a = [], c = {};
@@ -6376,28 +6359,28 @@ ${s}` : r, i = A("list:generate", {
6376
6359
  });
6377
6360
  let g = [];
6378
6361
  try {
6379
- const S = await M(
6362
+ const v = await M(
6380
6363
  () => _(f, { ...i, ...aa() }),
6381
6364
  {
6382
6365
  label: "list-generate",
6383
6366
  config: i
6384
6367
  }
6385
- ), v = S?.items || S;
6386
- g = Array.isArray(v) ? v.filter(Boolean) : [];
6387
- } catch (S) {
6388
- if (S.name === "AbortError")
6389
- 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;
6390
6373
  ne(
6391
- `Generate list [error]: ${S.message} ${f.slice(0, 100).replace(`
6374
+ `Generate list [error]: ${v.message} ${f.slice(0, 100).replace(`
6392
6375
  `, "\\n")}`
6393
6376
  ), l = !0;
6394
6377
  break;
6395
6378
  }
6396
- const m = g.filter((S) => !(S in c));
6379
+ const m = g.filter((v) => !(v in c));
6397
6380
  b += 1;
6398
- for (const S of m) {
6399
- const v = {
6400
- result: S,
6381
+ for (const v of m) {
6382
+ const S = {
6383
+ result: v,
6401
6384
  resultsAll: a,
6402
6385
  resultsNew: g,
6403
6386
  queryCount: b,
@@ -6405,11 +6388,11 @@ ${s}` : r, i = A("list:generate", {
6405
6388
  queryLimit: d,
6406
6389
  timeoutMs: h
6407
6390
  };
6408
- if (await p(v)) {
6391
+ if (await p(S)) {
6409
6392
  l = !0;
6410
6393
  break;
6411
6394
  }
6412
- await u(v) || (c[S] = !0, a.push(S), yield S);
6395
+ await u(S) || (c[v] = !0, a.push(v), yield v);
6413
6396
  }
6414
6397
  await p({
6415
6398
  result: void 0,
@@ -6423,7 +6406,7 @@ ${s}` : r, i = A("list:generate", {
6423
6406
  }
6424
6407
  };
6425
6408
  async function Ze(e, t = {}) {
6426
- 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);
6427
6410
  o.start();
6428
6411
  try {
6429
6412
  const { schema: i } = s, a = r ? `${n}
@@ -6436,7 +6419,7 @@ ${r}` : n, c = await M(
6436
6419
  }
6437
6420
  ), l = c?.items || c, u = Array.isArray(l) ? l : [];
6438
6421
  if (i && u.length > 0) {
6439
- o.emit({ event: k.step, stepName: "transform", itemCount: u.length });
6422
+ o.emit({ event: A.step, stepName: "transform", itemCount: u.length });
6440
6423
  const p = o.batch(u.length), d = [];
6441
6424
  for (const h of u) {
6442
6425
  const y = Vf(h, i), b = await M(() => _(y, s), {
@@ -6478,15 +6461,15 @@ const Yf = "http://json-schema.org/draft-07/schema#", Hf = "object", Qf = { item
6478
6461
  `);
6479
6462
  async function ca(e, t, n) {
6480
6463
  typeof t == "number" && (n = { ...n, count: t }, t = void 0), [t, n] = K(t, n);
6481
- const r = A(es, n), s = I(es, r.onProgress, r);
6482
- 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 });
6483
6466
  const { text: o, context: i } = N(t, []), a = await re("count", r, e.length * 2);
6484
6467
  try {
6485
6468
  const c = await _(ng(e, a, o, i), {
6486
6469
  ...r,
6487
6470
  responseFormat: tg
6488
6471
  }), l = c?.items || c;
6489
- 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 }), []);
6490
6473
  } catch (c) {
6491
6474
  throw s.error(c), c;
6492
6475
  }
@@ -6535,7 +6518,7 @@ function ns(e, t) {
6535
6518
  }
6536
6519
  const qn = Rn;
6537
6520
  async function mg(e, t, n = {}) {
6538
- 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.
6539
6522
 
6540
6523
  ${$(t, { tag: "score-specification" })}
6541
6524
 
@@ -6559,7 +6542,7 @@ ${o}` : r, a = s.spec || await qn(i, n);
6559
6542
  return mg(e, a, n);
6560
6543
  }
6561
6544
  async function rs(e, t, n, r) {
6562
- 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);
6563
6546
  h.progress({
6564
6547
  event: W.start,
6565
6548
  totalItems: e.length,
@@ -6573,12 +6556,12 @@ async function rs(e, t, n, r) {
6573
6556
  const g = await M(() => be(f.items, t, n), {
6574
6557
  label: "score:batch",
6575
6558
  config: r,
6576
- onProgress: L(i, "batch")
6559
+ onProgress: B(i, "batch")
6577
6560
  });
6578
6561
  ns(g, f.items.length).forEach((m, w) => {
6579
6562
  d[f.startIndex + w] = m;
6580
6563
  }), b = dg(f.items, g, c), h.emit({
6581
- event: k.phase,
6564
+ event: A.phase,
6582
6565
  phase: "anchors-established",
6583
6566
  anchors: b
6584
6567
  });
@@ -6601,10 +6584,10 @@ ${b}` : t;
6601
6584
  const w = await M(() => be(g, f, n), {
6602
6585
  label: "score:batch",
6603
6586
  config: r,
6604
- onProgress: L(i, "batch")
6587
+ onProgress: B(i, "batch")
6605
6588
  });
6606
- ns(w, g.length).forEach((S, v) => {
6607
- d[m + v] = S;
6589
+ ns(w, g.length).forEach((v, S) => {
6590
+ d[m + S] = v;
6608
6591
  });
6609
6592
  } catch (w) {
6610
6593
  if (h.error(w, { itemCount: g.length }), o === z.strict) throw w;
@@ -6624,11 +6607,11 @@ ${b}` : t;
6624
6607
  processedItems: y.count
6625
6608
  }), d;
6626
6609
  }
6627
- async function ke(e, t, n) {
6610
+ async function Ie(e, t, n) {
6628
6611
  [t, n] = K(t, n, ["spec", "anchors"]);
6629
- const { text: r, known: s, context: o } = N(t, ["spec", "anchors"]), { now: i } = n, a = A(ts, n), c = I(ts, a.onProgress, a);
6630
- c.start(), c.emit({ event: k.input, value: e });
6631
- 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(
6632
6615
  a,
6633
6616
  {
6634
6617
  maxParallel: 3,
@@ -6638,11 +6621,11 @@ async function ke(e, t, n) {
6638
6621
  anchoring: J(lg)
6639
6622
  }
6640
6623
  );
6641
- c.emit({ event: k.phase, phase: "generating-specification" });
6624
+ c.emit({ event: A.phase, phase: "generating-specification" });
6642
6625
  const y = o ? `${r}
6643
6626
 
6644
6627
  ${o}` : r, b = s.spec || await qn(y, a);
6645
- c.emit({ event: k.phase, phase: "scoring-items", specification: b });
6628
+ c.emit({ event: A.phase, phase: "scoring-items", specification: b });
6646
6629
  const f = fg(
6647
6630
  b,
6648
6631
  "Return ONLY the numeric score for each item according to the specification range."
@@ -6660,19 +6643,19 @@ ${o}` : r, b = s.spec || await qn(y, a);
6660
6643
  _providedAnchors: s.anchors
6661
6644
  }, w = await rs(e, f, g, m);
6662
6645
  for (let x = 1; x < u; x += 1) {
6663
- const E = [], O = [];
6664
- if (w.forEach((j, F) => {
6665
- j == null && (E.push(F), O.push(e[F]));
6666
- }), O.length === 0) break;
6667
- (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, {
6668
6651
  ...m,
6669
6652
  now: /* @__PURE__ */ new Date()
6670
- })).forEach((j, F) => {
6671
- j !== void 0 && (w[E[F]] = j);
6653
+ })).forEach((j, L) => {
6654
+ j !== void 0 && (w[E[L]] = j);
6672
6655
  });
6673
6656
  }
6674
- const S = w.filter((x) => x !== void 0).length, v = w.length - S, P = v > 0 ? T.partial : T.success;
6675
- 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;
6676
6659
  }
6677
6660
  function fg(e, t = "") {
6678
6661
  const n = `Apply this score specification to evaluate each item:
@@ -6690,7 +6673,7 @@ function gg({ spec: e, anchors: t, text: n, ...r }) {
6690
6673
  ...r
6691
6674
  };
6692
6675
  }
6693
- ke.knownTexts = ["spec", "anchors"];
6676
+ Ie.knownTexts = ["spec", "anchors"];
6694
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 = {
6695
6678
  type: yg,
6696
6679
  properties: bg,
@@ -6785,7 +6768,7 @@ ${s}` : os(e, t, n, r), a = xg(e.length, t.length), c = C("score_matrix_result",
6785
6768
  return Pg(l?.matrix, e.length, t.length);
6786
6769
  }
6787
6770
  async function as(e, t, n, r, s, o) {
6788
- 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);
6789
6772
  h.progress({
6790
6773
  event: W.start,
6791
6774
  totalItems: e.length,
@@ -6798,11 +6781,11 @@ async function as(e, t, n, r, s, o) {
6798
6781
  try {
6799
6782
  const m = await M(
6800
6783
  () => is(g.items, t, n, r, "", s),
6801
- { label: "score-matrix:batch", config: o, onProgress: L(c, "batch") }
6784
+ { label: "score-matrix:batch", config: o, onProgress: B(c, "batch") }
6802
6785
  );
6803
- m.forEach((w, S) => {
6804
- d[g.startIndex + S] = w;
6805
- }), 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" });
6806
6789
  } catch (m) {
6807
6790
  if (h.error(m, { batchIndex: 0, itemCount: g.items.length }), a === z.strict) throw m;
6808
6791
  }
@@ -6817,10 +6800,10 @@ async function as(e, t, n, r, s, o) {
6817
6800
  {
6818
6801
  label: "score-matrix:batch",
6819
6802
  config: o,
6820
- onProgress: L(c, "batch")
6803
+ onProgress: B(c, "batch")
6821
6804
  }
6822
- )).forEach((S, v) => {
6823
- d[m + v] = S;
6805
+ )).forEach((v, S) => {
6806
+ d[m + S] = v;
6824
6807
  });
6825
6808
  } catch (w) {
6826
6809
  if (h.error(w, { itemCount: g.length }), a === z.strict) throw w;
@@ -6846,10 +6829,10 @@ async function ua(e, t, n, r) {
6846
6829
  [n, r] = K(n, r, ["anchors"]);
6847
6830
  const { text: s, known: o, context: i } = N(n, ["anchors"]), a = i ? `${s}
6848
6831
 
6849
- ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
6850
- 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)
6851
6834
  return u.complete({ rows: 0, columns: c.length, outcome: T.success }), { matrix: [], dimensions: c.map((x) => x.dimension), scale: Ve };
6852
- 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(
6853
6836
  l,
6854
6837
  {
6855
6838
  maxParallel: 3,
@@ -6866,7 +6849,7 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
6866
6849
  anchoring: b,
6867
6850
  _providedAnchors: o.anchors
6868
6851
  };
6869
- u.emit({ event: k.phase, phase: "scoring-matrix" });
6852
+ u.emit({ event: A.phase, phase: "scoring-matrix" });
6870
6853
  const m = await as(
6871
6854
  e,
6872
6855
  c,
@@ -6876,43 +6859,43 @@ ${i}` : s, c = la(t), l = A(ss, r), u = I(ss, l.onProgress, l);
6876
6859
  g
6877
6860
  );
6878
6861
  for (let x = 1; x < d; x += 1) {
6879
- const E = [], O = [];
6880
- if (m.forEach((j, F) => {
6881
- j == null && (E.push(F), O.push(e[F]));
6882
- }), 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;
6883
6866
  u.emit({
6884
- event: k.phase,
6867
+ event: A.phase,
6885
6868
  phase: "retrying-missing",
6886
- count: O.length,
6869
+ count: I.length,
6887
6870
  attempt: x
6888
6871
  }), (await as(
6889
- O,
6872
+ I,
6890
6873
  c,
6891
6874
  a,
6892
6875
  Ve,
6893
6876
  f,
6894
6877
  { ...g, now: /* @__PURE__ */ new Date() }
6895
- )).forEach((j, F) => {
6896
- j !== void 0 && (m[E[F]] = j);
6878
+ )).forEach((j, L) => {
6879
+ j !== void 0 && (m[E[L]] = j);
6897
6880
  });
6898
6881
  }
6899
6882
  const w = m.map(
6900
6883
  (x) => x ?? c.map(() => ({ score: Ve.min, rationale: "scoring failed" }))
6901
- ), 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;
6902
6885
  return u.emit({
6903
- event: k.output,
6886
+ event: A.output,
6904
6887
  value: { rows: w.length, columns: c.length }
6905
- }), u.complete({ totalItems: e.length, successCount: S, failedItems: v, outcome: P }), {
6888
+ }), u.complete({ totalItems: e.length, successCount: v, failedItems: S, outcome: P }), {
6906
6889
  matrix: w,
6907
6890
  dimensions: c.map((x) => x.dimension),
6908
6891
  scale: Ve
6909
6892
  };
6910
6893
  }
6911
6894
  ua.knownTexts = ["anchors"];
6912
- 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 = {
6913
6896
  $schema: Eg,
6914
- type: Ig,
6915
- properties: kg,
6897
+ type: kg,
6898
+ properties: Ig,
6916
6899
  required: Ag,
6917
6900
  additionalProperties: Og
6918
6901
  }, cs = "tags", Cg = {
@@ -6935,7 +6918,7 @@ const Eg = "http://json-schema.org/draft-07/schema#", Ig = "object", kg = { item
6935
6918
  additionalProperties: !1
6936
6919
  };
6937
6920
  async function Fn(e, t = {}) {
6938
- 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);
6939
6922
  r.start();
6940
6923
  try {
6941
6924
  const s = "You are a tag specification generator. Create clear, actionable tagging criteria.", o = `Analyze these tagging instructions and generate a specification.
@@ -6964,10 +6947,10 @@ Keep it concise and actionable.`, i = await M(
6964
6947
  }
6965
6948
  }
6966
6949
  async function jg(e, t, n, r = {}) {
6967
- 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);
6968
6951
  o.start();
6969
6952
  try {
6970
- const { vocabularyMode: i } = await q(s, {
6953
+ const { vocabularyMode: i } = await F(s, {
6971
6954
  vocabularyMode: "strict"
6972
6955
  }), a = i === "open" ? `Available tags (prefer these, but you MAY suggest new tag IDs for items that don't fit any existing tag):
6973
6956
  ${$(JSON.stringify(n.tags), { tag: "available-tags" })}` : `Available tags (you MUST use only the "id" field from these tags):
@@ -7007,13 +6990,13 @@ ${o}` : r, c = s.spec || await Fn(a, n);
7007
6990
  }
7008
6991
  async function da(e, t, n) {
7009
6992
  [t, n] = K(t, n, Fe);
7010
- 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);
7011
6994
  s.start();
7012
6995
  try {
7013
- 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}
7014
6997
 
7015
6998
  ${a}` : o, p = i.spec || await Fn(u, r);
7016
- s.emit({ event: k.phase, phase: "applying-tags", specification: p });
6999
+ s.emit({ event: A.phase, phase: "applying-tags", specification: p });
7017
7000
  const d = Ng(
7018
7001
  p,
7019
7002
  c,
@@ -7026,7 +7009,7 @@ Return empty array when no tags apply.`,
7026
7009
  ), y = s.batch(h.length), b = {
7027
7010
  ...r,
7028
7011
  responseFormat: C("tags_map_result", Cg),
7029
- onProgress: L(r.onProgress, "tags:map")
7012
+ onProgress: B(r.onProgress, "tags:map")
7030
7013
  }, f = await Oe(h, d, b);
7031
7014
  return y(h.length), s.complete({ outcome: T.success }), f;
7032
7015
  } catch (o) {
@@ -7101,9 +7084,9 @@ function ma(e, { context: t = "", diversity: n } = {}) {
7101
7084
  async function ha(e, t = {}) {
7102
7085
  if (!e || typeof e != "string")
7103
7086
  throw new Error("categoryName must be a non-empty string");
7104
- 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);
7105
7088
  r.start();
7106
- 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, {
7107
7090
  diversity: J(Mg, ["diversity", "count"])
7108
7091
  }), { context: c = "" } = n, l = [o, c].filter(Boolean).join(`
7109
7092
 
@@ -7114,7 +7097,7 @@ async function ha(e, t = {}) {
7114
7097
  }), d = await Ze(p, {
7115
7098
  ...n,
7116
7099
  shouldStop: ({ resultsAll: h }) => h.length >= a,
7117
- onProgress: L(n.onProgress, "list:sampling")
7100
+ onProgress: B(n.onProgress, "list:sampling")
7118
7101
  });
7119
7102
  if (!d || d.length === 0)
7120
7103
  throw new Error(`No sample items generated for category: ${e}`);
@@ -7139,9 +7122,9 @@ const us = "collect-terms", Bg = (e, t) => {
7139
7122
  return s && r.push(s.trim()), r;
7140
7123
  };
7141
7124
  async function zn(e, t = {}) {
7142
- 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);
7143
7126
  i.start();
7144
- const { topN: a, chunkLen: c } = await q(o, {
7127
+ const { topN: a, chunkLen: c } = await F(o, {
7145
7128
  topN: 20,
7146
7129
  chunkLen: 1e3
7147
7130
  });
@@ -7157,7 +7140,7 @@ async function zn(e, t = {}) {
7157
7140
 
7158
7141
  ${s}` : "", w = await Ze(
7159
7142
  `key words and phrases that would help find documents about: ${g}${m}`,
7160
- { ...o, onProgress: L(o.onProgress, "list:extract") }
7143
+ { ...o, onProgress: B(o.onProgress, "list:extract") }
7161
7144
  );
7162
7145
  return y(1), w;
7163
7146
  },
@@ -7170,14 +7153,14 @@ ${s}` : "", w = await Ze(
7170
7153
  )).filter(Array.isArray).flat();
7171
7154
  l = Array.from(new Set(f.map((g) => g.trim()))).filter(Boolean);
7172
7155
  }
7173
- 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)
7174
7157
  return i.complete({ outcome: T.success }), l;
7175
- const u = await ke(
7158
+ const u = await Ie(
7176
7159
  l,
7177
7160
  "relevance as a search term for finding information (1-10, higher is more important)",
7178
- { ...o, onProgress: L(o.onProgress, "score:rank") }
7161
+ { ...o, onProgress: B(o.onProgress, "score:rank") }
7179
7162
  ), d = l.map((h, y) => ({ term: h, score: u[y] ?? 0 })).toSorted((h, y) => y.score - h.score);
7180
- 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);
7181
7164
  } catch (l) {
7182
7165
  throw i.error(l), l;
7183
7166
  }
@@ -7200,25 +7183,25 @@ async function Un({
7200
7183
  throw new Error("At least one speaker is required");
7201
7184
  if (!a)
7202
7185
  throw new Error("Topic is required");
7203
- const u = A(ps, i), p = I(ps, u.onProgress, u);
7204
- 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 } });
7205
7188
  try {
7206
- 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(`
7207
7190
  `) : "", y = [
7208
7191
  o.customPrompt || "",
7209
7192
  d ? $(d, { tag: "conversation-history" }) : "",
7210
7193
  a ? $(a, { tag: "topic" }) : ""
7211
7194
  ].filter(Boolean).join(`
7212
7195
 
7213
- `), b = e.map((S, v) => {
7214
- const x = [S.name || `Speaker ${v + 1}`];
7215
- S.bio && x.push(`Bio: ${S.bio}`), S.agenda && x.push(`Agenda: ${S.agenda}`);
7216
- 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) ?? [];
7217
7200
  if (E.length > 0) {
7218
- const O = E.map((R) => `[${R.time}] ${R.comment}`).join(`
7201
+ const I = E.map((R) => `[${R.time}] ${R.comment}`).join(`
7219
7202
  `);
7220
7203
  x.push(`Prior statements:
7221
- ${O}`);
7204
+ ${I}`);
7222
7205
  }
7223
7206
  return x.join(`
7224
7207
  `);
@@ -7231,9 +7214,9 @@ ${O}`);
7231
7214
 
7232
7215
  `), m = p.batch(e.length), w = await Oe(b, g, {
7233
7216
  ...u,
7234
- onProgress: L(u.onProgress, "conversation-turn-reduce:map")
7217
+ onProgress: B(u.onProgress, "conversation-turn-reduce:map")
7235
7218
  });
7236
- 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;
7237
7220
  } catch (d) {
7238
7221
  throw p.error(d), d;
7239
7222
  }
@@ -7291,9 +7274,9 @@ class vt {
7291
7274
  throw new Error("Duplicate speaker id");
7292
7275
  s.add(p.id);
7293
7276
  });
7294
- const { text: o, context: i } = N(t, []), a = A(st, r), c = I(st, a.onProgress, a);
7295
- c.start(), c.emit({ event: k.input, value: { topic: o, speakers: n } });
7296
- 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, {
7297
7280
  depth: J(Fg),
7298
7281
  maxParallel: J(zg)
7299
7282
  });
@@ -7307,7 +7290,7 @@ class vt {
7307
7290
  constructor(t, n, r = {}, s = {}) {
7308
7291
  const o = r.emitter && r.config;
7309
7292
  this.emitter = o ? r.emitter : void 0, this.bundleContext = o ? r.bundleContext ?? "" : "";
7310
- const i = o ? r.config : A(st, r), {
7293
+ const i = o ? r.config : O(st, r), {
7311
7294
  rules: a = {},
7312
7295
  speakFn: c,
7313
7296
  bulkSpeakFn: l,
@@ -7328,7 +7311,7 @@ class vt {
7328
7311
  turnPolicy: a.turnPolicy || ds(this.speakers)
7329
7312
  },
7330
7313
  a
7331
- ), 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();
7332
7315
  }
7333
7316
  _push(t, n) {
7334
7317
  const r = (n ?? "").trim();
@@ -7356,7 +7339,7 @@ class vt {
7356
7339
  speakerMemory: o,
7357
7340
  rules: this.rules,
7358
7341
  llm: this.llm,
7359
- onProgress: L(this.runConfig.onProgress, `round-${t}`)
7342
+ onProgress: B(this.runConfig.onProgress, `round-${t}`)
7360
7343
  })).forEach((a, c) => {
7361
7344
  this._push(s[c].id, a);
7362
7345
  }) : this.speakFn && (await Q(
@@ -7373,7 +7356,7 @@ class vt {
7373
7356
  speakerMemory: o,
7374
7357
  rules: this.rules,
7375
7358
  llm: this.llm,
7376
- onProgress: L(this.runConfig.onProgress, `round-${t}`)
7359
+ onProgress: B(this.runConfig.onProgress, `round-${t}`)
7377
7360
  });
7378
7361
  return { speaker: a, comment: c };
7379
7362
  } catch (c) {
@@ -7389,7 +7372,7 @@ class vt {
7389
7372
  c && this._push(a.id, c);
7390
7373
  }), t += 1, n(1);
7391
7374
  }
7392
- 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;
7393
7376
  } catch (t) {
7394
7377
  throw this.emitter.error(t), t;
7395
7378
  }
@@ -7407,7 +7390,7 @@ const Ug = "http://json-schema.org/draft-07/schema#", Wg = "object", Vg = { mean
7407
7390
  Gg
7408
7391
  ), Hg = (e) => `List all distinct dictionary meanings or common uses of ${$(e, { tag: "term" })}.
7409
7392
  Return a JSON object with a "meanings" array containing the distinct meanings.`, fa = async (e, t = {}) => {
7410
- const n = A("disambiguate:meanings", {
7393
+ const n = O("disambiguate:meanings", {
7411
7394
  llm: { fast: !0, good: !0, cheap: !0 },
7412
7395
  ...t
7413
7396
  }), r = Hg(e), s = await M(
@@ -7426,27 +7409,27 @@ async function ga(e, t, n) {
7426
7409
  [t, n] = K(t, n);
7427
7410
  const { text: r, context: s } = N(t, []), o = s ? `${r}
7428
7411
 
7429
- ${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);
7430
7413
  a.start();
7431
7414
  try {
7432
- a.emit({ event: k.step, stepName: "extracting-meanings", term: e });
7415
+ a.emit({ event: A.step, stepName: "extracting-meanings", term: e });
7433
7416
  const c = await fa(e, {
7434
7417
  ...i,
7435
- onProgress: L(i.onProgress, "meanings")
7418
+ onProgress: B(i.onProgress, "meanings")
7436
7419
  });
7437
7420
  a.emit({
7438
- event: k.step,
7421
+ event: A.step,
7439
7422
  stepName: "scoring-meanings",
7440
7423
  term: e,
7441
7424
  meanings: c,
7442
7425
  meaningCount: c.length
7443
7426
  });
7444
- const l = await ke(
7427
+ const l = await Ie(
7445
7428
  c,
7446
7429
  `how well this meaning of ${$(e, { tag: "term" })} matches the context: ${$(o, { tag: "context" })}`,
7447
7430
  {
7448
7431
  ...i,
7449
- onProgress: L(i.onProgress, "score:relevance")
7432
+ onProgress: B(i.onProgress, "score:relevance")
7450
7433
  }
7451
7434
  );
7452
7435
  let u = 0, p = -1 / 0;
@@ -7731,10 +7714,10 @@ class et {
7731
7714
  static async create(t, n = {}) {
7732
7715
  const { text: r, context: s } = N(t, []), o = [n.bundleContext, s].filter(Boolean).join(`
7733
7716
 
7734
- `), i = A(r, n), a = I(r, i.onProgress, i);
7717
+ `), i = O(r, n), a = k(r, i.onProgress, i);
7735
7718
  a.start();
7736
7719
  try {
7737
- const { temperature: c, variety: l } = await q(i, {
7720
+ const { temperature: c, variety: l } = await F(i, {
7738
7721
  temperature: void 0,
7739
7722
  variety: J(gs)
7740
7723
  }), u = new et(r, n, i, {
@@ -7783,17 +7766,17 @@ class et {
7783
7766
  }
7784
7767
  }
7785
7768
  const va = async (e, t = {}) => {
7786
- const { text: n, context: r } = N(e, []), s = A(fs, t), o = I(fs, s.onProgress, s);
7787
- 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 });
7788
7771
  try {
7789
7772
  const i = o.batch(1);
7790
- o.emit({ event: k.phase, phase: "tree-construction" });
7773
+ o.emit({ event: A.phase, phase: "tree-construction" });
7791
7774
  const a = await et.create(n, {
7792
7775
  ...s,
7793
7776
  bundleContext: r,
7794
- onProgress: L(s.onProgress, "tree-construction")
7777
+ onProgress: B(s.onProgress, "tree-construction")
7795
7778
  });
7796
- 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;
7797
7780
  } catch (i) {
7798
7781
  throw o.error(i), i;
7799
7782
  }
@@ -8015,7 +7998,7 @@ function Ey(e, t, n, r, s = St) {
8015
7998
  avgChunkSize: a
8016
7999
  };
8017
8000
  }
8018
- function Iy(e, t, n) {
8001
+ function ky(e, t, n) {
8019
8002
  const r = e.length, s = Ta(n, r), o = Py(t, s, r), i = [];
8020
8003
  for (let a = 0; a < r; a += o)
8021
8004
  i.push({
@@ -8026,7 +8009,7 @@ function Iy(e, t, n) {
8026
8009
  });
8027
8010
  return i;
8028
8011
  }
8029
- async function ky(e, t, n = {}) {
8012
+ async function Iy(e, t, n = {}) {
8030
8013
  if (t < an)
8031
8014
  return { expansions: [e], tokensUsed: 0 };
8032
8015
  try {
@@ -8034,7 +8017,7 @@ async function ky(e, t, n = {}) {
8034
8017
  ...n,
8035
8018
  topN: 5,
8036
8019
  chunkLen: 500,
8037
- onProgress: L(n.onProgress, "collect-terms:query-expansion")
8020
+ onProgress: B(n.onProgress, "collect-terms:query-expansion")
8038
8021
  });
8039
8022
  return {
8040
8023
  expansions: [e, ...r],
@@ -8070,13 +8053,13 @@ async function _y(e, t, n, r = {}) {
8070
8053
  const o = e.slice(0, n), i = o.map((l) => {
8071
8054
  const u = l.text.replace(/\s+/g, " ").trim();
8072
8055
  return (u.match(/^[^.!?]{1,300}[.!?]/)?.[0] || u.slice(0, 300)).trim();
8073
- }), a = await ke(
8056
+ }), a = await Ie(
8074
8057
  i,
8075
8058
  `relevance to query: ${$(t, { tag: "query" })} (0=unrelated, 5=partially related, 10=directly answers)`,
8076
8059
  {
8077
8060
  ...r,
8078
8061
  batchSize: yy,
8079
- onProgress: L(r.onProgress, "score:edge-ranking")
8062
+ onProgress: B(r.onProgress, "score:edge-ranking")
8080
8063
  }
8081
8064
  );
8082
8065
  return {
@@ -8104,7 +8087,7 @@ async function Cy(e, t, n, r, s, o = {}) {
8104
8087
  {
8105
8088
  ...o,
8106
8089
  batchSize: 10,
8107
- onProgress: L(o.onProgress, "map:compression")
8090
+ onProgress: B(o.onProgress, "map:compression")
8108
8091
  }
8109
8092
  ), d = [];
8110
8093
  let h = 0;
@@ -8177,7 +8160,7 @@ async function Ea(e, t, n) {
8177
8160
  [t, n] = K(t, n, ["expansions"]);
8178
8161
  const { text: r, known: s, context: o } = N(t, ["expansions"]), i = o ? `${r}
8179
8162
 
8180
- ${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);
8181
8164
  c.start();
8182
8165
  const {
8183
8166
  targetSize: l,
@@ -8189,7 +8172,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8189
8172
  llmScoring: b,
8190
8173
  llmCompression: f,
8191
8174
  scoringTokenRatio: g
8192
- } = await q(a, {
8175
+ } = await F(a, {
8193
8176
  targetSize: _e.targetSize,
8194
8177
  tokenBudget: _e.tokenBudget,
8195
8178
  gapFillerBudgetRatio: _e.gapFillerBudgetRatio,
@@ -8225,62 +8208,62 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8225
8208
  try {
8226
8209
  m.targetSize <= 0 && (m.targetSize = _e.targetSize), m.chunkSize <= 0 && (m.chunkSize = _e.chunkSize), m.tokenBudget <= 0 && (m.tokenBudget = _e.tokenBudget);
8227
8210
  let w = m.tokenBudget;
8228
- c.emit({ event: k.phase, phase: "chunking" });
8229
- const S = Iy(e, m.chunkSize, m.targetSize), v = Ey(
8230
- S,
8211
+ c.emit({ event: A.phase, phase: "chunking" });
8212
+ const v = ky(e, m.chunkSize, m.targetSize), S = Ey(
8213
+ v,
8231
8214
  m.targetSize,
8232
8215
  w,
8233
8216
  e.length,
8234
8217
  g
8235
8218
  );
8236
- !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" });
8237
8220
  const P = a;
8238
8221
  let x, E = 0;
8239
8222
  if (s.expansions)
8240
- 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);
8241
8224
  else if (y) {
8242
- const B = await ky(i, w, P);
8243
- x = B.expansions, E = B.tokensUsed;
8225
+ const D = await Iy(i, w, P);
8226
+ x = D.expansions, E = D.tokensUsed;
8244
8227
  } else
8245
8228
  x = [i];
8246
- w -= E, c.emit({ event: k.phase, phase: "tfidf-scoring", expansions: x });
8247
- const O = Ay(S, x), { selected: R, candidates: j, sizeUsed: F } = Oy(
8248
- O,
8249
- 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
8250
8233
  );
8251
- c.emit({ event: k.phase, phase: "edge-scoring" });
8252
- 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, {
8253
8236
  ...P,
8254
8237
  llmWeight: h
8255
8238
  }) : { scored: [], tokensUsed: 0 };
8256
8239
  w -= Y;
8257
- let H = vs(R, F, V, m.targetSize);
8258
- c.emit({ event: k.phase, phase: "compression" });
8240
+ let H = vs(R, L, V, m.targetSize);
8241
+ c.emit({ event: A.phase, phase: "compression" });
8259
8242
  const ee = m.targetSize - H.size;
8260
- let pe = 0;
8261
- const G = Math.min(v.avgChunkSize * 0.5, 200);
8262
- if (f && ee > G && v.chunksWeCanCompress > 0) {
8263
- const B = jy(O, H.chunks), { compressed: X, tokensUsed: ce } = await Cy(
8264
- 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,
8265
8248
  i,
8266
- v.chunksWeCanCompress,
8249
+ S.chunksWeCanCompress,
8267
8250
  ee,
8268
- v,
8251
+ S,
8269
8252
  { ...P, compressionRatio: d }
8270
8253
  );
8271
- 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);
8272
8255
  }
8273
- c.emit({ event: k.phase, phase: "assembly" });
8256
+ c.emit({ event: A.phase, phase: "assembly" });
8274
8257
  let te = H.chunks, ie = 0;
8275
8258
  if (m.gapFillerBudgetRatio > 0) {
8276
- 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);
8277
8260
  if (ce > 0) {
8278
- const ve = Ly(O, te, ce);
8261
+ const ve = Ly(I, te, ce);
8279
8262
  ve.length > 0 && (te = [...te, ...ve], ie = ve.length);
8280
8263
  }
8281
8264
  }
8282
- const de = Ny(te);
8283
- let Z = Ry(de);
8265
+ const pe = Ny(te);
8266
+ let Z = Ry(pe);
8284
8267
  Z.length > m.targetSize * 3 && (Z = Pa(Z.slice(0, m.targetSize * 2)));
8285
8268
  const we = {
8286
8269
  content: Z,
@@ -8289,15 +8272,15 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8289
8272
  finalSize: Z.length,
8290
8273
  reductionRatio: (1 - Z.length / e.length).toFixed(2),
8291
8274
  allocation: {
8292
- tfIdfBudget: v.tfIdfBudget,
8293
- reservedForLLM: v.reservedSpace,
8294
- 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)
8295
8278
  },
8296
8279
  chunks: {
8297
- total: S.length,
8280
+ total: v.length,
8298
8281
  tfIdfSelected: R.length,
8299
- llmSelected: te.filter((B) => B.llmScore && !B.compressed).length,
8300
- 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,
8301
8284
  gapFillers: ie
8302
8285
  },
8303
8286
  tokens: {
@@ -8306,7 +8289,7 @@ ${o}` : r, a = A(bs, n), c = I(bs, a.onProgress, a);
8306
8289
  breakdown: {
8307
8290
  expansion: E,
8308
8291
  scoring: Y || 0,
8309
- compression: pe || 0
8292
+ compression: ue || 0
8310
8293
  }
8311
8294
  }
8312
8295
  }
@@ -8335,10 +8318,10 @@ const By = "http://json-schema.org/draft-07/schema#", Dy = "object", qy = !1, Fy
8335
8318
  Return JSON with "template" and "variables" where each variable has "original", "candidate", and "confidence".${t ? `
8336
8319
 
8337
8320
  ${t}` : ""}`;
8338
- async function Ia(e, t = {}) {
8321
+ async function ka(e, t = {}) {
8339
8322
  const { text: n, context: r } = N(e, []), s = r ? `${n}
8340
8323
 
8341
- ${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);
8342
8325
  i.start();
8343
8326
  try {
8344
8327
  const a = Ky(o.creativity), c = Gy(s, { creativityGuidance: a }), l = await _(c, {
@@ -8350,12 +8333,12 @@ ${r}` : n, o = A(Ss, t), i = I(Ss, o.onProgress, o);
8350
8333
  throw i.error(a), a;
8351
8334
  }
8352
8335
  }
8353
- Ia.knownTexts = [];
8336
+ ka.knownTexts = [];
8354
8337
  const xs = "filter-ambiguous";
8355
- async function ka(e, t = {}) {
8356
- 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);
8357
8340
  i.start();
8358
- const { topN: a } = await q(o, {
8341
+ const { topN: a } = await F(o, {
8359
8342
  topN: 10
8360
8343
  });
8361
8344
  try {
@@ -8371,17 +8354,17 @@ async function ka(e, t = {}) {
8371
8354
  return i.complete({ outcome: T.success }), [];
8372
8355
  const f = s ? `
8373
8356
 
8374
- ${s}` : "", g = await ke(
8357
+ ${s}` : "", g = await Ie(
8375
8358
  b,
8376
8359
  `How ambiguous or easily misinterpreted is this sentence?${f}`,
8377
8360
  {
8378
8361
  ...o,
8379
- onProgress: L(o.onProgress, "score:sentence-ambiguity")
8362
+ onProgress: B(o.onProgress, "score:sentence-ambiguity")
8380
8363
  }
8381
8364
  );
8382
8365
  c = b.map((m, w) => ({ sentence: m, score: g[w] ?? 0 })).toSorted((m, w) => w.score - m.score).slice(0, a);
8383
8366
  }
8384
- i.emit({ event: k.phase, phase: "ranked", rankedSentences: c });
8367
+ i.emit({ event: A.phase, phase: "ranked", rankedSentences: c });
8385
8368
  const l = i.batch(c.length), p = (await Q(
8386
8369
  c,
8387
8370
  async ({ sentence: b }) => {
@@ -8389,7 +8372,7 @@ ${s}` : "", g = await ke(
8389
8372
  ...o,
8390
8373
  attachments: { text: b },
8391
8374
  targetNewItemsCount: 5,
8392
- onProgress: L(o.onProgress, "list:extract")
8375
+ onProgress: B(o.onProgress, "list:extract")
8393
8376
  });
8394
8377
  return l(1), f.map((g) => ({ term: g, sentence: b }));
8395
8378
  },
@@ -8402,12 +8385,12 @@ ${s}` : "", g = await ke(
8402
8385
  )).filter(Array.isArray).flat();
8403
8386
  if (p.length === 0)
8404
8387
  return i.complete({ outcome: T.success }), [];
8405
- const d = await ke(
8388
+ const d = await Ie(
8406
8389
  p.map((b) => `${b.term} | ${b.sentence}`),
8407
8390
  "Score how ambiguous the term is within the sentence.",
8408
8391
  {
8409
8392
  ...o,
8410
- onProgress: L(o.onProgress, "score:term-ambiguity")
8393
+ onProgress: B(o.onProgress, "score:term-ambiguity")
8411
8394
  }
8412
8395
  ), y = p.map((b, f) => ({ ...b, score: d[f] ?? 0 })).toSorted((b, f) => (f.score || 0) - (b.score || 0));
8413
8396
  return i.complete({ outcome: T.success }), y.slice(0, a);
@@ -8415,7 +8398,7 @@ ${s}` : "", g = await ke(
8415
8398
  throw i.error(c), c;
8416
8399
  }
8417
8400
  }
8418
- ka.knownTexts = ["rankedSentences"];
8401
+ Ia.knownTexts = ["rankedSentences"];
8419
8402
  function Aa(e, t = 5, n = 50) {
8420
8403
  if (e.length === 0) return [];
8421
8404
  const r = [], s = Math.max(1, Math.floor(t * (1 - n / 100)));
@@ -8439,9 +8422,9 @@ async function Oa(e, t, n) {
8439
8422
  if (e.length === 1) return e[0];
8440
8423
  const { text: r, context: s } = N(t, []), o = s ? `${r}
8441
8424
 
8442
- ${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);
8443
8426
  a.start();
8444
- const { styleHint: c, windowSize: l, overlapPercent: u } = await q(i, {
8427
+ const { styleHint: c, windowSize: l, overlapPercent: u } = await F(i, {
8445
8428
  fidelity: J(Yy, ["windowSize", "overlapPercent"]),
8446
8429
  styleHint: ""
8447
8430
  });
@@ -8450,7 +8433,7 @@ ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
8450
8433
  p,
8451
8434
  async (f, g) => {
8452
8435
  a.emit({
8453
- event: k.step,
8436
+ event: A.step,
8454
8437
  stepName: "processing-window",
8455
8438
  windowNumber: g + 1,
8456
8439
  totalWindows: p.length
@@ -8458,19 +8441,19 @@ ${s}` : r, i = A($s, n), a = I($s, i.onProgress, i);
8458
8441
  const m = f.fragments.map((P, x) => `${x + 1}. ${P}`).join(`
8459
8442
  `), w = c ? `
8460
8443
 
8461
- ${$(c, { tag: "style-guidance" })}` : "", S = `${o}${w}
8444
+ ${$(c, { tag: "style-guidance" })}` : "", v = `${o}${w}
8462
8445
 
8463
8446
  Window ${g + 1} of ${p.length} - Join these fragments:
8464
8447
 
8465
8448
  ${$(m, { tag: "fragments" })}
8466
8449
 
8467
- 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), {
8468
8451
  label: `join-window-${g + 1}`,
8469
8452
  config: i,
8470
- onProgress: L(i.onProgress, "window")
8453
+ onProgress: B(i.onProgress, "window")
8471
8454
  });
8472
8455
  return d(1), {
8473
- content: v || f.fragments.join(" "),
8456
+ content: S || f.fragments.join(" "),
8474
8457
  window: f
8475
8458
  };
8476
8459
  },
@@ -8483,16 +8466,16 @@ Important: This is part of a larger sequence. Join these fragments while being m
8483
8466
  let b = y[0].content;
8484
8467
  for (let f = 1; f < y.length; f++) {
8485
8468
  a.emit({
8486
- event: k.step,
8469
+ event: A.step,
8487
8470
  stepName: "stitching",
8488
8471
  stitchNumber: f,
8489
8472
  totalStitches: y.length - 1
8490
8473
  });
8491
- 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);
8492
- if (S <= v) {
8493
- 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 ? `
8494
8477
 
8495
- ${$(c, { tag: "style-guidance" })}` : "", E = P.join(" | "), O = `${o}${x}
8478
+ ${$(c, { tag: "style-guidance" })}` : "", E = P.join(" | "), I = `${o}${x}
8496
8479
 
8497
8480
  Stitch these two sections by resolving their overlapping region:
8498
8481
 
@@ -8505,7 +8488,7 @@ ${$(E, { tag: "overlapping-fragments" })}
8505
8488
  The terminal ends of both sections should be preserved. Only resolve the overlapping middle region where these fragments appear.
8506
8489
 
8507
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.`;
8508
- b = await M(() => _(O, i), {
8491
+ b = await M(() => _(I, i), {
8509
8492
  label: `join-stitch-${f}`,
8510
8493
  config: i
8511
8494
  }) || b;
@@ -8545,7 +8528,7 @@ const Hy = {
8545
8528
  additionalProperties: !1
8546
8529
  }, { asUndefinedByDefault: Qy, contentIsQuestion: Xy } = oe, Ps = "name";
8547
8530
  async function _a(e, t = {}) {
8548
- 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);
8549
8532
  o.start();
8550
8533
  const i = [
8551
8534
  `${Xy} Suggest a concise, memorable name for the <subject>.
@@ -8595,7 +8578,7 @@ ${r}
8595
8578
  The value should be the generated name.`;
8596
8579
  };
8597
8580
  async function Ca(e, t = [], n = {}) {
8598
- 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);
8599
8582
  i.start();
8600
8583
  try {
8601
8584
  const a = eb(r, t), c = s ? `${a}
@@ -8651,9 +8634,9 @@ const Es = {
8651
8634
  required: ["people"],
8652
8635
  additionalProperties: !1
8653
8636
  }
8654
- }, Is = "people";
8637
+ }, ks = "people";
8655
8638
  async function ja(e, t = 3, n = {}) {
8656
- const r = A(Is, n), s = I(Is, r.onProgress, r);
8639
+ const r = O(ks, n), s = k(ks, r.onProgress, r);
8657
8640
  s.start();
8658
8641
  try {
8659
8642
  const { text: o, context: i } = N(e, []), a = i ? `
@@ -8681,12 +8664,12 @@ const tb = "object", nb = { references: { type: "array", items: { type: "object"
8681
8664
  properties: nb,
8682
8665
  required: rb,
8683
8666
  additionalProperties: sb
8684
- }, ks = "pop-reference", ib = C("pop_reference_result", ob);
8667
+ }, Is = "pop-reference", ib = C("pop_reference_result", ob);
8685
8668
  async function Na(e, t, n) {
8686
8669
  [t, n] = K(t, n);
8687
- 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);
8688
8671
  i.start();
8689
- const { referenceContext: a, referencesPerSource: c } = await q(o, {
8672
+ const { referenceContext: a, referencesPerSource: c } = await F(o, {
8690
8673
  referenceContext: !1,
8691
8674
  referencesPerSource: 2
8692
8675
  }), { include: l = [] } = o;
@@ -8791,9 +8774,9 @@ One question per string.`;
8791
8774
  }, gb = async function* (t, n = {}) {
8792
8775
  const { text: r, context: s } = N(t, []), o = s ? `${r}
8793
8776
 
8794
- ${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);
8795
8778
  a.start();
8796
- const { exploration: c } = await q(i, {
8779
+ const { exploration: c } = await F(i, {
8797
8780
  exploration: J(lb)
8798
8781
  }), l = [], u = {}, p = [];
8799
8782
  let d = !1, h = o;
@@ -8802,7 +8785,7 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
8802
8785
  try {
8803
8786
  for (; !d; ) {
8804
8787
  if (a.emit({
8805
- event: k.step,
8788
+ event: A.step,
8806
8789
  stepName: "generating-round",
8807
8790
  attempt: g + 1,
8808
8791
  questionsFound: l.length
@@ -8827,18 +8810,18 @@ ${s}` : r, i = A(As, n), a = I(As, i.onProgress, i);
8827
8810
  ...i,
8828
8811
  temperature: f,
8829
8812
  responseFormat: C("questions_list", ab)
8830
- }, S = await M(() => _(m, w), {
8813
+ }, v = await M(() => _(m, w), {
8831
8814
  label: "questions-generate",
8832
8815
  config: i
8833
- }), v = pb(S, c);
8816
+ }), S = pb(v, c);
8834
8817
  if (c < 0.5) {
8835
- const x = Math.floor(Math.random() * v.length);
8836
- h = v[x];
8818
+ const x = Math.floor(Math.random() * S.length);
8819
+ h = S[x];
8837
8820
  }
8838
- const P = v.filter((x) => !(x in u));
8821
+ const P = S.filter((x) => !(x in u));
8839
8822
  g += 1;
8840
8823
  for (const x of P) {
8841
- if (await b(x, l, v, g)) {
8824
+ if (await b(x, l, S, g)) {
8842
8825
  d = !0;
8843
8826
  break;
8844
8827
  }
@@ -8908,7 +8891,7 @@ function un(e) {
8908
8891
  }));
8909
8892
  }
8910
8893
  async function La(e, t = {}) {
8911
- const n = A("relations:spec", t), { canonicalization: r } = await q(n, {
8894
+ const n = O("relations:spec", t), { canonicalization: r } = await F(n, {
8912
8895
  canonicalization: J(Ma)
8913
8896
  }), s = "You are a relation specification generator. Create a clear, concise specification for relation extraction.";
8914
8897
  let o, i, a;
@@ -8953,7 +8936,7 @@ Use natural language, not symbolic identifiers or linked data formats.`, await M
8953
8936
  );
8954
8937
  }
8955
8938
  async function Pb(e, t, n = {}) {
8956
- const r = A("relations:apply", n), { canonicalization: s } = await q(r, {
8939
+ const r = O("relations:apply", n), { canonicalization: s } = await F(r, {
8957
8940
  canonicalization: J(Ma)
8958
8941
  }), { entities: o } = r;
8959
8942
  let i = `Apply the relation specification to extract relations from this text.
@@ -9001,13 +8984,13 @@ Canonicalization: LOOSE — preserve original entity forms from the text. Only m
9001
8984
  }
9002
8985
  async function Ba(e, t, n) {
9003
8986
  [t, n] = K(t, n, ["spec"]);
9004
- 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);
9005
8988
  a.start();
9006
8989
  try {
9007
8990
  const c = o ? `${r}
9008
8991
 
9009
8992
  ${o}` : r, l = s.spec || await La(c, i);
9010
- a.emit({ event: k.phase, phase: "applying-relations", specification: l });
8993
+ a.emit({ event: A.phase, phase: "applying-relations", specification: l });
9011
8994
  const p = (await Pb(e, l, i)).items || [];
9012
8995
  return a.complete({ outcome: T.success }), p;
9013
8996
  } catch (c) {
@@ -9015,11 +8998,11 @@ ${o}` : r, l = s.spec || await La(c, i);
9015
8998
  }
9016
8999
  }
9017
9000
  Ba.knownTexts = ["spec"];
9018
- 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 = {
9019
9002
  $schema: Tb,
9020
9003
  $id: Eb,
9021
- type: Ib,
9022
- properties: kb,
9004
+ type: kb,
9005
+ properties: Ib,
9023
9006
  required: Ab,
9024
9007
  description: Ob
9025
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 = {
@@ -9171,7 +9154,7 @@ const Tb = "http://json-schema.org/draft-07/schema#", Eb = "http://example.com/s
9171
9154
  async function Va(e, t, n = {}) {
9172
9155
  const { text: r, context: s } = N(e, []), o = s ? `${r}
9173
9156
 
9174
- ${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);
9175
9158
  a.start();
9176
9159
  try {
9177
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), {
@@ -9251,7 +9234,7 @@ A: ${p.answer}`).join(`
9251
9234
  {
9252
9235
  label: "socratic-ask",
9253
9236
  config: o,
9254
- onProgress: L(o?.onProgress, "ask")
9237
+ onProgress: B(o?.onProgress, "ask")
9255
9238
  }
9256
9239
  );
9257
9240
  }, Sw = async ({
@@ -9278,15 +9261,15 @@ A: ${p.answer}`).join(`
9278
9261
  {
9279
9262
  label: "socratic-answer",
9280
9263
  config: o,
9281
- onProgress: L(o?.onProgress, "answer")
9264
+ onProgress: B(o?.onProgress, "answer")
9282
9265
  }
9283
9266
  );
9284
9267
  };
9285
9268
  class tt {
9286
9269
  static async create(t, n = {}) {
9287
- const { text: r, context: s } = N(t, []), o = A(it, n), i = I(it, o.onProgress, o);
9288
- i.start(), i.emit({ event: k.input, value: r });
9289
- 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, {
9290
9273
  challenge: J(Cs, ["challenge", "temperature"])
9291
9274
  });
9292
9275
  return new tt(
@@ -9303,8 +9286,8 @@ class tt {
9303
9286
  this.emitter = s ? n.emitter : void 0, this.bundleContext = s ? n.bundleContext ?? "" : "";
9304
9287
  const o = s ? n.config : n, { ask: i = vw, answer: a = Sw, llm: c, abortSignal: l } = o;
9305
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) {
9306
- const u = A(it, o);
9307
- 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);
9308
9291
  }
9309
9292
  this.abortSignal = l;
9310
9293
  }
@@ -9314,7 +9297,7 @@ class tt {
9314
9297
  async step() {
9315
9298
  const t = this.history.length + 1;
9316
9299
  this.emitter.emit({
9317
- event: k.step,
9300
+ event: A.step,
9318
9301
  stepName: "asking-question",
9319
9302
  turnNumber: t,
9320
9303
  topic: this.statement
@@ -9329,7 +9312,7 @@ class tt {
9329
9312
  bundleContext: this.bundleContext
9330
9313
  });
9331
9314
  this.emitter.emit({
9332
- event: k.step,
9315
+ event: A.step,
9333
9316
  stepName: "answering-question",
9334
9317
  turnNumber: t,
9335
9318
  question: n
@@ -9350,12 +9333,12 @@ class tt {
9350
9333
  const n = this.emitter.batch(t);
9351
9334
  for (let r = 0; r < t; r += 1)
9352
9335
  this.emitter.emit({
9353
- event: k.phase,
9336
+ event: A.phase,
9354
9337
  phase: `round-${r + 1}`,
9355
9338
  round: r + 1,
9356
9339
  totalRounds: t
9357
9340
  }), await this.step(), n(1);
9358
- 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;
9359
9342
  } catch (n) {
9360
9343
  throw this.emitter.error(n), n;
9361
9344
  }
@@ -9413,17 +9396,17 @@ const Ns = "split", zt = { short: 0.5, long: 0.1 }, Pw = (e) => e === void 0 ? z
9413
9396
  - Each section should be substantively different from adjacent sections
9414
9397
  - Preserve ALL original text exactly - only add delimiters
9415
9398
  - For topic changes: Look for shifts in subject matter, not just related themes
9416
- - 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:
9417
9400
  - Only insert "${e}" at semantic boundaries - where the meaning, topic, or argument shifts
9418
9401
  - Ignore structural markers like paragraph breaks, headings, or bullet lists unless they coincide with a genuine meaning shift
9419
9402
  - A new example or anecdote supporting the SAME point is NOT a split boundary
9420
9403
  - Split when the author moves to a different claim, a different subject, or a different phase of reasoning
9421
9404
  - Preserve ALL original text exactly - only add delimiters
9422
- - 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 = {}) => {
9423
9406
  const { previousContent: s = "", targetSplitCount: o = void 0, mode: i = "structural" } = r, a = o ? `
9424
9407
  - Aim for approximately ${o} sections in this chunk` : "", c = s ? `
9425
9408
 
9426
- ${$(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);
9427
9410
  return `You are marking split points in text with "${n}".
9428
9411
 
9429
9412
  ${$(t, { tag: "instructions" })}
@@ -9436,7 +9419,7 @@ async function Ja(e, t, n) {
9436
9419
  [t, n] = K(t, n);
9437
9420
  const { text: r, context: s } = N(t, []), o = s ? `${r}
9438
9421
 
9439
- ${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);
9440
9423
  a.start();
9441
9424
  const {
9442
9425
  chunkLen: c,
@@ -9444,7 +9427,7 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
9444
9427
  temperature: u,
9445
9428
  preservation: p,
9446
9429
  mode: d
9447
- } = await q(i, {
9430
+ } = await F(i, {
9448
9431
  chunkLen: 4e3,
9449
9432
  targetSplitsPerChunk: void 0,
9450
9433
  temperature: 0.1,
@@ -9458,28 +9441,28 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
9458
9441
  try {
9459
9442
  const f = Kn(e, c), g = a.batch(f.length), m = await Q(
9460
9443
  f,
9461
- async (v, P) => {
9462
- const E = kw(v, o, h, {
9444
+ async (S, P) => {
9445
+ const E = Iw(S, o, h, {
9463
9446
  targetSplitCount: l,
9464
9447
  mode: d
9465
- }), O = {
9448
+ }), I = {
9466
9449
  ...i,
9467
9450
  temperature: u
9468
9451
  };
9469
9452
  try {
9470
- const R = await M(() => _(E, O), {
9453
+ const R = await M(() => _(E, I), {
9471
9454
  label: "split",
9472
9455
  config: i,
9473
- onProgress: L(i.onProgress, "chunk")
9456
+ onProgress: B(i.onProgress, "chunk")
9474
9457
  }), j = R.replace(
9475
9458
  new RegExp(h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
9476
9459
  ""
9477
- ), F = v.trim(), V = F.length < 100 ? y : b;
9478
- 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(
9479
9462
  `Split output differs significantly from input for chunk ${P + 1}, using original chunk`
9480
- ), g(1), v) : (g(1), R);
9463
+ ), g(1), S) : (g(1), R);
9481
9464
  } catch (R) {
9482
- 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;
9483
9466
  }
9484
9467
  },
9485
9468
  {
@@ -9488,12 +9471,12 @@ ${s}` : r, i = A(Ns, { llm: { fast: !0, good: !0, cheap: !0 }, ...n }), a = I(Ns
9488
9471
  abortSignal: i.abortSignal,
9489
9472
  label: "split chunks"
9490
9473
  }
9491
- ), 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);
9492
9475
  return a.complete({
9493
9476
  outcome: T.success,
9494
9477
  chunks: f.length,
9495
- segments: S.length
9496
- }), S;
9478
+ segments: v.length
9479
+ }), v;
9497
9480
  } catch (f) {
9498
9481
  throw a.error(f), f;
9499
9482
  }
@@ -9546,7 +9529,7 @@ class Ka extends Map {
9546
9529
  targetTokensTotalRatio: a = jw(i),
9547
9530
  ...c
9548
9531
  }) {
9549
- 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)
9550
9533
  this.targetTokens = o;
9551
9534
  else if (s && n) {
9552
9535
  this.promptTokens = n.toTokens(s).length;
@@ -9564,7 +9547,7 @@ class Ka extends Map {
9564
9547
  return { totalSizeWeight: t, budgets: r };
9565
9548
  }
9566
9549
  async myFillCache() {
9567
- const t = I(Ms, this.runConfig.onProgress, this.runConfig);
9550
+ const t = k(Ms, this.runConfig.onProgress, this.runConfig);
9568
9551
  t.start();
9569
9552
  try {
9570
9553
  const { budgets: n } = this.calculateBudgets(), r = t.batch(n.length);
@@ -9595,7 +9578,7 @@ class Ka extends Map {
9595
9578
  }
9596
9579
  const y = c.toTokens(h).length;
9597
9580
  t.emit({
9598
- event: k.step,
9581
+ event: A.step,
9599
9582
  stepName: "context-trim",
9600
9583
  key: s,
9601
9584
  originalTokens: l,
@@ -9685,7 +9668,7 @@ function Gn(e, t, n = {}) {
9685
9668
  });
9686
9669
  });
9687
9670
  const a = Object.entries(i).map(([m, w]) => ({
9688
- tag: e.tags.find((S) => S.id === m),
9671
+ tag: e.tags.find((v) => v.id === m),
9689
9672
  count: w
9690
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 = {
9691
9674
  totalItems: t.length,
@@ -9721,7 +9704,7 @@ function Gn(e, t, n = {}) {
9721
9704
  };
9722
9705
  }
9723
9706
  async function Dw(e, t, n = {}) {
9724
- 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.
9725
9708
 
9726
9709
  ${$(e, { tag: "tag-system-specification" })}
9727
9710
 
@@ -9749,7 +9732,7 @@ The vocabulary should be complete enough to categorize diverse items along the i
9749
9732
  );
9750
9733
  }
9751
9734
  async function qw(e, t, n, r = {}) {
9752
- 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.
9753
9736
 
9754
9737
  ${$(n, { tag: "original-specification" })}
9755
9738
 
@@ -9787,7 +9770,7 @@ Return an improved vocabulary that provides better coverage and clearer distinct
9787
9770
  async function Ya(e, t, n = {}) {
9788
9771
  const { text: r, known: s, context: o } = N(e, ["initialVocab"]), i = o ? `${r}
9789
9772
 
9790
- ${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);
9791
9774
  c.start();
9792
9775
  try {
9793
9776
  const { tagger: l, sampleSize: u = 50 } = a;
@@ -9799,19 +9782,19 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
9799
9782
  else {
9800
9783
  const b = t.slice(0, Math.min(u, t.length));
9801
9784
  c.emit({
9802
- event: k.step,
9785
+ event: A.step,
9803
9786
  stepName: "generate-initial-vocabulary",
9804
9787
  sampleCount: b.length
9805
9788
  }), p = await Dw(i, b, a);
9806
9789
  }
9807
9790
  c.emit({
9808
- event: k.step,
9791
+ event: A.step,
9809
9792
  stepName: "apply-tags",
9810
9793
  itemCount: t.length,
9811
9794
  initialVocab: p
9812
9795
  });
9813
9796
  const d = await l(t, p), h = Gn(p, d);
9814
- c.emit({ event: k.step, stepName: "refine-vocabulary", statistics: h });
9797
+ c.emit({ event: A.step, stepName: "refine-vocabulary", statistics: h });
9815
9798
  const y = await qw(p, d, i, a);
9816
9799
  return c.complete({ outcome: T.success }), y;
9817
9800
  } catch (l) {
@@ -9821,9 +9804,9 @@ ${o}` : r, a = A(Ls, n), c = I(Ls, a.onProgress, a);
9821
9804
  Ya.knownTexts = ["initialVocab"];
9822
9805
  const Bs = "themes", Fw = (e) => e.split(/\n{2,}/).map((t) => t.trim()).filter(Boolean);
9823
9806
  async function Ha(e, t = {}) {
9824
- 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);
9825
9808
  i.start();
9826
- const { topN: a } = await q(o, {
9809
+ const { topN: a } = await F(o, {
9827
9810
  topN: void 0
9828
9811
  });
9829
9812
  try {
@@ -9833,25 +9816,25 @@ async function Ha(e, t = {}) {
9833
9816
  else {
9834
9817
  const h = Fw(n);
9835
9818
  i.emit({
9836
- event: k.phase,
9819
+ event: A.phase,
9837
9820
  phase: "extraction"
9838
9821
  });
9839
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 ? `
9840
9823
 
9841
9824
  ${s}` : ""}`, f = Wn(h);
9842
- c = (await Ie(f, b, {
9825
+ c = (await ke(f, b, {
9843
9826
  ...o,
9844
- onProgress: L(o.onProgress, "themes:extract")
9827
+ onProgress: B(o.onProgress, "themes:extract")
9845
9828
  })).split(",").map((m) => m.trim()).filter(Boolean);
9846
9829
  }
9847
9830
  i.emit({
9848
- event: k.phase,
9831
+ event: A.phase,
9849
9832
  phase: "refinement",
9850
9833
  rawThemes: c
9851
9834
  });
9852
- 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, {
9853
9836
  ...o,
9854
- onProgress: L(o.onProgress, "themes:refine")
9837
+ onProgress: B(o.onProgress, "themes:refine")
9855
9838
  })).split(",").map((h) => h.trim()).filter(Boolean);
9856
9839
  return i.complete({ outcome: T.success, themes: d.length }), d;
9857
9840
  } catch (c) {
@@ -9922,9 +9905,9 @@ async function Vw(e, t = {}) {
9922
9905
  }
9923
9906
  async function Qa(e, t, n) {
9924
9907
  [t, n] = K(t, n, ["knowledge"]);
9925
- 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(`
9926
9909
 
9927
- `), c = I(Ds, i.onProgress, i);
9910
+ `), c = k(Ds, i.onProgress, i);
9928
9911
  c.start();
9929
9912
  const {
9930
9913
  chunkSize: l,
@@ -9934,7 +9917,7 @@ async function Qa(e, t, n) {
9934
9917
  llmDedup: h,
9935
9918
  knowledgeBase: y,
9936
9919
  enrichMap: b
9937
- } = await q(i, {
9920
+ } = await F(i, {
9938
9921
  enrichment: J(zw, ["llmDedup", "knowledgeBase", "enrichMap"]),
9939
9922
  chunkSize: 2e3,
9940
9923
  overlap: 200,
@@ -9942,26 +9925,26 @@ async function Qa(e, t, n) {
9942
9925
  errorPosture: z.resilient
9943
9926
  }), f = s.knowledge, { onProgress: g, batchSize: m, now: w } = i;
9944
9927
  try {
9945
- 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 = [];
9946
9929
  let E = 0;
9947
9930
  await Q(
9948
9931
  P,
9949
- async (j, F) => {
9932
+ async (j, L) => {
9950
9933
  try {
9951
9934
  const V = await M(
9952
9935
  () => Vw(j, { ...i, now: w, systemPrompt: a }),
9953
9936
  {
9954
- label: `timeline chunk ${F + 1}`,
9937
+ label: `timeline chunk ${L + 1}`,
9955
9938
  config: i
9956
9939
  }
9957
9940
  );
9958
- x.push(...V), g?.(F + 1, P.length);
9941
+ x.push(...V), g?.(L + 1, P.length);
9959
9942
  } catch (V) {
9960
9943
  if (E++, d === z.strict) throw V;
9961
9944
  i.logger?.warn && i.logger.warn(
9962
- `Timeline extraction failed for chunk ${F + 1}:`,
9945
+ `Timeline extraction failed for chunk ${L + 1}:`,
9963
9946
  V.message
9964
- ), g?.(F + 1, P.length);
9947
+ ), g?.(L + 1, P.length);
9965
9948
  }
9966
9949
  },
9967
9950
  {
@@ -9970,20 +9953,20 @@ async function Qa(e, t, n) {
9970
9953
  label: "timeline chunks",
9971
9954
  abortSignal: i.abortSignal
9972
9955
  }
9973
- ), ne(`Timeline: processed ${P.length} chunks, found ${x.length} total events`), v(1);
9974
- let O = Ww([x]);
9975
- if (h && O.length > 0) {
9976
- const j = O.map((H) => `- ${H.timestamp}: ${H.name}`).join(`
9977
- `), 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.
9978
9961
 
9979
- ${$(j, { tag: "events" })}`, V = await _(F, {
9962
+ ${$(j, { tag: "events" })}`, V = await _(L, {
9980
9963
  ...i,
9981
9964
  systemPrompt: "You are a timeline deduplication engine. Return all unique events, merging only true duplicates.",
9982
9965
  responseFormat: C(Le.name, Le.schema)
9983
9966
  }), Y = V?.events || V;
9984
- Array.isArray(Y) && Y.length > 0 && (O = Ke(Y)), v(1);
9967
+ Array.isArray(Y) && Y.length > 0 && (I = Ke(Y)), S(1);
9985
9968
  }
9986
- if ((y || f) && O.length > 0) {
9969
+ if ((y || f) && I.length > 0) {
9987
9970
  let j = [];
9988
9971
  if (f)
9989
9972
  try {
@@ -10002,24 +9985,24 @@ Given the current knowledge base and a new event, return an updated knowledge ba
10002
9985
  4. Adds important related events that fall within the timeline scope (between first and last events)
10003
9986
  5. Include events that provide crucial context or fill important gaps
10004
9987
 
10005
- 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, {
10006
9989
  ...i,
10007
9990
  initial: JSON.stringify({ events: [] }),
10008
9991
  responseFormat: C(Le.name, Le.schema),
10009
9992
  ...m !== void 0 && { batchSize: m },
10010
- onProgress: L(i.onProgress, "reduce:knowledge-base")
9993
+ onProgress: B(i.onProgress, "reduce:knowledge-base")
10011
9994
  });
10012
9995
  try {
10013
- j = Ke(de.events || []);
9996
+ j = Ke(pe.events || []);
10014
9997
  } catch (Z) {
10015
9998
  ne("Failed to parse knowledge base:", Z.message);
10016
9999
  }
10017
10000
  }
10018
- c.emit({ event: k.phase, phase: "enrichment", knowledgeBase: j }), v(1);
10019
- 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(`
10020
10003
  `), V = `Given an extracted event, enrich it using this knowledge base:
10021
10004
 
10022
- ${$(F, { tag: "knowledge-base" })}
10005
+ ${$(L, { tag: "knowledge-base" })}
10023
10006
 
10024
10007
  Rules:
10025
10008
  1. If the knowledge base has a more accurate date for this event, use it
@@ -10028,33 +10011,33 @@ Rules:
10028
10011
  4. Keep the original if the knowledge base doesn't have better information
10029
10012
 
10030
10013
  Return the enriched event as: "YYYY-MM-DD: Event name" or with the appropriate timestamp format.`, H = (await Oe(
10031
- O.map((G) => `${G.timestamp}: ${G.name}`),
10014
+ I.map((G) => `${G.timestamp}: ${G.name}`),
10032
10015
  V,
10033
10016
  {
10034
10017
  ...i,
10035
10018
  ...m !== void 0 && { batchSize: m },
10036
10019
  maxParallel: p,
10037
- onProgress: L(i.onProgress, "map:enrichment")
10020
+ onProgress: B(i.onProgress, "map:enrichment")
10038
10021
  }
10039
10022
  )).map((G, te) => {
10040
- if (!G) return O[te];
10023
+ if (!G) return I[te];
10041
10024
  const ie = G.indexOf(":");
10042
10025
  if (ie > 0) {
10043
- 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;
10044
10027
  return {
10045
- timestamp: de,
10028
+ timestamp: pe,
10046
10029
  name: Z,
10047
10030
  ...we && { enriched: !0 }
10048
10031
  };
10049
10032
  }
10050
- return O[te];
10051
- }), ee = new Set(H.map((G) => G.name.toLowerCase())), pe = j.filter((G) => !ee.has(G.name.toLowerCase()));
10052
- 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);
10053
10036
  }
10054
10037
  const R = E > 0 ? T.partial : T.success;
10055
- return c.complete({ outcome: R }), O;
10056
- } catch (S) {
10057
- throw c.error(S), S;
10038
+ return c.complete({ outcome: R }), I;
10039
+ } catch (v) {
10040
+ throw c.error(v), v;
10058
10041
  }
10059
10042
  }
10060
10043
  Qa.knownTexts = ["knowledge"];
@@ -10113,7 +10096,7 @@ ${r}
10113
10096
  </error>`));
10114
10097
  }
10115
10098
  async function ec(e, t, n = {}) {
10116
- 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);
10117
10100
  s.start();
10118
10101
  let o;
10119
10102
  try {
@@ -10170,9 +10153,9 @@ function Zw(e, t) {
10170
10153
  }
10171
10154
  async function tc(e, t, n) {
10172
10155
  [t, n] = K(t, n);
10173
- 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);
10174
10157
  i.start();
10175
- const { chunkSize: a, strictness: c } = await q(o, {
10158
+ const { chunkSize: a, strictness: c } = await F(o, {
10176
10159
  chunkSize: 1e3,
10177
10160
  strictness: J(Xw)
10178
10161
  });
@@ -10184,9 +10167,9 @@ ${s}` : "", h = `${$(r, { tag: "removal_criteria" })}
10184
10167
  NOTE: These text blocks are in REVERSE order (from end to beginning of document).
10185
10168
  Score how important THE ENTIRE TEXT BLOCK is to KEEP in the document (0 = should be removed, 10 = must keep).
10186
10169
  Each item in the list is ONE complete text block - evaluate it as a whole unit.
10187
- 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, {
10188
10171
  ...o,
10189
- onProgress: L(o.onProgress, "score:relevance")
10172
+ onProgress: B(o.onProgress, "score:relevance")
10190
10173
  // Don't use stopOnThreshold - we need all scores to find high ones
10191
10174
  })).findIndex((g) => (g ?? 1 / 0) < c);
10192
10175
  let f;
@@ -10247,9 +10230,9 @@ ${$(e, { tag: "intent" })}`, Yn = ["scientific", "causal", "softCover"], nv = {
10247
10230
  }[e] ?? Kt, oc = async (e, t = {}) => {
10248
10231
  const { text: n, context: r } = N(e, []), s = r ? `
10249
10232
 
10250
- ${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);
10251
10234
  i.start();
10252
- const { strategies: a, variantCount: c } = await q(o, {
10235
+ const { strategies: a, variantCount: c } = await F(o, {
10253
10236
  coverage: J(rv, ["strategies", "variantCount"])
10254
10237
  }), l = a.map(
10255
10238
  (u) => `${nv[u](n, c)}${s}`
@@ -10261,7 +10244,7 @@ ${r}` : "", o = A(Us, { llm: { sensitive: !0 }, ...t }), i = I(Us, o.onProgress,
10261
10244
  const h = await M(() => _(d, { ...o, responseFormat: tv }), {
10262
10245
  label: "veiled-variants",
10263
10246
  config: o,
10264
- onProgress: L(o.onProgress, "strategy")
10247
+ onProgress: B(o.onProgress, "strategy")
10265
10248
  });
10266
10249
  return u(1), h;
10267
10250
  },
@@ -10367,22 +10350,22 @@ async function pv(e, { columns: t = 2, tileHeight: n = 300, gutter: r = 4, quali
10367
10350
  w: f.info.width,
10368
10351
  h: f.info.height
10369
10352
  })), l = Math.ceil(e.length / t), u = Array.from({ length: t }, (f, g) => {
10370
- const m = c.filter((w, S) => S % t === g);
10353
+ const m = c.filter((w, v) => v % t === g);
10371
10354
  return m.length > 0 ? Math.max(...m.map((w) => w.w)) : 0;
10372
10355
  }), p = u.reduce((f, g) => f + g, 0) + r * (t - 1), d = l * n + r * (l - 1), h = [];
10373
10356
  for (let f = 0; f < c.length; f++) {
10374
- 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);
10375
- if (c[f].x = w, c[f].y = S, h.push({ input: a[f].data, left: w, top: S }), c[f].label) {
10376
- 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(
10377
- `<svg width="${c[f].w}" height="${v}">
10378
- <rect x="0" y="0" width="${c[f].w}" height="${v}" fill="rgba(0,0,0,0.6)"/>
10379
- <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>
10380
10363
  </svg>`
10381
10364
  );
10382
10365
  h.push({
10383
10366
  input: E,
10384
10367
  left: w,
10385
- top: S + c[f].h - v
10368
+ top: v + c[f].h - S
10386
10369
  });
10387
10370
  }
10388
10371
  }
@@ -10421,16 +10404,16 @@ const Vs = "analyze-image", dv = C("analysis", {
10421
10404
  [t, n] = K(t, n);
10422
10405
  const { text: r, context: s } = N(t, []), o = s ? `${r}
10423
10406
 
10424
- ${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);
10425
10408
  a.start();
10426
10409
  const c = hv(e), l = c.length;
10427
10410
  try {
10428
- const { tile: u } = await q(i, {
10411
+ const { tile: u } = await F(i, {
10429
10412
  tile: !1
10430
10413
  }), p = u && c.length > 1;
10431
10414
  let d;
10432
10415
  if (p) {
10433
- 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, {
10434
10417
  labels: g.length > 0 ? g : void 0
10435
10418
  });
10436
10419
  a.emit({
@@ -10449,7 +10432,7 @@ ${s}` : r, i = A(Vs, n), a = I(Vs, i.onProgress, i);
10449
10432
  const h = Zo(o, d), y = i.responseFormat ? i : { ...i, responseFormat: dv }, b = await M(() => _(h, y), {
10450
10433
  label: "analyze-image:llm",
10451
10434
  config: i,
10452
- onProgress: L(i.onProgress, "llm")
10435
+ onProgress: B(i.onProgress, "llm")
10453
10436
  });
10454
10437
  return a.complete({ outcome: T.success, imageCount: l, tiled: p }), b;
10455
10438
  } catch (u) {
@@ -10461,9 +10444,9 @@ const Js = "auto";
10461
10444
  async function uc(e, t = {}) {
10462
10445
  const { text: n, context: r } = N(e, []), s = r ? `${n}
10463
10446
 
10464
- ${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);
10465
10448
  i.start();
10466
- const { schemas: a, defaultFunction: c, defaultArguments: l } = await q(o, {
10449
+ const { schemas: a, defaultFunction: c, defaultArguments: l } = await F(o, {
10467
10450
  schemas: Ua,
10468
10451
  defaultFunction: void 0,
10469
10452
  defaultArguments: {}
@@ -10551,8 +10534,8 @@ async function wv({
10551
10534
  onProgress: a,
10552
10535
  operation: c
10553
10536
  }) {
10554
- const l = A(Ks, { onProgress: a, operation: c }), u = I(Ks, l.onProgress, l);
10555
- 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 });
10556
10539
  let p;
10557
10540
  try {
10558
10541
  if (t === void 0 && !n)
@@ -10566,7 +10549,7 @@ async function wv({
10566
10549
  let y;
10567
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);
10568
10551
  }
10569
- 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 });
10570
10553
  } catch (d) {
10571
10554
  throw u.error(d), d;
10572
10555
  }
@@ -10658,7 +10641,7 @@ ${o}`), t === "error")
10658
10641
  return e;
10659
10642
  }
10660
10643
  async function $v(e, t, n, r = {}) {
10661
- const s = A("expect", r), { mode: o } = await q(s, {
10644
+ const s = O("expect", r), { mode: o } = await F(s, {
10662
10645
  mode: $e.VERBLETS_LLM_EXPECT_MODE || "none"
10663
10646
  });
10664
10647
  if (t === void 0 && !n)
@@ -10690,7 +10673,7 @@ const Gs = "intent", Pv = (e) => {
10690
10673
  }[e] : e;
10691
10674
  }, Tv = C("intent_result", yt);
10692
10675
  async function dc(e, t, n = {}) {
10693
- 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);
10694
10677
  i.start();
10695
10678
  try {
10696
10679
  if (!Array.isArray(t) || t.length === 0)
@@ -10752,10 +10735,10 @@ class Ev {
10752
10735
  return this;
10753
10736
  }
10754
10737
  }
10755
- function Iv(e, t = void 0) {
10738
+ function kv(e, t = void 0) {
10756
10739
  return new Ev(e, t);
10757
10740
  }
10758
- function kv(e) {
10741
+ function Iv(e) {
10759
10742
  const n = new Error().stack.split(`
10760
10743
  `);
10761
10744
  if (e === void 0) {
@@ -10784,7 +10767,7 @@ function Av(e) {
10784
10767
  } : { file: "unknown", line: 0 };
10785
10768
  }
10786
10769
  function Ov(e = 0) {
10787
- const t = kv(4 + e);
10770
+ const t = Iv(4 + e);
10788
10771
  return {
10789
10772
  filePath: t.file,
10790
10773
  line: t.line
@@ -10839,18 +10822,18 @@ function Hs(e) {
10839
10822
  }
10840
10823
  const Qs = "llm-logger";
10841
10824
  function mc(e = {}) {
10842
- const t = A(Qs, e), n = I(Qs, t.onProgress, t);
10825
+ const t = O(Qs, e), n = k(Qs, t.onProgress, t);
10843
10826
  n.start();
10844
10827
  try {
10845
- let g = function(m, w = "log", S = 0) {
10846
- const v = Ov(S), P = {
10828
+ let g = function(m, w = "log", v = 0) {
10829
+ const S = Ov(v), P = {
10847
10830
  id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
10848
10831
  ts: /* @__PURE__ */ new Date(),
10849
10832
  raw: m,
10850
10833
  // Store original data as-is (any structure)
10851
10834
  meta: /* @__PURE__ */ new Map([
10852
10835
  ["level", w],
10853
- ["fileContext", v]
10836
+ ["fileContext", S]
10854
10837
  ]),
10855
10838
  attachments: {},
10856
10839
  // AI enrichments to merge
@@ -10883,8 +10866,8 @@ function mc(e = {}) {
10883
10866
  ...m.ts ? {} : { ts: P.ts },
10884
10867
  ...m.level ? {} : { level: w },
10885
10868
  // Add file context
10886
- ...m.file ? {} : { file: v.filePath },
10887
- ...m.line ? {} : { line: v.line }
10869
+ ...m.file ? {} : { file: S.filePath },
10870
+ ...m.line ? {} : { line: S.line }
10888
10871
  } : E = {
10889
10872
  data: m,
10890
10873
  id: P.id,
@@ -10928,17 +10911,17 @@ function mc(e = {}) {
10928
10911
  hostLogger: c = void 0
10929
10912
  } = e, l = new Mn(r), u = [], p = c ? Hs(c) : void 0, d = /* @__PURE__ */ new Map();
10930
10913
  s.forEach((m) => {
10931
- 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, []);
10932
10915
  });
10933
10916
  const h = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
10934
10917
  let b = !1;
10935
10918
  o.forEach((m) => {
10936
10919
  const w = l.registerReader();
10937
10920
  y.set(m.processorId, w), h.set(m.processorId, -1);
10938
- const S = m.batchSize || 10, v = async () => {
10921
+ const v = m.batchSize || 10, S = async () => {
10939
10922
  if (!b)
10940
10923
  try {
10941
- 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
10942
10925
  # Processor: ${m.processorId} (${m.description || "No description"})
10943
10926
  # Batch size: ${P.data.length} logs
10944
10927
  # Task: Analyze the following NDJSON log entries and return bulk adjustments
@@ -10959,32 +10942,32 @@ function mc(e = {}) {
10959
10942
  # ]
10960
10943
  #
10961
10944
  # NDJSON Log Data:
10962
- ` + x, R = await m.process(O);
10945
+ ` + x, R = await m.process(I);
10963
10946
  if (Array.isArray(R))
10964
10947
  for (const j of R) {
10965
- const F = u.findIndex((V) => V.id === j.logId);
10966
- if (F !== -1) {
10967
- const V = u[F];
10948
+ const L = u.findIndex((V) => V.id === j.logId);
10949
+ if (L !== -1) {
10950
+ const V = u[L];
10968
10951
  if (j.adjustments)
10969
10952
  for (const [Y, H] of Object.entries(j.adjustments))
10970
10953
  Ys(V.attachments, Y, H);
10971
10954
  j.aiMeta && (V.aiMeta || (V.aiMeta = {}), Object.assign(V.aiMeta, j.aiMeta));
10972
10955
  }
10973
10956
  }
10974
- h.set(m.processorId, P.lastOffset), b || setTimeout(v, 0);
10957
+ h.set(m.processorId, P.lastOffset), b || setTimeout(S, 0);
10975
10958
  } catch (P) {
10976
- 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);
10977
10960
  }
10978
10961
  };
10979
- v();
10962
+ S();
10980
10963
  });
10981
10964
  const f = () => {
10982
10965
  for (const [m, w] of d)
10983
10966
  if (w.length > 0) {
10984
- const S = s.find((v) => v.laneId === m);
10985
- if (S) {
10986
- const v = w.filter((P) => !P.aiMeta?.skip);
10987
- 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;
10988
10971
  }
10989
10972
  }
10990
10973
  };
@@ -11007,17 +10990,17 @@ function mc(e = {}) {
11007
10990
  trace: (m, w = 0) => g(m, "trace", w),
11008
10991
  fatal: (m, w = 0) => g(m, "fatal", w),
11009
10992
  // Enhanced attachment API
11010
- attachToLog: (m, w, S) => {
11011
- const v = u.findIndex((P) => P.id === m);
11012
- 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;
11013
10996
  },
11014
10997
  getLogAttachment: (m, w) => {
11015
- const S = u.find((v) => v.id === m);
11016
- 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;
11017
11000
  },
11018
11001
  markLogSkippable: (m, w = !0) => {
11019
- const S = u.findIndex((v) => v.id === m);
11020
- 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;
11021
11004
  },
11022
11005
  // Ring buffer access - legacy API compatibility
11023
11006
  ringBuffer: {
@@ -11065,15 +11048,15 @@ function mc(e = {}) {
11065
11048
  }),
11066
11049
  // Wait for all processors to catch up to current write position
11067
11050
  waitForProcessing: async (m = 3e4) => {
11068
- const w = Date.now(), v = l.getStats().writeOffset;
11069
- if (v === 0)
11051
+ const w = Date.now(), S = l.getStats().writeOffset;
11052
+ if (S === 0)
11070
11053
  return;
11071
11054
  f();
11072
- const P = (x, E) => E + 1 < v;
11055
+ const P = (x, E) => E + 1 < S;
11073
11056
  for (; Date.now() - w < m; ) {
11074
11057
  let x = !0;
11075
- for (const [E, O] of h)
11076
- if (P(E, O)) {
11058
+ for (const [E, I] of h)
11059
+ if (P(E, I)) {
11077
11060
  x = !1;
11078
11061
  break;
11079
11062
  }
@@ -11085,9 +11068,9 @@ function mc(e = {}) {
11085
11068
  }
11086
11069
  if (p) {
11087
11070
  const x = [];
11088
- for (const [E, O] of h)
11089
- if (P(E, O)) {
11090
- const R = v - O - 1;
11071
+ for (const [E, I] of h)
11072
+ if (P(E, I)) {
11073
+ const R = S - I - 1;
11091
11074
  x.push(`${E} (${R} logs pending)`);
11092
11075
  }
11093
11076
  p.warn(
@@ -11220,7 +11203,7 @@ Provide:
11220
11203
  additionalProperties: !1
11221
11204
  };
11222
11205
  async function pn(e, t = {}) {
11223
- 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);
11224
11207
  o.start();
11225
11208
  try {
11226
11209
  const {
@@ -11276,7 +11259,7 @@ const Lv = {
11276
11259
  additionalProperties: !1
11277
11260
  }, Zs = "sentiment";
11278
11261
  async function hc(e, t = {}) {
11279
- 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);
11280
11263
  o.start();
11281
11264
  const i = [
11282
11265
  `Identify the overall sentiment of the following text as "positive", "negative", or "neutral".
@@ -11367,21 +11350,21 @@ function gc({
11367
11350
  llm: o,
11368
11351
  ...i
11369
11352
  } = {}) {
11370
- const { text: a, context: c } = N(e, []), l = A(eo, { llm: o, ...i }), u = I(eo, l.onProgress, l);
11371
- 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 });
11372
11355
  const p = l.now ?? /* @__PURE__ */ new Date(), d = u.batch();
11373
11356
  let h, y = 0, b = 0, f = r;
11374
11357
  const g = [];
11375
11358
  let m = !0, w;
11376
- const S = async () => {
11359
+ const v = async () => {
11377
11360
  if (!m) return;
11378
- w || (w = await q(l, {
11361
+ w || (w = await F(l, {
11379
11362
  tolerance: J(Wv)
11380
11363
  }));
11381
11364
  const { tolerance: P } = w;
11382
11365
  try {
11383
11366
  u.emit({
11384
- event: k.step,
11367
+ event: A.step,
11385
11368
  stepName: "tick",
11386
11369
  tickNumber: y + 1
11387
11370
  }), f = await t({
@@ -11389,7 +11372,7 @@ function gc({
11389
11372
  lastInvocationResult: f,
11390
11373
  initial: r
11391
11374
  });
11392
- const x = fc(a, f), O = [
11375
+ const x = fc(a, f), I = [
11393
11376
  `${Bv} ${x}`,
11394
11377
  `${Dv} ${qv}`,
11395
11378
  'Your response should be an ISO date or a short duration like "10 minutes".',
@@ -11401,7 +11384,7 @@ function gc({
11401
11384
  ].filter(Boolean).join(`
11402
11385
 
11403
11386
  `), R = await M(
11404
- () => _(O, {
11387
+ () => _(I, {
11405
11388
  ...l,
11406
11389
  responseFormat: zv
11407
11390
  }),
@@ -11413,21 +11396,21 @@ function gc({
11413
11396
  g.push(R), g.length > n && g.shift();
11414
11397
  const j = await Uv(R, l);
11415
11398
  if (s) {
11416
- const F = new Date(Date.now() + j);
11399
+ const L = new Date(Date.now() + j);
11417
11400
  await s({
11418
11401
  timingString: R,
11419
11402
  data: f,
11420
- nextDate: F
11403
+ nextDate: L
11421
11404
  });
11422
11405
  }
11423
11406
  u.measure({
11424
11407
  metric: ge.tickDuration,
11425
11408
  value: Date.now() - p.getTime(),
11426
11409
  tickNumber: y + 1
11427
- }), b = 0, y += 1, d(1), m && (h = setTimeout(S, j));
11410
+ }), b = 0, y += 1, d(1), m && (h = setTimeout(v, j));
11428
11411
  } catch (x) {
11429
11412
  if (ne(`Error in setInterval step: ${x.message}`), b += 1, u.emit({
11430
- event: k.step,
11413
+ event: A.step,
11431
11414
  stepName: "tick-error",
11432
11415
  tickNumber: y + 1,
11433
11416
  error: x.message,
@@ -11442,10 +11425,10 @@ function gc({
11442
11425
  m = !1, clearTimeout(h), u.error(x);
11443
11426
  return;
11444
11427
  }
11445
- m && (h = setTimeout(S, 1e3));
11428
+ m && (h = setTimeout(v, 1e3));
11446
11429
  }
11447
11430
  };
11448
- return h = setTimeout(S, 0), () => {
11431
+ return h = setTimeout(v, 0), () => {
11449
11432
  m = !1, clearTimeout(h), u.complete({ outcome: T.success, ticks: y });
11450
11433
  };
11451
11434
  }
@@ -11460,7 +11443,7 @@ function xt(e, t = {}) {
11460
11443
  return r = r.replace(/[^\S\n]+/g, " "), r.trim();
11461
11444
  }
11462
11445
  function Vv() {
11463
- const e = D("VERBLETS_EMBED_MODEL");
11446
+ const e = q("VERBLETS_EMBED_MODEL");
11464
11447
  return {
11465
11448
  [e]: {
11466
11449
  name: e,
@@ -11491,7 +11474,7 @@ function Vv() {
11491
11474
  };
11492
11475
  }
11493
11476
  function Jv() {
11494
- const e = D("VERBLETS_EMBED_MODEL");
11477
+ const e = q("VERBLETS_EMBED_MODEL");
11495
11478
  return [
11496
11479
  { match: { good: !0, multi: !1 }, use: e },
11497
11480
  { use: "Xenova/clip-vit-base-patch16" }
@@ -11540,16 +11523,16 @@ async function Yv(e) {
11540
11523
  const { batchSize: y = r, abortSignal: b } = h, f = dn(d, y), g = [];
11541
11524
  for (const m of f) {
11542
11525
  b?.throwIfAborted();
11543
- 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];
11544
11527
  for (let x = 0; x < m.length; x++)
11545
- 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))));
11546
11529
  }
11547
11530
  return g;
11548
11531
  }, embedImages: async (d, h = {}) => {
11549
11532
  const { batchSize: y = s, abortSignal: b } = h, f = dn(d, y), g = [];
11550
11533
  for (const m of f) {
11551
11534
  b?.throwIfAborted();
11552
- 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];
11553
11536
  for (let E = 0; E < m.length; E++)
11554
11537
  g.push(no(new Float32Array(P.data.slice(E * x, (E + 1) * x))));
11555
11538
  }
@@ -11755,7 +11738,7 @@ const Zv = {
11755
11738
  additionalProperties: !1
11756
11739
  }, ro = "embed-rewrite-query";
11757
11740
  async function Tc(e, t = {}) {
11758
- 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);
11759
11742
  o.start();
11760
11743
  try {
11761
11744
  const i = li(n), a = r ? `${i}
@@ -11790,10 +11773,10 @@ const eS = {
11790
11773
  }[e] : e;
11791
11774
  };
11792
11775
  async function Ec(e, t = {}) {
11793
- 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);
11794
11777
  o.start();
11795
11778
  try {
11796
- const { divergence: i, count: a } = await q(s, {
11779
+ const { divergence: i, count: a } = await F(s, {
11797
11780
  divergence: J(tS),
11798
11781
  count: 3
11799
11782
  }), c = ui(n, a, { divergenceGuidance: i }), l = r ? `${c}
@@ -11827,11 +11810,11 @@ const nS = {
11827
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."
11828
11811
  }[e] : e;
11829
11812
  };
11830
- async function Ic(e, t = {}) {
11831
- 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);
11832
11815
  o.start();
11833
11816
  try {
11834
- const { abstraction: i, count: a } = await q(s, {
11817
+ const { abstraction: i, count: a } = await F(s, {
11835
11818
  abstraction: J(rS),
11836
11819
  count: 3
11837
11820
  }), c = pi(n, a, { abstractionGuidance: i }), l = r ? `${c}
@@ -11845,7 +11828,7 @@ ${r}` : c, u = await _(l, {
11845
11828
  throw o.error(i), i;
11846
11829
  }
11847
11830
  }
11848
- Ic.knownTexts = [];
11831
+ kc.knownTexts = [];
11849
11832
  const sS = {
11850
11833
  type: "object",
11851
11834
  properties: {
@@ -11865,11 +11848,11 @@ const sS = {
11865
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."
11866
11849
  }[e] : e;
11867
11850
  };
11868
- async function kc(e, t = {}) {
11869
- 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);
11870
11853
  o.start();
11871
11854
  try {
11872
- const { granularity: i } = await q(s, {
11855
+ const { granularity: i } = await F(s, {
11873
11856
  granularity: J(oS)
11874
11857
  }), a = di(n, { granularityGuidance: i }), c = r ? `${a}
11875
11858
 
@@ -11882,7 +11865,7 @@ ${r}` : a, l = await _(c, {
11882
11865
  throw o.error(i), i;
11883
11866
  }
11884
11867
  }
11885
- kc.knownTexts = [];
11868
+ Ic.knownTexts = [];
11886
11869
  const iS = {
11887
11870
  type: "object",
11888
11871
  properties: {
@@ -11895,7 +11878,7 @@ const iS = {
11895
11878
  additionalProperties: !1
11896
11879
  }, ao = "embed-rewrite-to-output-doc";
11897
11880
  async function Ac(e, t = {}) {
11898
- 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);
11899
11882
  o.start();
11900
11883
  try {
11901
11884
  const i = ad(n), a = r ? `${i}
@@ -12068,9 +12051,9 @@ const vS = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
12068
12051
  openai: vS
12069
12052
  };
12070
12053
  async function xS(e, t = {}) {
12071
- const n = A("agent", t), r = I("agent", n.onProgress, n);
12054
+ const n = O("agent", t), r = k("agent", n.onProgress, n);
12072
12055
  r.start({ instruction: e.slice(0, 200) });
12073
- const s = await q(n, {
12056
+ const s = await F(n, {
12074
12057
  maxTurns: void 0,
12075
12058
  cwd: void 0,
12076
12059
  systemPrompt: void 0,
@@ -12152,7 +12135,7 @@ async function ES(e, t, n = {}) {
12152
12135
  label: a = "pMap"
12153
12136
  } = n;
12154
12137
  if (!t || t.length === 0) return [];
12155
- const c = I(a, i);
12138
+ const c = k(a, i);
12156
12139
  c.start();
12157
12140
  const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
12158
12141
  let d = 0;
@@ -12176,7 +12159,7 @@ async function ES(e, t, n = {}) {
12176
12159
  throw c.error(h), h;
12177
12160
  }
12178
12161
  }
12179
- async function IS(e, t, n = {}) {
12162
+ async function kS(e, t, n = {}) {
12180
12163
  const {
12181
12164
  maxParallel: r = 3,
12182
12165
  errorPosture: s = z.resilient,
@@ -12185,7 +12168,7 @@ async function IS(e, t, n = {}) {
12185
12168
  label: a = "pFilter"
12186
12169
  } = n;
12187
12170
  if (!t || t.length === 0) return [];
12188
- const c = I(a, i);
12171
+ const c = k(a, i);
12189
12172
  c.start();
12190
12173
  const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
12191
12174
  let d = 0;
@@ -12210,7 +12193,7 @@ async function IS(e, t, n = {}) {
12210
12193
  throw c.error(h), h;
12211
12194
  }
12212
12195
  }
12213
- async function kS(e, t, n = {}) {
12196
+ async function IS(e, t, n = {}) {
12214
12197
  const {
12215
12198
  maxParallel: r = 3,
12216
12199
  errorPosture: s = z.resilient,
@@ -12219,7 +12202,7 @@ async function kS(e, t, n = {}) {
12219
12202
  label: a = "pFind"
12220
12203
  } = n;
12221
12204
  if (!t || t.length === 0) return;
12222
- const c = I(a, i);
12205
+ const c = k(a, i);
12223
12206
  c.start();
12224
12207
  const l = c.batch(t.length), u = Ce(r)(t);
12225
12208
  let p = 0;
@@ -12248,7 +12231,7 @@ async function kS(e, t, n = {}) {
12248
12231
  }
12249
12232
  }
12250
12233
  async function AS(e, t, n, r = {}) {
12251
- 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);
12252
12235
  a.start();
12253
12236
  const c = a.batch(t.length);
12254
12237
  let l = n;
@@ -12271,7 +12254,7 @@ async function OS(e, t, n = {}) {
12271
12254
  label: a = "pGroup"
12272
12255
  } = n;
12273
12256
  if (!t || t.length === 0) return {};
12274
- const c = I(a, i);
12257
+ const c = k(a, i);
12275
12258
  c.start();
12276
12259
  const l = c.batch(t.length), u = new Array(t.length), p = Ce(r)(t);
12277
12260
  let d = 0;
@@ -12306,7 +12289,7 @@ async function OS(e, t, n = {}) {
12306
12289
  async function _S(e, t, n = {}) {
12307
12290
  const { abortSignal: r, onProgress: s, label: o = "mapEach" } = n;
12308
12291
  if (!t || t.length === 0) return [];
12309
- const i = I(o, s);
12292
+ const i = k(o, s);
12310
12293
  i.start();
12311
12294
  const a = i.batch(t.length), c = new Array(t.length);
12312
12295
  try {
@@ -12322,7 +12305,7 @@ async function _S(e, t, n = {}) {
12322
12305
  async function CS(e, t, n = {}) {
12323
12306
  const { abortSignal: r, onProgress: s, label: o = "filterEach" } = n;
12324
12307
  if (!t || t.length === 0) return [];
12325
- const i = I(o, s);
12308
+ const i = k(o, s);
12326
12309
  i.start();
12327
12310
  const a = i.batch(t.length), c = [];
12328
12311
  try {
@@ -12338,7 +12321,7 @@ async function CS(e, t, n = {}) {
12338
12321
  async function jS(e, t, n = {}) {
12339
12322
  const { abortSignal: r, onProgress: s, label: o = "findEach" } = n;
12340
12323
  if (!t || t.length === 0) return;
12341
- const i = I(o, s);
12324
+ const i = k(o, s);
12342
12325
  i.start();
12343
12326
  const a = i.batch(t.length);
12344
12327
  try {
@@ -12355,7 +12338,7 @@ async function jS(e, t, n = {}) {
12355
12338
  }
12356
12339
  }
12357
12340
  async function NS(e, t, n, r = {}) {
12358
- 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);
12359
12342
  a.start();
12360
12343
  const c = a.batch(t.length);
12361
12344
  let l = n;
@@ -12372,7 +12355,7 @@ async function NS(e, t, n, r = {}) {
12372
12355
  async function RS(e, t, n = {}) {
12373
12356
  const { abortSignal: r, onProgress: s, label: o = "groupEach" } = n;
12374
12357
  if (!t || t.length === 0) return {};
12375
- const i = I(o, s);
12358
+ const i = k(o, s);
12376
12359
  i.start();
12377
12360
  const a = i.batch(t.length), c = {};
12378
12361
  try {
@@ -12632,8 +12615,8 @@ const US = {
12632
12615
  }).join(`
12633
12616
  `), QS = (e, t, n, r) => {
12634
12617
  const s = async (o, i = {}) => {
12635
- 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);
12636
- 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" });
12637
12620
  const d = r(o, c), h = a ? u + ai : u, y = a ? [ci, ...d] : d, b = await M(
12638
12621
  () => _(y.join(`
12639
12622
 
@@ -12748,7 +12731,7 @@ ${n.join(", ")}
12748
12731
  `);
12749
12732
  }
12750
12733
  async function lx({ exampleTexts: e, projectionNames: t, propertyNames: n }, r = {}) {
12751
- const s = A(uo, r), o = I(uo, s.onProgress, s);
12734
+ const s = O(uo, r), o = k(uo, s.onProgress, s);
12752
12735
  o.start();
12753
12736
  try {
12754
12737
  const i = cx({ exampleTexts: e, projectionNames: t, propertyNames: n }), a = await M(
@@ -12832,27 +12815,27 @@ async function bx(e, t, n) {
12832
12815
  });
12833
12816
  }
12834
12817
  async function wx({ sourceTexts: e, schema: t }, n = {}) {
12835
- const r = A(po, n), s = I(po, r.onProgress, r);
12818
+ const r = O(po, n), s = k(po, r.onProgress, r);
12836
12819
  s.start();
12837
12820
  try {
12838
12821
  const {
12839
12822
  maxParallel: o,
12840
12823
  batchSize: i,
12841
12824
  errorPosture: a
12842
- } = await q(r, {
12825
+ } = await F(r, {
12843
12826
  maxParallel: 3,
12844
12827
  batchSize: 5,
12845
12828
  errorPosture: z.resilient
12846
12829
  }), c = [];
12847
12830
  for (let d = 0; d < e.length; d += i)
12848
12831
  c.push(e.slice(d, d + i));
12849
- s.emit({ event: k.phase, phase: "fragmenting", totalBatches: c.length });
12832
+ s.emit({ event: A.phase, phase: "fragmenting", totalBatches: c.length });
12850
12833
  const l = s.batch(e.length), p = (await Q(
12851
12834
  c,
12852
12835
  async (d) => {
12853
12836
  const h = await bx(d, t, {
12854
12837
  ...r,
12855
- onProgress: L(r.onProgress, "batch")
12838
+ onProgress: B(r.onProgress, "batch")
12856
12839
  });
12857
12840
  return l(d.length), h;
12858
12841
  },
@@ -12903,7 +12886,7 @@ function Tx(e, t) {
12903
12886
  `);
12904
12887
  }
12905
12888
  async function Ex({ schema: e, studySet: t }, n = {}) {
12906
- const r = A(mo, n), s = I(mo, r.onProgress, r);
12889
+ const r = O(mo, n), s = k(mo, r.onProgress, r);
12907
12890
  s.start();
12908
12891
  try {
12909
12892
  const o = Tx(e, t), i = await M(
@@ -12941,10 +12924,10 @@ function ft(e) {
12941
12924
  for (let s = 0; s < e.length; s++) n[s] = e[s] * r;
12942
12925
  return n;
12943
12926
  }
12944
- function Ix(e, t, n) {
12927
+ function kx(e, t, n) {
12945
12928
  return Pe(e, n) - Pe(e, t);
12946
12929
  }
12947
- function kx(e, t) {
12930
+ function Ix(e, t) {
12948
12931
  const n = new Float32Array(e.length);
12949
12932
  for (let r = 0; r < e.length; r++) n[r] = e[r] * t;
12950
12933
  return n;
@@ -12976,22 +12959,22 @@ async function _x({ fragmentSets: e, schema: t }, n = {}) {
12976
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();
12977
12960
  for (const g of e)
12978
12961
  for (const m of g.fragments) {
12979
- 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}`;
12980
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));
12981
- const v = m.sourceIds?.[0] ?? g.fragmentSetId;
12982
- u.has(v) || u.set(v, /* @__PURE__ */ new Map());
12983
- const P = u.get(v);
12984
- 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);
12985
12968
  }
12986
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 = [];
12987
12970
  for (const [g, m] of u) {
12988
- const w = {}, S = [];
12971
+ const w = {}, v = [];
12989
12972
  for (const [P, x] of m) {
12990
- const E = x.map(h), O = mn(E);
12991
- 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));
12992
12975
  }
12993
- const v = S.length > 0 ? ft(mn(S)) : void 0;
12994
- 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 });
12995
12978
  }
12996
12979
  const b = await Ox(t, o), f = b !== t._poles ? { ...t, _poles: b } : t;
12997
12980
  return { states: y, schema: f };
@@ -13001,7 +12984,7 @@ function Cx({ states: e, editsByProjectionName: t }) {
13001
12984
  const r = {};
13002
12985
  for (const [s, o] of Object.entries(n.vectorsByProjectionName)) {
13003
12986
  const i = t[s];
13004
- 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);
13005
12988
  }
13006
12989
  return {
13007
12990
  stateId: n.stateId,
@@ -13038,9 +13021,9 @@ function Lc(e, t, n, r) {
13038
13021
  }
13039
13022
  let u = 0, p = 0, d = 0;
13040
13023
  for (const [m, w] of Object.entries(c.projectionWeights)) {
13041
- const S = e.vectorsByProjectionName[m];
13042
- if (!S) continue;
13043
- 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);
13044
13027
  u += x * P, p += P, d += 1;
13045
13028
  }
13046
13029
  if (p === 0) {
@@ -13080,12 +13063,12 @@ async function Lx({ leftStates: e, rightStates: t, intent: n }, r = {}) {
13080
13063
  for (const [f, g] of l) {
13081
13064
  const m = p.vectorsByProjectionName[f], w = d.vectorsByProjectionName[f];
13082
13065
  if (m && w) {
13083
- let S = Pe(m, w);
13066
+ let v = Pe(m, w);
13084
13067
  if (c) {
13085
- const v = Pe(c, m), P = Pe(c, w);
13086
- 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;
13087
13070
  }
13088
- h += S * g, y += g;
13071
+ h += v * g, y += g;
13089
13072
  }
13090
13073
  }
13091
13074
  const b = y > 0 ? h / y : 0;
@@ -13121,7 +13104,7 @@ const Bx = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13121
13104
  debugPromptGlobally: Po,
13122
13105
  debugPromptGloballyIfChanged: To,
13123
13106
  debugResultGlobally: Eo,
13124
- debugResultGloballyIfChanged: Io,
13107
+ debugResultGloballyIfChanged: ko,
13125
13108
  defaultRules: vn,
13126
13109
  findRule: mu,
13127
13110
  systemPrompt: ae
@@ -13216,19 +13199,19 @@ function zx(e = {}) {
13216
13199
  "eventToTrace",
13217
13200
  "scopePhase",
13218
13201
  "nameStep"
13219
- ]), S = /* @__PURE__ */ new Set(["embedObject"]), v = {};
13202
+ ]), v = /* @__PURE__ */ new Set(["embedObject"]), S = {};
13220
13203
  for (const [P, x] of Object.entries(rl))
13221
13204
  if (!w.has(P)) {
13222
- if (S.has(P) && typeof x == "object" && x !== null) {
13223
- v[P] = Object.fromEntries(
13224
- 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)])
13225
13208
  );
13226
13209
  continue;
13227
13210
  }
13228
- v[P] = hn(m, x);
13211
+ S[P] = hn(m, x);
13229
13212
  }
13230
13213
  return {
13231
- ...v,
13214
+ ...S,
13232
13215
  config: m,
13233
13216
  modelService: y,
13234
13217
  embeddingService: b,
@@ -13246,13 +13229,13 @@ export {
13246
13229
  Pi as A,
13247
13230
  Rn as B,
13248
13231
  xm as C,
13249
- k as D,
13232
+ A as D,
13250
13233
  z as E,
13251
13234
  Ei as F,
13252
13235
  Ti as G,
13253
13236
  Cm as H,
13254
- Ii as I,
13255
- ki as J,
13237
+ ki as I,
13238
+ Ii as J,
13256
13239
  Ai as K,
13257
13240
  Oi as L,
13258
13241
  Ci as M,
@@ -13297,8 +13280,8 @@ export {
13297
13280
  va as aM,
13298
13281
  wa as aN,
13299
13282
  Ea as aO,
13300
- Ia as aP,
13301
- ka as aQ,
13283
+ ka as aP,
13284
+ Ia as aQ,
13302
13285
  Oa as aR,
13303
13286
  _a as aS,
13304
13287
  Ca as aT,
@@ -13322,11 +13305,11 @@ export {
13322
13305
  Ze as ak,
13323
13306
  Gf as al,
13324
13307
  be as am,
13325
- ue as an,
13308
+ me as an,
13326
13309
  je as ao,
13327
13310
  ca as ap,
13328
13311
  Oe as aq,
13329
- ke as ar,
13312
+ Ie as ar,
13330
13313
  qn as as,
13331
13314
  hg as at,
13332
13315
  gg as au,
@@ -13348,8 +13331,8 @@ export {
13348
13331
  Qa as b8,
13349
13332
  ec as b9,
13350
13333
  Ec as bA,
13351
- Ic as bB,
13352
- kc as bC,
13334
+ kc as bB,
13335
+ Ic as bC,
13353
13336
  Ac as bD,
13354
13337
  xt as bE,
13355
13338
  aS as bF,
@@ -13400,7 +13383,7 @@ export {
13400
13383
  er as bx,
13401
13384
  Pc as by,
13402
13385
  Tc as bz,
13403
- I as c,
13386
+ k as c,
13404
13387
  ye as c0,
13405
13388
  fe as c1,
13406
13389
  cp as c2,
@@ -13410,7 +13393,7 @@ export {
13410
13393
  U as c6,
13411
13394
  qe as c7,
13412
13395
  ES as c8,
13413
- IS as c9,
13396
+ kS as c9,
13414
13397
  nu as cA,
13415
13398
  eu as cB,
13416
13399
  ru as cC,
@@ -13430,7 +13413,7 @@ export {
13430
13413
  zx as cQ,
13431
13414
  Sl as cR,
13432
13415
  il as cS,
13433
- kS as ca,
13416
+ IS as ca,
13434
13417
  AS as cb,
13435
13418
  OS as cc,
13436
13419
  _S as cd,
@@ -13438,7 +13421,7 @@ export {
13438
13421
  jS as cf,
13439
13422
  NS as cg,
13440
13423
  RS as ch,
13441
- In as ci,
13424
+ kn as ci,
13442
13425
  Aa as cj,
13443
13426
  MS as ck,
13444
13427
  xn as cl,
@@ -13458,20 +13441,20 @@ export {
13458
13441
  Zl as cz,
13459
13442
  $ as d,
13460
13443
  W as e,
13461
- Ie as f,
13462
- q as g,
13444
+ ke as f,
13445
+ F as g,
13463
13446
  K as h,
13464
13447
  o0 as i,
13465
13448
  C as j,
13466
13449
  N as k,
13467
13450
  M as l,
13468
13451
  cv as m,
13469
- A as n,
13452
+ O as n,
13470
13453
  ac as o,
13471
13454
  Q as p,
13472
13455
  ov as q,
13473
13456
  _ as r,
13474
- L as s,
13457
+ B as s,
13475
13458
  Ux as t,
13476
13459
  On as u,
13477
13460
  _n as v,