@clazic/kordoc 2.2.1 → 2.2.3
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/{chunk-3NF22UFF.js → chunk-NND6AJ7Y.js} +4 -4
- package/dist/{chunk-7MXQWWUW.js → chunk-Z24TFFSO.js} +2 -2
- package/dist/cli.js +17 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +38 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -15
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{provider-XVKP5OGI.js → provider-EPHXUWRL.js} +2 -8
- package/dist/{provider-XVKP5OGI.js.map → provider-EPHXUWRL.js.map} +1 -1
- package/dist/{resolve-Z4DEPDUS.js → resolve-H4SNHDDT.js} +38 -8
- package/dist/resolve-H4SNHDDT.js.map +1 -0
- package/dist/{utils-I4UIMOH7.js → utils-Q3MHKY3T.js} +2 -2
- package/dist/{watch-XPLMUIZB.js → watch-RVLVNLCX.js} +3 -3
- package/package.json +2 -1
- package/dist/resolve-Z4DEPDUS.js.map +0 -1
- /package/dist/{chunk-3NF22UFF.js.map → chunk-NND6AJ7Y.js.map} +0 -0
- /package/dist/{chunk-7MXQWWUW.js.map → chunk-Z24TFFSO.js.map} +0 -0
- /package/dist/{utils-I4UIMOH7.js.map → utils-Q3MHKY3T.js.map} +0 -0
- /package/dist/{watch-XPLMUIZB.js.map → watch-RVLVNLCX.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -2014,7 +2014,7 @@ var init_auto_detect = __esm({
|
|
|
2014
2014
|
|
|
2015
2015
|
// src/ocr/cli-provider.ts
|
|
2016
2016
|
import { spawnSync } from "child_process";
|
|
2017
|
-
import { writeFileSync, unlinkSync, mkdtempSync } from "fs";
|
|
2017
|
+
import { writeFileSync, readFileSync, unlinkSync, mkdtempSync } from "fs";
|
|
2018
2018
|
import { join } from "path";
|
|
2019
2019
|
import { tmpdir } from "os";
|
|
2020
2020
|
function getTempDir() {
|
|
@@ -2042,8 +2042,11 @@ function createCliOcrProvider(mode) {
|
|
|
2042
2042
|
};
|
|
2043
2043
|
}
|
|
2044
2044
|
function callCli(mode, imagePath) {
|
|
2045
|
+
if (mode === "codex") {
|
|
2046
|
+
return callCodexCli(imagePath);
|
|
2047
|
+
}
|
|
2045
2048
|
const args = buildCliArgs(mode, imagePath);
|
|
2046
|
-
const result = spawnSync(mode
|
|
2049
|
+
const result = spawnSync(mode, args, {
|
|
2047
2050
|
encoding: "utf-8",
|
|
2048
2051
|
timeout: 6e4,
|
|
2049
2052
|
maxBuffer: 10 * 1024 * 1024
|
|
@@ -2057,25 +2060,52 @@ function callCli(mode, imagePath) {
|
|
|
2057
2060
|
}
|
|
2058
2061
|
return result.stdout || "";
|
|
2059
2062
|
}
|
|
2063
|
+
function callCodexCli(imagePath) {
|
|
2064
|
+
const outPath = join(getTempDir(), `codex-out-${Date.now()}.txt`);
|
|
2065
|
+
try {
|
|
2066
|
+
const args = ["exec", OCR_PROMPT, "--image", imagePath, "--output-last-message", outPath];
|
|
2067
|
+
const result = spawnSync("codex", args, {
|
|
2068
|
+
encoding: "utf-8",
|
|
2069
|
+
timeout: 9e4,
|
|
2070
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
2071
|
+
input: ""
|
|
2072
|
+
// stdin EOF 즉시 전달 (대화형 입력 차단)
|
|
2073
|
+
});
|
|
2074
|
+
if (result.error) {
|
|
2075
|
+
throw new Error(`codex CLI \uC2E4\uD589 \uC2E4\uD328: ${result.error.message}`);
|
|
2076
|
+
}
|
|
2077
|
+
if (result.status !== 0) {
|
|
2078
|
+
const errMsg = result.stderr?.trim() || `exit code ${result.status}`;
|
|
2079
|
+
throw new Error(`codex OCR \uC2E4\uD328: ${errMsg}`);
|
|
2080
|
+
}
|
|
2081
|
+
try {
|
|
2082
|
+
return readFileSync(outPath, "utf-8");
|
|
2083
|
+
} catch {
|
|
2084
|
+
return result.stdout || "";
|
|
2085
|
+
}
|
|
2086
|
+
} finally {
|
|
2087
|
+
try {
|
|
2088
|
+
unlinkSync(outPath);
|
|
2089
|
+
} catch {
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2060
2093
|
function buildCliArgs(mode, imagePath) {
|
|
2061
2094
|
const promptWithImage = `${OCR_PROMPT}
|
|
2062
2095
|
|
|
2063
2096
|
\uC774\uBBF8\uC9C0: @${imagePath}`;
|
|
2064
|
-
const promptOnly = OCR_PROMPT;
|
|
2065
2097
|
switch (mode) {
|
|
2066
2098
|
case "gemini":
|
|
2067
2099
|
return ["--prompt", promptWithImage, "--yolo"];
|
|
2068
2100
|
case "claude":
|
|
2069
2101
|
return ["--print", promptWithImage];
|
|
2070
|
-
case "codex":
|
|
2071
|
-
return ["exec", "--image", imagePath, promptOnly];
|
|
2072
2102
|
default:
|
|
2073
2103
|
throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 CLI: ${mode}`);
|
|
2074
2104
|
}
|
|
2075
2105
|
}
|
|
2076
2106
|
async function callOllamaApi(imagePath) {
|
|
2077
|
-
const { readFileSync } = await import("fs");
|
|
2078
|
-
const imageBase64 =
|
|
2107
|
+
const { readFileSync: readFileSync2 } = await import("fs");
|
|
2108
|
+
const imageBase64 = readFileSync2(imagePath).toString("base64");
|
|
2079
2109
|
const model = process.env.KORDOC_OLLAMA_MODEL || "gemma4:27b";
|
|
2080
2110
|
const host = process.env.KORDOC_OLLAMA_HOST || "http://localhost:11434";
|
|
2081
2111
|
const response = await fetch(`${host}/api/chat`, {
|
|
@@ -2338,13 +2368,7 @@ async function ocrPages(doc, provider, pageFilter, effectivePageCount, warnings)
|
|
|
2338
2368
|
return blocks;
|
|
2339
2369
|
}
|
|
2340
2370
|
async function renderPageToPng(page) {
|
|
2341
|
-
|
|
2342
|
-
try {
|
|
2343
|
-
const canvasModule = await import("canvas");
|
|
2344
|
-
createCanvas = canvasModule.createCanvas;
|
|
2345
|
-
} catch {
|
|
2346
|
-
throw new Error("OCR\uC744 \uC0AC\uC6A9\uD558\uB824\uBA74 'canvas' \uD328\uD0A4\uC9C0\uB97C \uC124\uCE58\uD558\uC138\uC694: npm install canvas");
|
|
2347
|
-
}
|
|
2371
|
+
const { createCanvas } = await import("@napi-rs/canvas");
|
|
2348
2372
|
const scale = 2;
|
|
2349
2373
|
const viewport = page.getViewport({ scale });
|
|
2350
2374
|
const canvas = createCanvas(Math.floor(viewport.width), Math.floor(viewport.height));
|
|
@@ -2408,7 +2432,7 @@ import JSZip2 from "jszip";
|
|
|
2408
2432
|
import { DOMParser } from "@xmldom/xmldom";
|
|
2409
2433
|
|
|
2410
2434
|
// src/utils.ts
|
|
2411
|
-
var VERSION = true ? "2.2.
|
|
2435
|
+
var VERSION = true ? "2.2.3" : "0.0.0-dev";
|
|
2412
2436
|
function toArrayBuffer(buf) {
|
|
2413
2437
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
2414
2438
|
return buf.buffer;
|