@clazic/kordoc 2.4.8 → 2.4.10

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/dist/index.js CHANGED
@@ -2059,6 +2059,12 @@ function createCliOcrProvider(mode) {
2059
2059
  }
2060
2060
  };
2061
2061
  }
2062
+ function checkForLimitError(output, mode) {
2063
+ const lower = output.toLowerCase();
2064
+ if (lower.includes("usage limit") || lower.includes("rate limit")) {
2065
+ throw new Error(`${mode} \uC0AC\uC6A9\uB7C9/\uC18D\uB3C4 \uC81C\uD55C: ${output.trim().slice(0, 200)}`);
2066
+ }
2067
+ }
2062
2068
  function callCli(mode, imagePath) {
2063
2069
  if (mode === "codex") {
2064
2070
  return callCodexCli(imagePath);
@@ -2079,7 +2085,9 @@ function callCli(mode, imagePath) {
2079
2085
  const errMsg = result.stderr?.trim() || `exit code ${result.status}`;
2080
2086
  throw new Error(`${mode} OCR \uC2E4\uD328: ${errMsg}`);
2081
2087
  }
2082
- return result.stdout || "";
2088
+ const output = result.stdout || "";
2089
+ checkForLimitError(output, mode);
2090
+ return output;
2083
2091
  }
2084
2092
  function callCodexCli(imagePath) {
2085
2093
  const outPath = join(tmpdir(), `kordoc-codex-out-${Date.now()}.txt`);
@@ -2102,11 +2110,14 @@ function callCodexCli(imagePath) {
2102
2110
  const errMsg = result.stderr?.trim() || `exit code ${result.status}`;
2103
2111
  throw new Error(`codex OCR \uC2E4\uD328: ${errMsg}`);
2104
2112
  }
2113
+ let text;
2105
2114
  try {
2106
- return readFileSync(outPath, "utf-8");
2115
+ text = readFileSync(outPath, "utf-8");
2107
2116
  } catch {
2108
- return result.stdout || "";
2117
+ text = result.stdout || "";
2109
2118
  }
2119
+ checkForLimitError(text, "codex");
2120
+ return text;
2110
2121
  } finally {
2111
2122
  try {
2112
2123
  unlinkSync(outPath);
@@ -2374,7 +2385,9 @@ ${fileRefs}`;
2374
2385
  const errMsg = result.stderr?.trim() || `exit code ${result.exitCode}`;
2375
2386
  throw new Error(`${mode} \uBC30\uCE58 OCR \uC2E4\uD328: ${errMsg}`);
2376
2387
  }
2377
- return result.stdout || "";
2388
+ const output = result.stdout || "";
2389
+ checkForLimitError2(output, mode);
2390
+ return output;
2378
2391
  }
2379
2392
  async function callBatchCodexCli(imagePaths) {
2380
2393
  const outPath = join2(tmpdir2(), `kordoc-codex-batch-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`);
@@ -2395,11 +2408,14 @@ async function callBatchCodexCli(imagePaths) {
2395
2408
  const errMsg = result.stderr?.trim() || `exit code ${result.exitCode}`;
2396
2409
  throw new Error(`codex \uBC30\uCE58 OCR \uC2E4\uD328: ${errMsg}`);
2397
2410
  }
2411
+ let text;
2398
2412
  try {
2399
- return readFileSync2(outPath, "utf-8");
2413
+ text = readFileSync2(outPath, "utf-8");
2400
2414
  } catch {
2401
- return result.stdout || "";
2415
+ text = result.stdout || "";
2402
2416
  }
2417
+ checkForLimitError2(text, "codex");
2418
+ return text;
2403
2419
  } finally {
2404
2420
  try {
2405
2421
  unlinkSync2(outPath);
@@ -2407,6 +2423,12 @@ async function callBatchCodexCli(imagePaths) {
2407
2423
  }
2408
2424
  }
2409
2425
  }
2426
+ function checkForLimitError2(output, mode) {
2427
+ const lower = output.toLowerCase();
2428
+ if (lower.includes("usage limit") || lower.includes("rate limit")) {
2429
+ throw new Error(`${mode} \uC0AC\uC6A9\uB7C9/\uC18D\uB3C4 \uC81C\uD55C: ${output.trim().slice(0, 200)}`);
2430
+ }
2431
+ }
2410
2432
  function stripCodeFence2(text) {
2411
2433
  const match = text.match(/^```(?:markdown|md)?\s*\n([\s\S]*?)\n```\s*$/m);
2412
2434
  return match ? match[1].trim() : text;
@@ -2834,7 +2856,7 @@ import JSZip2 from "jszip";
2834
2856
  import { DOMParser } from "@xmldom/xmldom";
2835
2857
 
2836
2858
  // src/utils.ts
2837
- var VERSION = true ? "2.4.8" : "0.0.0-dev";
2859
+ var VERSION = true ? "2.4.10" : "0.0.0-dev";
2838
2860
  function toArrayBuffer(buf) {
2839
2861
  if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
2840
2862
  return buf.buffer;