@johpaz/hive-sdk 0.0.5 → 0.0.7

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.
Files changed (75) hide show
  1. package/dist/agents/index.js +171573 -11091
  2. package/dist/channels/index.js +3702 -51
  3. package/dist/cron/index.js +806 -7
  4. package/dist/database/index.js +2636 -2
  5. package/dist/ethics/index.js +2636 -2
  6. package/dist/hivelearn/index.d.ts +11 -0
  7. package/dist/hivelearn/index.js +5033 -0
  8. package/dist/hivelearn/src/agent/agent-loop.d.ts +14 -0
  9. package/dist/hivelearn/src/agent/executor.d.ts +10 -0
  10. package/dist/hivelearn/src/agent/prompts.d.ts +1 -0
  11. package/dist/hivelearn/src/agent/runner.d.ts +8 -0
  12. package/dist/hivelearn/src/agent/tool-map.d.ts +12 -0
  13. package/dist/hivelearn/src/agents/coordinator.prompt.d.ts +9 -0
  14. package/dist/hivelearn/src/agents/prompts/audio.prompt.d.ts +1 -0
  15. package/dist/hivelearn/src/agents/prompts/challenge.prompt.d.ts +1 -0
  16. package/dist/hivelearn/src/agents/prompts/code.prompt.d.ts +1 -0
  17. package/dist/hivelearn/src/agents/prompts/evaluation.prompt.d.ts +1 -0
  18. package/dist/hivelearn/src/agents/prompts/exercise.prompt.d.ts +1 -0
  19. package/dist/hivelearn/src/agents/prompts/explanation.prompt.d.ts +1 -0
  20. package/dist/hivelearn/src/agents/prompts/feedback.prompt.d.ts +1 -0
  21. package/dist/hivelearn/src/agents/prompts/gamification.prompt.d.ts +1 -0
  22. package/dist/hivelearn/src/agents/prompts/gif.prompt.d.ts +1 -0
  23. package/dist/hivelearn/src/agents/prompts/infographic.prompt.d.ts +1 -0
  24. package/dist/hivelearn/src/agents/prompts/intent.prompt.d.ts +1 -0
  25. package/dist/hivelearn/src/agents/prompts/profile.prompt.d.ts +1 -0
  26. package/dist/hivelearn/src/agents/prompts/quiz.prompt.d.ts +1 -0
  27. package/dist/hivelearn/src/agents/prompts/structure.prompt.d.ts +1 -0
  28. package/dist/hivelearn/src/agents/prompts/svg.prompt.d.ts +1 -0
  29. package/dist/hivelearn/src/agents/registry.d.ts +43 -0
  30. package/dist/hivelearn/src/cache/CacheInvalidator.d.ts +9 -0
  31. package/dist/hivelearn/src/cache/NodeCache.d.ts +15 -0
  32. package/dist/hivelearn/src/events/swarm-events.d.ts +12 -0
  33. package/dist/hivelearn/src/index.d.ts +17 -0
  34. package/dist/hivelearn/src/persistence/LessonPersistence.d.ts +90 -0
  35. package/dist/hivelearn/src/scheduler/dag/DAGScheduler.d.ts +29 -0
  36. package/dist/hivelearn/src/scheduler/dag/EventBridge.d.ts +16 -0
  37. package/dist/hivelearn/src/scheduler/dag/TaskGraph.d.ts +18 -0
  38. package/dist/hivelearn/src/scheduler/dag/TaskNode.d.ts +40 -0
  39. package/dist/hivelearn/src/scheduler/dag/TaskResult.d.ts +19 -0
  40. package/dist/hivelearn/src/scheduler/dag/errors.d.ts +17 -0
  41. package/dist/hivelearn/src/scheduler/dag/index.d.ts +13 -0
  42. package/dist/hivelearn/src/scheduler/dag/strategies/ParallelStrategy.d.ts +11 -0
  43. package/dist/hivelearn/src/swarm/HiveLearnSwarm.d.ts +16 -0
  44. package/dist/hivelearn/src/swarm/orchestrator.d.ts +15 -0
  45. package/dist/hivelearn/src/swarm/presets/HiveLearnPreset.d.ts +35 -0
  46. package/dist/hivelearn/src/swarm/session.d.ts +15 -0
  47. package/dist/hivelearn/src/tools/canvas/disenar-estructura.tool.d.ts +3 -0
  48. package/dist/hivelearn/src/tools/canvas/poblar-nodo.tool.d.ts +2 -0
  49. package/dist/hivelearn/src/tools/content/generar-audio.tool.d.ts +2 -0
  50. package/dist/hivelearn/src/tools/content/generar-codigo.tool.d.ts +2 -0
  51. package/dist/hivelearn/src/tools/content/generar-ejercicio.tool.d.ts +2 -0
  52. package/dist/hivelearn/src/tools/content/generar-explicacion.tool.d.ts +2 -0
  53. package/dist/hivelearn/src/tools/content/generar-frames-gif.tool.d.ts +2 -0
  54. package/dist/hivelearn/src/tools/content/generar-imagen.tool.d.ts +2 -0
  55. package/dist/hivelearn/src/tools/content/generar-infografia.tool.d.ts +2 -0
  56. package/dist/hivelearn/src/tools/content/generar-quiz.tool.d.ts +2 -0
  57. package/dist/hivelearn/src/tools/content/generar-reto.tool.d.ts +2 -0
  58. package/dist/hivelearn/src/tools/content/generar-svg.tool.d.ts +2 -0
  59. package/dist/hivelearn/src/tools/coordinator/delegar-enjambre.tool.d.ts +6 -0
  60. package/dist/hivelearn/src/tools/coordinator/revisar-programa.tool.d.ts +6 -0
  61. package/dist/hivelearn/src/tools/evaluation/calificar-evaluacion.tool.d.ts +20 -0
  62. package/dist/hivelearn/src/tools/evaluation/generar-evaluacion.tool.d.ts +2 -0
  63. package/dist/hivelearn/src/tools/index.d.ts +26 -0
  64. package/dist/hivelearn/src/tools/profile/clasificar-intencion.tool.d.ts +2 -0
  65. package/dist/hivelearn/src/tools/search/buscar-curriculo-existente.tool.d.ts +2 -0
  66. package/dist/hivelearn/src/tools/search/buscar-en-hivelearn.tool.d.ts +2 -0
  67. package/dist/hivelearn/src/types/tool.d.ts +17 -0
  68. package/dist/hivelearn/src/types.d.ts +187 -0
  69. package/dist/hivelearn/src/utils/logger.d.ts +21 -0
  70. package/dist/index.js +172848 -11349
  71. package/dist/mcp/index.js +25 -0
  72. package/dist/skills/index.js +2636 -2
  73. package/dist/tools/index.js +167497 -7015
  74. package/package.json +9 -3
  75. package/src/hivelearn/index.ts +43 -0
@@ -1,4 +1,6 @@
1
1
  // @bun
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
2
4
  var __defProp = Object.defineProperty;
3
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -6,6 +8,28 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  function __accessProp(key) {
7
9
  return this[key];
8
10
  }
11
+ var __toESMCache_node;
12
+ var __toESMCache_esm;
13
+ var __toESM = (mod, isNodeMode, target) => {
14
+ var canCache = mod != null && typeof mod === "object";
15
+ if (canCache) {
16
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17
+ var cached = cache.get(mod);
18
+ if (cached)
19
+ return cached;
20
+ }
21
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
22
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
23
+ for (let key of __getOwnPropNames(mod))
24
+ if (!__hasOwnProp.call(to, key))
25
+ __defProp(to, key, {
26
+ get: __accessProp.bind(mod, key),
27
+ enumerable: true
28
+ });
29
+ if (canCache)
30
+ cache.set(mod, to);
31
+ return to;
32
+ };
9
33
  var __toCommonJS = (from) => {
10
34
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
35
  if (entry)
@@ -23,6 +47,7 @@ var __toCommonJS = (from) => {
23
47
  return entry;
24
48
  };
25
49
  var __moduleCache;
50
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
26
51
  var __returnValue = (v) => v;
27
52
  function __exportSetter(name, newValue) {
28
53
  this[name] = __returnValue.bind(null, newValue);
@@ -1654,8 +1679,781 @@ var init_sqlite = __esm(() => {
1654
1679
  dbService = new DatabaseService;
1655
1680
  });
1656
1681
 
1682
+ // ../../node_modules/.bun/croner@10.0.1/node_modules/croner/dist/croner.js
1683
+ function T(s) {
1684
+ return Date.UTC(s.y, s.m - 1, s.d, s.h, s.i, s.s);
1685
+ }
1686
+ function D(s, e) {
1687
+ return s.y === e.y && s.m === e.m && s.d === e.d && s.h === e.h && s.i === e.i && s.s === e.s;
1688
+ }
1689
+ function A(s, e) {
1690
+ let t = new Date(Date.parse(s));
1691
+ if (isNaN(t))
1692
+ throw new Error("Invalid ISO8601 passed to timezone parser.");
1693
+ let r = s.substring(9);
1694
+ return r.includes("Z") || r.includes("+") || r.includes("-") ? b(t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate(), t.getUTCHours(), t.getUTCMinutes(), t.getUTCSeconds(), "Etc/UTC") : b(t.getFullYear(), t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), e);
1695
+ }
1696
+ function v(s, e, t) {
1697
+ return k(A(s, e), t);
1698
+ }
1699
+ function k(s, e) {
1700
+ let t = new Date(T(s)), r = g(t, s.tz), n = T(s), i = T(r), a = n - i, o = new Date(t.getTime() + a), h = g(o, s.tz);
1701
+ if (D(h, s)) {
1702
+ let u = new Date(o.getTime() - 3600000), d = g(u, s.tz);
1703
+ return D(d, s) ? u : o;
1704
+ }
1705
+ let l = new Date(o.getTime() + T(s) - T(h)), y = g(l, s.tz);
1706
+ if (D(y, s))
1707
+ return l;
1708
+ if (e)
1709
+ throw new Error("Invalid date passed to fromTZ()");
1710
+ return o.getTime() > l.getTime() ? o : l;
1711
+ }
1712
+ function g(s, e) {
1713
+ let t, r;
1714
+ try {
1715
+ t = new Intl.DateTimeFormat("en-US", { timeZone: e, year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric", hour12: false }), r = t.formatToParts(s);
1716
+ } catch (i) {
1717
+ let a = i instanceof Error ? i.message : String(i);
1718
+ throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`);
1719
+ }
1720
+ let n = { year: 0, month: 0, day: 0, hour: 0, minute: 0, second: 0 };
1721
+ for (let i of r)
1722
+ (i.type === "year" || i.type === "month" || i.type === "day" || i.type === "hour" || i.type === "minute" || i.type === "second") && (n[i.type] = parseInt(i.value, 10));
1723
+ if (isNaN(n.year) || isNaN(n.month) || isNaN(n.day) || isNaN(n.hour) || isNaN(n.minute) || isNaN(n.second))
1724
+ throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);
1725
+ return n.hour === 24 && (n.hour = 0), { y: n.year, m: n.month, d: n.day, h: n.hour, i: n.minute, s: n.second, tz: e };
1726
+ }
1727
+ function b(s, e, t, r, n, i, a) {
1728
+ return { y: s, m: e, d: t, h: r, i: n, s: i, tz: a };
1729
+ }
1730
+ function R(s2) {
1731
+ if (s2 === undefined && (s2 = {}), delete s2.name, s2.legacyMode !== undefined && s2.domAndDow === undefined ? s2.domAndDow = !s2.legacyMode : s2.domAndDow === undefined && (s2.domAndDow = false), s2.legacyMode = !s2.domAndDow, s2.paused = s2.paused === undefined ? false : s2.paused, s2.maxRuns = s2.maxRuns === undefined ? 1 / 0 : s2.maxRuns, s2.catch = s2.catch === undefined ? false : s2.catch, s2.interval = s2.interval === undefined ? 0 : parseInt(s2.interval.toString(), 10), s2.utcOffset = s2.utcOffset === undefined ? undefined : parseInt(s2.utcOffset.toString(), 10), s2.dayOffset = s2.dayOffset === undefined ? 0 : parseInt(s2.dayOffset.toString(), 10), s2.unref = s2.unref === undefined ? false : s2.unref, s2.mode = s2.mode === undefined ? "auto" : s2.mode, s2.alternativeWeekdays = s2.alternativeWeekdays === undefined ? false : s2.alternativeWeekdays, s2.sloppyRanges = s2.sloppyRanges === undefined ? false : s2.sloppyRanges, !["auto", "5-part", "6-part", "7-part", "5-or-6-parts", "6-or-7-parts"].includes(s2.mode))
1732
+ throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");
1733
+ if (s2.startAt && (s2.startAt = new m(s2.startAt, s2.timezone)), s2.stopAt && (s2.stopAt = new m(s2.stopAt, s2.timezone)), s2.interval !== null) {
1734
+ if (isNaN(s2.interval))
1735
+ throw new Error("CronOptions: Supplied value for interval is not a number");
1736
+ if (s2.interval < 0)
1737
+ throw new Error("CronOptions: Supplied value for interval can not be negative");
1738
+ }
1739
+ if (s2.utcOffset !== undefined) {
1740
+ if (isNaN(s2.utcOffset))
1741
+ throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");
1742
+ if (s2.utcOffset < -870 || s2.utcOffset > 870)
1743
+ throw new Error("CronOptions: utcOffset out of bounds.");
1744
+ if (s2.utcOffset !== undefined && s2.timezone)
1745
+ throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.");
1746
+ }
1747
+ if (s2.unref !== true && s2.unref !== false)
1748
+ throw new Error("CronOptions: Unref should be either true, false or undefined(false).");
1749
+ if (s2.dayOffset !== undefined && s2.dayOffset !== 0 && isNaN(s2.dayOffset))
1750
+ throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");
1751
+ return s2;
1752
+ }
1753
+ function p(s2) {
1754
+ return Object.prototype.toString.call(s2) === "[object Function]" || typeof s2 == "function" || s2 instanceof Function;
1755
+ }
1756
+ function _(s2) {
1757
+ return p(s2);
1758
+ }
1759
+ function x(s2) {
1760
+ typeof Deno < "u" && typeof Deno.unrefTimer < "u" ? Deno.unrefTimer(s2) : s2 && typeof s2.unref < "u" && s2.unref();
1761
+ }
1762
+ var O, C = class {
1763
+ pattern;
1764
+ timezone;
1765
+ mode;
1766
+ alternativeWeekdays;
1767
+ sloppyRanges;
1768
+ second;
1769
+ minute;
1770
+ hour;
1771
+ day;
1772
+ month;
1773
+ dayOfWeek;
1774
+ year;
1775
+ lastDayOfMonth;
1776
+ lastWeekday;
1777
+ nearestWeekdays;
1778
+ starDOM;
1779
+ starDOW;
1780
+ starYear;
1781
+ useAndLogic;
1782
+ constructor(e, t, r) {
1783
+ this.pattern = e, this.timezone = t, this.mode = r?.mode ?? "auto", this.alternativeWeekdays = r?.alternativeWeekdays ?? false, this.sloppyRanges = r?.sloppyRanges ?? false, this.second = Array(60).fill(0), this.minute = Array(60).fill(0), this.hour = Array(24).fill(0), this.day = Array(31).fill(0), this.month = Array(12).fill(0), this.dayOfWeek = Array(7).fill(0), this.year = Array(1e4).fill(0), this.lastDayOfMonth = false, this.lastWeekday = false, this.nearestWeekdays = Array(31).fill(0), this.starDOM = false, this.starDOW = false, this.starYear = false, this.useAndLogic = false, this.parse();
1784
+ }
1785
+ parse() {
1786
+ if (!(typeof this.pattern == "string" || this.pattern instanceof String))
1787
+ throw new TypeError("CronPattern: Pattern has to be of type string.");
1788
+ this.pattern.indexOf("@") >= 0 && (this.pattern = this.handleNicknames(this.pattern).trim());
1789
+ let e = this.pattern.match(/\S+/g) || [""], t = e.length;
1790
+ if (e.length < 5 || e.length > 7)
1791
+ throw new TypeError("CronPattern: invalid configuration format ('" + this.pattern + "'), exactly five, six, or seven space separated parts are required.");
1792
+ if (this.mode !== "auto") {
1793
+ let n;
1794
+ switch (this.mode) {
1795
+ case "5-part":
1796
+ n = 5;
1797
+ break;
1798
+ case "6-part":
1799
+ n = 6;
1800
+ break;
1801
+ case "7-part":
1802
+ n = 7;
1803
+ break;
1804
+ case "5-or-6-parts":
1805
+ n = [5, 6];
1806
+ break;
1807
+ case "6-or-7-parts":
1808
+ n = [6, 7];
1809
+ break;
1810
+ default:
1811
+ n = 0;
1812
+ }
1813
+ if (!(Array.isArray(n) ? n.includes(t) : t === n)) {
1814
+ let a = Array.isArray(n) ? n.join(" or ") : n.toString();
1815
+ throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`);
1816
+ }
1817
+ }
1818
+ if (e.length === 5 && e.unshift("0"), e.length === 6 && e.push("*"), e[3].toUpperCase() === "LW" ? (this.lastWeekday = true, e[3] = "") : e[3].toUpperCase().indexOf("L") >= 0 && (e[3] = e[3].replace(/L/gi, ""), this.lastDayOfMonth = true), e[3] == "*" && (this.starDOM = true), e[6] == "*" && (this.starYear = true), e[4].length >= 3 && (e[4] = this.replaceAlphaMonths(e[4])), e[5].length >= 3 && (e[5] = this.alternativeWeekdays ? this.replaceAlphaDaysQuartz(e[5]) : this.replaceAlphaDays(e[5])), e[5].startsWith("+") && (this.useAndLogic = true, e[5] = e[5].substring(1), e[5] === ""))
1819
+ throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");
1820
+ switch (e[5] == "*" && (this.starDOW = true), this.pattern.indexOf("?") >= 0 && (e[0] = e[0].replace(/\?/g, "*"), e[1] = e[1].replace(/\?/g, "*"), e[2] = e[2].replace(/\?/g, "*"), e[3] = e[3].replace(/\?/g, "*"), e[4] = e[4].replace(/\?/g, "*"), e[5] = e[5].replace(/\?/g, "*"), e[6] && (e[6] = e[6].replace(/\?/g, "*"))), this.mode) {
1821
+ case "5-part":
1822
+ e[0] = "0", e[6] = "*";
1823
+ break;
1824
+ case "6-part":
1825
+ e[6] = "*";
1826
+ break;
1827
+ case "5-or-6-parts":
1828
+ e[6] = "*";
1829
+ break;
1830
+ case "6-or-7-parts":
1831
+ break;
1832
+ case "7-part":
1833
+ case "auto":
1834
+ break;
1835
+ }
1836
+ this.throwAtIllegalCharacters(e), this.partToArray("second", e[0], 0, 1), this.partToArray("minute", e[1], 0, 1), this.partToArray("hour", e[2], 0, 1), this.partToArray("day", e[3], -1, 1), this.partToArray("month", e[4], -1, 1);
1837
+ let r = this.alternativeWeekdays ? -1 : 0;
1838
+ this.partToArray("dayOfWeek", e[5], r, 63), this.partToArray("year", e[6], 0, 1), !this.alternativeWeekdays && this.dayOfWeek[7] && (this.dayOfWeek[0] = this.dayOfWeek[7]);
1839
+ }
1840
+ partToArray(e, t, r, n) {
1841
+ let i = this[e], a = e === "day" && this.lastDayOfMonth, o = e === "day" && this.lastWeekday;
1842
+ if (t === "" && !a && !o)
1843
+ throw new TypeError("CronPattern: configuration entry " + e + " (" + t + ") is empty, check for trailing spaces.");
1844
+ if (t === "*")
1845
+ return i.fill(n);
1846
+ let h = t.split(",");
1847
+ if (h.length > 1)
1848
+ for (let l = 0;l < h.length; l++)
1849
+ this.partToArray(e, h[l], r, n);
1850
+ else
1851
+ t.indexOf("-") !== -1 && t.indexOf("/") !== -1 ? this.handleRangeWithStepping(t, e, r, n) : t.indexOf("-") !== -1 ? this.handleRange(t, e, r, n) : t.indexOf("/") !== -1 ? this.handleStepping(t, e, r, n) : t !== "" && this.handleNumber(t, e, r, n);
1852
+ }
1853
+ throwAtIllegalCharacters(e) {
1854
+ for (let t = 0;t < e.length; t++)
1855
+ if ((t === 3 ? /[^/*0-9,\-WwLl]+/ : t === 5 ? /[^/*0-9,\-#Ll]+/ : /[^/*0-9,\-]+/).test(e[t]))
1856
+ throw new TypeError("CronPattern: configuration entry " + t + " (" + e[t] + ") contains illegal characters.");
1857
+ }
1858
+ handleNumber(e, t, r, n) {
1859
+ let i = this.extractNth(e, t), a = e.toUpperCase().includes("W");
1860
+ if (t !== "day" && a)
1861
+ throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");
1862
+ a && (t = "nearestWeekdays");
1863
+ let o = parseInt(i[0], 10) + r;
1864
+ if (isNaN(o))
1865
+ throw new TypeError("CronPattern: " + t + " is not a number: '" + e + "'");
1866
+ this.setPart(t, o, i[1] || n);
1867
+ }
1868
+ setPart(e, t, r) {
1869
+ if (!Object.prototype.hasOwnProperty.call(this, e))
1870
+ throw new TypeError("CronPattern: Invalid part specified: " + e);
1871
+ if (e === "dayOfWeek") {
1872
+ if (t === 7 && (t = 0), t < 0 || t > 6)
1873
+ throw new RangeError("CronPattern: Invalid value for dayOfWeek: " + t);
1874
+ this.setNthWeekdayOfMonth(t, r);
1875
+ return;
1876
+ }
1877
+ if (e === "second" || e === "minute") {
1878
+ if (t < 0 || t >= 60)
1879
+ throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
1880
+ } else if (e === "hour") {
1881
+ if (t < 0 || t >= 24)
1882
+ throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
1883
+ } else if (e === "day" || e === "nearestWeekdays") {
1884
+ if (t < 0 || t >= 31)
1885
+ throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
1886
+ } else if (e === "month") {
1887
+ if (t < 0 || t >= 12)
1888
+ throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
1889
+ } else if (e === "year" && (t < 1 || t >= 1e4))
1890
+ throw new RangeError("CronPattern: Invalid value for " + e + ": " + t + " (supported range: 1-9999)");
1891
+ this[e][t] = r;
1892
+ }
1893
+ validateNotNaN(e, t) {
1894
+ if (isNaN(e))
1895
+ throw new TypeError(t);
1896
+ }
1897
+ validateRange(e, t, r, n, i) {
1898
+ if (e > t)
1899
+ throw new TypeError("CronPattern: From value is larger than to value: '" + i + "'");
1900
+ if (r !== undefined) {
1901
+ if (r === 0)
1902
+ throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
1903
+ if (r > this[n].length)
1904
+ throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part (" + this[n].length + ")");
1905
+ }
1906
+ }
1907
+ handleRangeWithStepping(e, t, r, n) {
1908
+ if (e.toUpperCase().includes("W"))
1909
+ throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");
1910
+ let i = this.extractNth(e, t), a = i[0].match(/^(\d+)-(\d+)\/(\d+)$/);
1911
+ if (a === null)
1912
+ throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '" + e + "'");
1913
+ let [, o, h, l] = a, y = parseInt(o, 10) + r, u = parseInt(h, 10) + r, d = parseInt(l, 10);
1914
+ this.validateNotNaN(y, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(u, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateNotNaN(d, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(y, u, d, t, e);
1915
+ for (let c = y;c <= u; c += d)
1916
+ this.setPart(t, c, i[1] || n);
1917
+ }
1918
+ extractNth(e, t) {
1919
+ let r = e, n;
1920
+ if (r.includes("#")) {
1921
+ if (t !== "dayOfWeek")
1922
+ throw new Error("CronPattern: nth (#) only allowed in day-of-week field");
1923
+ n = r.split("#")[1], r = r.split("#")[0];
1924
+ } else if (r.toUpperCase().endsWith("L")) {
1925
+ if (t !== "dayOfWeek")
1926
+ throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");
1927
+ n = "L", r = r.slice(0, -1);
1928
+ }
1929
+ return [r, n];
1930
+ }
1931
+ handleRange(e, t, r, n) {
1932
+ if (e.toUpperCase().includes("W"))
1933
+ throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");
1934
+ let i = this.extractNth(e, t), a = i[0].split("-");
1935
+ if (a.length !== 2)
1936
+ throw new TypeError("CronPattern: Syntax error, illegal range: '" + e + "'");
1937
+ let o = parseInt(a[0], 10) + r, h = parseInt(a[1], 10) + r;
1938
+ this.validateNotNaN(o, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(h, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateRange(o, h, undefined, t, e);
1939
+ for (let l = o;l <= h; l++)
1940
+ this.setPart(t, l, i[1] || n);
1941
+ }
1942
+ handleStepping(e, t, r, n) {
1943
+ if (e.toUpperCase().includes("W"))
1944
+ throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");
1945
+ let i = this.extractNth(e, t), a = i[0].split("/");
1946
+ if (a.length !== 2)
1947
+ throw new TypeError("CronPattern: Syntax error, illegal stepping: '" + e + "'");
1948
+ if (this.sloppyRanges)
1949
+ a[0] === "" && (a[0] = "*");
1950
+ else {
1951
+ if (a[0] === "")
1952
+ throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
1953
+ if (a[0] !== "*")
1954
+ throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
1955
+ }
1956
+ let o = 0;
1957
+ a[0] !== "*" && (o = parseInt(a[0], 10) + r);
1958
+ let h = parseInt(a[1], 10);
1959
+ this.validateNotNaN(h, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(0, this[t].length - 1, h, t, e);
1960
+ for (let l = o;l < this[t].length; l += h)
1961
+ this.setPart(t, l, i[1] || n);
1962
+ }
1963
+ replaceAlphaDays(e) {
1964
+ return e.replace(/-sun/gi, "-7").replace(/sun/gi, "0").replace(/mon/gi, "1").replace(/tue/gi, "2").replace(/wed/gi, "3").replace(/thu/gi, "4").replace(/fri/gi, "5").replace(/sat/gi, "6");
1965
+ }
1966
+ replaceAlphaDaysQuartz(e) {
1967
+ return e.replace(/sun/gi, "1").replace(/mon/gi, "2").replace(/tue/gi, "3").replace(/wed/gi, "4").replace(/thu/gi, "5").replace(/fri/gi, "6").replace(/sat/gi, "7");
1968
+ }
1969
+ replaceAlphaMonths(e) {
1970
+ return e.replace(/jan/gi, "1").replace(/feb/gi, "2").replace(/mar/gi, "3").replace(/apr/gi, "4").replace(/may/gi, "5").replace(/jun/gi, "6").replace(/jul/gi, "7").replace(/aug/gi, "8").replace(/sep/gi, "9").replace(/oct/gi, "10").replace(/nov/gi, "11").replace(/dec/gi, "12");
1971
+ }
1972
+ handleNicknames(e) {
1973
+ let t = e.trim().toLowerCase();
1974
+ if (t === "@yearly" || t === "@annually")
1975
+ return "0 0 1 1 *";
1976
+ if (t === "@monthly")
1977
+ return "0 0 1 * *";
1978
+ if (t === "@weekly")
1979
+ return "0 0 * * 0";
1980
+ if (t === "@daily" || t === "@midnight")
1981
+ return "0 0 * * *";
1982
+ if (t === "@hourly")
1983
+ return "0 * * * *";
1984
+ if (t === "@reboot")
1985
+ throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");
1986
+ return e;
1987
+ }
1988
+ setNthWeekdayOfMonth(e, t) {
1989
+ if (typeof t != "number" && t.toUpperCase() === "L")
1990
+ this.dayOfWeek[e] = this.dayOfWeek[e] | 32;
1991
+ else if (t === 63)
1992
+ this.dayOfWeek[e] = 63;
1993
+ else if (t < 6 && t > 0)
1994
+ this.dayOfWeek[e] = this.dayOfWeek[e] | O[t - 1];
1995
+ else
1996
+ throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`);
1997
+ }
1998
+ }, P, f, m = class s {
1999
+ tz;
2000
+ ms;
2001
+ second;
2002
+ minute;
2003
+ hour;
2004
+ day;
2005
+ month;
2006
+ year;
2007
+ constructor(e, t) {
2008
+ if (this.tz = t, e && e instanceof Date)
2009
+ if (!isNaN(e))
2010
+ this.fromDate(e);
2011
+ else
2012
+ throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
2013
+ else if (e == null)
2014
+ this.fromDate(new Date);
2015
+ else if (e && typeof e == "string")
2016
+ this.fromString(e);
2017
+ else if (e instanceof s)
2018
+ this.fromCronDate(e);
2019
+ else
2020
+ throw new TypeError("CronDate: Invalid type (" + typeof e + ") passed to CronDate constructor");
2021
+ }
2022
+ getLastDayOfMonth(e, t) {
2023
+ return t !== 1 ? P[t] : new Date(Date.UTC(e, t + 1, 0)).getUTCDate();
2024
+ }
2025
+ getLastWeekday(e, t) {
2026
+ let r = this.getLastDayOfMonth(e, t), i = new Date(Date.UTC(e, t, r)).getUTCDay();
2027
+ return i === 0 ? r - 2 : i === 6 ? r - 1 : r;
2028
+ }
2029
+ getNearestWeekday(e, t, r) {
2030
+ let n = this.getLastDayOfMonth(e, t);
2031
+ if (r > n)
2032
+ return -1;
2033
+ let a = new Date(Date.UTC(e, t, r)).getUTCDay();
2034
+ return a === 0 ? r === n ? r - 2 : r + 1 : a === 6 ? r === 1 ? r + 2 : r - 1 : r;
2035
+ }
2036
+ isNthWeekdayOfMonth(e, t, r, n) {
2037
+ let a = new Date(Date.UTC(e, t, r)).getUTCDay(), o = 0;
2038
+ for (let h = 1;h <= r; h++)
2039
+ new Date(Date.UTC(e, t, h)).getUTCDay() === a && o++;
2040
+ if (n & 63 && O[o - 1] & n)
2041
+ return true;
2042
+ if (n & 32) {
2043
+ let h = this.getLastDayOfMonth(e, t);
2044
+ for (let l = r + 1;l <= h; l++)
2045
+ if (new Date(Date.UTC(e, t, l)).getUTCDay() === a)
2046
+ return false;
2047
+ return true;
2048
+ }
2049
+ return false;
2050
+ }
2051
+ fromDate(e) {
2052
+ if (this.tz !== undefined)
2053
+ if (typeof this.tz == "number")
2054
+ this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes() + this.tz, this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), this.apply();
2055
+ else
2056
+ try {
2057
+ let t = g(e, this.tz);
2058
+ this.ms = e.getMilliseconds(), this.second = t.s, this.minute = t.i, this.hour = t.h, this.day = t.d, this.month = t.m - 1, this.year = t.y;
2059
+ } catch (t) {
2060
+ let r = t instanceof Error ? t.message : String(t);
2061
+ throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`);
2062
+ }
2063
+ else
2064
+ this.ms = e.getMilliseconds(), this.second = e.getSeconds(), this.minute = e.getMinutes(), this.hour = e.getHours(), this.day = e.getDate(), this.month = e.getMonth(), this.year = e.getFullYear();
2065
+ }
2066
+ fromCronDate(e) {
2067
+ this.tz = e.tz, this.year = e.year, this.month = e.month, this.day = e.day, this.hour = e.hour, this.minute = e.minute, this.second = e.second, this.ms = e.ms;
2068
+ }
2069
+ apply() {
2070
+ if (this.month > 11 || this.month < 0 || this.day > P[this.month] || this.day < 1 || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
2071
+ let e = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
2072
+ return this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes(), this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), true;
2073
+ } else
2074
+ return false;
2075
+ }
2076
+ fromString(e) {
2077
+ if (typeof this.tz == "number") {
2078
+ let t = v(e);
2079
+ this.ms = t.getUTCMilliseconds(), this.second = t.getUTCSeconds(), this.minute = t.getUTCMinutes(), this.hour = t.getUTCHours(), this.day = t.getUTCDate(), this.month = t.getUTCMonth(), this.year = t.getUTCFullYear(), this.apply();
2080
+ } else
2081
+ return this.fromDate(v(e, this.tz));
2082
+ }
2083
+ findNext(e, t, r, n) {
2084
+ return this._findMatch(e, t, r, n, 1);
2085
+ }
2086
+ _findMatch(e, t, r, n, i) {
2087
+ let a = this[t], o;
2088
+ r.lastDayOfMonth && (o = this.getLastDayOfMonth(this.year, this.month));
2089
+ let h = !r.starDOW && t == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : undefined, l = this[t] + n, y = i === 1 ? (u) => u < r[t].length : (u) => u >= 0;
2090
+ for (let u = l;y(u); u += i) {
2091
+ let d = r[t][u];
2092
+ if (t === "day" && !d) {
2093
+ for (let c = 0;c < r.nearestWeekdays.length; c++)
2094
+ if (r.nearestWeekdays[c]) {
2095
+ let M = this.getNearestWeekday(this.year, this.month, c - n);
2096
+ if (M === -1)
2097
+ continue;
2098
+ if (M === u - n) {
2099
+ d = 1;
2100
+ break;
2101
+ }
2102
+ }
2103
+ }
2104
+ if (t === "day" && r.lastWeekday) {
2105
+ let c = this.getLastWeekday(this.year, this.month);
2106
+ u - n === c && (d = 1);
2107
+ }
2108
+ if (t === "day" && r.lastDayOfMonth && u - n == o && (d = 1), t === "day" && !r.starDOW) {
2109
+ let c = r.dayOfWeek[(h + (u - n - 1)) % 7];
2110
+ if (c && c & 63)
2111
+ c = this.isNthWeekdayOfMonth(this.year, this.month, u - n, c) ? 1 : 0;
2112
+ else if (c)
2113
+ throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);
2114
+ r.useAndLogic ? d = d && c : !e.domAndDow && !r.starDOM ? d = d || c : d = d && c;
2115
+ }
2116
+ if (d)
2117
+ return this[t] = u - n, a !== this[t] ? 2 : 1;
2118
+ }
2119
+ return 3;
2120
+ }
2121
+ recurse(e, t, r) {
2122
+ if (r === 0 && !e.starYear) {
2123
+ if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
2124
+ let i = -1;
2125
+ for (let a = this.year + 1;a < e.year.length && a < 1e4; a++)
2126
+ if (e.year[a] === 1) {
2127
+ i = a;
2128
+ break;
2129
+ }
2130
+ if (i === -1)
2131
+ return null;
2132
+ this.year = i, this.month = 0, this.day = 1, this.hour = 0, this.minute = 0, this.second = 0, this.ms = 0;
2133
+ }
2134
+ if (this.year >= 1e4)
2135
+ return null;
2136
+ }
2137
+ let n = this.findNext(t, f[r][0], e, f[r][2]);
2138
+ if (n > 1) {
2139
+ let i = r + 1;
2140
+ for (;i < f.length; )
2141
+ this[f[i][0]] = -f[i][2], i++;
2142
+ if (n === 3) {
2143
+ if (this[f[r][1]]++, this[f[r][0]] = -f[r][2], this.apply(), r === 0 && !e.starYear) {
2144
+ for (;this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0 && this.year < 1e4; )
2145
+ this.year++;
2146
+ if (this.year >= 1e4 || this.year >= e.year.length)
2147
+ return null;
2148
+ }
2149
+ return this.recurse(e, t, 0);
2150
+ } else if (this.apply())
2151
+ return this.recurse(e, t, r - 1);
2152
+ }
2153
+ return r += 1, r >= f.length ? this : (e.starYear ? this.year >= 3000 : this.year >= 1e4) ? null : this.recurse(e, t, r);
2154
+ }
2155
+ increment(e, t, r) {
2156
+ return this.second += t.interval !== undefined && t.interval > 1 && r ? t.interval : 1, this.ms = 0, this.apply(), this.recurse(e, t, 0);
2157
+ }
2158
+ decrement(e, t) {
2159
+ return this.second -= t.interval !== undefined && t.interval > 1 ? t.interval : 1, this.ms = 0, this.apply(), this.recurseBackward(e, t, 0, 0);
2160
+ }
2161
+ recurseBackward(e, t, r, n = 0) {
2162
+ if (n > 1e4)
2163
+ return null;
2164
+ if (r === 0 && !e.starYear) {
2165
+ if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
2166
+ let a = -1;
2167
+ for (let o = this.year - 1;o >= 0; o--)
2168
+ if (e.year[o] === 1) {
2169
+ a = o;
2170
+ break;
2171
+ }
2172
+ if (a === -1)
2173
+ return null;
2174
+ this.year = a, this.month = 11, this.day = 31, this.hour = 23, this.minute = 59, this.second = 59, this.ms = 0;
2175
+ }
2176
+ if (this.year < 0)
2177
+ return null;
2178
+ }
2179
+ let i = this.findPrevious(t, f[r][0], e, f[r][2]);
2180
+ if (i > 1) {
2181
+ let a = r + 1;
2182
+ for (;a < f.length; ) {
2183
+ let o = f[a][0], h = f[a][2], l = this.getMaxPatternValue(o, e, h);
2184
+ this[o] = l, a++;
2185
+ }
2186
+ if (i === 3) {
2187
+ if (this[f[r][1]]--, r === 0) {
2188
+ let y = this.getLastDayOfMonth(this.year, this.month);
2189
+ this.day > y && (this.day = y);
2190
+ }
2191
+ if (r === 1)
2192
+ if (this.day <= 0)
2193
+ this.day = 1;
2194
+ else {
2195
+ let y = this.year, u = this.month;
2196
+ for (;u < 0; )
2197
+ u += 12, y--;
2198
+ for (;u > 11; )
2199
+ u -= 12, y++;
2200
+ let d = u !== 1 ? P[u] : new Date(Date.UTC(y, u + 1, 0)).getUTCDate();
2201
+ this.day > d && (this.day = d);
2202
+ }
2203
+ this.apply();
2204
+ let o = f[r][0], h = f[r][2], l = this.getMaxPatternValue(o, e, h);
2205
+ if (o === "day") {
2206
+ let y = this.getLastDayOfMonth(this.year, this.month);
2207
+ this[o] = Math.min(l, y);
2208
+ } else
2209
+ this[o] = l;
2210
+ if (this.apply(), r === 0) {
2211
+ let y = f[1][2], u = this.getMaxPatternValue("day", e, y), d = this.getLastDayOfMonth(this.year, this.month), c = Math.min(u, d);
2212
+ c !== this.day && (this.day = c, this.hour = this.getMaxPatternValue("hour", e, f[2][2]), this.minute = this.getMaxPatternValue("minute", e, f[3][2]), this.second = this.getMaxPatternValue("second", e, f[4][2]));
2213
+ }
2214
+ if (r === 0 && !e.starYear) {
2215
+ for (;this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0; )
2216
+ this.year--;
2217
+ if (this.year < 0)
2218
+ return null;
2219
+ }
2220
+ return this.recurseBackward(e, t, 0, n + 1);
2221
+ } else if (this.apply())
2222
+ return this.recurseBackward(e, t, r - 1, n + 1);
2223
+ }
2224
+ return r += 1, r >= f.length ? this : this.year < 0 ? null : this.recurseBackward(e, t, r, n + 1);
2225
+ }
2226
+ getMaxPatternValue(e, t, r) {
2227
+ if (e === "day" && t.lastDayOfMonth)
2228
+ return this.getLastDayOfMonth(this.year, this.month);
2229
+ if (e === "day" && !t.starDOW)
2230
+ return this.getLastDayOfMonth(this.year, this.month);
2231
+ for (let n = t[e].length - 1;n >= 0; n--)
2232
+ if (t[e][n])
2233
+ return n - r;
2234
+ return t[e].length - 1 - r;
2235
+ }
2236
+ findPrevious(e, t, r, n) {
2237
+ return this._findMatch(e, t, r, n, -1);
2238
+ }
2239
+ getDate(e) {
2240
+ return e || this.tz === undefined ? new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms) : typeof this.tz == "number" ? new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms)) : k(b(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz), false);
2241
+ }
2242
+ getTime() {
2243
+ return this.getDate(false).getTime();
2244
+ }
2245
+ match(e, t) {
2246
+ if (!e.starYear && (this.year < 0 || this.year >= e.year.length || e.year[this.year] === 0))
2247
+ return false;
2248
+ for (let r = 0;r < f.length; r++) {
2249
+ let n = f[r][0], i = f[r][2], a = this[n];
2250
+ if (a + i < 0 || a + i >= e[n].length)
2251
+ return false;
2252
+ let o = e[n][a + i];
2253
+ if (n === "day") {
2254
+ if (!o) {
2255
+ for (let h = 0;h < e.nearestWeekdays.length; h++)
2256
+ if (e.nearestWeekdays[h]) {
2257
+ let l = this.getNearestWeekday(this.year, this.month, h - i);
2258
+ if (l !== -1 && l === a) {
2259
+ o = 1;
2260
+ break;
2261
+ }
2262
+ }
2263
+ }
2264
+ if (e.lastWeekday) {
2265
+ let h = this.getLastWeekday(this.year, this.month);
2266
+ a === h && (o = 1);
2267
+ }
2268
+ if (e.lastDayOfMonth) {
2269
+ let h = this.getLastDayOfMonth(this.year, this.month);
2270
+ a === h && (o = 1);
2271
+ }
2272
+ if (!e.starDOW) {
2273
+ let h = new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay(), l = e.dayOfWeek[(h + (a - 1)) % 7];
2274
+ l && l & 63 && (l = this.isNthWeekdayOfMonth(this.year, this.month, a, l) ? 1 : 0), e.useAndLogic ? o = o && l : !t.domAndDow && !e.starDOM ? o = o || l : o = o && l;
2275
+ }
2276
+ }
2277
+ if (!o)
2278
+ return false;
2279
+ }
2280
+ return true;
2281
+ }
2282
+ }, W, w, E = class {
2283
+ name;
2284
+ options;
2285
+ _states;
2286
+ fn;
2287
+ getTz() {
2288
+ return this.options.timezone || this.options.utcOffset;
2289
+ }
2290
+ applyDayOffset(e) {
2291
+ if (this.options.dayOffset !== undefined && this.options.dayOffset !== 0) {
2292
+ let t = this.options.dayOffset * 24 * 60 * 60 * 1000;
2293
+ return new Date(e.getTime() + t);
2294
+ }
2295
+ return e;
2296
+ }
2297
+ constructor(e, t, r) {
2298
+ let n, i;
2299
+ if (p(t))
2300
+ i = t;
2301
+ else if (typeof t == "object")
2302
+ n = t;
2303
+ else if (t !== undefined)
2304
+ throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");
2305
+ if (p(r))
2306
+ i = r;
2307
+ else if (typeof r == "object")
2308
+ n = r;
2309
+ else if (r !== undefined)
2310
+ throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");
2311
+ if (this.name = n?.name, this.options = R(n), this._states = { kill: false, blocking: false, previousRun: undefined, currentRun: undefined, once: undefined, currentTimeout: undefined, maxRuns: n ? n.maxRuns : undefined, paused: n ? n.paused : false, pattern: new C("* * * * *", undefined, { mode: "auto" }) }, e && (e instanceof Date || typeof e == "string" && e.indexOf(":") > 0) ? this._states.once = new m(e, this.getTz()) : this._states.pattern = new C(e, this.options.timezone, { mode: this.options.mode, alternativeWeekdays: this.options.alternativeWeekdays, sloppyRanges: this.options.sloppyRanges }), this.name) {
2312
+ if (w.find((o) => o.name === this.name))
2313
+ throw new Error("Cron: Tried to initialize new named job '" + this.name + "', but name already taken.");
2314
+ w.push(this);
2315
+ }
2316
+ return i !== undefined && _(i) && (this.fn = i, this.schedule()), this;
2317
+ }
2318
+ nextRun(e) {
2319
+ let t = this._next(e);
2320
+ return t ? this.applyDayOffset(t.getDate(false)) : null;
2321
+ }
2322
+ nextRuns(e, t) {
2323
+ this._states.maxRuns !== undefined && e > this._states.maxRuns && (e = this._states.maxRuns);
2324
+ let r = t || this._states.currentRun || undefined;
2325
+ return this._enumerateRuns(e, r, "next");
2326
+ }
2327
+ previousRuns(e, t) {
2328
+ return this._enumerateRuns(e, t || undefined, "previous");
2329
+ }
2330
+ _enumerateRuns(e, t, r) {
2331
+ let n = [], i = t ? new m(t, this.getTz()) : null, a = r === "next" ? this._next : this._previous;
2332
+ for (;e--; ) {
2333
+ let o = a.call(this, i);
2334
+ if (!o)
2335
+ break;
2336
+ let h = o.getDate(false);
2337
+ n.push(this.applyDayOffset(h)), i = o;
2338
+ }
2339
+ return n;
2340
+ }
2341
+ match(e) {
2342
+ if (this._states.once) {
2343
+ let r = new m(e, this.getTz());
2344
+ r.ms = 0;
2345
+ let n = new m(this._states.once, this.getTz());
2346
+ return n.ms = 0, r.getTime() === n.getTime();
2347
+ }
2348
+ let t = new m(e, this.getTz());
2349
+ return t.ms = 0, t.match(this._states.pattern, this.options);
2350
+ }
2351
+ getPattern() {
2352
+ if (!this._states.once)
2353
+ return this._states.pattern ? this._states.pattern.pattern : undefined;
2354
+ }
2355
+ getOnce() {
2356
+ return this._states.once ? this._states.once.getDate() : null;
2357
+ }
2358
+ isRunning() {
2359
+ let e = this.nextRun(this._states.currentRun), t = !this._states.paused, r = this.fn !== undefined, n = !this._states.kill;
2360
+ return t && r && n && e !== null;
2361
+ }
2362
+ isStopped() {
2363
+ return this._states.kill;
2364
+ }
2365
+ isBusy() {
2366
+ return this._states.blocking;
2367
+ }
2368
+ currentRun() {
2369
+ return this._states.currentRun ? this._states.currentRun.getDate() : null;
2370
+ }
2371
+ previousRun() {
2372
+ return this._states.previousRun ? this._states.previousRun.getDate() : null;
2373
+ }
2374
+ msToNext(e) {
2375
+ let t = this._next(e);
2376
+ return t ? e instanceof m || e instanceof Date ? t.getTime() - e.getTime() : t.getTime() - new m(e).getTime() : null;
2377
+ }
2378
+ stop() {
2379
+ this._states.kill = true, this._states.currentTimeout && clearTimeout(this._states.currentTimeout);
2380
+ let e = w.indexOf(this);
2381
+ e >= 0 && w.splice(e, 1);
2382
+ }
2383
+ pause() {
2384
+ return this._states.paused = true, !this._states.kill;
2385
+ }
2386
+ resume() {
2387
+ return this._states.paused = false, !this._states.kill;
2388
+ }
2389
+ schedule(e) {
2390
+ if (e && this.fn)
2391
+ throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");
2392
+ e && (this.fn = e);
2393
+ let t = this.msToNext(), r = this.nextRun(this._states.currentRun);
2394
+ return t == null || isNaN(t) || r === null ? this : (t > W && (t = W), this._states.currentTimeout = setTimeout(() => this._checkTrigger(r), t), this._states.currentTimeout && this.options.unref && x(this._states.currentTimeout), this);
2395
+ }
2396
+ async _trigger(e) {
2397
+ this._states.blocking = true, this._states.currentRun = new m(undefined, this.getTz());
2398
+ try {
2399
+ if (this.options.catch)
2400
+ try {
2401
+ this.fn !== undefined && await this.fn(this, this.options.context);
2402
+ } catch (t) {
2403
+ if (p(this.options.catch))
2404
+ try {
2405
+ this.options.catch(t, this);
2406
+ } catch {}
2407
+ }
2408
+ else
2409
+ this.fn !== undefined && await this.fn(this, this.options.context);
2410
+ } finally {
2411
+ this._states.previousRun = new m(e, this.getTz()), this._states.blocking = false;
2412
+ }
2413
+ }
2414
+ async trigger() {
2415
+ await this._trigger();
2416
+ }
2417
+ runsLeft() {
2418
+ return this._states.maxRuns;
2419
+ }
2420
+ _checkTrigger(e) {
2421
+ let t = new Date, r = !this._states.paused && t.getTime() >= e.getTime(), n = this._states.blocking && this.options.protect;
2422
+ r && !n ? (this._states.maxRuns !== undefined && this._states.maxRuns--, this._trigger()) : r && n && p(this.options.protect) && setTimeout(() => this.options.protect(this), 0), this.schedule();
2423
+ }
2424
+ _next(e) {
2425
+ let t = !!(e || this._states.currentRun), r = false;
2426
+ !e && this.options.startAt && this.options.interval && ([e, t] = this._calculatePreviousRun(e, t), r = !e), e = new m(e, this.getTz()), this.options.startAt && e && e.getTime() < this.options.startAt.getTime() && (e = this.options.startAt);
2427
+ let n = this._states.once || new m(e, this.getTz());
2428
+ return !r && n !== this._states.once && (n = n.increment(this._states.pattern, this.options, t)), this._states.once && this._states.once.getTime() <= e.getTime() || n === null || this._states.maxRuns !== undefined && this._states.maxRuns <= 0 || this._states.kill || this.options.stopAt && n.getTime() >= this.options.stopAt.getTime() ? null : n;
2429
+ }
2430
+ _previous(e) {
2431
+ let t = new m(e, this.getTz());
2432
+ this.options.stopAt && t.getTime() > this.options.stopAt.getTime() && (t = this.options.stopAt);
2433
+ let r = new m(t, this.getTz());
2434
+ return this._states.once ? this._states.once.getTime() < t.getTime() ? this._states.once : null : (r = r.decrement(this._states.pattern, this.options), r === null || this.options.startAt && r.getTime() < this.options.startAt.getTime() ? null : r);
2435
+ }
2436
+ _calculatePreviousRun(e, t) {
2437
+ let r = new m(undefined, this.getTz()), n = e;
2438
+ if (this.options.startAt.getTime() <= r.getTime()) {
2439
+ n = this.options.startAt;
2440
+ let i = n.getTime() + this.options.interval * 1000;
2441
+ for (;i <= r.getTime(); )
2442
+ n = new m(n, this.getTz()).increment(this._states.pattern, this.options, true), i = n.getTime() + this.options.interval * 1000;
2443
+ t = true;
2444
+ }
2445
+ return n === null && (n = undefined), [n, t];
2446
+ }
2447
+ };
2448
+ var init_croner = __esm(() => {
2449
+ O = [1, 2, 4, 8, 16];
2450
+ P = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2451
+ f = [["month", "year", 0], ["day", "month", -1], ["hour", "day", 0], ["minute", "hour", 0], ["second", "minute", 0]];
2452
+ W = 30 * 1000;
2453
+ w = [];
2454
+ });
2455
+
1657
2456
  // ../core/src/tools/cron/index.ts
1658
- import { Cron as Cron2 } from "croner";
1659
2457
  function setSchedulerInstance2(scheduler) {
1660
2458
  _scheduler2 = scheduler;
1661
2459
  }
@@ -1689,9 +2487,9 @@ function resolveBestChannel(userId, explicitChannel) {
1689
2487
  }
1690
2488
  if (!bestChannel) {
1691
2489
  const preferred = ["telegram", "discord", "slack", "whatsapp", "webchat"];
1692
- for (const p of preferred) {
1693
- if (identities.some((i) => i.channel === p)) {
1694
- bestChannel = p;
2490
+ for (const p2 of preferred) {
2491
+ if (identities.some((i) => i.channel === p2)) {
2492
+ bestChannel = p2;
1695
2493
  break;
1696
2494
  }
1697
2495
  }
@@ -1716,6 +2514,7 @@ var log2, _scheduler2 = null, cronCreateTool, cronListTool, cronPauseTool, cronR
1716
2514
  var init_cron = __esm(() => {
1717
2515
  init_sqlite();
1718
2516
  init_logger();
2517
+ init_croner();
1719
2518
  log2 = logger.child("CronTools");
1720
2519
  cronCreateTool = {
1721
2520
  name: "cron.create",
@@ -1761,7 +2560,7 @@ var init_cron = __esm(() => {
1761
2560
  }
1762
2561
  if (cron_expression) {
1763
2562
  try {
1764
- new Cron2(cron_expression);
2563
+ new E(cron_expression);
1765
2564
  } catch (err) {
1766
2565
  return { ok: false, error: `Invalid cron expression: ${err.message}` };
1767
2566
  }
@@ -2069,7 +2868,7 @@ var init_cron = __esm(() => {
2069
2868
  // ../core/src/tools/schedule.ts
2070
2869
  init_sqlite();
2071
2870
  init_logger();
2072
- import { Cron } from "croner";
2871
+ init_croner();
2073
2872
  var log = logger.child("ScheduleTools");
2074
2873
  var _scheduler = null;
2075
2874
  function setSchedulerInstance(scheduler) {
@@ -2124,7 +2923,7 @@ var scheduleCreateTool = {
2124
2923
  }
2125
2924
  if (cron_expression) {
2126
2925
  try {
2127
- new Cron(cron_expression);
2926
+ new E(cron_expression);
2128
2927
  } catch (err) {
2129
2928
  return { ok: false, error: `Invalid cron expression: ${err.message}` };
2130
2929
  }