@epam/ai-dial-chat-shared 1.3.0-dev.103 → 1.3.0-dev.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@epam/ai-dial-chat-shared",
3
3
  "description": "Shared domain models, utilities, and UI components for AI DIAL Chat libraries",
4
- "version": "1.3.0-dev.103",
4
+ "version": "1.3.0-dev.106",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "sideEffects": [
package/utils/latex.d.ts CHANGED
@@ -13,9 +13,10 @@
13
13
  * open, not against the few characters after the amount: `$1 - \frac{3}{p} < 1$` reads as
14
14
  * a price for one character and as LaTeX for the rest of the line.
15
15
  *
16
- * The `\(...\)`/`\[...\]` delimiters LLMs commonly emit are deliberately left as-is: they are
17
- * recognized directly by `micromark-extension-llm-math`, which the consuming app's bundler
18
- * config aliases in place of the default `micromark-extension-math` used by `remark-math`.
16
+ * The `\(...\)`/`\[...\]` delimiters LLMs commonly emit are left as-is around a formula: they
17
+ * are recognized directly by `micromark-extension-llm-math`, which the consuming app's bundler
18
+ * config aliases in place of the default `micromark-extension-math` used by `remark-math`. A
19
+ * pair wrapping a link or a URL is escaped prose and is turned back into literal brackets.
19
20
  */
20
21
  export declare const preprocessLaTeX: (content: string) => string;
21
22
  //# sourceMappingURL=latex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"latex.d.ts","sourceRoot":"","sources":["../../src/utils/latex.ts"],"names":[],"mappings":"AA0SA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,MAoEjD,CAAC"}
1
+ {"version":3,"file":"latex.d.ts","sourceRoot":"","sources":["../../src/utils/latex.ts"],"names":[],"mappings":"AAuWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,MAoEjD,CAAC"}
package/utils/latex.js CHANGED
@@ -1,15 +1,23 @@
1
1
  //#region src/utils/latex.ts
2
- var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\{[^}]*\}\$/g, i = /\$\$([\s\S]*?)\$\$/g, a = /^[ \t]*\r?\n/, o = /\r?\n[ \t]*$/, s = /\d+(?:,\d{3})*(?:\.\d+)?(?:[KMBkmb])?/y, c = /\s|[^a-zA-Z\d]/y, l = /[\^_\\]/y, u = /(?:[<>]|\\(?:le|leq|ll|ge|geq|gg|ne|neq|approx|equiv|sim|simeq|cong|in|notin|subset|subseteq|supset|supseteq|to|rightarrow|leftarrow|mapsto|implies|iff)\b)/y, d = /\\[a-zA-Z]|[\^_]/, f = (i) => {
2
+ var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\{[^}]*\}\$/g, i = /\]\(|:\/\//, a = {
3
+ "[": "]",
4
+ "(": ")"
5
+ }, o = {
6
+ "[": "&#91;",
7
+ "]": "&#93;",
8
+ "(": "&#40;",
9
+ ")": "&#41;"
10
+ }, s = /\$\$([\s\S]*?)\$\$/g, c = /^[ \t]*\r?\n/, l = /\r?\n[ \t]*$/, u = /\d+(?:,\d{3})*(?:\.\d+)?(?:[KMBkmb])?/y, d = /\s|[^a-zA-Z\d]/y, f = /[\^_\\]/y, p = /(?:[<>]|\\(?:le|leq|ll|ge|geq|gg|ne|neq|approx|equiv|sim|simeq|cong|in|notin|subset|subseteq|supset|supseteq|to|rightarrow|leftarrow|mapsto|implies|iff)\b)/y, m = /\\[a-zA-Z]|[\^_]/, h = (i) => {
3
11
  let a = i.replace(e, "$\\\\ce{");
4
12
  return a = a.replace(t, "$\\\\pu{"), a = a.replace(n, (e) => `$${e}$`), a = a.replace(r, (e) => `$${e}$`), a;
5
- }, p = (e) => {
13
+ }, g = (e) => {
6
14
  let t = [], n = -1, r = -1;
7
15
  for (let i = 0; i < e.length; i++) {
8
16
  let a = e[i];
9
17
  a === "`" && i + 2 < e.length && e[i + 1] === "`" && e[i + 2] === "`" ? r === -1 ? (r = i, i += 2) : (t.push([r, i + 2]), r = -1, i += 2) : a === "`" && r === -1 && (n === -1 ? n = i : (t.push([n, i]), n = -1));
10
18
  }
11
19
  return t;
12
- }, m = (e, t) => {
20
+ }, _ = (e, t) => {
13
21
  let n = 0, r = t.length - 1;
14
22
  for (; n <= r;) {
15
23
  let i = Math.floor((n + r) / 2), [a, o] = t[i];
@@ -17,28 +25,38 @@ var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\
17
25
  e < a ? r = i - 1 : n = i + 1;
18
26
  }
19
27
  return !1;
20
- }, h = (e, t, n) => (e.lastIndex = n, e.exec(t)), g = /\s/, _ = (e, t) => {
28
+ }, v = (e, t, n) => (e.lastIndex = n, e.exec(t)), y = /\s/, b = (e, t) => {
21
29
  let n = t;
22
- for (; n < e.length && g.test(e[n]);) n++;
30
+ for (; n < e.length && y.test(e[n]);) n++;
23
31
  return n;
24
- }, v = (e) => {
32
+ }, x = (e) => {
25
33
  if (!e.includes("$$")) return e;
26
- let t = p(e), n = [], r = 0, s;
27
- for (i.lastIndex = 0; (s = i.exec(e)) !== null;) {
28
- let i = s.index, c = i + s[0].length, l = s[1];
29
- if (m(i, t)) continue;
30
- let u = e.lastIndexOf("\n", i - 1) + 1;
31
- if (e.slice(u, i).trim() !== "") continue;
32
- let d = e.indexOf("\n", c), f = e.slice(c, d === -1 ? e.length : d);
33
- if (!l.includes("\n") && (f.trim() !== "" || l.trim() === "")) continue;
34
- let p = l.replace(a, "").replace(o, "");
35
- n.push(e.slice(r, i)), n.push(`$$\n${p}\n$$${f.trim() === "" ? "" : "\n"}`), r = c;
34
+ let t = g(e), n = [], r = 0, i;
35
+ for (s.lastIndex = 0; (i = s.exec(e)) !== null;) {
36
+ let a = i.index, o = a + i[0].length, s = i[1];
37
+ if (_(a, t)) continue;
38
+ let u = e.lastIndexOf("\n", a - 1) + 1;
39
+ if (e.slice(u, a).trim() !== "") continue;
40
+ let d = e.indexOf("\n", o), f = e.slice(o, d === -1 ? e.length : d);
41
+ if (!s.includes("\n") && (f.trim() !== "" || s.trim() === "")) continue;
42
+ let p = s.replace(c, "").replace(l, "");
43
+ n.push(e.slice(r, a)), n.push(`$$\n${p}\n$$${f.trim() === "" ? "" : "\n"}`), r = o;
36
44
  }
37
45
  return n.push(e.substring(r)), n.join("");
38
- }, y = (e, t) => {
39
- let n = h(s, e, t + 1);
46
+ }, S = (e) => {
47
+ if (!e.includes("\\[") && !e.includes("\\(")) return e;
48
+ let t = g(e), n = [], r = 0;
49
+ for (let s = 0; s < e.length - 1; s++) {
50
+ let c = e[s + 1], l = a[c];
51
+ if (e[s] !== "\\" || l == null || s > 0 && e[s - 1] === "\\" || _(s, t)) continue;
52
+ let u = e.indexOf(`\\${l}`, s + 2);
53
+ u !== -1 && i.test(e.slice(s + 2, u)) && (n.push(e.slice(r, s), o[c], e.slice(s + 2, u), o[l]), r = u + 2, s = u + 1);
54
+ }
55
+ return r === 0 ? e : (n.push(e.substring(r)), n.join(""));
56
+ }, C = (e, t) => {
57
+ let n = v(u, e, t + 1);
40
58
  return n ? t + 1 + n[0].length : -1;
41
- }, b = (e, t) => t >= e.length ? !0 : !(!h(c, e, t) || h(l, e, t) || h(u, e, _(e, t))), x = (e, t) => {
59
+ }, w = (e, t) => t >= e.length ? !0 : !(!v(d, e, t) || v(f, e, t) || v(p, e, b(e, t))), T = (e, t) => {
42
60
  let n = [];
43
61
  for (let r = 0; r < e.length; r++) {
44
62
  if (e[r] !== "$") continue;
@@ -48,21 +66,21 @@ var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\
48
66
  r = i;
49
67
  continue;
50
68
  }
51
- r > 0 && e[r - 1] === "\\" || m(r, t) || n.push(r);
69
+ r > 0 && e[r - 1] === "\\" || _(r, t) || n.push(r);
52
70
  }
53
71
  return n;
54
- }, S = (e, t, n, r) => {
72
+ }, E = (e, t, n, r) => {
55
73
  if (n <= t + 1 || e[n - 1] === "`") return !1;
56
74
  for (let i = t + 1; i < n; i++) if (e[i] === "\n" || e[i] === "$" && !(e[i - 1] === "\\" || r.has(i))) return !1;
57
75
  return !0;
58
- }, C = (e, t, n, r) => n !== void 0 && S(e, t, n, r) && d.test(e.slice(t + 1, n)), w = (e) => {
59
- if (!e.includes("$")) return e;
60
- let t = e;
61
- (e.includes("\\ce{") || e.includes("\\pu{")) && (t = f(e)), t = v(t);
62
- let n = p(t), r = x(t, n), i = /* @__PURE__ */ new Map(), a = -1;
76
+ }, D = (e, t, n, r) => n !== void 0 && E(e, t, n, r) && m.test(e.slice(t + 1, n)), O = (e) => {
77
+ let t = S(e);
78
+ if (!t.includes("$")) return t;
79
+ (t.includes("\\ce{") || t.includes("\\pu{")) && (t = h(t)), t = x(t);
80
+ let n = g(t), r = T(t, n), i = /* @__PURE__ */ new Map(), a = -1;
63
81
  for (let e = 0; e < r.length; e++) {
64
- let n = r[e], o = y(t, n);
65
- if (o !== -1 && b(t, o) && (a !== -1 || !C(t, n, r[e + 1], i))) {
82
+ let n = r[e], o = C(t, n);
83
+ if (o !== -1 && w(t, o) && (a !== -1 || !D(t, n, r[e + 1], i))) {
66
84
  i.set(n, "\\$"), a === -1 && r[e + 1] === o && (i.set(o, "\\$"), e++);
67
85
  continue;
68
86
  }
@@ -70,7 +88,7 @@ var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\
70
88
  a = n;
71
89
  continue;
72
90
  }
73
- S(t, a, n, i) ? (i.set(a, "$$"), i.set(n, "$$"), a = -1) : a = n;
91
+ E(t, a, n, i) ? (i.set(a, "$$"), i.set(n, "$$"), a = -1) : a = n;
74
92
  }
75
93
  if (i.size === 0) return t;
76
94
  let o = [], s = 0;
@@ -78,4 +96,4 @@ var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\
78
96
  return o.push(t.substring(s)), o.join("");
79
97
  };
80
98
  //#endregion
81
- export { w as preprocessLaTeX };
99
+ export { O as preprocessLaTeX };