fraudTech commited on
Commit
ceea2c9
·
1 Parent(s): e63ea04

Change to use MathJax

Browse files
web/package-lock.json CHANGED
@@ -9,6 +9,7 @@
9
  "version": "0.1.0",
10
  "dependencies": {
11
  "axios": "^1.6.2",
 
12
  "katex": "^0.16.27",
13
  "react": "^18.2.0",
14
  "react-dom": "^18.2.0",
@@ -709,6 +710,27 @@
709
  "node": ">=12"
710
  }
711
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  "node_modules/@jridgewell/gen-mapping": {
713
  "version": "0.3.13",
714
  "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
@@ -759,6 +781,24 @@
759
  "@jridgewell/sourcemap-codec": "^1.4.14"
760
  }
761
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762
  "node_modules/@rolldown/pluginutils": {
763
  "version": "1.0.0-beta.27",
764
  "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz",
@@ -1242,6 +1282,15 @@
1242
  "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
1243
  }
1244
  },
 
 
 
 
 
 
 
 
 
1245
  "node_modules/asynckit": {
1246
  "version": "0.4.0",
1247
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -1279,6 +1328,19 @@
1279
  "baseline-browser-mapping": "dist/cli.js"
1280
  }
1281
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
1282
  "node_modules/browserslist": {
1283
  "version": "4.28.1",
1284
  "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.1.tgz",
@@ -1641,6 +1703,15 @@
1641
  "url": "https://github.com/sponsors/sindresorhus"
1642
  }
1643
  },
 
 
 
 
 
 
 
 
 
1644
  "node_modules/estree-util-is-identifier-name": {
1645
  "version": "3.0.0",
1646
  "resolved": "https://registry.npmjs.org/estree-util-is-identifier-name/-/estree-util-is-identifier-name-3.0.0.tgz",
@@ -1785,6 +1856,23 @@
1785
  "node": ">= 0.4"
1786
  }
1787
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1788
  "node_modules/gopd": {
1789
  "version": "1.2.0",
1790
  "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
@@ -2309,6 +2397,48 @@
2309
  "node": ">= 0.4"
2310
  }
2311
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2312
  "node_modules/mdast-util-find-and-replace": {
2313
  "version": "3.0.2",
2314
  "resolved": "https://registry.npmjs.org/mdast-util-find-and-replace/-/mdast-util-find-and-replace-3.0.2.tgz",
@@ -2598,6 +2728,12 @@
2598
  "url": "https://opencollective.com/unified"
2599
  }
2600
  },
 
 
 
 
 
 
2601
  "node_modules/micromark": {
2602
  "version": "4.0.2",
2603
  "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.2.tgz",
@@ -3201,6 +3337,39 @@
3201
  "node": ">= 0.6"
3202
  }
3203
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3204
  "node_modules/ms": {
3205
  "version": "2.1.3",
3206
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -3233,6 +3402,12 @@
3233
  "dev": true,
3234
  "license": "MIT"
3235
  },
 
 
 
 
 
 
3236
  "node_modules/parse-entities": {
3237
  "version": "4.0.2",
3238
  "resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-4.0.2.tgz",
@@ -3270,6 +3445,31 @@
3270
  "url": "https://github.com/inikulin/parse5?sponsor=1"
3271
  }
3272
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3273
  "node_modules/picocolors": {
3274
  "version": "1.1.1",
3275
  "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@@ -3627,6 +3827,25 @@
3627
  "url": "https://opencollective.com/unified"
3628
  }
3629
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3630
  "node_modules/rollup": {
3631
  "version": "4.54.0",
3632
  "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.54.0.tgz",
@@ -3708,6 +3927,29 @@
3708
  "url": "https://github.com/sponsors/wooorm"
3709
  }
3710
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3711
  "node_modules/stringify-entities": {
3712
  "version": "4.0.4",
3713
  "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
@@ -4032,6 +4274,12 @@
4032
  "url": "https://github.com/sponsors/wooorm"
4033
  }
4034
  },
 
 
 
 
 
 
4035
  "node_modules/xtend": {
4036
  "version": "4.0.2",
4037
  "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
 
9
  "version": "0.1.0",
10
  "dependencies": {
11
  "axios": "^1.6.2",
12
+ "better-react-mathjax": "^2.4.0-beta-1",
13
  "katex": "^0.16.27",
14
  "react": "^18.2.0",
15
  "react-dom": "^18.2.0",
 
710
  "node": ">=12"
711
  }
712
  },
713
+ "node_modules/@isaacs/balanced-match": {
714
+ "version": "4.0.1",
715
+ "resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
716
+ "integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
717
+ "license": "MIT",
718
+ "engines": {
719
+ "node": "20 || >=22"
720
+ }
721
+ },
722
+ "node_modules/@isaacs/brace-expansion": {
723
+ "version": "5.0.0",
724
+ "resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.0.tgz",
725
+ "integrity": "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==",
726
+ "license": "MIT",
727
+ "dependencies": {
728
+ "@isaacs/balanced-match": "^4.0.1"
729
+ },
730
+ "engines": {
731
+ "node": "20 || >=22"
732
+ }
733
+ },
734
  "node_modules/@jridgewell/gen-mapping": {
735
  "version": "0.3.13",
736
  "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
 
781
  "@jridgewell/sourcemap-codec": "^1.4.14"
782
  }
783
  },
784
+ "node_modules/@mathjax/mathjax-newcm-font": {
785
+ "version": "4.1.0",
786
+ "resolved": "https://registry.npmjs.org/@mathjax/mathjax-newcm-font/-/mathjax-newcm-font-4.1.0.tgz",
787
+ "integrity": "sha512-n10AwYubUa2hyOzxSRzkwRrgCVns083zkentryXICMPKaWT/watfvK2sUk5D9Bow9mpDfoqb5EWApuUvqnlzaw==",
788
+ "license": "Apache-2.0"
789
+ },
790
+ "node_modules/@mathjax/src": {
791
+ "version": "4.1.0",
792
+ "resolved": "https://registry.npmjs.org/@mathjax/src/-/src-4.1.0.tgz",
793
+ "integrity": "sha512-xnBL2E5uNHR82iLiUVJXYicKh/Jbq2I1+8yCpcBfJqLEM6CrAR9zBpYYkAFtC/Myvykd5U5uMmRrtr49AKk0TA==",
794
+ "license": "Apache-2.0",
795
+ "dependencies": {
796
+ "@mathjax/mathjax-newcm-font": "4.1.0",
797
+ "mhchemparser": "^4.2.1",
798
+ "mj-context-menu": "^1.0.0",
799
+ "speech-rule-engine": "5.0.0-beta.3"
800
+ }
801
+ },
802
  "node_modules/@rolldown/pluginutils": {
803
  "version": "1.0.0-beta.27",
804
  "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz",
 
1282
  "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
1283
  }
1284
  },
1285
+ "node_modules/@xmldom/xmldom": {
1286
+ "version": "0.9.8",
1287
+ "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.9.8.tgz",
1288
+ "integrity": "sha512-p96FSY54r+WJ50FIOsCOjyj/wavs8921hG5+kVMmZgKcvIKxMXHTrjNJvRgWa/zuX3B6t2lijLNFaOyuxUH+2A==",
1289
+ "license": "MIT",
1290
+ "engines": {
1291
+ "node": ">=14.6"
1292
+ }
1293
+ },
1294
  "node_modules/asynckit": {
1295
  "version": "0.4.0",
1296
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
 
1328
  "baseline-browser-mapping": "dist/cli.js"
1329
  }
1330
  },
1331
+ "node_modules/better-react-mathjax": {
1332
+ "version": "2.4.0-beta-1",
1333
+ "resolved": "https://registry.npmjs.org/better-react-mathjax/-/better-react-mathjax-2.4.0-beta-1.tgz",
1334
+ "integrity": "sha512-idLyXS//8ESuZl2gVSHWx57EbkzX23rjG40RejXUp7V0Yfm5EQMRng6FEx6opk0vP5BuHNIulCoB7Qf6NELiXQ==",
1335
+ "license": "MIT",
1336
+ "dependencies": {
1337
+ "@mathjax/src": "^4.0.0",
1338
+ "mathjax-full": "^3.2.2"
1339
+ },
1340
+ "peerDependencies": {
1341
+ "react": ">=16.8"
1342
+ }
1343
+ },
1344
  "node_modules/browserslist": {
1345
  "version": "4.28.1",
1346
  "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.1.tgz",
 
1703
  "url": "https://github.com/sponsors/sindresorhus"
1704
  }
1705
  },
1706
+ "node_modules/esm": {
1707
+ "version": "3.2.25",
1708
+ "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
1709
+ "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
1710
+ "license": "MIT",
1711
+ "engines": {
1712
+ "node": ">=6"
1713
+ }
1714
+ },
1715
  "node_modules/estree-util-is-identifier-name": {
1716
  "version": "3.0.0",
1717
  "resolved": "https://registry.npmjs.org/estree-util-is-identifier-name/-/estree-util-is-identifier-name-3.0.0.tgz",
 
1856
  "node": ">= 0.4"
1857
  }
1858
  },
1859
+ "node_modules/glob": {
1860
+ "version": "13.0.0",
1861
+ "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.0.tgz",
1862
+ "integrity": "sha512-tvZgpqk6fz4BaNZ66ZsRaZnbHvP/jG3uKJvAZOwEVUL4RTA5nJeeLYfyN9/VA8NX/V3IBG+hkeuGpKjvELkVhA==",
1863
+ "license": "BlueOak-1.0.0",
1864
+ "dependencies": {
1865
+ "minimatch": "^10.1.1",
1866
+ "minipass": "^7.1.2",
1867
+ "path-scurry": "^2.0.0"
1868
+ },
1869
+ "engines": {
1870
+ "node": "20 || >=22"
1871
+ },
1872
+ "funding": {
1873
+ "url": "https://github.com/sponsors/isaacs"
1874
+ }
1875
+ },
1876
  "node_modules/gopd": {
1877
  "version": "1.2.0",
1878
  "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
 
2397
  "node": ">= 0.4"
2398
  }
2399
  },
2400
+ "node_modules/mathjax-full": {
2401
+ "version": "3.2.2",
2402
+ "resolved": "https://registry.npmjs.org/mathjax-full/-/mathjax-full-3.2.2.tgz",
2403
+ "integrity": "sha512-+LfG9Fik+OuI8SLwsiR02IVdjcnRCy5MufYLi0C3TdMT56L/pjB0alMVGgoWJF8pN9Rc7FESycZB9BMNWIid5w==",
2404
+ "deprecated": "Version 4 replaces this package with the scoped package @mathjax/src",
2405
+ "license": "Apache-2.0",
2406
+ "dependencies": {
2407
+ "esm": "^3.2.25",
2408
+ "mhchemparser": "^4.1.0",
2409
+ "mj-context-menu": "^0.6.1",
2410
+ "speech-rule-engine": "^4.0.6"
2411
+ }
2412
+ },
2413
+ "node_modules/mathjax-full/node_modules/commander": {
2414
+ "version": "13.1.0",
2415
+ "resolved": "https://registry.npmjs.org/commander/-/commander-13.1.0.tgz",
2416
+ "integrity": "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==",
2417
+ "license": "MIT",
2418
+ "engines": {
2419
+ "node": ">=18"
2420
+ }
2421
+ },
2422
+ "node_modules/mathjax-full/node_modules/mj-context-menu": {
2423
+ "version": "0.6.1",
2424
+ "resolved": "https://registry.npmjs.org/mj-context-menu/-/mj-context-menu-0.6.1.tgz",
2425
+ "integrity": "sha512-7NO5s6n10TIV96d4g2uDpG7ZDpIhMh0QNfGdJw/W47JswFcosz457wqz/b5sAKvl12sxINGFCn80NZHKwxQEXA==",
2426
+ "license": "Apache-2.0"
2427
+ },
2428
+ "node_modules/mathjax-full/node_modules/speech-rule-engine": {
2429
+ "version": "4.1.2",
2430
+ "resolved": "https://registry.npmjs.org/speech-rule-engine/-/speech-rule-engine-4.1.2.tgz",
2431
+ "integrity": "sha512-S6ji+flMEga+1QU79NDbwZ8Ivf0S/MpupQQiIC0rTpU/ZTKgcajijJJb1OcByBQDjrXCN1/DJtGz4ZJeBMPGJw==",
2432
+ "license": "Apache-2.0",
2433
+ "dependencies": {
2434
+ "@xmldom/xmldom": "0.9.8",
2435
+ "commander": "13.1.0",
2436
+ "wicked-good-xpath": "1.3.0"
2437
+ },
2438
+ "bin": {
2439
+ "sre": "bin/sre"
2440
+ }
2441
+ },
2442
  "node_modules/mdast-util-find-and-replace": {
2443
  "version": "3.0.2",
2444
  "resolved": "https://registry.npmjs.org/mdast-util-find-and-replace/-/mdast-util-find-and-replace-3.0.2.tgz",
 
2728
  "url": "https://opencollective.com/unified"
2729
  }
2730
  },
2731
+ "node_modules/mhchemparser": {
2732
+ "version": "4.2.1",
2733
+ "resolved": "https://registry.npmjs.org/mhchemparser/-/mhchemparser-4.2.1.tgz",
2734
+ "integrity": "sha512-kYmyrCirqJf3zZ9t/0wGgRZ4/ZJw//VwaRVGA75C4nhE60vtnIzhl9J9ndkX/h6hxSN7pjg/cE0VxbnNM+bnDQ==",
2735
+ "license": "Apache-2.0"
2736
+ },
2737
  "node_modules/micromark": {
2738
  "version": "4.0.2",
2739
  "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.2.tgz",
 
3337
  "node": ">= 0.6"
3338
  }
3339
  },
3340
+ "node_modules/minimatch": {
3341
+ "version": "10.1.1",
3342
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz",
3343
+ "integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==",
3344
+ "license": "BlueOak-1.0.0",
3345
+ "dependencies": {
3346
+ "@isaacs/brace-expansion": "^5.0.0"
3347
+ },
3348
+ "engines": {
3349
+ "node": "20 || >=22"
3350
+ },
3351
+ "funding": {
3352
+ "url": "https://github.com/sponsors/isaacs"
3353
+ }
3354
+ },
3355
+ "node_modules/minipass": {
3356
+ "version": "7.1.2",
3357
+ "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz",
3358
+ "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==",
3359
+ "license": "ISC",
3360
+ "engines": {
3361
+ "node": ">=16 || 14 >=14.17"
3362
+ }
3363
+ },
3364
+ "node_modules/mj-context-menu": {
3365
+ "version": "1.0.0",
3366
+ "resolved": "https://registry.npmjs.org/mj-context-menu/-/mj-context-menu-1.0.0.tgz",
3367
+ "integrity": "sha512-OSgBFQRCVhrZwRa9lhqnKcJU92dd/YXgBjup0uyeuj9bOaVsf4myOyrjU4PfhYkdDk6AqVUTov7v5uFMvIbduA==",
3368
+ "license": "Apache-2.0",
3369
+ "dependencies": {
3370
+ "rimraf": "^6.0.1"
3371
+ }
3372
+ },
3373
  "node_modules/ms": {
3374
  "version": "2.1.3",
3375
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
 
3402
  "dev": true,
3403
  "license": "MIT"
3404
  },
3405
+ "node_modules/package-json-from-dist": {
3406
+ "version": "1.0.1",
3407
+ "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
3408
+ "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
3409
+ "license": "BlueOak-1.0.0"
3410
+ },
3411
  "node_modules/parse-entities": {
3412
  "version": "4.0.2",
3413
  "resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-4.0.2.tgz",
 
3445
  "url": "https://github.com/inikulin/parse5?sponsor=1"
3446
  }
3447
  },
3448
+ "node_modules/path-scurry": {
3449
+ "version": "2.0.1",
3450
+ "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.1.tgz",
3451
+ "integrity": "sha512-oWyT4gICAu+kaA7QWk/jvCHWarMKNs6pXOGWKDTr7cw4IGcUbW+PeTfbaQiLGheFRpjo6O9J0PmyMfQPjH71oA==",
3452
+ "license": "BlueOak-1.0.0",
3453
+ "dependencies": {
3454
+ "lru-cache": "^11.0.0",
3455
+ "minipass": "^7.1.2"
3456
+ },
3457
+ "engines": {
3458
+ "node": "20 || >=22"
3459
+ },
3460
+ "funding": {
3461
+ "url": "https://github.com/sponsors/isaacs"
3462
+ }
3463
+ },
3464
+ "node_modules/path-scurry/node_modules/lru-cache": {
3465
+ "version": "11.2.5",
3466
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.5.tgz",
3467
+ "integrity": "sha512-vFrFJkWtJvJnD5hg+hJvVE8Lh/TcMzKnTgCWmtBipwI5yLX/iX+5UB2tfuyODF5E7k9xEzMdYgGqaSb1c0c5Yw==",
3468
+ "license": "BlueOak-1.0.0",
3469
+ "engines": {
3470
+ "node": "20 || >=22"
3471
+ }
3472
+ },
3473
  "node_modules/picocolors": {
3474
  "version": "1.1.1",
3475
  "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
 
3827
  "url": "https://opencollective.com/unified"
3828
  }
3829
  },
3830
+ "node_modules/rimraf": {
3831
+ "version": "6.1.2",
3832
+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.1.2.tgz",
3833
+ "integrity": "sha512-cFCkPslJv7BAXJsYlK1dZsbP8/ZNLkCAQ0bi1hf5EKX2QHegmDFEFA6QhuYJlk7UDdc+02JjO80YSOrWPpw06g==",
3834
+ "license": "BlueOak-1.0.0",
3835
+ "dependencies": {
3836
+ "glob": "^13.0.0",
3837
+ "package-json-from-dist": "^1.0.1"
3838
+ },
3839
+ "bin": {
3840
+ "rimraf": "dist/esm/bin.mjs"
3841
+ },
3842
+ "engines": {
3843
+ "node": "20 || >=22"
3844
+ },
3845
+ "funding": {
3846
+ "url": "https://github.com/sponsors/isaacs"
3847
+ }
3848
+ },
3849
  "node_modules/rollup": {
3850
  "version": "4.54.0",
3851
  "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.54.0.tgz",
 
3927
  "url": "https://github.com/sponsors/wooorm"
3928
  }
3929
  },
3930
+ "node_modules/speech-rule-engine": {
3931
+ "version": "5.0.0-beta.3",
3932
+ "resolved": "https://registry.npmjs.org/speech-rule-engine/-/speech-rule-engine-5.0.0-beta.3.tgz",
3933
+ "integrity": "sha512-wSrjCo8h4SJmGtjicD0OrTuCNH/wEaMsV+ktA1D9C2IPnensiP4pfPv+DnEZDMbauC5SCSE1prP5KA0z/W8bLg==",
3934
+ "license": "Apache-2.0",
3935
+ "dependencies": {
3936
+ "@xmldom/xmldom": "0.9.8",
3937
+ "commander": "14.0.2",
3938
+ "wicked-good-xpath": "1.3.0"
3939
+ },
3940
+ "bin": {
3941
+ "sre": "bin/sre"
3942
+ }
3943
+ },
3944
+ "node_modules/speech-rule-engine/node_modules/commander": {
3945
+ "version": "14.0.2",
3946
+ "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.2.tgz",
3947
+ "integrity": "sha512-TywoWNNRbhoD0BXs1P3ZEScW8W5iKrnbithIl0YH+uCmBd0QpPOA8yc82DS3BIE5Ma6FnBVUsJ7wVUDz4dvOWQ==",
3948
+ "license": "MIT",
3949
+ "engines": {
3950
+ "node": ">=20"
3951
+ }
3952
+ },
3953
  "node_modules/stringify-entities": {
3954
  "version": "4.0.4",
3955
  "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
 
4274
  "url": "https://github.com/sponsors/wooorm"
4275
  }
4276
  },
4277
+ "node_modules/wicked-good-xpath": {
4278
+ "version": "1.3.0",
4279
+ "resolved": "https://registry.npmjs.org/wicked-good-xpath/-/wicked-good-xpath-1.3.0.tgz",
4280
+ "integrity": "sha512-Gd9+TUn5nXdwj/hFsPVx5cuHHiF5Bwuc30jZ4+ronF1qHK5O7HD0sgmXWSEgwKquT3ClLoKPVbO6qGwVwLzvAw==",
4281
+ "license": "MIT"
4282
+ },
4283
  "node_modules/xtend": {
4284
  "version": "4.0.2",
4285
  "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
web/package.json CHANGED
@@ -10,6 +10,7 @@
10
  },
11
  "dependencies": {
12
  "axios": "^1.6.2",
 
13
  "katex": "^0.16.27",
14
  "react": "^18.2.0",
15
  "react-dom": "^18.2.0",
 
10
  },
11
  "dependencies": {
12
  "axios": "^1.6.2",
13
+ "better-react-mathjax": "^2.4.0-beta-1",
14
  "katex": "^0.16.27",
15
  "react": "^18.2.0",
16
  "react-dom": "^18.2.0",
web/src/App.css CHANGED
@@ -537,107 +537,321 @@ body {
537
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
538
  }
539
 
540
- /* KaTeX Math Rendering Styles */
541
- .message-content .katex {
542
- font-size: 1.1em;
 
 
 
543
  color: #e8d4c0 !important;
 
544
  }
545
 
546
- .message-content .katex-display {
547
- margin: 1rem 0;
 
 
 
 
 
 
 
 
548
  padding: 1rem;
549
- background: rgba(42, 37, 32, 0.3);
550
- border-left: 2px solid #6e5d4d;
551
  border-radius: 4px;
552
  overflow-x: auto;
553
  overflow-y: hidden;
554
  }
555
 
556
- .message-content .katex-display > .katex {
 
 
557
  text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  color: #e8d4c0 !important;
559
- white-space: normal;
560
  }
561
 
562
- /* Inline math */
563
- .message-content .katex-inline {
564
- padding: 0 0.2rem;
 
 
 
 
 
 
565
  }
566
 
567
- /* Better spacing for inline math in paragraphs */
568
- .message-content p .katex {
569
- margin: 0 0.2em;
570
  }
571
 
572
- /* Math operators and symbols */
573
- .message-content .katex .mord,
574
- .message-content .katex .mbin,
575
- .message-content .katex .mrel,
576
- .message-content .katex .mop,
577
- .message-content .katex .base {
578
  color: #e8d4c0 !important;
579
  }
580
 
581
- /* Fractions and matrices */
582
- .message-content .katex .frac-line {
583
  border-bottom-color: #c9b8a3 !important;
584
  }
585
 
586
- .message-content .katex .svg-align {
587
- border-color: #c9b8a3 !important;
 
 
 
 
 
588
  }
589
 
590
- /* Math text and operators */
591
- .message-content .katex .mathrm,
592
- .message-content .katex .mathit,
593
- .message-content .katex .mathbf,
594
- .message-content .katex .mathbb {
595
  color: #e8d4c0 !important;
596
  }
597
 
598
- /* KaTeX Error Handling */
599
- .message-content .katex-error {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  color: #d49999 !important;
601
- background: rgba(212, 153, 153, 0.1);
602
- padding: 0.2rem 0.4rem;
603
- border-radius: 3px;
604
  border: 1px dashed #d49999;
 
 
605
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
606
  font-size: 0.9em;
607
  }
608
 
609
- /* Ensure all nested KaTeX elements inherit proper color */
610
- .message-content .katex span,
611
- .message-content .katex .mord,
612
- .message-content .katex .minner {
613
- color: inherit;
614
- }
615
-
616
- /* Math in code blocks should not be processed by KaTeX */
617
- .message-content pre .katex,
618
- .message-content code .katex {
619
- font-size: 1em;
 
620
  }
621
 
622
  /* Scrollbar for overflow math */
623
- .message-content .katex-display::-webkit-scrollbar {
624
- height: 6px;
625
  }
626
 
627
- .message-content .katex-display::-webkit-scrollbar-track {
628
  background: #211d1a;
629
- border-radius: 3px;
630
  }
631
 
632
- .message-content .katex-display::-webkit-scrollbar-thumb {
633
  background: #3a342e;
634
- border-radius: 3px;
635
  }
636
 
637
- .message-content .katex-display::-webkit-scrollbar-thumb:hover {
638
  background: #4a433c;
639
  }
640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  .tool-calls {
642
  margin-top: 1rem;
643
  padding-top: 1rem;
 
537
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
538
  }
539
 
540
+ /* ============================================
541
+ MATHJAX MATH RENDERING STYLES
542
+ ============================================ */
543
+
544
+ /* MathJax Container */
545
+ .message-content mjx-container {
546
  color: #e8d4c0 !important;
547
+ font-size: 1.05em;
548
  }
549
 
550
+ /* Inline Math (text style) */
551
+ .message-content mjx-container[display="false"] {
552
+ display: inline-block;
553
+ margin: 0 0.15em;
554
+ }
555
+
556
+ /* Display Math (block style) */
557
+ .message-content mjx-container[display="true"] {
558
+ display: block;
559
+ margin: 1.25rem 0;
560
  padding: 1rem;
561
+ background: rgba(42, 37, 32, 0.4);
562
+ border-left: 3px solid #8b7355;
563
  border-radius: 4px;
564
  overflow-x: auto;
565
  overflow-y: hidden;
566
  }
567
 
568
+ /* Ensure display math is centered */
569
+ .message-content mjx-container[display="true"] mjx-math {
570
+ display: inline-block;
571
  text-align: center;
572
+ margin: 0 auto;
573
+ }
574
+
575
+ /* MathJax SVG output specific */
576
+ .message-content mjx-container svg {
577
+ display: inline-block;
578
+ vertical-align: middle;
579
+ }
580
+
581
+ /* MathJax CHTML output specific */
582
+ .message-content mjx-container mjx-math {
583
+ color: #e8d4c0 !important;
584
+ }
585
+
586
+ /* All MathJax text elements */
587
+ .message-content mjx-container mjx-mi,
588
+ .message-content mjx-container mjx-mo,
589
+ .message-content mjx-container mjx-mn,
590
+ .message-content mjx-container mjx-ms,
591
+ .message-content mjx-container mjx-mspace,
592
+ .message-content mjx-container mjx-mtext,
593
+ .message-content mjx-container mjx-c {
594
  color: #e8d4c0 !important;
 
595
  }
596
 
597
+ /* MathJax operators and relations */
598
+ .message-content mjx-container mjx-mo {
599
+ color: #e8d4c0 !important;
600
+ }
601
+
602
+ /* MathJax identifiers (variables) */
603
+ .message-content mjx-container mjx-mi {
604
+ color: #e8d4c0 !important;
605
+ font-style: italic;
606
  }
607
 
608
+ /* MathJax numbers */
609
+ .message-content mjx-container mjx-mn {
610
+ color: #e8d4c0 !important;
611
  }
612
 
613
+ /* Fractions */
614
+ .message-content mjx-container mjx-frac {
 
 
 
 
615
  color: #e8d4c0 !important;
616
  }
617
 
618
+ .message-content mjx-container mjx-frac mjx-line {
 
619
  border-bottom-color: #c9b8a3 !important;
620
  }
621
 
622
+ /* Roots (square roots, nth roots) */
623
+ .message-content mjx-container mjx-sqrt {
624
+ color: #e8d4c0 !important;
625
+ }
626
+
627
+ .message-content mjx-container mjx-sqrt mjx-surd {
628
+ color: #c9b8a3 !important;
629
  }
630
 
631
+ /* Subscripts and superscripts */
632
+ .message-content mjx-container mjx-sub,
633
+ .message-content mjx-container mjx-sup,
634
+ .message-content mjx-container mjx-subsup {
 
635
  color: #e8d4c0 !important;
636
  }
637
 
638
+ /* Delimiters (parentheses, brackets, braces) */
639
+ .message-content mjx-container mjx-delim,
640
+ .message-content mjx-container mjx-open,
641
+ .message-content mjx-container mjx-close {
642
+ color: #c9b8a3 !important;
643
+ }
644
+
645
+ /* Stretchy delimiters */
646
+ .message-content mjx-container mjx-stretchy-v,
647
+ .message-content mjx-container mjx-stretchy-h {
648
+ color: #c9b8a3 !important;
649
+ }
650
+
651
+ /* MathJax tables (matrices, arrays, cases) */
652
+ .message-content mjx-container mjx-table,
653
+ .message-content mjx-container mjx-mtable {
654
+ color: #e8d4c0 !important;
655
+ }
656
+
657
+ .message-content mjx-container mjx-mtable mjx-mtr {
658
+ color: #e8d4c0 !important;
659
+ }
660
+
661
+ .message-content mjx-container mjx-mtable mjx-mtd {
662
+ color: #e8d4c0 !important;
663
+ padding: 0.3em 0.5em;
664
+ }
665
+
666
+ /* Blackboard bold (\mathbb) */
667
+ .message-content mjx-container mjx-mi[mathvariant="double-struck"],
668
+ .message-content mjx-container mjx-mn[mathvariant="double-struck"] {
669
+ color: #e8d4c0 !important;
670
+ }
671
+
672
+ /* Script/calligraphic (\mathcal) */
673
+ .message-content mjx-container mjx-mi[mathvariant="script"] {
674
+ color: #e8d4c0 !important;
675
+ }
676
+
677
+ /* Fraktur (\mathfrak) */
678
+ .message-content mjx-container mjx-mi[mathvariant="fraktur"] {
679
+ color: #e8d4c0 !important;
680
+ }
681
+
682
+ /* Bold math */
683
+ .message-content mjx-container mjx-mi[mathvariant="bold"],
684
+ .message-content mjx-container mjx-mo[mathvariant="bold"] {
685
+ color: #e8d4c0 !important;
686
+ font-weight: bold;
687
+ }
688
+
689
+ /* Equation numbers (AMS environments) */
690
+ .message-content mjx-container mjx-mlabeledtr mjx-mtd:first-child {
691
+ color: #a89784 !important;
692
+ font-size: 0.9em;
693
+ }
694
+
695
+ /* Multi-line equation alignment */
696
+ .message-content mjx-container mjx-mlabeledtr {
697
+ color: #e8d4c0 !important;
698
+ }
699
+
700
+ /* Under/over braces and arrows */
701
+ .message-content mjx-container mjx-under,
702
+ .message-content mjx-container mjx-over {
703
+ color: #e8d4c0 !important;
704
+ }
705
+
706
+ /* Accents (hat, bar, tilde, etc.) */
707
+ .message-content mjx-container mjx-accent {
708
+ color: #e8d4c0 !important;
709
+ }
710
+
711
+ /* Menclose (boxes, circles around math) */
712
+ .message-content mjx-container mjx-menclose {
713
+ color: #e8d4c0 !important;
714
+ }
715
+
716
+ /* Action elements (tooltips, etc.) */
717
+ .message-content mjx-container mjx-maction {
718
+ color: #e8d4c0 !important;
719
+ }
720
+
721
+ /* Error handling for bad math */
722
+ .message-content mjx-container mjx-merror {
723
  color: #d49999 !important;
724
+ background: rgba(212, 153, 153, 0.15);
 
 
725
  border: 1px dashed #d49999;
726
+ border-radius: 3px;
727
+ padding: 0.2em 0.4em;
728
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
729
  font-size: 0.9em;
730
  }
731
 
732
+ /* MathJax loading indicator */
733
+ .message-content mjx-container mjx-assistive-mml {
734
+ position: absolute;
735
+ left: 0;
736
+ top: 0;
737
+ clip: rect(1px, 1px, 1px, 1px);
738
+ clip-path: inset(50%);
739
+ height: 1px;
740
+ width: 1px;
741
+ overflow: hidden;
742
+ padding: 0;
743
+ border: 0;
744
  }
745
 
746
  /* Scrollbar for overflow math */
747
+ .message-content mjx-container[display="true"]::-webkit-scrollbar {
748
+ height: 8px;
749
  }
750
 
751
+ .message-content mjx-container[display="true"]::-webkit-scrollbar-track {
752
  background: #211d1a;
753
+ border-radius: 4px;
754
  }
755
 
756
+ .message-content mjx-container[display="true"]::-webkit-scrollbar-thumb {
757
  background: #3a342e;
758
+ border-radius: 4px;
759
  }
760
 
761
+ .message-content mjx-container[display="true"]::-webkit-scrollbar-thumb:hover {
762
  background: #4a433c;
763
  }
764
 
765
+ /* Firefox scrollbar support */
766
+ .message-content mjx-container[display="true"] {
767
+ scrollbar-width: thin;
768
+ scrollbar-color: #3a342e #211d1a;
769
+ }
770
+
771
+ /* Prevent math in code blocks from being processed */
772
+ .message-content pre mjx-container,
773
+ .message-content code mjx-container {
774
+ display: none;
775
+ }
776
+
777
+ /* ============================================
778
+ MATH PREVIEW STYLES (User Input)
779
+ ============================================ */
780
+
781
+ .input-wrapper {
782
+ display: flex;
783
+ flex-direction: column;
784
+ flex: 1;
785
+ gap: 0.5rem;
786
+ }
787
+
788
+ .math-preview {
789
+ background: #1a1614;
790
+ border: 1px solid #3a342e;
791
+ border-radius: 4px;
792
+ padding: 0.75rem 1rem;
793
+ margin-top: 0.25rem;
794
+ }
795
+
796
+ .math-preview-label {
797
+ font-size: 0.75rem;
798
+ color: #8b7355;
799
+ text-transform: uppercase;
800
+ letter-spacing: 0.5px;
801
+ margin-bottom: 0.5rem;
802
+ font-weight: 600;
803
+ }
804
+
805
+ .math-preview-content {
806
+ color: #d4c5b9;
807
+ line-height: 1.6;
808
+ }
809
+
810
+ .math-preview-content mjx-container {
811
+ font-size: 1em;
812
+ }
813
+
814
+ /* Math preview inline math */
815
+ .math-preview-content mjx-container[display="false"] {
816
+ margin: 0 0.1em;
817
+ }
818
+
819
+ /* Math preview display math */
820
+ .math-preview-content mjx-container[display="true"] {
821
+ margin: 0.75rem 0;
822
+ padding: 0.75rem;
823
+ }
824
+
825
+ /* ============================================
826
+ MATHJAX CONTEXT LOADING STATE
827
+ ============================================ */
828
+
829
+ .mathjax-loading {
830
+ display: flex;
831
+ align-items: center;
832
+ justify-content: center;
833
+ padding: 1rem;
834
+ color: #8b7355;
835
+ font-size: 0.9rem;
836
+ }
837
+
838
+ .mathjax-loading::after {
839
+ content: '';
840
+ width: 16px;
841
+ height: 16px;
842
+ border: 2px solid #3a342e;
843
+ border-top-color: #8b7355;
844
+ border-radius: 50%;
845
+ margin-left: 0.5rem;
846
+ animation: spin 1s linear infinite;
847
+ }
848
+
849
+ @keyframes spin {
850
+ to {
851
+ transform: rotate(360deg);
852
+ }
853
+ }
854
+
855
  .tool-calls {
856
  margin-top: 1rem;
857
  padding-top: 1rem;
web/src/App.tsx CHANGED
@@ -1,12 +1,16 @@
1
  import React, { useState, useRef, useEffect, useMemo } from 'react';
2
  import ReactMarkdown from 'react-markdown';
3
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
4
- import remarkMath from 'remark-math';
5
  import remarkGfm from 'remark-gfm';
6
- import rehypeKatex from 'rehype-katex';
7
- import 'katex/dist/katex.min.css';
8
  import Login from './Login';
9
  import './App.css';
 
 
 
 
 
 
10
 
11
 
12
  const LOGIC_SAYINGS = [
@@ -112,19 +116,6 @@ const LOGIC_SAYINGS = [
112
  "Logic enforces rationality",
113
  ];
114
 
115
- // Process math content to handle common LaTeX issues
116
- function preprocessMathContent(content: string): string {
117
- if (!content) return content;
118
-
119
- let processed = content;
120
-
121
- // Only protect currency amounts from being parsed as math
122
- // Replace $number with \$number (unless already escaped)
123
- processed = processed.replace(/(?<!\\)\$(\d+(?:\.\d{2})?)/g, '\\$$1');
124
-
125
- return processed;
126
- }
127
-
128
 
129
 
130
  // Eye-health optimized warm syntax highlighting theme
@@ -188,7 +179,7 @@ interface Message {
188
  content: string;
189
  timestamp: Date;
190
  toolCalls?: ToolCall[];
191
- thinkingContent?: string; // Intermediate working text
192
  }
193
 
194
  interface ToolCall {
@@ -196,9 +187,9 @@ interface ToolCall {
196
  name: string;
197
  input: string;
198
  output: string;
199
- error?: boolean; // Tool execution failed
200
- isGenerating?: boolean; // AI is writing the code
201
- isExecuting?: boolean; // Code is running in sandbox
202
  }
203
 
204
  interface User {
@@ -207,7 +198,144 @@ interface User {
207
  }
208
 
209
  const GATEWAY_URL = import.meta.env.VITE_GATEWAY_URL || 'https://deepthoughtai-evo-gateway.hf.space';
210
- console.log('App Gateway URL:', GATEWAY_URL); // Debug log
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
  function App() {
213
  const [isAuthenticated, setIsAuthenticated] = useState(false);
@@ -218,17 +346,16 @@ function App() {
218
  const [isLoading, setIsLoading] = useState(false);
219
  const [responseComplete, setResponseComplete] = useState(false);
220
  const [statusMessage, setStatusMessage] = useState('');
 
221
  const messagesEndRef = useRef<HTMLDivElement>(null);
222
  const messagesContainerRef = useRef<HTMLDivElement>(null);
223
  const abortControllerRef = useRef<AbortController | null>(null);
224
 
225
- // Select a random logic saying on component mount
226
  const randomSaying = useMemo(
227
  () => LOGIC_SAYINGS[Math.floor(Math.random() * LOGIC_SAYINGS.length)],
228
  []
229
  );
230
 
231
- // Verify authentication via session on mount
232
  useEffect(() => {
233
  const verifyAuth = async () => {
234
  try {
@@ -246,7 +373,6 @@ function App() {
246
  setUser(data.user);
247
  setIsAuthenticated(true);
248
  } else {
249
- // Clear invalid session
250
  localStorage.removeItem('session_id');
251
  setSessionId(null);
252
  }
@@ -261,12 +387,10 @@ function App() {
261
  }, [sessionId]);
262
 
263
  useEffect(() => {
264
- // Only auto-scroll if user is near bottom (within 100px)
265
  const container = messagesContainerRef.current;
266
  if (container) {
267
  const isNearBottom = container.scrollHeight - container.scrollTop - container.clientHeight < 100;
268
  if (isNearBottom) {
269
- // Use requestAnimationFrame to avoid scroll conflicts
270
  requestAnimationFrame(() => {
271
  messagesEndRef.current?.scrollIntoView({ behavior: 'smooth', block: 'end' });
272
  });
@@ -291,7 +415,6 @@ function App() {
291
  setResponseComplete(false);
292
  setStatusMessage('Connecting to AI model...');
293
 
294
- // Create a temporary assistant message that will be updated
295
  const assistantId = (Date.now() + 1).toString();
296
  const assistantMessage: Message = {
297
  id: assistantId,
@@ -304,14 +427,12 @@ function App() {
304
  setMessages((prev) => [...prev, assistantMessage]);
305
 
306
  try {
307
- // Create new AbortController for this request
308
  abortControllerRef.current = new AbortController();
309
 
310
  const headers: HeadersInit = {
311
  'Content-Type': 'application/json'
312
  };
313
 
314
- // Add Authorization header with session ID
315
  if (sessionId) {
316
  headers['Authorization'] = `Bearer ${sessionId}`;
317
  }
@@ -321,7 +442,6 @@ function App() {
321
  headers,
322
  body: JSON.stringify({
323
  message: currentInput
324
- // API key now comes from backend environment
325
  }),
326
  signal: abortControllerRef.current.signal,
327
  });
@@ -343,7 +463,6 @@ function App() {
343
  const { done, value } = await reader.read();
344
 
345
  if (done) {
346
- // Stream ended - immediately clear ALL loading state
347
  setIsLoading(false);
348
  setResponseComplete(true);
349
  setStatusMessage('');
@@ -366,11 +485,8 @@ function App() {
366
  const data = JSON.parse(dataMatch[1]);
367
 
368
  if (event === 'status') {
369
- // Update status message to show with loading indicator
370
  setStatusMessage(data.message || 'Processing...');
371
  } else if (event === 'content_chunk') {
372
- // Stream content chunks as they arrive (like CLI)
373
- // CRITICAL: Immediately hide spinner when content starts streaming
374
  setIsLoading(false);
375
  setResponseComplete(true);
376
  setStatusMessage('');
@@ -379,7 +495,6 @@ function App() {
379
  prev.map((msg) => {
380
  if (msg.id !== assistantId) return msg;
381
 
382
- // Just accumulate content directly without headers (like CLI)
383
  return {
384
  ...msg,
385
  content: (msg.content || '') + data.chunk,
@@ -387,7 +502,6 @@ function App() {
387
  })
388
  );
389
  } else if (event === 'tool_start') {
390
- // Add tool call placeholder with generating state
391
  setStatusMessage(`Generating ${data.name}...`);
392
  setMessages((prev) =>
393
  prev.map((msg) =>
@@ -410,7 +524,6 @@ function App() {
410
  )
411
  );
412
  } else if (event === 'tool_executing') {
413
- // Tool is now executing - update status
414
  setStatusMessage(`Executing ${data.name}...`);
415
  setMessages((prev) =>
416
  prev.map((msg) =>
@@ -427,16 +540,12 @@ function App() {
427
  )
428
  );
429
  } else if (event === 'tool_complete') {
430
- // Update tool call with result and detect errors
431
  setStatusMessage('');
432
  const output = data.output || '';
433
 
434
- // Strategy: Check the LAST line for success/failure indicators
435
- // This avoids false positives from status markers (❌ Not needed) in the middle
436
  const lines = output.trim().split('\n');
437
  const lastLine = lines[lines.length - 1] || '';
438
 
439
- // Success indicators on the last line
440
  const hasFinalSuccess =
441
  lastLine.includes('✅ Classification stored') ||
442
  lastLine.includes('✅ Lean 4 code compiled successfully') ||
@@ -447,7 +556,6 @@ function App() {
447
  /✅.*completed/i.test(lastLine) ||
448
  lastLine.includes('✅');
449
 
450
- // Actual failure indicators (not status markers like "❌ Not needed")
451
  const hasActualFailure =
452
  output.includes('❌ BLOCKED') ||
453
  output.includes('❌ Python execution failed') ||
@@ -456,14 +564,12 @@ function App() {
456
  output.includes('❌ Not found in Mathlib') ||
457
  output.includes('Exit code: 0') === false && /Exit code: \d+/.test(output);
458
 
459
- // Determine error state
460
  let hasError = false;
461
  if (hasFinalSuccess) {
462
- hasError = false; // Explicit success on last line
463
  } else if (hasActualFailure) {
464
- hasError = true; // Explicit failure
465
  } else {
466
- // Fallback: check for Error: prefix
467
  hasError = output.startsWith('Error:') || output.includes('\nError:');
468
  }
469
 
@@ -482,12 +588,10 @@ function App() {
482
  )
483
  );
484
  } else if (event === 'done') {
485
- // Stream completed - ensure all loading states are cleared
486
  setIsLoading(false);
487
  setResponseComplete(true);
488
  setStatusMessage('');
489
  } else if (event === 'error') {
490
- // Error occurred
491
  setIsLoading(false);
492
  setResponseComplete(true);
493
  setStatusMessage('');
@@ -505,7 +609,6 @@ function App() {
505
  }
506
  }
507
  } catch (error) {
508
- // Don't show error message if request was aborted (user clicked New Chat)
509
  if (error instanceof Error && error.name === 'AbortError') {
510
  console.log('Request aborted by user');
511
  return;
@@ -526,7 +629,6 @@ function App() {
526
  )
527
  );
528
  } finally {
529
- // Final safety net - ensure ALL loading states are cleared
530
  setIsLoading(false);
531
  setResponseComplete(true);
532
  setStatusMessage('');
@@ -546,7 +648,6 @@ function App() {
546
  const svg = btn.querySelector('svg');
547
 
548
  navigator.clipboard.writeText(content).then(() => {
549
- // Change icon to checkmark
550
  if (svg) {
551
  const originalSVG = svg.innerHTML;
552
  svg.innerHTML = '<polyline points="20 6 9 17 4 12" stroke="currentColor" stroke-width="2.5" fill="none"></polyline>';
@@ -568,12 +669,10 @@ function App() {
568
 
569
  let fullText = '';
570
 
571
- // Add main message content
572
  if (message.content) {
573
  fullText += message.content + '\n\n';
574
  }
575
 
576
- // Add all tool calls with their inputs and outputs
577
  if (message.toolCalls && message.toolCalls.length > 0) {
578
  fullText += '=== Tool Calls ===\n\n';
579
  message.toolCalls.forEach((tool, idx) => {
@@ -587,7 +686,6 @@ function App() {
587
  }
588
 
589
  navigator.clipboard.writeText(fullText.trim()).then(() => {
590
- // Change icon to checkmark
591
  if (svg) {
592
  const originalSVG = svg.innerHTML;
593
  svg.innerHTML = '<polyline points="20 6 9 17 4 12" stroke="currentColor" stroke-width="2.5" fill="none"></polyline>';
@@ -604,7 +702,6 @@ function App() {
604
  };
605
 
606
  const handleLogin = (sessionId: string, userData: User) => {
607
- // Store session ID
608
  if (sessionId) {
609
  localStorage.setItem('session_id', sessionId);
610
  setSessionId(sessionId);
@@ -614,13 +711,11 @@ function App() {
614
  };
615
 
616
  const handleNewChat = async () => {
617
- // Cancel any ongoing request
618
  if (abortControllerRef.current) {
619
  abortControllerRef.current.abort();
620
  abortControllerRef.current = null;
621
  }
622
 
623
- // Clear backend conversation history
624
  try {
625
  const headers: HeadersInit = {
626
  'Content-Type': 'application/json'
@@ -640,7 +735,6 @@ function App() {
640
  console.error('Failed to clear chat history:', error);
641
  }
642
 
643
- // Clear frontend state
644
  setMessages([]);
645
  setInput('');
646
  setIsLoading(false);
@@ -663,7 +757,6 @@ function App() {
663
  console.error('Logout failed:', error);
664
  }
665
 
666
- // Clear session from localStorage
667
  localStorage.removeItem('session_id');
668
  setSessionId(null);
669
  setUser(null);
@@ -676,226 +769,182 @@ function App() {
676
  }
677
 
678
  return (
679
- <div className="app">
680
- <header className="header">
681
- <div className="header-left">
682
- <h1 className="logo-text">evo</h1>
683
- <span className="version">v1.0</span>
684
- </div>
685
- <div className="header-right">
686
- <button
687
- className="new-chat-btn"
688
- onClick={handleNewChat}
689
- style={{ marginRight: '1rem' }}
690
- >
691
- New Chat
692
- </button>
693
- <span className="user-info">👤 {user?.name}</span>
694
- <button className="logout-btn" onClick={handleLogout}>
695
- Logout
696
- </button>
697
- </div>
698
- </header>
699
- <div className="chat-container">
700
- <div className="messages" ref={messagesContainerRef}>
701
- {messages.length === 0 && (
702
- <div className="welcome">
703
- <div className="examples">
704
- <h3>Try these examples:</h3>
705
- <button onClick={() => setInput("What is the derivative of x^2 + 1?")} className="example-btn">
706
- Calculate derivative
707
- </button>
708
- <button onClick={() => setInput("How many Rs in strawberry")} className="example-btn">
709
- Count characters
710
- </button>
711
- <button onClick={() => setInput("Prove derivative of x^2 is 2x")} className="example-btn">
712
- Prove a theorem
713
- </button>
714
- <button onClick={() => setInput("9.9 and 9.11 which is bigger?")} className="example-btn">
715
- Compare decimals
716
- </button>
717
- <button onClick={() => setInput("What is a Large Language Model?")} className="example-btn">
718
- General question
719
- </button>
 
 
720
  </div>
721
- </div>
722
- )}
723
- {messages.map((message) => {
724
- // Don't render empty assistant messages while loading
725
- if (message.role === 'assistant' && !message.content && (!message.toolCalls || message.toolCalls.length === 0)) {
726
- return null;
727
- }
728
-
729
- return (
730
- <div key={message.id} className={`message message-${message.role}`}>
731
- <div className="message-header">
732
- <span className="message-role">
733
- {message.role === 'user' ? 'You' : 'Assistant'}
734
- </span>
735
- <div className="message-header-right">
736
- {message.role === 'assistant' && (
 
 
 
 
 
 
 
 
 
 
 
 
 
737
  <button
738
  className="copy-markdown-btn"
739
- onClick={(e) => copyEverything(message, e)}
740
- title="Copy everything (including expanders)"
741
  >
742
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
743
  <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
744
  <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
745
- <circle cx="11.5" cy="11.5" r="1.5" fill="currentColor"></circle>
746
- <circle cx="16.5" cy="11.5" r="1.5" fill="currentColor"></circle>
747
- <circle cx="11.5" cy="16.5" r="1.5" fill="currentColor"></circle>
748
- <circle cx="16.5" cy="16.5" r="1.5" fill="currentColor"></circle>
749
  </svg>
750
  </button>
751
- )}
752
- <button
753
- className="copy-markdown-btn"
754
- onClick={(e) => copyAsMarkdown(message.content, e)}
755
- title="Copy as markdown"
756
- >
757
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
758
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
759
- <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
760
- </svg>
761
- </button>
762
- <span className="message-time">
763
- {message.timestamp.toLocaleTimeString()}
764
- </span>
765
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766
  </div>
767
- {/* Final response content */}
768
- {message.content && (
769
- <div className="message-content">
770
- <ReactMarkdown
771
- remarkPlugins={[
772
- remarkGfm, // Run GFM first to protect code blocks
773
- [remarkMath, { singleDollarTextMath: true }] // Enable single-dollar math for inline equations
774
- ]}
775
- rehypePlugins={[
776
- [rehypeKatex, {
777
- strict: false, // Don't throw on unknown commands
778
- throwOnError: false, // Render errors as text instead of crashing
779
- errorColor: '#d49999', // Use error color from theme
780
- displayMode: false, // Inline math by default
781
- trust: true, // Trust LaTeX commands
782
- macros: { // Common math macros
783
- "\\R": "\\mathbb{R}",
784
- "\\N": "\\mathbb{N}",
785
- "\\Z": "\\mathbb{Z}",
786
- "\\Q": "\\mathbb{Q}",
787
- "\\C": "\\mathbb{C}",
788
- }
789
- }]
790
- ]}
791
- components={{
792
- code({ className, children, ...props }: any) {
793
- const match = /language-(\w+)/.exec(className || '');
794
- return match ? (
795
- <SyntaxHighlighter
796
- style={terminalTheme as any}
797
- language={match[1]}
798
- PreTag="div"
799
- {...props}
800
- >
801
- {String(children).replace(/\n$/, '')}
802
- </SyntaxHighlighter>
803
- ) : (
804
- <code className={className} {...props}>
805
- {children}
806
- </code>
807
- );
808
- },
809
- // Handle math nodes that fail to render
810
- span({ className, children, ...props }: any) {
811
- if (className?.includes('katex-error')) {
812
- return <span className="katex-error" {...props}>{children}</span>;
813
- }
814
- return <span className={className} {...props}>{children}</span>;
815
- }
816
- }}
817
- >
818
- {preprocessMathContent(message.content)}
819
- </ReactMarkdown>
820
- </div>
821
- )}
822
- {/* Tool calls - unchanged from original */}
823
- {message.toolCalls && message.toolCalls.length > 0 && (
824
- <div className="tool-calls">
825
- {message.toolCalls.map((tool, idx) => (
826
- <details key={idx} className="tool-call">
827
- <summary className="tool-call-header">
828
- <span className="tool-name">{tool.name}</span>
829
- {tool.isGenerating && (
830
- <span className="tool-status generating">
831
- <span className="dot"></span>
832
- <span className="dot"></span>
833
- <span className="dot"></span>
834
- <span className="status-text">Generating...</span>
835
- </span>
836
- )}
837
- {tool.isExecuting && (
838
- <span className="tool-status executing">
839
- <span className="dot"></span>
840
- <span className="dot"></span>
841
- <span className="dot"></span>
842
- <span className="status-text">Executing...</span>
843
- </span>
844
- )}
845
- {tool.output && !tool.isGenerating && !tool.isExecuting && (
846
- tool.error ? (
847
- <span className="crossmark">✗</span>
848
- ) : (
849
- <span className="checkmark">✓</span>
850
- )
851
- )}
852
- </summary>
853
- <div className="tool-call-content">
854
- <details className="tool-section">
855
- <summary className="tool-section-label">Input:</summary>
856
- <pre className="tool-code tool-input-scroll">{tool.input}</pre>
857
- </details>
858
- {tool.output && (
859
- <div className="tool-section">
860
- <div className="tool-section-label">Output:</div>
861
- <pre className="tool-output">{tool.output}</pre>
862
- </div>
863
- )}
864
- </div>
865
- </details>
866
- ))}
867
- </div>
868
  )}
869
  </div>
870
- );
871
- })}
872
- {/* Only show spinner if loading AND response is not complete AND no content yet in the last message */}
873
- {isLoading && !responseComplete && (
874
- <div className="typing-indicator">
875
- <span></span>
876
- <span></span>
877
- <span></span>
878
- <em className="status-message">{statusMessage || 'Thinking...'}</em>
879
- </div>
880
- )}
881
- <div ref={messagesEndRef} />
882
- </div>
883
- <div className="input-container">
884
- <textarea
885
- value={input}
886
- onChange={(e) => setInput(e.target.value)}
887
- onKeyPress={handleKeyPress}
888
- placeholder={`${randomSaying} (Shift+Enter for new line)`}
889
- disabled={isLoading}
890
- rows={3}
891
- />
892
- <button onClick={handleSendMessage} disabled={isLoading || !input.trim()} className="send-btn">
893
- {isLoading ? 'Sending...' : 'Send'}
894
- </button>
895
  </div>
896
  </div>
897
- </div>
898
  );
899
  }
900
 
901
- export default App;
 
1
  import React, { useState, useRef, useEffect, useMemo } from 'react';
2
  import ReactMarkdown from 'react-markdown';
3
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
 
4
  import remarkGfm from 'remark-gfm';
5
+ import { MathJaxContext, MathJax } from 'better-react-mathjax';
 
6
  import Login from './Login';
7
  import './App.css';
8
+ import {
9
+ mathJaxConfig,
10
+ preprocessMathContent,
11
+ hasMathContent,
12
+ extractMathExpressions
13
+ } from './mathjax-config';
14
 
15
 
16
  const LOGIC_SAYINGS = [
 
116
  "Logic enforces rationality",
117
  ];
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
 
121
  // Eye-health optimized warm syntax highlighting theme
 
179
  content: string;
180
  timestamp: Date;
181
  toolCalls?: ToolCall[];
182
+ thinkingContent?: string;
183
  }
184
 
185
  interface ToolCall {
 
187
  name: string;
188
  input: string;
189
  output: string;
190
+ error?: boolean;
191
+ isGenerating?: boolean;
192
+ isExecuting?: boolean;
193
  }
194
 
195
  interface User {
 
198
  }
199
 
200
  const GATEWAY_URL = import.meta.env.VITE_GATEWAY_URL || 'https://deepthoughtai-evo-gateway.hf.space';
201
+ console.log('App Gateway URL:', GATEWAY_URL);
202
+
203
+ /**
204
+ * Component to render content with MathJax
205
+ * Separates text from math for proper rendering
206
+ */
207
+ const MathContent: React.FC<{ content: string }> = ({ content }) => {
208
+ const processed = preprocessMathContent(content);
209
+
210
+ // Split content into math and non-math segments
211
+ // Pattern: display math $$...$$ or inline math $...$
212
+ const segments: Array<{ type: 'text' | 'math'; content: string; display?: boolean }> = [];
213
+
214
+ // Match display math first ($$...$$)
215
+ const displayMathRegex = /\$\$([\s\S]*?)\$\$/g;
216
+ let lastIndex = 0;
217
+ let match;
218
+
219
+ while ((match = displayMathRegex.exec(processed)) !== null) {
220
+ // Add text before this math block
221
+ if (match.index > lastIndex) {
222
+ segments.push({
223
+ type: 'text',
224
+ content: processed.slice(lastIndex, match.index)
225
+ });
226
+ }
227
+
228
+ // Add the math block (without delimiters for MathJax)
229
+ segments.push({
230
+ type: 'math',
231
+ content: match[1].trim(),
232
+ display: true
233
+ });
234
+
235
+ lastIndex = match.index + match[0].length;
236
+ }
237
+
238
+ // Add remaining text
239
+ if (lastIndex < processed.length) {
240
+ const remaining = processed.slice(lastIndex);
241
+
242
+ // Now process inline math in remaining text
243
+ const inlineSegments = remaining.split(/(\$[^$\n]+?\$)/g);
244
+
245
+ for (let i = 0; i < inlineSegments.length; i++) {
246
+ const segment = inlineSegments[i];
247
+
248
+ if (segment.startsWith('$') && segment.endsWith('$') && segment.length > 2) {
249
+ // This is inline math
250
+ segments.push({
251
+ type: 'math',
252
+ content: segment.slice(1, -1),
253
+ display: false
254
+ });
255
+ } else if (segment) {
256
+ segments.push({
257
+ type: 'text',
258
+ content: segment
259
+ });
260
+ }
261
+ }
262
+ }
263
+
264
+ // If no segments were created (no math found), treat entire content as text
265
+ if (segments.length === 0) {
266
+ segments.push({ type: 'text', content: processed });
267
+ }
268
+
269
+ return (
270
+ <>
271
+ {segments.map((segment, index) => {
272
+ if (segment.type === 'math') {
273
+ // Wrap in appropriate delimiters for MathJax
274
+ const mathContent = segment.display
275
+ ? `$$${segment.content}$$`
276
+ : `$${segment.content}$`;
277
+
278
+ return (
279
+ <MathJax
280
+ key={index}
281
+ inline={!segment.display}
282
+ dynamic
283
+ >
284
+ {mathContent}
285
+ </MathJax>
286
+ );
287
+ } else {
288
+ // Render text through ReactMarkdown (no math)
289
+ return (
290
+ <ReactMarkdown
291
+ key={index}
292
+ remarkPlugins={[remarkGfm]}
293
+ components={{
294
+ code({ className, children, ...props }: any) {
295
+ const match = /language-(\w+)/.exec(className || '');
296
+ return match ? (
297
+ <SyntaxHighlighter
298
+ style={terminalTheme as any}
299
+ language={match[1]}
300
+ PreTag="div"
301
+ {...props}
302
+ >
303
+ {String(children).replace(/\n$/, '')}
304
+ </SyntaxHighlighter>
305
+ ) : (
306
+ <code className={className} {...props}>
307
+ {children}
308
+ </code>
309
+ );
310
+ }
311
+ }}
312
+ >
313
+ {segment.content}
314
+ </ReactMarkdown>
315
+ );
316
+ }
317
+ })}
318
+ </>
319
+ );
320
+ };
321
+
322
+ /**
323
+ * Math Preview Component for User Input
324
+ */
325
+ const MathPreview: React.FC<{ content: string }> = ({ content }) => {
326
+ const hasMath = hasMathContent(content);
327
+
328
+ if (!hasMath) return null;
329
+
330
+ return (
331
+ <div className="math-preview">
332
+ <div className="math-preview-label">Math Preview</div>
333
+ <div className="math-preview-content">
334
+ <MathContent content={content} />
335
+ </div>
336
+ </div>
337
+ );
338
+ };
339
 
340
  function App() {
341
  const [isAuthenticated, setIsAuthenticated] = useState(false);
 
346
  const [isLoading, setIsLoading] = useState(false);
347
  const [responseComplete, setResponseComplete] = useState(false);
348
  const [statusMessage, setStatusMessage] = useState('');
349
+ const [showMathPreview, setShowMathPreview] = useState(true);
350
  const messagesEndRef = useRef<HTMLDivElement>(null);
351
  const messagesContainerRef = useRef<HTMLDivElement>(null);
352
  const abortControllerRef = useRef<AbortController | null>(null);
353
 
 
354
  const randomSaying = useMemo(
355
  () => LOGIC_SAYINGS[Math.floor(Math.random() * LOGIC_SAYINGS.length)],
356
  []
357
  );
358
 
 
359
  useEffect(() => {
360
  const verifyAuth = async () => {
361
  try {
 
373
  setUser(data.user);
374
  setIsAuthenticated(true);
375
  } else {
 
376
  localStorage.removeItem('session_id');
377
  setSessionId(null);
378
  }
 
387
  }, [sessionId]);
388
 
389
  useEffect(() => {
 
390
  const container = messagesContainerRef.current;
391
  if (container) {
392
  const isNearBottom = container.scrollHeight - container.scrollTop - container.clientHeight < 100;
393
  if (isNearBottom) {
 
394
  requestAnimationFrame(() => {
395
  messagesEndRef.current?.scrollIntoView({ behavior: 'smooth', block: 'end' });
396
  });
 
415
  setResponseComplete(false);
416
  setStatusMessage('Connecting to AI model...');
417
 
 
418
  const assistantId = (Date.now() + 1).toString();
419
  const assistantMessage: Message = {
420
  id: assistantId,
 
427
  setMessages((prev) => [...prev, assistantMessage]);
428
 
429
  try {
 
430
  abortControllerRef.current = new AbortController();
431
 
432
  const headers: HeadersInit = {
433
  'Content-Type': 'application/json'
434
  };
435
 
 
436
  if (sessionId) {
437
  headers['Authorization'] = `Bearer ${sessionId}`;
438
  }
 
442
  headers,
443
  body: JSON.stringify({
444
  message: currentInput
 
445
  }),
446
  signal: abortControllerRef.current.signal,
447
  });
 
463
  const { done, value } = await reader.read();
464
 
465
  if (done) {
 
466
  setIsLoading(false);
467
  setResponseComplete(true);
468
  setStatusMessage('');
 
485
  const data = JSON.parse(dataMatch[1]);
486
 
487
  if (event === 'status') {
 
488
  setStatusMessage(data.message || 'Processing...');
489
  } else if (event === 'content_chunk') {
 
 
490
  setIsLoading(false);
491
  setResponseComplete(true);
492
  setStatusMessage('');
 
495
  prev.map((msg) => {
496
  if (msg.id !== assistantId) return msg;
497
 
 
498
  return {
499
  ...msg,
500
  content: (msg.content || '') + data.chunk,
 
502
  })
503
  );
504
  } else if (event === 'tool_start') {
 
505
  setStatusMessage(`Generating ${data.name}...`);
506
  setMessages((prev) =>
507
  prev.map((msg) =>
 
524
  )
525
  );
526
  } else if (event === 'tool_executing') {
 
527
  setStatusMessage(`Executing ${data.name}...`);
528
  setMessages((prev) =>
529
  prev.map((msg) =>
 
540
  )
541
  );
542
  } else if (event === 'tool_complete') {
 
543
  setStatusMessage('');
544
  const output = data.output || '';
545
 
 
 
546
  const lines = output.trim().split('\n');
547
  const lastLine = lines[lines.length - 1] || '';
548
 
 
549
  const hasFinalSuccess =
550
  lastLine.includes('✅ Classification stored') ||
551
  lastLine.includes('✅ Lean 4 code compiled successfully') ||
 
556
  /✅.*completed/i.test(lastLine) ||
557
  lastLine.includes('✅');
558
 
 
559
  const hasActualFailure =
560
  output.includes('❌ BLOCKED') ||
561
  output.includes('❌ Python execution failed') ||
 
564
  output.includes('❌ Not found in Mathlib') ||
565
  output.includes('Exit code: 0') === false && /Exit code: \d+/.test(output);
566
 
 
567
  let hasError = false;
568
  if (hasFinalSuccess) {
569
+ hasError = false;
570
  } else if (hasActualFailure) {
571
+ hasError = true;
572
  } else {
 
573
  hasError = output.startsWith('Error:') || output.includes('\nError:');
574
  }
575
 
 
588
  )
589
  );
590
  } else if (event === 'done') {
 
591
  setIsLoading(false);
592
  setResponseComplete(true);
593
  setStatusMessage('');
594
  } else if (event === 'error') {
 
595
  setIsLoading(false);
596
  setResponseComplete(true);
597
  setStatusMessage('');
 
609
  }
610
  }
611
  } catch (error) {
 
612
  if (error instanceof Error && error.name === 'AbortError') {
613
  console.log('Request aborted by user');
614
  return;
 
629
  )
630
  );
631
  } finally {
 
632
  setIsLoading(false);
633
  setResponseComplete(true);
634
  setStatusMessage('');
 
648
  const svg = btn.querySelector('svg');
649
 
650
  navigator.clipboard.writeText(content).then(() => {
 
651
  if (svg) {
652
  const originalSVG = svg.innerHTML;
653
  svg.innerHTML = '<polyline points="20 6 9 17 4 12" stroke="currentColor" stroke-width="2.5" fill="none"></polyline>';
 
669
 
670
  let fullText = '';
671
 
 
672
  if (message.content) {
673
  fullText += message.content + '\n\n';
674
  }
675
 
 
676
  if (message.toolCalls && message.toolCalls.length > 0) {
677
  fullText += '=== Tool Calls ===\n\n';
678
  message.toolCalls.forEach((tool, idx) => {
 
686
  }
687
 
688
  navigator.clipboard.writeText(fullText.trim()).then(() => {
 
689
  if (svg) {
690
  const originalSVG = svg.innerHTML;
691
  svg.innerHTML = '<polyline points="20 6 9 17 4 12" stroke="currentColor" stroke-width="2.5" fill="none"></polyline>';
 
702
  };
703
 
704
  const handleLogin = (sessionId: string, userData: User) => {
 
705
  if (sessionId) {
706
  localStorage.setItem('session_id', sessionId);
707
  setSessionId(sessionId);
 
711
  };
712
 
713
  const handleNewChat = async () => {
 
714
  if (abortControllerRef.current) {
715
  abortControllerRef.current.abort();
716
  abortControllerRef.current = null;
717
  }
718
 
 
719
  try {
720
  const headers: HeadersInit = {
721
  'Content-Type': 'application/json'
 
735
  console.error('Failed to clear chat history:', error);
736
  }
737
 
 
738
  setMessages([]);
739
  setInput('');
740
  setIsLoading(false);
 
757
  console.error('Logout failed:', error);
758
  }
759
 
 
760
  localStorage.removeItem('session_id');
761
  setSessionId(null);
762
  setUser(null);
 
769
  }
770
 
771
  return (
772
+ <MathJaxContext config={mathJaxConfig}>
773
+ <div className="app">
774
+ <header className="header">
775
+ <div className="header-left">
776
+ <h1 className="logo-text">evo</h1>
777
+ <span className="version">v1.0</span>
778
+ </div>
779
+ <div className="header-right">
780
+ <button
781
+ className="new-chat-btn"
782
+ onClick={handleNewChat}
783
+ style={{ marginRight: '1rem' }}
784
+ >
785
+ New Chat
786
+ </button>
787
+ <span className="user-info">👤 {user?.name}</span>
788
+ <button className="logout-btn" onClick={handleLogout}>
789
+ Logout
790
+ </button>
791
+ </div>
792
+ </header>
793
+ <div className="chat-container">
794
+ <div className="messages" ref={messagesContainerRef}>
795
+ {messages.length === 0 && (
796
+ <div className="welcome">
797
+ <div className="examples">
798
+ <h3>Try these examples:</h3>
799
+ <button onClick={() => setInput("What is the derivative of x^2 + 1?")} className="example-btn">
800
+ Calculate derivative
801
+ </button>
802
+ <button onClick={() => setInput("How many Rs in strawberry")} className="example-btn">
803
+ Count characters
804
+ </button>
805
+ <button onClick={() => setInput("Prove derivative of x^2 is 2x")} className="example-btn">
806
+ Prove a theorem
807
+ </button>
808
+ <button onClick={() => setInput("9.9 and 9.11 which is bigger?")} className="example-btn">
809
+ Compare decimals
810
+ </button>
811
+ <button onClick={() => setInput("What is a Large Language Model?")} className="example-btn">
812
+ General question
813
+ </button>
814
+ </div>
815
  </div>
816
+ )}
817
+ {messages.map((message) => {
818
+ if (message.role === 'assistant' && !message.content && (!message.toolCalls || message.toolCalls.length === 0)) {
819
+ return null;
820
+ }
821
+
822
+ return (
823
+ <div key={message.id} className={`message message-${message.role}`}>
824
+ <div className="message-header">
825
+ <span className="message-role">
826
+ {message.role === 'user' ? 'You' : 'Assistant'}
827
+ </span>
828
+ <div className="message-header-right">
829
+ {message.role === 'assistant' && (
830
+ <button
831
+ className="copy-markdown-btn"
832
+ onClick={(e) => copyEverything(message, e)}
833
+ title="Copy everything (including expanders)"
834
+ >
835
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
836
+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
837
+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
838
+ <circle cx="11.5" cy="11.5" r="1.5" fill="currentColor"></circle>
839
+ <circle cx="16.5" cy="11.5" r="1.5" fill="currentColor"></circle>
840
+ <circle cx="11.5" cy="16.5" r="1.5" fill="currentColor"></circle>
841
+ <circle cx="16.5" cy="16.5" r="1.5" fill="currentColor"></circle>
842
+ </svg>
843
+ </button>
844
+ )}
845
  <button
846
  className="copy-markdown-btn"
847
+ onClick={(e) => copyAsMarkdown(message.content, e)}
848
+ title="Copy as markdown"
849
  >
850
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
851
  <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
852
  <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
 
 
 
 
853
  </svg>
854
  </button>
855
+ <span className="message-time">
856
+ {message.timestamp.toLocaleTimeString()}
857
+ </span>
858
+ </div>
 
 
 
 
 
 
 
 
 
 
859
  </div>
860
+ {/* Message content with MathJax */}
861
+ {message.content && (
862
+ <div className="message-content">
863
+ <MathContent content={message.content} />
864
+ </div>
865
+ )}
866
+ {/* Tool calls */}
867
+ {message.toolCalls && message.toolCalls.length > 0 && (
868
+ <div className="tool-calls">
869
+ {message.toolCalls.map((tool, idx) => (
870
+ <details key={idx} className="tool-call">
871
+ <summary className="tool-call-header">
872
+ <span className="tool-name">{tool.name}</span>
873
+ {tool.isGenerating && (
874
+ <span className="tool-status generating">
875
+ <span className="dot"></span>
876
+ <span className="dot"></span>
877
+ <span className="dot"></span>
878
+ <span className="status-text">Generating...</span>
879
+ </span>
880
+ )}
881
+ {tool.isExecuting && (
882
+ <span className="tool-status executing">
883
+ <span className="dot"></span>
884
+ <span className="dot"></span>
885
+ <span className="dot"></span>
886
+ <span className="status-text">Executing...</span>
887
+ </span>
888
+ )}
889
+ {tool.output && !tool.isGenerating && !tool.isExecuting && (
890
+ tool.error ? (
891
+ <span className="crossmark">✗</span>
892
+ ) : (
893
+ <span className="checkmark">✓</span>
894
+ )
895
+ )}
896
+ </summary>
897
+ <div className="tool-call-content">
898
+ <details className="tool-section">
899
+ <summary className="tool-section-label">Input:</summary>
900
+ <pre className="tool-code tool-input-scroll">{tool.input}</pre>
901
+ </details>
902
+ {tool.output && (
903
+ <div className="tool-section">
904
+ <div className="tool-section-label">Output:</div>
905
+ <pre className="tool-output">{tool.output}</pre>
906
+ </div>
907
+ )}
908
+ </div>
909
+ </details>
910
+ ))}
911
+ </div>
912
+ )}
913
  </div>
914
+ );
915
+ })}
916
+ {isLoading && !responseComplete && (
917
+ <div className="typing-indicator">
918
+ <span></span>
919
+ <span></span>
920
+ <span></span>
921
+ <em className="status-message">{statusMessage || 'Thinking...'}</em>
922
+ </div>
923
+ )}
924
+ <div ref={messagesEndRef} />
925
+ </div>
926
+ <div className="input-container">
927
+ <div className="input-wrapper">
928
+ <textarea
929
+ value={input}
930
+ onChange={(e) => setInput(e.target.value)}
931
+ onKeyPress={handleKeyPress}
932
+ placeholder={`${randomSaying} (Shift+Enter for new line)`}
933
+ disabled={isLoading}
934
+ rows={3}
935
+ />
936
+ {showMathPreview && input && (
937
+ <MathPreview content={input} />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
938
  )}
939
  </div>
940
+ <button onClick={handleSendMessage} disabled={isLoading || !input.trim()} className="send-btn">
941
+ {isLoading ? 'Sending...' : 'Send'}
942
+ </button>
943
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944
  </div>
945
  </div>
946
+ </MathJaxContext>
947
  );
948
  }
949
 
950
+ export default App;
web/src/mathjax-config.ts ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * MathJax Configuration for EVO AI
3
+ *
4
+ * This configures MathJax v3 for optimal math rendering.
5
+ * MathJax supports full AMS-LaTeX environments (align, equation, etc.)
6
+ * that KaTeX cannot handle.
7
+ */
8
+
9
+ export const mathJaxConfig = {
10
+ // Use TeX input with AMS extensions
11
+ tex: {
12
+ // Inline math delimiters
13
+ inlineMath: [
14
+ ['$', '$'],
15
+ ['\\(', '\\)']
16
+ ],
17
+ // Display math delimiters
18
+ displayMath: [
19
+ ['$$', '$$'],
20
+ ['\\[', '\\]']
21
+ ],
22
+ // Enable AMS math environments
23
+ packages: {
24
+ '[+]': ['ams', 'amscd', 'boldsymbol', 'newcommand', 'unicode', 'html', 'verb']
25
+ },
26
+ // Allow escaped dollar signs
27
+ processEscapes: true,
28
+ // Don't process math inside these tags
29
+ processEnvironments: true,
30
+ // Macros for common symbols
31
+ macros: {
32
+ R: '{\\mathbb{R}}',
33
+ N: '{\\mathbb{N}}',
34
+ Z: '{\\mathbb{Z}}',
35
+ Q: '{\\mathbb{Q}}',
36
+ C: '{\\mathbb{C}}',
37
+ F: '{\\mathbb{F}}',
38
+ eps: '{\\varepsilon}',
39
+ blank: '{\\vphantom{X}}',
40
+ },
41
+ // Tags for equations
42
+ tags: 'ams',
43
+ // Use left alignment for equation numbers
44
+ tagIndent: '0.8em',
45
+ // Format for tag side
46
+ tagSide: 'right',
47
+ // Allow \color, \href, etc.
48
+ safeProtocols: {
49
+ http: true,
50
+ https: true,
51
+ file: true,
52
+ javascript: false
53
+ }
54
+ },
55
+ // SVG output for crisp rendering at all zoom levels
56
+ svg: {
57
+ // Scale factor
58
+ scale: 1.0,
59
+ // Minimum scale
60
+ minScale: 0.5,
61
+ // Match font to page
62
+ matchFontHeight: true,
63
+ // FontCache for performance
64
+ fontCache: 'global',
65
+ // mtextInheritFont: inherit surrounding text font for \text{}
66
+ mtextInheritFont: true,
67
+ // Add explicit namespaces
68
+ addMMLclasses: false
69
+ },
70
+ // CommonHTML output option (fallback)
71
+ chtml: {
72
+ scale: 1.0,
73
+ minScale: 0.5,
74
+ matchFontHeight: true,
75
+ mtextInheritFont: true
76
+ },
77
+ // Startup configuration
78
+ startup: {
79
+ // Elements to typeset (null = all)
80
+ elements: null,
81
+ // Typeset immediately on ready
82
+ typeset: true,
83
+ // Ready function (if needed)
84
+ ready: () => {
85
+ console.log('MathJax is ready');
86
+ }
87
+ },
88
+ // Loader configuration
89
+ loader: {
90
+ // Load these components
91
+ load: [
92
+ '[tex]/ams',
93
+ '[tex]/amscd',
94
+ '[tex]/boldsymbol',
95
+ '[tex]/newcommand',
96
+ '[tex]/unicode',
97
+ '[tex]/html',
98
+ '[tex]/verb'
99
+ ]
100
+ },
101
+ // Document options
102
+ document: {
103
+ // InputJax priority
104
+ InputJax: ['tex'],
105
+ // OutputJax priority
106
+ OutputJax: ['svg', 'chtml']
107
+ }
108
+ };
109
+
110
+ /**
111
+ * Process content to make it MathJax-safe
112
+ * Handles common issues that break MathJax rendering
113
+ */
114
+ export function preprocessMathContent(content: string): string {
115
+ if (!content) return content;
116
+
117
+ let processed = content;
118
+
119
+ // Step 1: Protect currency amounts from being parsed as math
120
+ // Strategy: Replace $number with a placeholder, restore after
121
+ const currencyPlaceholders: string[] = [];
122
+
123
+ // Match currency patterns: $123, $123.45, $1,234.56, $1.2M, etc.
124
+ processed = processed.replace(
125
+ /(?<!\\)\$([\d,]+(?:\.\d{1,2})?(?:\s*[KMBT])?\b)(?!\d)/g,
126
+ (match) => {
127
+ currencyPlaceholders.push(match);
128
+ return `<<CURRENCY_${currencyPlaceholders.length - 1}>>`;
129
+ }
130
+ );
131
+
132
+ // Step 2: Normalize various LaTeX delimiters to MathJax-compatible format
133
+
134
+ // Convert \( ... \) to $...$ (inline math)
135
+ // Use non-greedy match with negative lookbehind for escape
136
+ processed = processed.replace(
137
+ /(?<!\\)\\\((.+?)(?<!\\)\\\)/gs,
138
+ (_, math) => `$${math.trim()}$`
139
+ );
140
+
141
+ // Convert \[ ... \] to $$...$$ (display math)
142
+ processed = processed.replace(
143
+ /(?<!\\)\\\[\s*([\s\S]*?)(?<!\\)\\\]/g,
144
+ (_, math) => `$$${math.trim()}$$`
145
+ );
146
+
147
+ // Step 3: Fix spacing issues around single dollar signs
148
+ // $ x $ should become $x$
149
+ processed = processed.replace(/\$\s+(.+?)\s+\$/g, '$$$1$$');
150
+
151
+ // Step 4: Ensure display math with newlines is properly formatted
152
+ // MathJax needs $$ on separate lines for multi-line display math
153
+ processed = processed.replace(
154
+ /\$\$([\s\S]*?)\$\$/g,
155
+ (match, math) => {
156
+ const trimmed = math.trim();
157
+ // If math contains newlines and isn't already wrapped, ensure clean formatting
158
+ if (trimmed.includes('\n')) {
159
+ return `$$\n${trimmed}\n$$`;
160
+ }
161
+ return `$$${trimmed}$$`;
162
+ }
163
+ );
164
+
165
+ // Step 5: Handle begin/end environments that might be inline
166
+ // Ensure \begin{align}...\end{align} is in display mode
167
+ processed = processed.replace(
168
+ /([^$]|^)(\\begin\{(align|aligned|equation|gather|multline|eqnarray)\*?\})/g,
169
+ '$1$$$$$2'
170
+ );
171
+ processed = processed.replace(
172
+ /(\\end\{(align|aligned|equation|gather|multline|eqnarray)\*?\})([^$]|$)/g,
173
+ '$1$$$3'
174
+ );
175
+
176
+ // Step 6: Restore currency placeholders
177
+ currencyPlaceholders.forEach((original, index) => {
178
+ processed = processed.replace(
179
+ `<<CURRENCY_${index}>>`,
180
+ original.replace('$', '\\$') // Escape the $
181
+ );
182
+ });
183
+
184
+ // Step 7: Handle cases where we have unescaped $ followed by text
185
+ // This catches edge cases where LLM forgot to use $$ for display math
186
+ // But be careful not to break valid inline math
187
+
188
+ // Step 8: Fix common LaTeX errors from LLMs
189
+
190
+ // Fix double backslashes that should be single in text
191
+ // (but preserve \\ for line breaks in matrices/arrays)
192
+
193
+ // Ensure \par is handled properly
194
+ processed = processed.replace(/\\par\s+/g, '\n\n');
195
+
196
+ return processed;
197
+ }
198
+
199
+ /**
200
+ * Extract math expressions from content for validation/preview
201
+ */
202
+ export function extractMathExpressions(content: string): Array<{
203
+ type: 'inline' | 'display';
204
+ content: string;
205
+ raw: string;
206
+ }> {
207
+ const expressions: Array<{ type: 'inline' | 'display'; content: string; raw: string }> = [];
208
+
209
+ // Extract display math $$...$$
210
+ const displayRegex = /\$\$([\s\S]*?)\$\$/g;
211
+ let match;
212
+ while ((match = displayRegex.exec(content)) !== null) {
213
+ expressions.push({
214
+ type: 'display',
215
+ content: match[1].trim(),
216
+ raw: match[0]
217
+ });
218
+ }
219
+
220
+ // Extract inline math $...$ (but not $$...$$)
221
+ const inlineRegex = /(?<!\$)\$([^$\n]+?)\$(?!\$)/g;
222
+ while ((match = inlineRegex.exec(content)) !== null) {
223
+ expressions.push({
224
+ type: 'inline',
225
+ content: match[1].trim(),
226
+ raw: match[0]
227
+ });
228
+ }
229
+
230
+ return expressions;
231
+ }
232
+
233
+ /**
234
+ * Check if content contains valid-looking math
235
+ */
236
+ export function hasMathContent(content: string): boolean {
237
+ if (!content) return false;
238
+
239
+ // Check for common math patterns
240
+ const patterns = [
241
+ /\$[^$]+\$/, // Inline math
242
+ /\$\$[\s\S]*?\$\$/, // Display math
243
+ /\\\([\s\S]*?\\\)/, // \(...\)
244
+ /\\\[[\s\S]*?\\\]/, // \[...\]
245
+ /\\begin\{(align|aligned|equation|gather|multline|math|displaymath)/, // Environments
246
+ /\\(frac|sum|prod|int|lim|sqrt|alpha|beta|gamma|delta|epsilon|pi|theta|phi|lambda)/, // Common commands
247
+ /_[a-zA-Z0-9]/, // Subscripts
248
+ /\^[a-zA-Z0-9]/, // Superscripts
249
+ ];
250
+
251
+ return patterns.some(pattern => pattern.test(content));
252
+ }
253
+
254
+ /**
255
+ * Sanitize math content to prevent XSS while preserving LaTeX
256
+ * MathJax's safe extension handles most of this, but we add extra protection
257
+ */
258
+ export function sanitizeMathContent(content: string): string {
259
+ if (!content) return content;
260
+
261
+ // Remove script tags (though MathJax shouldn't execute them anyway)
262
+ let sanitized = content.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
263
+
264
+ // Remove event handlers
265
+ sanitized = sanitized.replace(/\s*on\w+\s*=\s*["'][^"']*["']/gi, '');
266
+
267
+ // Allow only safe HTML tags that don't interfere with math
268
+ // (MathJax handles the rest)
269
+
270
+ return sanitized;
271
+ }
web/src/test-math.html ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Math Rendering Test</title>
5
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.27/dist/katex.min.css">
6
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.16.27/dist/katex.min.js"></script>
7
+ <style>
8
+ body {
9
+ font-family: monospace;
10
+ background: #1a1614;
11
+ color: #d4c5b9;
12
+ padding: 2rem;
13
+ }
14
+ .test-case {
15
+ border: 1px solid #3a342e;
16
+ margin: 1rem 0;
17
+ padding: 1rem;
18
+ background: #211d1a;
19
+ }
20
+ .test-label {
21
+ color: #8b7355;
22
+ font-size: 0.8rem;
23
+ margin-bottom: 0.5rem;
24
+ }
25
+ .katex { color: #e8d4c0; }
26
+ .error { color: #d49999; }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <h2>LaTeX Rendering Test Cases</h2>
31
+
32
+ <div class="test-case">
33
+ <div class="test-label">Test 1: Inline Math ($...$)</div>
34
+ <div id="test1"></div>
35
+ </div>
36
+
37
+ <div class="test-case">
38
+ <div class="test-label">Test 2: Display Math ($$...$$)</div>
39
+ <div id="test2"></div>
40
+ </div>
41
+
42
+ <div class="test-case">
43
+ <div class="test-label">Test 3: Fractions in Display Mode</div>
44
+ <div id="test3"></div>
45
+ </div>
46
+
47
+ <div class="test-case">
48
+ <div class="test-label">Test 4: Matrix</div>
49
+ <div id="test4"></div>
50
+ </div>
51
+
52
+ <div class="test-case">
53
+ <div class="test-label">Test 5: Currency (should NOT render as math)</div>
54
+ <div id="test5"></div>
55
+ </div>
56
+
57
+ <script>
58
+ const tests = [
59
+ { id: 'test1', tex: 'x^2 + y^2 = r^2', display: false },
60
+ { id: 'test2', tex: 'E = mc^2', display: true },
61
+ { id: 'test3', tex: '\\frac{d}{dx}\\left( \\frac{x^2}{1+x} \\right) = \\frac{2x(1+x) - x^2}{(1+x)^2}', display: true },
62
+ { id: 'test4', tex: '\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}', display: true },
63
+ { id: 'test5', tex: 'The price is $123.45 and the budget is $1,000', display: false },
64
+ ];
65
+
66
+ tests.forEach(test => {
67
+ const el = document.getElementById(test.id);
68
+ try {
69
+ // Preprocess currency protection
70
+ let processed = test.tex.replace(/(?<!\\)\$(\d+(?:\.\d{2})?)/g, '\\$$1');
71
+
72
+ if (test.id === 'test5') {
73
+ // For currency test, show raw text
74
+ el.innerHTML = `<span style="color: #7d9d7a;">${processed}</span>`;
75
+ } else {
76
+ katex.render(processed, el, {
77
+ throwOnError: false,
78
+ strict: false,
79
+ displayMode: test.display,
80
+ errorColor: '#d49999'
81
+ });
82
+ }
83
+ } catch (e) {
84
+ el.innerHTML = `<span class="error">Error: ${e.message}</span>`;
85
+ }
86
+ });
87
+ </script>
88
+ </body>
89
+ </html>