kordoc parse-worker ๋ ํ๋ก์ธ์ค๋ฅผ ๋์ ๋ ์ฑ stdin ์ JSON ํ ์ค๋ง๋ค stdout ์ JSON ํ ์ค๋ก ๋ตํฉ๋๋ค(NDJSON, UTF-8).
ํ์ผ๋ง๋ค node ๋ฅผ ์๋ก ๋์ฐ์ง ์์ผ๋ฏ๋ก ์์ง ์ด๊ธฐํ ๋น์ฉ์ด ํ ๋ฒ๋ง ๋ญ๋๋ค.
JavaยทPython SDK(sdk/java, sdk/python)๋ protocol 2 ๋ฅผ ์๋๋ค.
| ๋ฒ์ | ์คํ | ์ฉ๋ |
|---|---|---|
| 1 | kordoc parse-worker (๊ธฐ๋ณธ) |
์ข ์ ๊ณ์ฝ. ์์ฒญยท์๋ตยท๋์์ ๋ฐ๊พธ์ง ์์ต๋๋ค |
| 2 | kordoc parse-worker --protocol 2 |
ParseOptions ์ ๋ฌ, ์ด๋ฏธ์ง ํ์ผ ์ ์ก, ์ค๋ฅ code, ์
์ถ๋ ฅ ์ํ |
์ง์ํ์ง ์๋ ๋ฒ์ ์ ์ฃผ๋ฉด ready ์ค ์์ด stderr ์ ์ฌ์ ๋ฅผ ์ฐ๊ณ ์ข ๋ฃ ์ฝ๋ 2 ๋ก ๋๋ฉ๋๋ค.
{"ready":true,"version":"4.19.2","protocol":2,"capabilities":["parse","options","transport.images.inline","transport.images.files"]}ํธ์คํธ๋ protocol ๊ณผ ํ์ํ capabilities ๋ฅผ ํ์ธํฉ๋๋ค. ๋ง์ง ์์ผ๋ฉด ๋ค๋ฅธ ์คํ ๋ฐฉ์์ผ๋ก ๋์ฒดํ์ง ๋ง๊ณ ์ค๋ฅ๋ก ๋๋ด์ผ ํฉ๋๋ค.
ready ๋ ์์ฒญ์ ๋ฐ์ ์ ์๋ค๋ ๋ป์ผ ๋ฟ, ์๋ฐ์
์ด ๋๋ฌ๋ค๋ ๋ป์ ์๋๋๋ค.
{"id":1,"cmd":"parse","file":"/abs/๋ฌธ์.hwpx","options":{"tableFormat":"gfm","ocr":false},"transport":{"images":"inline"}}
{"cmd":"quit"}| ํ๋ | ํ์ | ์ค๋ช |
|---|---|---|
id |
O | ์์ ์์ ํ ์ ์. ์์ปค ์๋ช
๋์ ๋ค์ ์ฐ๋ฉด DUPLICATE_ID |
cmd |
O | "parse" ๋๋ "quit" |
file |
O | ์ ๋ ฅ ํ์ผ์ ์ ๋ ๊ฒฝ๋ก |
options |
์๋ ํ์ฉ ๋ชฉ๋ก์ ParseOptions |
|
transport |
์ ํ ํค images("inline"ยท"files"), assetsDir(์ ๋ ๊ฒฝ๋ก), result("markdown"ยท"blocks") |
์์ฒญ์ ํ ๋ฒ์ ํ๋์ฉ ์์๋๋ก ์ฒ๋ฆฌํฉ๋๋ค. ๋์์ ์ฒ๋ฆฌํ๋ ค๋ฉด ์์ปค๋ฅผ ์ฌ๋ฌ ๊ฐ ๋์๋๋ค.
{"cmd":"quit"} ์ด๋ stdin EOF ๋ฅผ ๋ฐ์ผ๋ฉด ๋ง์ง๋ง ์๋ต๊น์ง ๋ค ์ด ๋ค ์ข
๋ฃ ์ฝ๋ 0 ์ผ๋ก ๋๋ฉ๋๋ค.
stdout ์ด ๋ซํ๋ฉด(EPIPE) ๋จ์ ์์ฒญ์ ๋ฒ๋ฆฌ๊ณ , stdin EOF ๋ฅผ ๊ธฐ๋ค๋ฆฌ์ง ์์ ์ฑ ์ข
๋ฃ ์ฝ๋ 0 ์ผ๋ก ๋๋ฉ๋๋ค.
์์ปค๋ stdout ์ด ๋ซํ ๊ฒ์ ๋ค์ ์๋ต์ ์ธ ๋ ์์์ฑ๋๋ค. ๊ทธ ๋ฐ์ ์ฐ๊ธฐ ์ค๋ฅ๋ 0 ์ด ์๋ ์ฝ๋๋ก ๋๋ฉ๋๋ค.
| ๋ฌถ์ | ํค |
|---|---|
| ํยท๊ตฌ์กฐ | tableFormat("gfm"), htmlTables, htmlCellLinks, layoutTables("visual"ยท"keep"), classifyTables, tables |
| ํ ์คํธยท์์ | plain, scriptTags, removeHeaderFooter, dedupeRunningHeaders |
| ๋น ๋ด์ฉยท์ ๋ ฅ๋ | keepTrailingEmptyCols, keepEmptyParagraphs, includeFieldPlaceholders |
| ๋ฒ์ยท์ด๋ฏธ์ง | pages(๋ฌธ์์ด ๋๋ ์์ ์ ์ ๋ฐฐ์ด), images, inlineImages, qrCodes, charts, imageFormat("png"ยท"webp"), imagePlacement("page-end"ยท"flow"), dropBlankImages |
| OCRยท์ํธ | ocr(trueยทfalseยท"force"), ocrLines(trueยทfalseยท"all"), ocrLineCandidates(0ocrLines ์ ํจ๊ป), ocrChars(trueยทfalse ๋๋ 0ocrLines ์ ํจ๊ป), ocrDet("mobile"ยท"server"ยท"medium"ยท{path, sha256}), ocrDetLongSide(32~4096 ์ ์), ocrRec("handwriting"ยท"auto"ยท"printed"ยท{path, sha256}), ocrRecDict({path, sha256}), pageImages(trueยทfalseยท"png"ยท"webp"), formulaOcr, password |
- ํค๋ฅผ ๋นผ๋ฉด ์์ง ๊ธฐ๋ณธ๊ฐ์
๋๋ค.
false๋ฅผ ์ฃผ๋ฉด ์ค์ ๋กfalse๋ฅผ ๋๊น๋๋ค(์:ocr: false๋ OCR ๋). - ๋ชฉ๋ก์ ์๋ ํค, ์๋ชป๋ ํ์
,
htmlTables์tableFormat๋์ ์ง์ ์INVALID_OPTIONS์ ๋๋ค. - ํจ์ ๊ฐ(
ocrํ๋ก๋ฐ์ด๋,onProgress)์ ๋ฐ์ง ์์ต๋๋ค.filePath๋ ์์ปค๊ฐfile๋ก ์ ํ๋ฉฐ ์์ฒญ์ผ๋ก ๋ฐ๊ฟ ์ ์์ต๋๋ค. {path, sha256}์path๋ ์ ๋ ๊ฒฝ๋ก,sha256์ 16์ง 64์์ ๋๋ค. ๋ค๋ฅธ ํคยท์๋ ๊ฒฝ๋กยทURL ์INVALID_OPTIONS์ ๋๋ค. ํ์ผ์ด ์๊ฑฐ๋ SHA-256 ์ด ๋ค๋ฅธ ๊ฒ์ ํ์ฑ ๋ ์๋ฆฝ๋๋ค(์ด๋ฏธ์ง๋success: false, PDF ๋OCR_FAILED๊ฒฝ๊ณ ).- protocol 1 ์
ocr: "off" | "auto"๋ฌธ์์ด์ protocol 2 ์์ ์ฐ์ง ์์ต๋๋ค.
{"id":1,"rss":123456789,"result":{"success":true,"fileType":"hwpx","markdown":"โฆ","blocks":[โฆ]}}
{"id":2,"rss":123456789,"result":{"success":false,"fileType":"unknown","error":"โฆ","code":"FILE_NOT_FOUND"}}
{"id":3,"error":{"code":"INVALID_OPTIONS","message":"options: Unrecognized key(s) in object: 'filePath'"}}transport.result๋ฅผ ์๋ตํ๋ฉดresult๋kordoc ๋ฌธ์ --format json๊ณผ ๊ฐ์ParseResult์ ๋๋ค.transport.result์"markdown"์ ์ง์ ํ๋ฉด ์ฑ๊ณต ์๋ต์result์success,fileType,markdown,warnings๋ง ๋ด์ต๋๋ค."blocks"๋ ์ฌ๊ธฐ์blocks๋ฅผ ์ถ๊ฐํฉ๋๋ค. ๊ฒฝ๊ณ ๊ฐ ์์ผ๋ฉดwarnings๋ ๋น ๋ฐฐ์ด์ ๋๋ค.- ์์ปค๋ ํ๋๋ฅผ ๊ณ ๋ฅธ ๋ค ์๋ต ์ค ์ํ์ ์ ์ฉํฉ๋๋ค. ํ์ฑ ์คํจ๋ ๋ชจ๋ ๋ชจ๋์์ ๊ธฐ์กด
success: false๊ฒฐ๊ณผ๋ก ๋ตํฉ๋๋ค.transport.result์transport.images: "files"๋ฅผ ํจ๊ป ์ง์ ํ๋ฉดINVALID_REQUEST๋ก ๋ตํฉ๋๋ค. error๋ ์์ฒญ์ด๋ ์ ์ก์ด ์๋ชป๋ ๊ฒฝ์ฐ์ ๋๋ค. ์์ฒญ์ ์ฌ๋ฐ๋ฅธid๊ฐ ์์ผ๋ฉด ํจ๊ป ๋๋ ค์ค๋๋ค.rss๋ ์๋ต ์ง์ ์ ์์ปค RSS(๋ฐ์ดํธ)์ ๋๋ค. ์ฒ๋ฆฌ ์ค ์ต๋๊ฐ์ด ์๋๋๋ค. ํธ์คํธ๊ฐ ์์ปค ๊ต์ฒด ์์ ์ ์ ํ๋ ๋ฐ ์๋๋ค.
| error.code | ๋ป |
|---|---|
INVALID_JSON |
JSON ์ด ์๋ ์ค(NaNยทInfinity ํฌํจ). id ์์ด ๋ตํฉ๋๋ค |
INVALID_REQUEST |
๊ฐ์ฒด๊ฐ ์๋, idยทcmdยทfileยทtransport ๊ฐ ์๋ชป๋จ, ๋ชจ๋ฅด๋ ์ต์์ ํ๋ |
INVALID_OPTIONS |
options ํ์ฉ ๋ชฉ๋กยทํ์
์๋ฐ, ํจ๊ป ์ธ ์ ์๋ ์ต์
|
UNSUPPORTED_COMMAND |
๋ชจ๋ฅด๋ cmd |
DUPLICATE_ID |
์ด๋ฏธ ์ด id |
REQUEST_TOO_LARGE |
์์ฒญ ์ค์ด ์ํ์ ๋์(๊ธฐ๋ณธ 8MiB โ lint_blocks ๊ฐ ๋ฌธ์ ๊ธ์ ์ฃ๋๋ค, --max-request-bytes). id ์์ด ๋ตํฉ๋๋ค |
RESPONSE_TOO_LARGE |
์๋ต ์ค์ด ์ํ์ ๋์(๊ธฐ๋ณธ 256MiB, --max-response-bytes). ์๋ฆฐ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ด์ง ์์ต๋๋ค |
ASSET_WRITE_FAILED |
files ์ ์ก์์ ์ด๋ฏธ์ง ํ์ผ์ ์ฐ์ง ๋ชปํจ |
LINT_FAILED |
lint_blocks ๊ฒ์ ์ค ์์ธ. ์์ปค๋ ๋ค์ ์์ฒญ์ ๊ณ์ ๋ฐ์ต๋๋ค |
์์ฒญยท์๋ต ์ํ์ ์ค ๋ \n ์ ๋บ UTF-8 ๋ฐ์ดํธ ์๋ก ์
๋๋ค.
์ด๋ฆฐ ๋ฌธ์๋ฅผ ๊ณ ์น๋ ๋๊ตฌ(ํ/๊ธ ์ค์๊ฐ ํธ์งยท๋ด์ฅ ํธ์ง๊ธฐ)๊ฐ ๋ฌธ๋จยทํ ์นธ์ ๋ธ๋ก์ผ๋ก ๋๊ฒจ, ์ง์ ์ ๋ธ๋ก idยท๋ธ๋ก ์ ์์น๋ก ๋ฐ๋๋ค.
ํ์ ์ kordoc lintยทMCP lint_document ์ ๊ฐ๋ค(runLintSuite). ๊ฐ์ ๋์์ด CLI kordoc lint-blocks, MCP lint_document ์ blocks, ๋ผ์ด๋ธ๋ฌ๋ฆฌ lintBlocks ์๋ ์๋ค.
{"id":7,"cmd":"lint_blocks","blocks":[{"id":"p1","text":"ํ์ 2026.1.6 ๊ฐ์ต"},{"id":"c1","text":"ํฉ๊ณ","table":{"id":"t1","row":0,"col":0}}],"options":{"budget":true}}
{"id":7,"result":{"findings":[{"block":"p1","offset":3,"length":8,"category":"notation","rule":"DATE_NO_SPACE","severity":"error","match":"2026.1.6","message":"โฆ","suggest":"โฆ"}],"summary":{"total":1,"errors":1,"ok":false}}}blocks: ๋ฌธ์ ์์๋๋ก. ํ ์นธ์table: {id, row, col}(0๋ถํฐ) โ ๊ฐ์ ํ id ์ ์นธ์ด ํ GFM ํ๋ก ๋ฌถ์ธ๋ค. ์นธ์ด ํ๋๋ฟ์ธ ํ๋ ๋ณธ๋ฌธ์ผ๋ก ๋ณธ๋ค.options:muncheยทslopยทlogicยทnumbersยทbudgetยทgate(๋ถ๋ฆฌ์ธ),preset(๋ฌธ์์ด, ํ๊ธ ๋ณ์นญ ๊ฐ๋ฅ). ๋ค๋ฅธ ํค๋INVALID_REQUEST, ๋ชจ๋ฅด๋ ํ๋ฆฌ์ ์INVALID_OPTIONS.- ์ง์ :
block(๋ธ๋ก์ ์ ํ ์ ์๋ ๋ฌธ์ ๋จ์ ์ง์ ์ null)ยทoffset(๋ธ๋ก ์ 0๋ถํฐ, UTF-16, ์ค ๋จ์ ์ง์ ์ null)ยทlengthยทcategory(notationยทmuncheยทslopยทlogicยทbudget)ยทruleยทseverityยทmatchยทmessageยทsuggest.numbers๋ฅผ ์ผ๋ฉดnumbers(ํ์ธ ๋ชฉ๋ก). - ์ํ: ๋ธ๋ก 20,000๊ฐ, ๋ธ๋ก ๊ธ 100,000์.
transport.images |
๋์ |
|---|---|
"inline" (๊ธฐ๋ณธ) |
์ด๋ฏธ์ง ๋ฐ์ดํธ๋ฅผ base64 ๋ฌธ์์ด๋ก ๊ฒฐ๊ณผ์ ์ฃ์ต๋๋ค(--format json ๊ณผ ๊ฐ์) |
"files" |
assetsDir ์๋ ์์ฒญ๋ง๋ค ์ ๋๋ ํฐ๋ฆฌ(kordoc-<id>-XXXXXX)๋ฅผ ๋ง๋ค์ด ๋ฐ์ดํธ๋ฅผ ์ฐ๊ณ , ๊ทธ ๊ฒฝ๋ก๋ฅผ ์๋ต assetsDir ๋ก ์ค๋๋ค |
files ์์๋ result.images[], result.pageImages[](์ต์
pageImages), ๋ธ๋ก์ imageData(๋ชฉ๋ก childrenยทํ ์นธ blocksยทcaptionBlocks ํฌํจ)์์ data ๋์ dataRef ๋ฅผ ๋ณด๋
๋๋ค.
{"filename":"image_001.png","mimeType":"image/png","source":"word/media/image1.png","dataRef":{"path":"image_001.png","byteLength":14}}dataRef.path๋ ์๋ตassetsDir๊ธฐ์ค ํ์ผ ์ด๋ฆ์ ๋๋ค. MarkdownยทIR ์ ์ด๋ฏธ์ง ์ด๋ฆ(filename)์ ๊ทธ๋๋ก์ ๋๋ค.- ๊ฐ์ ๋ฐ์ดํธ๋ ํ ํ์ผ์ ํจ๊ป ๊ฐ๋ฆฌํต๋๋ค. ์ด๋ฆ์ด ๊ฐ์๋ ๋ฐ์ดํธ๊ฐ ๋ค๋ฅด๋ฉด ๋ค๋ฅธ ํ์ผ๋ก ์๋๋ค.
- ํ์ผ์ ์๋ก ๋ง๋ค๊ธฐ๋ง ํ๊ณ ๊ธฐ์กด ํ์ผ์ด๋ ๋งํฌ๋ฅผ ๋ฎ์ด์ฐ์ง ์์ต๋๋ค.
assetsDir๊ฐ ๋งํฌ๋ฉด ์ค์ ๊ฒฝ๋ก ์๋์ ๋ง๋ญ๋๋ค. assetsDir์ ๊ทธ ์์ ํ์ผ์ ํธ์ถ์ ์์ ์ ๋๋ค. ์์ปค๋ ์๋ต์ ๋ณด๋ธ ๋ค ์ง์ฐ์ง ์์ต๋๋ค. ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ด์ง ๋ชปํ ์์ฒญ(RESPONSE_TOO_LARGEยทASSET_WRITE_FAILEDยทstdout ๋ซํ)์ ๋๋ ํฐ๋ฆฌ๋ง ์ง์๋๋ค.- ์์ปค๊ฐ ์๋ต ์ ์ ๊ฐ์ ์ข
๋ฃ๋๋ฉด(SDK ์ ์ ํ ์๊ฐยท์ทจ์ยทclose) ๊ทธ ์์ฒญ์
kordoc-<id>-*๋๋ ํฐ๋ฆฌ๊ฐ ๋จ์ ์ ์์ต๋๋ค. ํธ์ถ์๊ฐ ์ ๋ฆฌํฉ๋๋ค. - ์ด๋ฏธ์ง๊ฐ ์์ผ๋ฉด ๋๋ ํฐ๋ฆฌ๋ฅผ ๋ง๋ค์ง ์๊ณ ์๋ต์
assetsDir๋ฅผ ๋ฃ์ง ์์ต๋๋ค. options.inlineImages(Markdown ์ data URI)์options.images: false(๋ฐ์ดํธ ์ถ์ถ ์๋ต)๋ ์ ์ก ๋ชจ๋์ ๋ฐ๋ก ๋์ํฉ๋๋ค.
stdout ์๋ NDJSON ๋ง ์๋๋ค. ์์ง ๋ก๊ทธ์ PDF ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ฒฝ๊ณ ๋ stderr ๋ก ๊ฐ๋๋ค. ํธ์คํธ๋ stderr ๋ฅผ ๊ณ์ ์ฝ์ด ๋น์์ผ ์์ปค๊ฐ ๋งํ์ง ์์ต๋๋ค.
์์ {"ready":true,"version":"4.18.8","protocol":1}
์์ฒญ {"id":1,"file":"a.hwpx","images":false,"ocr":"off","formulaOcr":false,"password":null}
์๋ต {"id":1,"rss":123456789,"result":{โฆ}}
{"id":1,"error":"โฆ"} ์์ฒญ ์์ฒด๊ฐ ์๋ชป๋์ ๋
์ข
๋ฃ {"cmd":"quit"} ๋๋ stdin ๋ซํ
ocr ์ "off"(๊ธฐ๋ณธ, ์์ง ๊ธฐ๋ณธ๊ฐ) ยท "auto"(OCR ์ด ํ์ํ ์ชฝ๋ง) ยท "force"(์ ์ชฝ)์
๋๋ค.