2025-08-05 07:08:07 +00:00
|
|
|
syntax = "proto3";
|
|
|
|
|
|
|
|
|
|
package docreader;
|
|
|
|
|
|
|
|
|
|
option go_package = "github.com/Tencent/WeKnora/internal/docreader/proto";
|
|
|
|
|
|
|
|
|
|
service DocReader {
|
2026-02-28 05:22:07 +00:00
|
|
|
rpc Read(ReadRequest) returns (ReadResponse) {}
|
2026-06-02 01:50:09 +00:00
|
|
|
// ReadStream is the streaming counterpart of Read. It first emits one
|
|
|
|
|
// ReadStreamResponse carrying the parse metadata (markdown / metadata /
|
|
|
|
|
// error), then emits one message per image. This keeps every gRPC message
|
|
|
|
|
// small so large scanned PDFs (hundreds of page images, far exceeding the
|
|
|
|
|
// unary message-size cap) can be returned without RESOURCE_EXHAUSTED and
|
|
|
|
|
// with bounded memory on both ends.
|
|
|
|
|
rpc ReadStream(ReadRequest) returns (stream ReadStreamResponse) {}
|
2026-02-28 05:22:07 +00:00
|
|
|
rpc ListEngines(ListEnginesRequest) returns (ListEnginesResponse) {}
|
2025-08-05 07:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
message ReadConfig {
|
|
|
|
|
string parser_engine = 1;
|
|
|
|
|
map<string, string> parser_engine_overrides = 2;
|
2026-03-03 13:30:27 +00:00
|
|
|
// image_storage removed: image persistence is now handled entirely by the Go App.
|
|
|
|
|
// Field number 3 is reserved for backward compatibility.
|
|
|
|
|
reserved 3;
|
2025-08-10 09:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
// Unified read request: set file_content for file mode, url for URL mode.
|
|
|
|
|
message ReadRequest {
|
|
|
|
|
bytes file_content = 1;
|
|
|
|
|
string file_name = 2;
|
|
|
|
|
string file_type = 3;
|
|
|
|
|
string url = 4;
|
|
|
|
|
string title = 5;
|
|
|
|
|
ReadConfig config = 6;
|
|
|
|
|
string request_id = 7;
|
2025-08-10 09:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
message ImageRef {
|
|
|
|
|
string filename = 1;
|
|
|
|
|
string original_ref = 2;
|
|
|
|
|
string mime_type = 3;
|
|
|
|
|
string storage_key = 4; // download URL from shared storage
|
|
|
|
|
bytes image_data = 5; // inline bytes fallback
|
2025-08-05 07:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
feat(chat): open cited documents at the cited passage (#3700)
* feat(chat): open cited documents at the cited passage
Clicking a citation used to show only the parsed chunk. It now opens the
original file in the references panel, jumps to the cited place and
highlights it, narrowed to the sentence the citation supports.
Parsing records where each chunk sits in the original file
(chunks.source_locators): PDF page and paragraph boxes from the docreader,
MinerU and PaddleOCR-VL layouts; Word paragraphs, slides, sheet rows and
EPUB chapters aligned in Go against any parser engine's Markdown; text
offsets for Markdown/TXT; segment times for audio. Pipeline text rewrites
are followed with a line-diff remapper. Scanned PDF pages get their OCR
text as quotes at search time so a sentence can pick its page.
The frontend renders PDFs with pdf.js and every other previewable type
with the existing preview, then highlights with the CSS Custom Highlight
API in a highlighter yellow that stays visible against the brand green.
* fix(docreader): serialize source blocks outside main so tests import it
test_docx_tables stubs docreader.parser in sys.modules, so importing
docreader.main from a later test failed in the full unittest discover run.
The wire conversion now lives in docreader.source_wire, which needs only
the proto.
* fix(chat): tighten source locators from review
- Remap rewritten-line-for-line stretches by line so scanned PDF pages
no longer drift onto the wrong page.
- Keep the source preview mounted for citations in the file already open.
- Wait for in-flight PDF page renders before looking for the text layer.
- Count image rune offsets in one pass; stream xlsx rows up to maxUnits.
- Start text locators after a UTF-8 BOM, as viewers decode without it.
- Only re-query image children for scanned-page results.
- Seek audio citations without autoplay and drop stale seek listeners.
- Fix the SQLite migration's cross-reference to versioned/000113.
* fix(migrations): renumber chunk source locators after main's chunk_images
main took versioned 000113 and sqlite 000032 for chunk_images, so the
source_locators column moves to versioned 000114 and sqlite 000033.
2026-09-25 05:26:16 +00:00
|
|
|
// SourceBlock ties a range of markdown_content to the place in the original
|
|
|
|
|
// file it was parsed from, so a citation can open the file there.
|
|
|
|
|
message SourceBlock {
|
|
|
|
|
// Unicode code point offsets into markdown_content, end exclusive.
|
|
|
|
|
uint32 start = 1;
|
|
|
|
|
uint32 end = 2;
|
|
|
|
|
// JSON-encoded locator: {"type":"pdf","page":3,"bbox":[x0,y0,x1,y1]}
|
|
|
|
|
// with ordinals 1-based and bbox as fractions of the page, origin top-left.
|
|
|
|
|
string locator_json = 3;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
message ReadResponse {
|
|
|
|
|
string markdown_content = 1;
|
|
|
|
|
repeated ImageRef image_refs = 2;
|
|
|
|
|
string image_dir_path = 3;
|
|
|
|
|
map<string, string> metadata = 4;
|
|
|
|
|
string error = 5;
|
feat(chat): open cited documents at the cited passage (#3700)
* feat(chat): open cited documents at the cited passage
Clicking a citation used to show only the parsed chunk. It now opens the
original file in the references panel, jumps to the cited place and
highlights it, narrowed to the sentence the citation supports.
Parsing records where each chunk sits in the original file
(chunks.source_locators): PDF page and paragraph boxes from the docreader,
MinerU and PaddleOCR-VL layouts; Word paragraphs, slides, sheet rows and
EPUB chapters aligned in Go against any parser engine's Markdown; text
offsets for Markdown/TXT; segment times for audio. Pipeline text rewrites
are followed with a line-diff remapper. Scanned PDF pages get their OCR
text as quotes at search time so a sentence can pick its page.
The frontend renders PDFs with pdf.js and every other previewable type
with the existing preview, then highlights with the CSS Custom Highlight
API in a highlighter yellow that stays visible against the brand green.
* fix(docreader): serialize source blocks outside main so tests import it
test_docx_tables stubs docreader.parser in sys.modules, so importing
docreader.main from a later test failed in the full unittest discover run.
The wire conversion now lives in docreader.source_wire, which needs only
the proto.
* fix(chat): tighten source locators from review
- Remap rewritten-line-for-line stretches by line so scanned PDF pages
no longer drift onto the wrong page.
- Keep the source preview mounted for citations in the file already open.
- Wait for in-flight PDF page renders before looking for the text layer.
- Count image rune offsets in one pass; stream xlsx rows up to maxUnits.
- Start text locators after a UTF-8 BOM, as viewers decode without it.
- Only re-query image children for scanned-page results.
- Seek audio citations without autoplay and drop stale seek listeners.
- Fix the SQLite migration's cross-reference to versioned/000113.
* fix(migrations): renumber chunk source locators after main's chunk_images
main took versioned 000113 and sqlite 000032 for chunk_images, so the
source_locators column moves to versioned 000114 and sqlite 000033.
2026-09-25 05:26:16 +00:00
|
|
|
repeated SourceBlock source_blocks = 6;
|
2025-08-05 07:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-02 01:50:09 +00:00
|
|
|
// Metadata header for a streamed read. Sent exactly once, before any image.
|
|
|
|
|
message ReadStreamMeta {
|
|
|
|
|
string markdown_content = 1;
|
|
|
|
|
string image_dir_path = 2;
|
|
|
|
|
map<string, string> metadata = 3;
|
|
|
|
|
string error = 4;
|
|
|
|
|
uint32 image_count = 5; // best-effort total image count (0 if unknown)
|
feat(chat): open cited documents at the cited passage (#3700)
* feat(chat): open cited documents at the cited passage
Clicking a citation used to show only the parsed chunk. It now opens the
original file in the references panel, jumps to the cited place and
highlights it, narrowed to the sentence the citation supports.
Parsing records where each chunk sits in the original file
(chunks.source_locators): PDF page and paragraph boxes from the docreader,
MinerU and PaddleOCR-VL layouts; Word paragraphs, slides, sheet rows and
EPUB chapters aligned in Go against any parser engine's Markdown; text
offsets for Markdown/TXT; segment times for audio. Pipeline text rewrites
are followed with a line-diff remapper. Scanned PDF pages get their OCR
text as quotes at search time so a sentence can pick its page.
The frontend renders PDFs with pdf.js and every other previewable type
with the existing preview, then highlights with the CSS Custom Highlight
API in a highlighter yellow that stays visible against the brand green.
* fix(docreader): serialize source blocks outside main so tests import it
test_docx_tables stubs docreader.parser in sys.modules, so importing
docreader.main from a later test failed in the full unittest discover run.
The wire conversion now lives in docreader.source_wire, which needs only
the proto.
* fix(chat): tighten source locators from review
- Remap rewritten-line-for-line stretches by line so scanned PDF pages
no longer drift onto the wrong page.
- Keep the source preview mounted for citations in the file already open.
- Wait for in-flight PDF page renders before looking for the text layer.
- Count image rune offsets in one pass; stream xlsx rows up to maxUnits.
- Start text locators after a UTF-8 BOM, as viewers decode without it.
- Only re-query image children for scanned-page results.
- Seek audio citations without autoplay and drop stale seek listeners.
- Fix the SQLite migration's cross-reference to versioned/000113.
* fix(migrations): renumber chunk source locators after main's chunk_images
main took versioned 000113 and sqlite 000032 for chunk_images, so the
source_locators column moves to versioned 000114 and sqlite 000033.
2026-09-25 05:26:16 +00:00
|
|
|
repeated SourceBlock source_blocks = 6;
|
2026-06-02 01:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One frame of a ReadStream. The first frame carries `meta`; every subsequent
|
|
|
|
|
// frame carries a single `image`.
|
|
|
|
|
message ReadStreamResponse {
|
|
|
|
|
oneof payload {
|
|
|
|
|
ReadStreamMeta meta = 1;
|
|
|
|
|
ImageRef image = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
message ListEnginesRequest {
|
|
|
|
|
map<string, string> config_overrides = 1;
|
2025-08-05 07:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
message ParserEngineInfo {
|
|
|
|
|
string name = 1;
|
|
|
|
|
string description = 2;
|
|
|
|
|
repeated string file_types = 3;
|
|
|
|
|
bool available = 4;
|
|
|
|
|
string unavailable_reason = 5;
|
2025-08-05 07:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 05:22:07 +00:00
|
|
|
message ListEnginesResponse {
|
|
|
|
|
repeated ParserEngineInfo engines = 1;
|
2025-08-05 07:08:07 +00:00
|
|
|
}
|