@taloswork/ose-shared 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/package.json +3 -3
  2. package/skills/document/SKILL.md +135 -219
  3. package/skills/document/art-directions/base.css +27 -2
  4. package/skills/document/art-directions/cinematic-depth.css +3 -1
  5. package/skills/document/art-directions/collage-paper.css +5 -1
  6. package/skills/document/art-directions/editorial-cut.css +5 -1
  7. package/skills/document/art-directions/geometric-pop.css +6 -0
  8. package/skills/document/art-directions/gradient-mesh.css +5 -1
  9. package/skills/document/art-directions/illustrated-doodle.css +5 -0
  10. package/skills/document/art-directions/luxury-ornament.css +4 -1
  11. package/skills/document/art-directions/maximalist-blocks.css +6 -0
  12. package/skills/document/art-directions/technical-grid.css +4 -0
  13. package/skills/document/assets/fonts/fonts.json +2 -2
  14. package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Bold.ttf +0 -0
  15. package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Regular.ttf +0 -0
  16. package/skills/document/assets/pdf-fonts/OFL.txt +93 -0
  17. package/skills/document/assets/pdf-fonts/README.md +35 -0
  18. package/skills/document/assets/tessdata/LICENSE-Apache-2.0.txt +202 -0
  19. package/skills/document/assets/tessdata/README.md +21 -0
  20. package/skills/document/assets/tessdata/chi_sim.traineddata.gz +0 -0
  21. package/skills/document/assets/tessdata/eng.traineddata.gz +0 -0
  22. package/skills/document/bin/deck-build.cjs +12563 -83
  23. package/skills/document/bin/deck-chart.cjs +771 -0
  24. package/skills/document/bin/deck-plan.cjs +12414 -0
  25. package/skills/document/bin/deck-qa.cjs +1075 -266
  26. package/skills/document/bin/deck-scenario.cjs +1363 -0
  27. package/skills/document/bin/deck-styles.cjs +1604 -0
  28. package/skills/document/bin/doc-convert.cjs +308 -292
  29. package/skills/document/bin/doc-fill.cjs +73264 -192
  30. package/skills/document/bin/doc-gen.cjs +2491 -312
  31. package/skills/document/bin/doc-run.cjs +162 -24
  32. package/skills/document/bin/doc-scan.cjs +13 -0
  33. package/skills/document/bin/doc-text.cjs +13 -0
  34. package/skills/document/bin/doc-validate.cjs +838 -68
  35. package/skills/document/bin/doc-xml.cjs +9 -5
  36. package/skills/document/bin/docx-annotate.cjs +95 -19
  37. package/skills/document/bin/docx-defaults.cjs +9907 -0
  38. package/skills/document/bin/fontkit.cjs +1 -0
  39. package/skills/document/bin/html2pptx.cjs +36622 -31394
  40. package/skills/document/bin/ocr-worker.cjs +1 -0
  41. package/skills/document/bin/ocr.cjs +131 -40
  42. package/skills/document/bin/pdf-form.cjs +682 -177
  43. package/skills/document/bin/pdf-images.cjs +13 -0
  44. package/skills/document/bin/pdf-ops.cjs +642 -199
  45. package/skills/document/bin/pdf-render.cjs +19 -3
  46. package/skills/document/bin/pdf-tables.cjs +13 -0
  47. package/skills/document/bin/pptx-clone.cjs +3 -3
  48. package/skills/document/bin/pptx-notes.cjs +10038 -0
  49. package/skills/document/bin/pptx-slide.cjs +3 -3
  50. package/skills/document/bin/pptx-tokenize.cjs +19 -4
  51. package/skills/document/bin/template-skin.cjs +10910 -0
  52. package/skills/document/bin/xlsx-query.cjs +192 -61
  53. package/skills/document/bin-reference.md +61 -33
  54. package/skills/document/catalog.json +33 -32
  55. package/skills/document/content-pipeline.md +179 -257
  56. package/skills/document/deck-design.md +378 -638
  57. package/skills/document/generated-visuals.md +99 -0
  58. package/skills/document/layouts/MAINTAINERS.md +33 -0
  59. package/skills/document/layouts/README.md +49 -36
  60. package/skills/document/layouts/big-stat.tpl +1 -1
  61. package/skills/document/layouts/capacity.json +1 -0
  62. package/skills/document/layouts/cards-3.tpl +1 -1
  63. package/skills/document/layouts/chart-full.tpl +1 -1
  64. package/skills/document/layouts/chart-kpi.tpl +1 -1
  65. package/skills/document/layouts/comparison.tpl +1 -1
  66. package/skills/document/layouts/data-table.tpl +1 -1
  67. package/skills/document/layouts/funnel.tpl +1 -1
  68. package/skills/document/layouts/gantt.tpl +1 -1
  69. package/skills/document/layouts/hub-flow.tpl +4 -0
  70. package/skills/document/layouts/icon-row.tpl +1 -1
  71. package/skills/document/layouts/image-grid.tpl +1 -1
  72. package/skills/document/layouts/matrix-2x2.tpl +1 -1
  73. package/skills/document/layouts/mock-qa.tpl +4 -0
  74. package/skills/document/layouts/profiles.json +2 -2
  75. package/skills/document/layouts/pyramid.tpl +1 -1
  76. package/skills/document/layouts/radar.tpl +1 -1
  77. package/skills/document/layouts/ring-progress.tpl +1 -1
  78. package/skills/document/layouts/slots.json +1 -1
  79. package/skills/document/layouts/steps-vertical.tpl +1 -1
  80. package/skills/document/layouts/steps.tpl +1 -1
  81. package/skills/document/layouts/three-kpi.tpl +1 -1
  82. package/skills/document/layouts/timeline.tpl +1 -1
  83. package/skills/document/layouts/toc-panel.tpl +2 -2
  84. package/skills/document/layouts/two-kpi.tpl +2 -2
  85. package/skills/document/layouts/versus.tpl +1 -1
  86. package/skills/document/motion/README.md +3 -2
  87. package/skills/document/office.md +3 -3
  88. package/skills/document/packs/README.md +1 -1
  89. package/skills/document/packs/board-brief/backdrop.html +2 -0
  90. package/skills/document/packs/board-brief/pack.css +2 -1
  91. package/skills/document/packs/mckinsey-photo/backdrop.html +2 -0
  92. package/skills/document/packs/mckinsey-photo/pack.css +2 -1
  93. package/skills/document/packs/press-room/backdrop.html +2 -0
  94. package/skills/document/packs/press-room/pack.css +2 -1
  95. package/skills/document/packs/prismatic-3d/backdrop.html +2 -0
  96. package/skills/document/packs/prismatic-3d/pack.css +4 -1
  97. package/skills/document/pdf.md +60 -43
  98. package/skills/document/rewrite.md +257 -309
  99. package/skills/document/scenarios.json +1307 -0
  100. package/skills/document/scenarios.schema.json +104 -0
  101. package/skills/document/styles/README.md +15 -25
  102. package/skills/document/styles/_backdrops/rimlight.html +3 -2
  103. package/skills/document/styles/_contract-defaults.css +31 -2
  104. package/skills/document/styles/_samples/_groups/biz-premium.webp +0 -0
  105. package/skills/document/styles/_samples/mckinsey.webp +0 -0
  106. package/skills/document/styles/anthropic/skin.css +6 -3
  107. package/skills/document/styles/apple/skin.css +4 -3
  108. package/skills/document/styles/bistro-warm/backdrop.html +2 -0
  109. package/skills/document/styles/bistro-warm/skin.css +4 -1
  110. package/skills/document/styles/black-gold/skin.css +6 -5
  111. package/skills/document/styles/bold-clash/backdrop.html +2 -0
  112. package/skills/document/styles/bold-clash/skin.css +2 -1
  113. package/skills/document/styles/branding/skin.css +4 -4
  114. package/skills/document/styles/campus-teal/backdrop.html +2 -0
  115. package/skills/document/styles/campus-teal/skin.css +2 -1
  116. package/skills/document/styles/cinereel/skin.css +7 -3
  117. package/skills/document/styles/clinic-care/backdrop.html +2 -0
  118. package/skills/document/styles/clinic-care/skin.css +2 -1
  119. package/skills/document/styles/cool/skin.css +6 -5
  120. package/skills/document/styles/dark-glass/backdrop.html +2 -0
  121. package/skills/document/styles/dark-glass/skin.css +2 -1
  122. package/skills/document/styles/gov-brief/backdrop.html +2 -0
  123. package/skills/document/styles/gov-brief/skin.css +2 -1
  124. package/skills/document/styles/grid-tech/backdrop.html +2 -0
  125. package/skills/document/styles/grid-tech/skin.css +2 -1
  126. package/skills/document/styles/hand-drawn/skin.css +3 -3
  127. package/skills/document/styles/ivory-gold/skin.css +7 -6
  128. package/skills/document/styles/legal-slate/backdrop.html +2 -0
  129. package/skills/document/styles/legal-slate/skin.css +2 -1
  130. package/skills/document/styles/magazine-ink/skin.css +4 -3
  131. package/skills/document/styles/mckinsey/backdrop.html +7 -5
  132. package/skills/document/styles/mckinsey/skin.css +2 -1
  133. package/skills/document/styles/memphis/backdrop.html +2 -0
  134. package/skills/document/styles/memphis/skin.css +2 -1
  135. package/skills/document/styles/mono/skin.css +6 -2
  136. package/skills/document/styles/neon-cyber/backdrop.html +2 -0
  137. package/skills/document/styles/neon-cyber/skin.css +2 -1
  138. package/skills/document/styles/olive-gold/skin.css +7 -6
  139. package/skills/document/styles/organic-earth/backdrop.html +2 -0
  140. package/skills/document/styles/organic-earth/skin.css +2 -1
  141. package/skills/document/styles/pastel-saas/backdrop.html +2 -0
  142. package/skills/document/styles/pastel-saas/skin.css +2 -1
  143. package/skills/document/styles/portfolio-noir/backdrop.html +2 -0
  144. package/skills/document/styles/portfolio-noir/skin.css +2 -1
  145. package/skills/document/styles/retro-press/backdrop.html +2 -0
  146. package/skills/document/styles/retro-press/skin.css +2 -1
  147. package/skills/document/styles/sport-arena/backdrop.html +2 -0
  148. package/skills/document/styles/sport-arena/skin.css +4 -1
  149. package/skills/document/styles/swiss-grid/skin.css +10 -5
  150. package/skills/document/styles/wedding-blush/backdrop.html +2 -0
  151. package/skills/document/styles/wedding-blush/skin.css +4 -1
  152. package/skills/document/theme-system.md +85 -77
  153. package/skills/document/themes/README.md +7 -5
  154. package/skills/document/vision.md +8 -5
  155. package/skills/document/xlsx.md +15 -25
  156. package/skills/grill-me/SKILL.md +6 -0
  157. package/skills/grill-me/agents/openai.yaml +5 -0
  158. package/skills/grilling/SKILL.md +28 -0
  159. package/skills/grilling/agents/openai.yaml +3 -0
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ process.noDeprecation = true;
2
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
3
4
  var __commonJS = (cb, mod) => function __require() {
4
5
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -132,7 +132,7 @@ var require_runtime = __commonJS({
132
132
  return { __await: arg };
133
133
  };
134
134
  function AsyncIterator(generator, PromiseImpl) {
135
- function invoke(method, arg, resolve, reject) {
135
+ function invoke(method, arg, resolve2, reject) {
136
136
  var record = tryCatch(generator[method], generator, arg);
137
137
  if (record.type === "throw") {
138
138
  reject(record.arg);
@@ -141,24 +141,24 @@ var require_runtime = __commonJS({
141
141
  var value = result.value;
142
142
  if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
143
143
  return PromiseImpl.resolve(value.__await).then(function(value2) {
144
- invoke("next", value2, resolve, reject);
144
+ invoke("next", value2, resolve2, reject);
145
145
  }, function(err) {
146
- invoke("throw", err, resolve, reject);
146
+ invoke("throw", err, resolve2, reject);
147
147
  });
148
148
  }
149
149
  return PromiseImpl.resolve(value).then(function(unwrapped) {
150
150
  result.value = unwrapped;
151
- resolve(result);
151
+ resolve2(result);
152
152
  }, function(error) {
153
- return invoke("throw", error, resolve, reject);
153
+ return invoke("throw", error, resolve2, reject);
154
154
  });
155
155
  }
156
156
  }
157
157
  var previousPromise;
158
158
  function enqueue(method, arg) {
159
159
  function callInvokeWithMethodAndArg() {
160
- return new PromiseImpl(function(resolve, reject) {
161
- invoke(method, arg, resolve, reject);
160
+ return new PromiseImpl(function(resolve2, reject) {
161
+ invoke(method, arg, resolve2, reject);
162
162
  });
163
163
  }
164
164
  return previousPromise = // If enqueue has been called before, then we want to wait until
@@ -612,13 +612,13 @@ var require_createScheduler = __commonJS({
612
612
  }
613
613
  }
614
614
  };
615
- const queue = (action, payload) => new Promise((resolve, reject) => {
615
+ const queue = (action, payload) => new Promise((resolve2, reject) => {
616
616
  const job = createJob({ action, payload });
617
617
  jobQueue.push(async (w) => {
618
618
  jobQueue.shift();
619
619
  runningWorkers[w.id] = job;
620
620
  try {
621
- resolve(await w[action].apply(exports2, [...payload, job.id]));
621
+ resolve2(await w[action].apply(exports2, [...payload, job.id]));
622
622
  } catch (err) {
623
623
  reject(err);
624
624
  } finally {
@@ -6600,7 +6600,7 @@ var require_lib3 = __commonJS({
6600
6600
  let accum = [];
6601
6601
  let accumBytes = 0;
6602
6602
  let abort = false;
6603
- return new Body.Promise(function(resolve, reject) {
6603
+ return new Body.Promise(function(resolve2, reject) {
6604
6604
  let resTimeout;
6605
6605
  if (_this4.timeout) {
6606
6606
  resTimeout = setTimeout(function() {
@@ -6634,7 +6634,7 @@ var require_lib3 = __commonJS({
6634
6634
  }
6635
6635
  clearTimeout(resTimeout);
6636
6636
  try {
6637
- resolve(Buffer.concat(accum, accumBytes));
6637
+ resolve2(Buffer.concat(accum, accumBytes));
6638
6638
  } catch (err) {
6639
6639
  reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, "system", err));
6640
6640
  }
@@ -7309,7 +7309,7 @@ var require_lib3 = __commonJS({
7309
7309
  throw new Error("native promise missing, set fetch.Promise to your favorite alternative");
7310
7310
  }
7311
7311
  Body.Promise = fetch.Promise;
7312
- return new fetch.Promise(function(resolve, reject) {
7312
+ return new fetch.Promise(function(resolve2, reject) {
7313
7313
  const request = new Request(url, opts);
7314
7314
  const options = getNodeRequestOptions(request);
7315
7315
  const send = (options.protocol === "https:" ? https : http).request;
@@ -7442,7 +7442,7 @@ var require_lib3 = __commonJS({
7442
7442
  requestOpts.body = void 0;
7443
7443
  requestOpts.headers.delete("content-length");
7444
7444
  }
7445
- resolve(fetch(new Request(locationURL, requestOpts)));
7445
+ resolve2(fetch(new Request(locationURL, requestOpts)));
7446
7446
  finalize();
7447
7447
  return;
7448
7448
  }
@@ -7463,7 +7463,7 @@ var require_lib3 = __commonJS({
7463
7463
  const codings = headers.get("Content-Encoding");
7464
7464
  if (!request.compress || request.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
7465
7465
  response = new Response(body, response_options);
7466
- resolve(response);
7466
+ resolve2(response);
7467
7467
  return;
7468
7468
  }
7469
7469
  const zlibOptions = {
@@ -7473,7 +7473,7 @@ var require_lib3 = __commonJS({
7473
7473
  if (codings == "gzip" || codings == "x-gzip") {
7474
7474
  body = body.pipe(zlib.createGunzip(zlibOptions));
7475
7475
  response = new Response(body, response_options);
7476
- resolve(response);
7476
+ resolve2(response);
7477
7477
  return;
7478
7478
  }
7479
7479
  if (codings == "deflate" || codings == "x-deflate") {
@@ -7485,12 +7485,12 @@ var require_lib3 = __commonJS({
7485
7485
  body = body.pipe(zlib.createInflateRaw());
7486
7486
  }
7487
7487
  response = new Response(body, response_options);
7488
- resolve(response);
7488
+ resolve2(response);
7489
7489
  });
7490
7490
  raw.on("end", function() {
7491
7491
  if (!response) {
7492
7492
  response = new Response(body, response_options);
7493
- resolve(response);
7493
+ resolve2(response);
7494
7494
  }
7495
7495
  });
7496
7496
  return;
@@ -7498,11 +7498,11 @@ var require_lib3 = __commonJS({
7498
7498
  if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
7499
7499
  body = body.pipe(zlib.createBrotliDecompress());
7500
7500
  response = new Response(body, response_options);
7501
- resolve(response);
7501
+ resolve2(response);
7502
7502
  return;
7503
7503
  }
7504
7504
  response = new Response(body, response_options);
7505
- resolve(response);
7505
+ resolve2(response);
7506
7506
  });
7507
7507
  writeToStream(req, request);
7508
7508
  });
@@ -7662,8 +7662,8 @@ var require_createWorker = __commonJS({
7662
7662
  const lstmOnlyCore = [OEM.DEFAULT, OEM.LSTM_ONLY].includes(oem) && !options.legacyCore;
7663
7663
  let workerResReject;
7664
7664
  let workerResResolve;
7665
- const workerRes = new Promise((resolve, reject) => {
7666
- workerResResolve = resolve;
7665
+ const workerRes = new Promise((resolve2, reject) => {
7666
+ workerResResolve = resolve2;
7667
7667
  workerResReject = reject;
7668
7668
  });
7669
7669
  const workerError = (event) => {
@@ -7678,10 +7678,10 @@ var require_createWorker = __commonJS({
7678
7678
  const setReject = (promiseId, rej) => {
7679
7679
  rejects[promiseId] = rej;
7680
7680
  };
7681
- const startJob = ({ id: jobId, action, payload }) => new Promise((resolve, reject) => {
7681
+ const startJob = ({ id: jobId, action, payload }) => new Promise((resolve2, reject) => {
7682
7682
  log(`[${id}]: Start ${jobId}, action=${action}`);
7683
7683
  const promiseId = `${action}-${jobId}`;
7684
- setResolve(promiseId, resolve);
7684
+ setResolve(promiseId, resolve2);
7685
7685
  setReject(promiseId, reject);
7686
7686
  send(worker, {
7687
7687
  workerId: id,
@@ -8025,34 +8025,124 @@ var require_src = __commonJS({
8025
8025
 
8026
8026
  // apps/admin/data/skills.lib/document/bin-src/ocr.mjs
8027
8027
  var import_promises = require("node:fs/promises");
8028
+ var import_node_path3 = require("node:path");
8029
+
8030
+ // packages/core/dist/document/ocr.js
8031
+ var import_node_fs = require("node:fs");
8032
+ var import_node_path2 = require("node:path");
8033
+
8034
+ // packages/core/dist/fs/paths.js
8035
+ var import_node_os = require("node:os");
8028
8036
  var import_node_path = require("node:path");
8037
+ var TALOS_RESERVED_DIR_NAMES = {
8038
+ /** `<profilesRoot>/.bootstrap/` — pre-login installation configuration. */
8039
+ bootstrap: ".bootstrap",
8040
+ /** `bundled/.tmp/` — install staging and vacated installs awaiting cleanup. */
8041
+ installScratch: ".tmp",
8042
+ /** `bundled/.quarantine/` — integrity-failed bundles kept for post-mortem. */
8043
+ quarantine: ".quarantine",
8044
+ /** `data/ose/<id>/sessions/.locks/` — cross-process session ownership locks. */
8045
+ sessionLocks: ".locks"
8046
+ };
8047
+ var TALOS_BOOTSTRAP_DIR_NAME = TALOS_RESERVED_DIR_NAMES.bootstrap;
8048
+ function getTalosOsCacheDir() {
8049
+ if (process.platform === "darwin")
8050
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), "Library", "Caches", "Talos");
8051
+ if (process.platform === "win32") {
8052
+ const local = process.env.LOCALAPPDATA?.trim();
8053
+ return (0, import_node_path.join)(local ? local : (0, import_node_path.join)((0, import_node_os.homedir)(), "AppData", "Local"), "Talos", "Cache");
8054
+ }
8055
+ const xdg = process.env.XDG_CACHE_HOME?.trim();
8056
+ return (0, import_node_path.join)(xdg ? xdg : (0, import_node_path.join)((0, import_node_os.homedir)(), ".cache"), "talos");
8057
+ }
8029
8058
 
8030
8059
  // packages/core/dist/document/ocr.js
8031
- var LANG_RE = /^[a-z]{3}(\+[a-z]{3})*$/;
8060
+ var LANG_RE = /^[a-z]{3}(_[a-z]+)*(\+[a-z]{3}(_[a-z]+)*)*$/;
8061
+ function isValidOcrLang(lang) {
8062
+ return LANG_RE.test(lang);
8063
+ }
8064
+ function defaultOcrCachePath() {
8065
+ return (0, import_node_path2.join)(getTalosOsCacheDir(), "tessdata");
8066
+ }
8067
+ var CJK = "[\\u2e80-\\u2eff\\u3000-\\u303f\\u3040-\\u30ff\\u3100-\\u312f\\u31a0-\\u31ff\\u3200-\\u33ff\\u3400-\\u4dbf\\u4e00-\\u9fff\\uf900-\\ufaff\\ufe30-\\ufe4f\\uff00-\\uffef]";
8068
+ var CJK_GAP = new RegExp(`(${CJK})[ \\t]+(?=${CJK})`, "g");
8069
+ function tidyCjkSpacing(text) {
8070
+ return text.replace(CJK_GAP, "$1");
8071
+ }
8072
+ var UNSPACED_LANG = /^(chi_|jpn)/;
8073
+ var oneLine = (e) => String(e instanceof Error ? e.message : e).replace(/^Error:\s*/, "").replace(/\s+/g, " ").trim();
8032
8074
  async function ocrImage(image, opts = {}) {
8033
8075
  if (!image || image.length === 0)
8034
8076
  throw new Error("empty image");
8035
8077
  const lang = opts.lang ?? "eng";
8036
- if (!LANG_RE.test(lang))
8037
- throw new Error(`invalid lang "${lang}" (expected e.g. "eng" or "eng+deu")`);
8078
+ if (!isValidOcrLang(lang))
8079
+ throw new Error(`invalid lang "${lang}" (expected e.g. "eng", "chi_sim" or "chi_sim+eng")`);
8080
+ const langs = lang.split("+");
8081
+ const cachePath = opts.cachePath || defaultOcrCachePath();
8082
+ let langPath = opts.langPath;
8083
+ let cacheMethod;
8084
+ let notBundled = langs;
8085
+ if (!langPath && opts.bundledLangPath) {
8086
+ const bundledDir = opts.bundledLangPath;
8087
+ const packOf = (l) => (0, import_node_path2.join)(bundledDir, `${l}.traineddata.gz`);
8088
+ notBundled = langs.filter((l) => !(0, import_node_fs.existsSync)(packOf(l)));
8089
+ if (notBundled.length === 0) {
8090
+ langPath = bundledDir;
8091
+ cacheMethod = "none";
8092
+ } else {
8093
+ try {
8094
+ (0, import_node_fs.mkdirSync)(cachePath, { recursive: true });
8095
+ for (const l of langs) {
8096
+ const cached = (0, import_node_path2.join)(cachePath, `${l}.traineddata`);
8097
+ if (!notBundled.includes(l) && !(0, import_node_fs.existsSync)(cached))
8098
+ (0, import_node_fs.copyFileSync)(packOf(l), cached);
8099
+ }
8100
+ } catch {
8101
+ }
8102
+ }
8103
+ }
8104
+ if (cacheMethod !== "none") {
8105
+ try {
8106
+ (0, import_node_fs.mkdirSync)(cachePath, { recursive: true });
8107
+ } catch {
8108
+ }
8109
+ }
8038
8110
  const mod = await Promise.resolve().then(() => __toESM(require_src(), 1));
8039
- const recognize = mod.recognize ?? mod.default?.recognize;
8040
- if (typeof recognize !== "function")
8041
- throw new Error("tesseract.js is unavailable (recognize not found)");
8042
- let result;
8111
+ const createWorker = mod.createWorker ?? mod.default?.createWorker;
8112
+ if (typeof createWorker !== "function")
8113
+ throw new Error("tesseract.js is unavailable (createWorker not found)");
8114
+ let fail;
8115
+ const failed = new Promise((_, reject) => {
8116
+ fail = reject;
8117
+ });
8118
+ failed.catch(() => void 0);
8119
+ let worker;
8043
8120
  try {
8044
- result = await recognize(Buffer.from(image), lang, {
8045
- ...opts.langPath ? { langPath: opts.langPath } : {},
8046
- ...opts.cachePath ? { cachePath: opts.cachePath } : {},
8047
- ...opts.workerPath ? { workerPath: opts.workerPath } : {}
8048
- });
8121
+ worker = await Promise.race([
8122
+ createWorker(lang, 1, {
8123
+ cachePath,
8124
+ ...langPath ? { langPath } : {},
8125
+ ...cacheMethod ? { cacheMethod } : {},
8126
+ ...opts.workerPath ? { workerPath: opts.workerPath } : {},
8127
+ errorHandler: (e) => fail(new Error(oneLine(e)))
8128
+ }),
8129
+ failed
8130
+ ]);
8131
+ if (langs.some((l) => UNSPACED_LANG.test(l)))
8132
+ await worker.setParameters({ preserve_interword_spaces: "1" });
8133
+ const result = await Promise.race([worker.recognize(Buffer.from(image)), failed]);
8134
+ return { text: tidyCjkSpacing((result.data.text ?? "").trim()), confidence: result.data.confidence ?? 0 };
8049
8135
  } catch (e) {
8050
- throw new Error(`OCR failed (language data unavailable offline?): ${e.message}`);
8136
+ const msg = oneLine(e);
8137
+ const which = notBundled.length && !langPath ? ` for ${notBundled.join("+")} (not bundled; downloaded on first use, needs network)` : "";
8138
+ throw new Error(worker ? `OCR failed: ${msg}` : `OCR failed: could not load language data${which}: ${msg}`);
8139
+ } finally {
8140
+ await worker?.terminate().catch(() => void 0);
8051
8141
  }
8052
- return { text: (result.data.text ?? "").trim(), confidence: result.data.confidence ?? 0 };
8053
8142
  }
8054
8143
 
8055
8144
  // apps/admin/data/skills.lib/document/bin-src/ocr.mjs
8145
+ process.noDeprecation = true;
8056
8146
  function die(msg, code = 1) {
8057
8147
  process.stderr.write(`ocr: ${msg}
8058
8148
  `);
@@ -8062,15 +8152,16 @@ var IMG = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".bmp", ".pbm", ".we
8062
8152
  async function main() {
8063
8153
  const [file, lang] = process.argv.slice(2);
8064
8154
  if (!file) die("usage: ocr <image.png|jpg> [lang]", 64);
8065
- const ext = (0, import_node_path.extname)(file).toLowerCase();
8155
+ const ext = (0, import_node_path3.extname)(file).toLowerCase();
8066
8156
  if (!IMG.has(ext)) die(`expected an image (${[...IMG].join("/")}); for PDFs render a page first, then OCR`, 64);
8067
8157
  const bytes = new Uint8Array(await (0, import_promises.readFile)(file).catch((e) => die(`cannot read ${file}: ${e.message}`)));
8068
8158
  const cachePath = process.env.TALOS_TESSDATA || void 0;
8069
8159
  const langPath = process.env.TALOS_TESSDATA_LANGPATH || void 0;
8070
- const workerPath = (0, import_node_path.join)(__dirname, "ocr-worker.cjs");
8160
+ const workerPath = (0, import_node_path3.join)(__dirname, "ocr-worker.cjs");
8161
+ const bundledLangPath = (0, import_node_path3.join)(__dirname, "..", "assets", "tessdata");
8071
8162
  let result;
8072
8163
  try {
8073
- result = await ocrImage(bytes, { lang: lang || "eng", cachePath, langPath, workerPath });
8164
+ result = await ocrImage(bytes, { lang: lang || "eng", cachePath, langPath, bundledLangPath, workerPath });
8074
8165
  } catch (e) {
8075
8166
  die(e.message);
8076
8167
  }