@clazic/kordoc 2.2.2 → 2.2.4
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-UPJWEES3.js → chunk-FRUOLYOA.js} +2 -2
- package/dist/{chunk-64QPUEYH.js → chunk-RY4EXD2W.js} +3 -3
- package/dist/cli.js +17 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +44 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -11
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{resolve-Z4DEPDUS.js → resolve-C5F2MXLL.js} +45 -11
- package/dist/resolve-C5F2MXLL.js.map +1 -0
- package/dist/{utils-TPAR37RJ.js → utils-HOTLMIQL.js} +2 -2
- package/dist/{watch-FEW5NWVC.js → watch-E2YLCDHY.js} +3 -3
- package/package.json +1 -1
- package/dist/resolve-Z4DEPDUS.js.map +0 -1
- /package/dist/{chunk-UPJWEES3.js.map → chunk-FRUOLYOA.js.map} +0 -0
- /package/dist/{chunk-64QPUEYH.js.map → chunk-RY4EXD2W.js.map} +0 -0
- /package/dist/{utils-TPAR37RJ.js.map → utils-HOTLMIQL.js.map} +0 -0
- /package/dist/{watch-FEW5NWVC.js.map → watch-E2YLCDHY.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -2014,11 +2014,14 @@ 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,
|
|
2017
|
+
import { writeFileSync, readFileSync, unlinkSync, mkdirSync } from "fs";
|
|
2018
2018
|
import { join } from "path";
|
|
2019
2019
|
import { tmpdir } from "os";
|
|
2020
2020
|
function getTempDir() {
|
|
2021
|
-
if (!_tempDir)
|
|
2021
|
+
if (!_tempDir) {
|
|
2022
|
+
_tempDir = join(process.cwd(), ".kordoc-tmp");
|
|
2023
|
+
mkdirSync(_tempDir, { recursive: true });
|
|
2024
|
+
}
|
|
2022
2025
|
return _tempDir;
|
|
2023
2026
|
}
|
|
2024
2027
|
function createCliOcrProvider(mode) {
|
|
@@ -2042,8 +2045,11 @@ function createCliOcrProvider(mode) {
|
|
|
2042
2045
|
};
|
|
2043
2046
|
}
|
|
2044
2047
|
function callCli(mode, imagePath) {
|
|
2048
|
+
if (mode === "codex") {
|
|
2049
|
+
return callCodexCli(imagePath);
|
|
2050
|
+
}
|
|
2045
2051
|
const args = buildCliArgs(mode, imagePath);
|
|
2046
|
-
const result = spawnSync(mode
|
|
2052
|
+
const result = spawnSync(mode, args, {
|
|
2047
2053
|
encoding: "utf-8",
|
|
2048
2054
|
timeout: 6e4,
|
|
2049
2055
|
maxBuffer: 10 * 1024 * 1024
|
|
@@ -2057,27 +2063,55 @@ function callCli(mode, imagePath) {
|
|
|
2057
2063
|
}
|
|
2058
2064
|
return result.stdout || "";
|
|
2059
2065
|
}
|
|
2066
|
+
function callCodexCli(imagePath) {
|
|
2067
|
+
const outPath = join(tmpdir(), `kordoc-codex-out-${Date.now()}.txt`);
|
|
2068
|
+
try {
|
|
2069
|
+
const args = ["exec", OCR_PROMPT, "--image", imagePath, "--output-last-message", outPath];
|
|
2070
|
+
const result = spawnSync("codex", args, {
|
|
2071
|
+
encoding: "utf-8",
|
|
2072
|
+
timeout: 18e4,
|
|
2073
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
2074
|
+
input: ""
|
|
2075
|
+
// stdin EOF 즉시 전달 (대화형 입력 차단)
|
|
2076
|
+
});
|
|
2077
|
+
if (result.error) {
|
|
2078
|
+
throw new Error(`codex CLI \uC2E4\uD589 \uC2E4\uD328: ${result.error.message}`);
|
|
2079
|
+
}
|
|
2080
|
+
if (result.status !== 0) {
|
|
2081
|
+
const errMsg = result.stderr?.trim() || `exit code ${result.status}`;
|
|
2082
|
+
throw new Error(`codex OCR \uC2E4\uD328: ${errMsg}`);
|
|
2083
|
+
}
|
|
2084
|
+
try {
|
|
2085
|
+
return readFileSync(outPath, "utf-8");
|
|
2086
|
+
} catch {
|
|
2087
|
+
return result.stdout || "";
|
|
2088
|
+
}
|
|
2089
|
+
} finally {
|
|
2090
|
+
try {
|
|
2091
|
+
unlinkSync(outPath);
|
|
2092
|
+
} catch {
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2060
2096
|
function buildCliArgs(mode, imagePath) {
|
|
2061
2097
|
const promptWithImage = `${OCR_PROMPT}
|
|
2062
2098
|
|
|
2063
2099
|
\uC774\uBBF8\uC9C0: @${imagePath}`;
|
|
2064
|
-
const promptOnly = OCR_PROMPT;
|
|
2065
2100
|
switch (mode) {
|
|
2066
2101
|
case "gemini":
|
|
2067
2102
|
return ["--prompt", promptWithImage, "--yolo"];
|
|
2068
2103
|
case "claude":
|
|
2069
2104
|
return ["--print", promptWithImage];
|
|
2070
|
-
case "codex":
|
|
2071
|
-
return ["exec", "--image", imagePath, promptOnly];
|
|
2072
2105
|
default:
|
|
2073
2106
|
throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 CLI: ${mode}`);
|
|
2074
2107
|
}
|
|
2075
2108
|
}
|
|
2076
2109
|
async function callOllamaApi(imagePath) {
|
|
2077
|
-
const { readFileSync } = await import("fs");
|
|
2078
|
-
const imageBase64 =
|
|
2079
|
-
const model = process.env.KORDOC_OLLAMA_MODEL || "
|
|
2110
|
+
const { readFileSync: readFileSync2 } = await import("fs");
|
|
2111
|
+
const imageBase64 = readFileSync2(imagePath).toString("base64");
|
|
2112
|
+
const model = process.env.KORDOC_OLLAMA_MODEL || "qwen3-vl:8b";
|
|
2080
2113
|
const host = process.env.KORDOC_OLLAMA_HOST || "http://localhost:11434";
|
|
2114
|
+
const timeoutMs = Number(process.env.KORDOC_OLLAMA_TIMEOUT) || 12e4;
|
|
2081
2115
|
const response = await fetch(`${host}/api/chat`, {
|
|
2082
2116
|
method: "POST",
|
|
2083
2117
|
headers: { "Content-Type": "application/json" },
|
|
@@ -2090,7 +2124,7 @@ async function callOllamaApi(imagePath) {
|
|
|
2090
2124
|
}],
|
|
2091
2125
|
stream: false
|
|
2092
2126
|
}),
|
|
2093
|
-
signal: AbortSignal.timeout(
|
|
2127
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
2094
2128
|
});
|
|
2095
2129
|
if (!response.ok) {
|
|
2096
2130
|
throw new Error(`Ollama API \uC624\uB958: ${response.status} ${response.statusText}`);
|
|
@@ -2402,7 +2436,7 @@ import JSZip2 from "jszip";
|
|
|
2402
2436
|
import { DOMParser } from "@xmldom/xmldom";
|
|
2403
2437
|
|
|
2404
2438
|
// src/utils.ts
|
|
2405
|
-
var VERSION = true ? "2.2.
|
|
2439
|
+
var VERSION = true ? "2.2.4" : "0.0.0-dev";
|
|
2406
2440
|
function toArrayBuffer(buf) {
|
|
2407
2441
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
2408
2442
|
return buf.buffer;
|