token-goat 2.9.29 → 2.9.31
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/README.md +53 -42
- package/SECURITY.md +37 -11
- package/THIRD_PARTY_NOTICES.md +41 -4
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/native/win32-arm64/tg-hook.exe +0 -0
- package/dist/native/win32-x64/tg-hook.exe +0 -0
- package/dist/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-25TRAWET.mjs} +23 -6
- package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
- package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-2M7E4PF7.mjs} +43 -14
- package/dist/token-goat-chunk-2UPZGKKY.mjs +188 -0
- package/dist/token-goat-chunk-2WLPWKHV.mjs +135 -0
- package/dist/token-goat-chunk-2XBMMDBD.mjs +126 -0
- package/dist/token-goat-chunk-32ZOY4N5.mjs +23 -0
- package/dist/token-goat-chunk-3EZRNKTK.mjs +188 -0
- package/dist/token-goat-chunk-4ADZHI7J.mjs +63 -0
- package/dist/token-goat-chunk-4GBVPH3D.mjs +242 -0
- package/dist/{token-goat-chunk-2WOUYWLM.mjs → token-goat-chunk-4GILLLWY.mjs} +34 -7
- package/dist/token-goat-chunk-4NAPX7BA.mjs +90 -0
- package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-4SC7UJYV.mjs} +9981 -11563
- package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
- package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-4ZBFWLXF.mjs} +310 -441
- package/dist/token-goat-chunk-57BIAXJL.mjs +286 -0
- package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
- package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
- package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
- package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
- package/dist/token-goat-chunk-646E6U44.mjs +398 -0
- package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
- package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-6DG6HWP3.mjs} +13 -3
- package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
- package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
- package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-76FGDLRO.mjs} +574 -340
- package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7EZTZOMC.mjs} +780 -767
- package/dist/token-goat-chunk-7MAOA6X4.mjs +3647 -0
- package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
- package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
- package/dist/token-goat-chunk-AUNGYYQX.mjs +184 -0
- package/dist/token-goat-chunk-AUQYRMMH.mjs +2985 -0
- package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
- package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-BA4HI6BW.mjs} +1910 -165
- package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-BFCWY73P.mjs} +58 -20
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/token-goat-chunk-BWGFUZZE.mjs +25 -0
- package/dist/token-goat-chunk-C75NA7PL.mjs +322 -0
- package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
- package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
- package/dist/token-goat-chunk-CIMQ2BB3.mjs +233 -0
- package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-CJLS3CDL.mjs} +70 -18
- package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-CO3UYX6G.mjs} +7 -1
- package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
- package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
- package/dist/token-goat-chunk-CVCEVUGK.mjs +315 -0
- package/dist/token-goat-chunk-CXHOFN7R.mjs +371 -0
- package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
- package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-DGS2LVNA.mjs} +70 -160
- package/dist/{token-goat-chunk-L7H3U27L.mjs → token-goat-chunk-DOWRSMWO.mjs} +1 -1
- package/dist/token-goat-chunk-E45INMY3.mjs +71 -0
- package/dist/token-goat-chunk-EC5F37F4.mjs +244 -0
- package/dist/{token-goat-chunk-XTQAOTSO.mjs → token-goat-chunk-EDBDRVH5.mjs} +4 -1
- package/dist/token-goat-chunk-EELTBKDM.mjs +613 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-F4HYL64R.mjs} +12 -2
- package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
- package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
- package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-GL3ETKSC.mjs} +276 -19
- package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-GVB2MUST.mjs} +265 -1567
- package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HLPW63A7.mjs +48 -0
- package/dist/token-goat-chunk-HU4TORC5.mjs +1377 -0
- package/dist/token-goat-chunk-I7VKZZAW.mjs +35 -0
- package/dist/token-goat-chunk-IA6XSPE3.mjs +218 -0
- package/dist/token-goat-chunk-IAGXMHIK.mjs +863 -0
- package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-IK2DRMFX.mjs} +129 -74
- package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-INNPTRUX.mjs} +2954 -2783
- package/dist/token-goat-chunk-JJ5BX4F4.mjs +129 -0
- package/dist/token-goat-chunk-JVFSHVFJ.mjs +129 -0
- package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
- package/dist/token-goat-chunk-LCNQ2CNN.mjs +497 -0
- package/dist/token-goat-chunk-M3LFJDPU.mjs +58 -0
- package/dist/token-goat-chunk-M52KPT3C.mjs +87 -0
- package/dist/token-goat-chunk-MBEG42H7.mjs +150 -0
- package/dist/{token-goat-chunk-EVC4TOLE.mjs → token-goat-chunk-METECDOH.mjs} +3 -12
- package/dist/{token-goat-chunk-2AWQ2R5X.mjs → token-goat-chunk-MHX7XCC3.mjs} +3 -2
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
- package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-N5MMR2IW.mjs} +30 -8
- package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
- package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-NISNMD7T.mjs} +2545 -2953
- package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
- package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
- package/dist/token-goat-chunk-NSNSPPBG.mjs +69 -0
- package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
- package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
- package/dist/token-goat-chunk-ODBT2USM.mjs +800 -0
- package/dist/token-goat-chunk-OS5EM5PP.mjs +107 -0
- package/dist/token-goat-chunk-OUKDTVNU.mjs +1178 -0
- package/dist/token-goat-chunk-OXFMP75N.mjs +566 -0
- package/dist/{token-goat-chunk-ASLWOQ3I.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -1
- package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-P6HQSWQ3.mjs} +55 -47
- package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
- package/dist/token-goat-chunk-PFWIMH2E.mjs +261 -0
- package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
- package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
- package/dist/token-goat-chunk-PX5PQWTY.mjs +462 -0
- package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
- package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
- package/dist/token-goat-chunk-QH7YVYOY.mjs +3957 -0
- package/dist/token-goat-chunk-QLMUHEPB.mjs +43 -0
- package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-QQOJIHL3.mjs} +50 -14
- package/dist/token-goat-chunk-QQTWJY2O.mjs +85 -0
- package/dist/token-goat-chunk-QYHO5CPH.mjs +93 -0
- package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
- package/dist/token-goat-chunk-RSLPOBKQ.mjs +339 -0
- package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
- package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
- package/dist/{token-goat-chunk-PGTH2U4C.mjs → token-goat-chunk-SOAFZNNZ.mjs} +164 -40
- package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-SRTHT7KV.mjs} +33 -15
- package/dist/token-goat-chunk-T5P5ACNQ.mjs +212 -0
- package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
- package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
- package/dist/token-goat-chunk-TM6MC754.mjs +40 -0
- package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
- package/dist/token-goat-chunk-U2KSB4SG.mjs +56 -0
- package/dist/token-goat-chunk-U4WHMG6Y.mjs +898 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/token-goat-chunk-UGJHGR5A.mjs +52 -0
- package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-UOUDVA5U.mjs} +76 -16
- package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-URRJ33GR.mjs} +22 -4
- package/dist/token-goat-chunk-UZOROKIS.mjs +165 -0
- package/dist/token-goat-chunk-VIHGGGEI.mjs +4234 -0
- package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
- package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
- package/dist/token-goat-chunk-VWZA2H4P.mjs +368 -0
- package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-VXEXMJDL.mjs} +2964 -3153
- package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
- package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-WDH44VAU.mjs} +19 -22
- package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
- package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
- package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-XLRBNZCC.mjs} +40 -21
- package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-XRKUX6CM.mjs} +4 -0
- package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
- package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
- package/dist/token-goat-chunk-Y2ZTQOCL.mjs +35 -0
- package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-YB4VMGK2.mjs} +15 -4
- package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
- package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-YHVDKQBR.mjs} +389 -221
- package/dist/token-goat-chunk-YJB5XLWI.mjs +26 -0
- package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-YKB6AQG3.mjs} +53 -31
- package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
- package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
- package/dist/{token-goat-chunk-HUYUHODZ.mjs → token-goat-chunk-YY6AVUFL.mjs} +13246 -12247
- package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
- package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
- package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
- package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
- package/dist/token-goat-hook-client.cjs +87 -23
- package/dist/token-goat-hook-client.mjs +3 -3
- package/dist/token-goat-hook.mjs +76 -31
- package/dist/token-goat.core.mjs +6 -6
- package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
- package/docs/cli.md +113 -60
- package/docs/install.md +63 -20
- package/docs/security.md +10 -8
- package/package.json +18 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
- package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
- package/dist/token-goat-chunk-BGYOZ6DO.mjs +0 -24
- package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
- package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
- package/dist/token-goat-chunk-D4ETHJD6.mjs +0 -246
- package/dist/token-goat-chunk-DNRPXHYH.mjs +0 -1062
- package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
- package/dist/token-goat-chunk-FTP4U4QA.mjs +0 -64
- package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
- package/dist/token-goat-chunk-GLXRTTLE.mjs +0 -36
- package/dist/token-goat-chunk-H5J3C56Q.mjs +0 -1511
- package/dist/token-goat-chunk-IVWI2OCK.mjs +0 -368
- package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
- package/dist/token-goat-chunk-LZNBQTDK.mjs +0 -26
- package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
- package/dist/token-goat-chunk-RTMVLHWX.mjs +0 -7113
- package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
- package/dist/token-goat-chunk-VZQEWRVH.mjs +0 -312
- package/dist/token-goat-chunk-XYWPOSCN.mjs +0 -807
- package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
- package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
- package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
5
|
-
DEFAULT_TIMEOUT_SECONDS,
|
|
6
|
-
MAX_CAPTURE_BYTES,
|
|
7
|
-
resolveFilter,
|
|
8
|
-
run,
|
|
9
|
-
runRaw
|
|
10
|
-
} from "./token-goat-chunk-IVWI2OCK.mjs";
|
|
11
|
-
import "./token-goat-chunk-L7H3U27L.mjs";
|
|
12
|
-
import "./token-goat-chunk-ZER6EAXZ.mjs";
|
|
13
|
-
import "./token-goat-chunk-O6I2XU4P.mjs";
|
|
14
|
-
import "./token-goat-chunk-D4ETHJD6.mjs";
|
|
15
|
-
import "./token-goat-chunk-2WOUYWLM.mjs";
|
|
16
|
-
import "./token-goat-chunk-CIQ2FTY3.mjs";
|
|
17
|
-
import "./token-goat-chunk-435UQTKD.mjs";
|
|
18
|
-
import "./token-goat-chunk-7CPMDFGB.mjs";
|
|
19
|
-
import "./token-goat-chunk-TGOXNAHW.mjs";
|
|
20
|
-
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
21
|
-
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
22
|
-
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
23
|
-
import "./token-goat-chunk-XYWPOSCN.mjs";
|
|
24
|
-
import "./token-goat-chunk-TCQANXYC.mjs";
|
|
25
|
-
import "./token-goat-chunk-NMTKNYGF.mjs";
|
|
26
|
-
import "./token-goat-chunk-MELOKFDJ.mjs";
|
|
27
|
-
import "./token-goat-chunk-JTKCQMQA.mjs";
|
|
28
|
-
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
29
|
-
export {
|
|
30
|
-
DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
31
|
-
DEFAULT_TIMEOUT_SECONDS,
|
|
32
|
-
MAX_CAPTURE_BYTES,
|
|
33
|
-
resolveFilter,
|
|
34
|
-
run,
|
|
35
|
-
runRaw
|
|
36
|
-
};
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_OCR_LANG,
|
|
5
|
-
isSupportedOcrLang,
|
|
6
|
-
loadConfig,
|
|
7
|
-
resolveOcrLangs
|
|
8
|
-
} from "./token-goat-chunk-TGOXNAHW.mjs";
|
|
9
|
-
import {
|
|
10
|
-
ensureDirSync
|
|
11
|
-
} from "./token-goat-chunk-XYWPOSCN.mjs";
|
|
12
|
-
import {
|
|
13
|
-
fenceUntrustedOcrText
|
|
14
|
-
} from "./token-goat-chunk-NMTKNYGF.mjs";
|
|
15
|
-
import {
|
|
16
|
-
tokenGoatHome
|
|
17
|
-
} from "./token-goat-chunk-MELOKFDJ.mjs";
|
|
18
|
-
import {
|
|
19
|
-
init_define_import_meta_env
|
|
20
|
-
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
21
|
-
|
|
22
|
-
// src/image_ocr.ts
|
|
23
|
-
init_define_import_meta_env();
|
|
24
|
-
import { spawn } from "node:child_process";
|
|
25
|
-
import { createHash } from "node:crypto";
|
|
26
|
-
import * as fs from "node:fs";
|
|
27
|
-
import { createRequire } from "node:module";
|
|
28
|
-
import * as path from "node:path";
|
|
29
|
-
|
|
30
|
-
// src/ocr_hashes.ts
|
|
31
|
-
init_define_import_meta_env();
|
|
32
|
-
function ocrLangPath(lang) {
|
|
33
|
-
return `https://cdn.jsdelivr.net/npm/@tesseract.js-data/${lang}@1.0.0/4.0.0_best_int`;
|
|
34
|
-
}
|
|
35
|
-
var OCR_LANG_HASHES = {
|
|
36
|
-
eng: "5dc5d8d640a212c9d6184921ba103b186f50e0fed9ee716c53e6b312b400d747",
|
|
37
|
-
fra: "bf83833fa957ff0076f6aa93f69e3bdf7b014dea829ea0c0d6be6b48a3ceef6d",
|
|
38
|
-
spa: "0062377729b81cc268b1822f09eb1c08c09f3f7f1c6b422540b51555a7eeea70",
|
|
39
|
-
deu: "a1b72cc25753eac167edfef5af4448a8dc34973503a2265c34c84520f896eb03",
|
|
40
|
-
ita: "36ec897f5f1f489b257801881286167a79b99a16040c6fbc7e3e30f03821b10b",
|
|
41
|
-
por: "42fab1f017aedab69b92bdecc01bbb11166cd3b177575612ee860f8e2825ece0",
|
|
42
|
-
nld: "363c360db9838838ff7ed3d8b885b33acc0d61d37165708303cf8a81e50164f3",
|
|
43
|
-
pol: "02b89cad819f1374631b4a3c92bdac79c214150f97a3686df78de6c8c30782db",
|
|
44
|
-
rus: "eb9be824435f6bb0f993925acb85fd842c8418d6db7613c818e749e619a1ad6d",
|
|
45
|
-
tur: "f0127d0f3745f9c65e2ae7ec6b23198fbe5aa186a61b35661426f5e1ef9dedd7",
|
|
46
|
-
swe: "a4c33cbd23d988c84b5f9d5d5b2417fc16da061e3dc7b16acb904a4566088b14",
|
|
47
|
-
ara: "e7d6494e2ef249ee97ad151eb01e0e6ae3aaf429256442ad6af534862a2a8c0f",
|
|
48
|
-
chi_sim: "9784f7c917c546424b690fcde708ce1f604a4393d08bb51ddab146d7d7c794e6",
|
|
49
|
-
chi_tra: "6abfb87cce5db0d09624f16eedd8a0b24173718856121f721b6d1214193d4dab",
|
|
50
|
-
jpn: "1a0175291ea145d4a66be681d1084496f10af938aacab247c5d40b31359a604e",
|
|
51
|
-
kor: "ec1749377d49ac38fb3d3cd05dd5e2a53359d329f359762bc638a81132109992"
|
|
52
|
-
};
|
|
53
|
-
var SUPPORTED_OCR_LANGS = Object.fromEntries(
|
|
54
|
-
Object.entries(OCR_LANG_HASHES).map(([lang, sha256]) => [lang, { langPath: ocrLangPath(lang), sha256 }])
|
|
55
|
-
);
|
|
56
|
-
function getOcrLangSpec(lang) {
|
|
57
|
-
const tokens = lang.split("+");
|
|
58
|
-
const primary = tokens.find((t) => t !== DEFAULT_OCR_LANG && isSupportedOcrLang(t)) ?? tokens[0] ?? DEFAULT_OCR_LANG;
|
|
59
|
-
const active = isSupportedOcrLang(primary) ? primary : DEFAULT_OCR_LANG;
|
|
60
|
-
const sha256 = OCR_LANG_HASHES[active];
|
|
61
|
-
return {
|
|
62
|
-
langPath: ocrLangPath(active),
|
|
63
|
-
sha256
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/image_ocr.ts
|
|
68
|
-
var _ocrTimeoutMs = 12e3;
|
|
69
|
-
function setOcrTimeoutForTesting(ms) {
|
|
70
|
-
_ocrTimeoutMs = ms ?? 12e3;
|
|
71
|
-
}
|
|
72
|
-
function getActiveOcrLangs(lang) {
|
|
73
|
-
if (typeof lang === "string" && lang.trim()) {
|
|
74
|
-
return resolveOcrLangs(lang);
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const configured = loadConfig().image_shrink?.ocr_lang;
|
|
78
|
-
if (typeof configured === "string" && configured.trim()) {
|
|
79
|
-
return resolveOcrLangs(configured);
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
return [DEFAULT_OCR_LANG];
|
|
84
|
-
}
|
|
85
|
-
function resolveOcrLang(lang) {
|
|
86
|
-
return getActiveOcrLangs(lang).join("+");
|
|
87
|
-
}
|
|
88
|
-
var OCR_LANG_FILE = `${DEFAULT_OCR_LANG}.traineddata`;
|
|
89
|
-
var OCR_LANG_PATH = getOcrLangSpec("eng").langPath;
|
|
90
|
-
var OCR_LANG_SHA256 = getOcrLangSpec("eng").sha256;
|
|
91
|
-
function verifyOcrLangCache(lang) {
|
|
92
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
93
|
-
let anyAbsent = false;
|
|
94
|
-
for (const l of activeLangs) {
|
|
95
|
-
const spec = getOcrLangSpec(l);
|
|
96
|
-
const file = path.join(ocrCacheDir(), `${l}.traineddata`);
|
|
97
|
-
try {
|
|
98
|
-
if (!fs.existsSync(file)) {
|
|
99
|
-
anyAbsent = true;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const bytes = fs.readFileSync(file);
|
|
103
|
-
if (createHash("sha256").update(bytes).digest("hex") !== spec.sha256) {
|
|
104
|
-
return "mismatch";
|
|
105
|
-
}
|
|
106
|
-
} catch {
|
|
107
|
-
return "unreadable";
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return anyAbsent ? "absent" : "ok";
|
|
111
|
-
}
|
|
112
|
-
function quarantineOcrLangCache(lang) {
|
|
113
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
114
|
-
for (const l of activeLangs) {
|
|
115
|
-
const spec = getOcrLangSpec(l);
|
|
116
|
-
const file = path.join(ocrCacheDir(), `${l}.traineddata`);
|
|
117
|
-
try {
|
|
118
|
-
if (fs.existsSync(file)) {
|
|
119
|
-
const bytes = fs.readFileSync(file);
|
|
120
|
-
if (createHash("sha256").update(bytes).digest("hex") !== spec.sha256) {
|
|
121
|
-
fs.rmSync(file, { force: true });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch {
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
var _ocrIntegrityFailed = false;
|
|
129
|
-
function ocrIntegrityFailed() {
|
|
130
|
-
return _ocrIntegrityFailed;
|
|
131
|
-
}
|
|
132
|
-
function ocrBlockedOffline(lang) {
|
|
133
|
-
if (!loadConfig().network.offline) return false;
|
|
134
|
-
return verifyOcrLangCache(lang) === "absent";
|
|
135
|
-
}
|
|
136
|
-
function ocrCacheDir() {
|
|
137
|
-
return path.join(tokenGoatHome(), "ocr-cache");
|
|
138
|
-
}
|
|
139
|
-
function ensureOcrCacheDir() {
|
|
140
|
-
try {
|
|
141
|
-
ensureDirSync(ocrCacheDir());
|
|
142
|
-
} catch {
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
var _require = createRequire(import.meta.url);
|
|
146
|
-
var _tesseractEntryPath;
|
|
147
|
-
function resolveTesseractEntry() {
|
|
148
|
-
if (_tesseractEntryPath !== void 0) return _tesseractEntryPath;
|
|
149
|
-
try {
|
|
150
|
-
_tesseractEntryPath = _require.resolve("tesseract.js");
|
|
151
|
-
} catch {
|
|
152
|
-
_tesseractEntryPath = null;
|
|
153
|
-
}
|
|
154
|
-
return _tesseractEntryPath;
|
|
155
|
-
}
|
|
156
|
-
function isOcrEngineAvailable() {
|
|
157
|
-
return !_ocrUnavailableThisProcess && resolveTesseractEntry() !== null;
|
|
158
|
-
}
|
|
159
|
-
function setTesseractEntryForTesting(entryPath) {
|
|
160
|
-
_tesseractEntryPath = entryPath;
|
|
161
|
-
}
|
|
162
|
-
var _ocrUnavailableThisProcess = false;
|
|
163
|
-
function resetOcrStateForTesting() {
|
|
164
|
-
_ocrUnavailableThisProcess = false;
|
|
165
|
-
_ocrIntegrityFailed = false;
|
|
166
|
-
_tesseractEntryPath = void 0;
|
|
167
|
-
_ocrTimeoutMs = 12e3;
|
|
168
|
-
}
|
|
169
|
-
function buildChildScript(entryPath, cacheDir, lang) {
|
|
170
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
171
|
-
const activeLangString = activeLangs.join("+");
|
|
172
|
-
const spec = getOcrLangSpec(lang ?? activeLangString);
|
|
173
|
-
return [
|
|
174
|
-
`const { createWorker } = require(${JSON.stringify(entryPath)});`,
|
|
175
|
-
"const chunks = [];",
|
|
176
|
-
"process.stdin.on('data', (c) => chunks.push(c));",
|
|
177
|
-
"process.stdin.on('end', async () => {",
|
|
178
|
-
" try {",
|
|
179
|
-
" const buf = Buffer.concat(chunks);",
|
|
180
|
-
` const worker = await createWorker(${JSON.stringify(activeLangString)}, 1, { cachePath: ${JSON.stringify(cacheDir)}, langPath: ${JSON.stringify(spec.langPath)}, errorHandler: () => {} });`,
|
|
181
|
-
" const { data } = await worker.recognize(buf);",
|
|
182
|
-
" process.stdout.write(JSON.stringify({ text: data.text || '', confidence: data.confidence || 0 }));",
|
|
183
|
-
" await worker.terminate();",
|
|
184
|
-
" process.exit(0);",
|
|
185
|
-
" } catch (e) {",
|
|
186
|
-
" process.exit(1);",
|
|
187
|
-
" }",
|
|
188
|
-
"});"
|
|
189
|
-
].join("\n");
|
|
190
|
-
}
|
|
191
|
-
async function ocrImage(input, lang) {
|
|
192
|
-
if (_ocrUnavailableThisProcess) return null;
|
|
193
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
194
|
-
const entryPath = resolveTesseractEntry();
|
|
195
|
-
if (entryPath === null) return null;
|
|
196
|
-
if (ocrBlockedOffline(lang)) return null;
|
|
197
|
-
if (_ocrIntegrityFailed) return null;
|
|
198
|
-
if (verifyOcrLangCache(lang) === "mismatch") {
|
|
199
|
-
_ocrIntegrityFailed = true;
|
|
200
|
-
quarantineOcrLangCache(lang);
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
for (const l of activeLangs) {
|
|
204
|
-
if (l !== DEFAULT_OCR_LANG) {
|
|
205
|
-
const file = path.join(ocrCacheDir(), `${l}.traineddata`);
|
|
206
|
-
if (!fs.existsSync(file)) {
|
|
207
|
-
if (loadConfig().network.offline) return null;
|
|
208
|
-
try {
|
|
209
|
-
const res = await fetch(getOcrLangSpec(l).langPath + `/${l}.traineddata.gz`);
|
|
210
|
-
if (!res.ok) return null;
|
|
211
|
-
const gz = Buffer.from(await res.arrayBuffer());
|
|
212
|
-
const unzipped = (await import("node:zlib")).gunzipSync(gz);
|
|
213
|
-
if (createHash("sha256").update(unzipped).digest("hex") !== getOcrLangSpec(l).sha256) {
|
|
214
|
-
_ocrIntegrityFailed = true;
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
ensureOcrCacheDir();
|
|
218
|
-
fs.writeFileSync(file, unzipped);
|
|
219
|
-
} catch {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return new Promise((resolve) => {
|
|
226
|
-
let settled = false;
|
|
227
|
-
let child;
|
|
228
|
-
try {
|
|
229
|
-
ensureOcrCacheDir();
|
|
230
|
-
child = spawn(process.execPath, ["-e", buildChildScript(entryPath, ocrCacheDir(), lang)], {
|
|
231
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
232
|
-
});
|
|
233
|
-
} catch {
|
|
234
|
-
_ocrUnavailableThisProcess = true;
|
|
235
|
-
resolve(null);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const chunks = [];
|
|
239
|
-
const finish = (result, subprocessBroken) => {
|
|
240
|
-
if (settled) return;
|
|
241
|
-
settled = true;
|
|
242
|
-
clearTimeout(timer);
|
|
243
|
-
if (subprocessBroken) _ocrUnavailableThisProcess = true;
|
|
244
|
-
try {
|
|
245
|
-
child.kill();
|
|
246
|
-
} catch {
|
|
247
|
-
}
|
|
248
|
-
resolve(result);
|
|
249
|
-
};
|
|
250
|
-
const timer = setTimeout(() => finish(null, true), _ocrTimeoutMs);
|
|
251
|
-
child.stdout?.on("data", (c) => chunks.push(c));
|
|
252
|
-
child.on("error", () => finish(null, true));
|
|
253
|
-
child.on("close", (code) => {
|
|
254
|
-
if (code !== 0) {
|
|
255
|
-
finish(null, false);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
if (verifyOcrLangCache(lang) === "mismatch") {
|
|
259
|
-
_ocrIntegrityFailed = true;
|
|
260
|
-
quarantineOcrLangCache(lang);
|
|
261
|
-
finish(null, false);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
try {
|
|
265
|
-
const raw = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
266
|
-
const parsed = raw;
|
|
267
|
-
const text = typeof parsed.text === "string" ? parsed.text.trim() : "";
|
|
268
|
-
const confidence = typeof parsed.confidence === "number" ? parsed.confidence : 0;
|
|
269
|
-
finish({ text, confidence }, false);
|
|
270
|
-
} catch {
|
|
271
|
-
finish(null, false);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
try {
|
|
275
|
-
child.stdin?.end(input);
|
|
276
|
-
} catch {
|
|
277
|
-
finish(null, false);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
function isTextHeavy(result, minConfidence, minChars = 40) {
|
|
282
|
-
return result.confidence >= minConfidence && result.text.length >= minChars;
|
|
283
|
-
}
|
|
284
|
-
function formatOcrSummary(result, subject, originalBytes) {
|
|
285
|
-
const kb = Math.round(originalBytes / 1024);
|
|
286
|
-
const summary = `token-goat OCR'd ${subject} instead of shrinking it: text-heavy image detected (${Math.round(result.confidence)}% confidence), extracted ${result.text.length} chars of text from ${kb}kb of pixels.`;
|
|
287
|
-
return `${summary}
|
|
288
|
-
|
|
289
|
-
${fenceUntrustedOcrText(result.text)}`;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export {
|
|
293
|
-
SUPPORTED_OCR_LANGS,
|
|
294
|
-
getOcrLangSpec,
|
|
295
|
-
setOcrTimeoutForTesting,
|
|
296
|
-
getActiveOcrLangs,
|
|
297
|
-
resolveOcrLang,
|
|
298
|
-
OCR_LANG_FILE,
|
|
299
|
-
OCR_LANG_PATH,
|
|
300
|
-
OCR_LANG_SHA256,
|
|
301
|
-
verifyOcrLangCache,
|
|
302
|
-
quarantineOcrLangCache,
|
|
303
|
-
ocrIntegrityFailed,
|
|
304
|
-
ocrBlockedOffline,
|
|
305
|
-
isOcrEngineAvailable,
|
|
306
|
-
setTesseractEntryForTesting,
|
|
307
|
-
resetOcrStateForTesting,
|
|
308
|
-
buildChildScript,
|
|
309
|
-
ocrImage,
|
|
310
|
-
isTextHeavy,
|
|
311
|
-
formatOcrSummary
|
|
312
|
-
};
|