Commit 19230bf
authored
feat(connectors): hand source files to the document pipeline instead of extracting them (#6821)
* feat(connectors): hand source files to the document pipeline instead of extracting them
A connector that extracted text itself stranded the document on a second, weaker
parser. The shared pipeline routes PDFs to OCR — the only way a scanned page is
readable at all — and owns every other format's parser, but its OCR branch is
gated on `mimeType === 'application/pdf'` and connector documents were stored as
`text/plain`, so a connector PDF could never reach it. The same file dragged into
the UI was read by OCR; synced through a connector it got the local parser.
`ExternalDocument` can now carry the source file itself, and SharePoint and
OneDrive hand over anything the knowledge base can parse rather than extracting
it. The sync engine stores those bytes under the file's own name and type, so the
pipeline parses them exactly as it would an upload of the same file. Formats that
are already text stay on the text path: HTML still reduces to plain text and the
rest are UTF-8 decodes, so nothing already indexed changes representation.
The MIME type is derived from the extension rather than the source's own
declaration, so a provider that omits or mislabels it cannot strand a PDF on the
non-OCR path. Re-syncing an existing document now rewrites `mimeType` too, which
is what lets one stored as connector-extracted text stop declaring `text/plain`.
This removes the duplicate extraction path rather than leaving both in place:
`extractConnectorText` is text-only, and the guard against fabricated content
moves to the pipeline where parsing now happens. That guard still matters —
`DocParser` and `PptxParser` never throw, returning a placeholder sentence or
scraped archive bytes on a legacy binary or an image-only deck — so a `degraded`
result now fails the document with the same actionable message it produced
before, naming the modern container for legacy formats.
The in-flight byte budget already accounted for this: `estimateOpSizeBytes` reads
the true source size from listing metadata, so batching reserved against the real
file all along and merely over-reserved while only text was stored.
* fix(knowledge): guard every parser against empty output, not just the file parsers
Moving connector parsing into the pipeline exposed a gap on the OCR branch. OCR
reads a scanned page with no recoverable text as empty, and the empty-content
guard lived inside the file-parser path, so such a document chunked to nothing
and reported success — the same silently-complete-but-useless outcome the guard
exists to prevent. The check now sits above the parser choice and covers OCR
too.
Also preserves a source file's extension when its name is too long for a storage
key. The extension is what picks the parser; a truncated name would still parse
correctly by falling back to the display name, but only by luck.
* fix(knowledge): validate the stored artifact against the parser registry
Ten of the formats a connector now hands over — docm, dotx, xlsm, xlsb, xltx,
pptm, potx, odt, ods and odp — parse fine but are deliberately not offered as
upload types. `resolveStoredArtifactExtension` gated on the upload allowlist, so
it rejected every one of them and processing failed with `Unsupported file
type`. They worked before only because the connector extracted them itself and
stored the result as text.
The question the gate is asking is whether a parser can read the stored object,
which the parser registry answers; the upload allowlist answers a different
question about what we accept from a user.
Also matches the sibling comment style in the object literal it sits in, and
teaches two test mocks the newly imported symbol.
* fix(knowledge): carry the MIME type through hydration
A listing stub is built before the file is fetched and declares `text/plain` for
everything, so a hydrated PDF kept claiming plain text at the top level. Nothing
broke today only because storage reads `sourceFile.mimeType` — which is exactly
what makes it a trap: anything later reaching for `extDoc.mimeType`, the obvious
field, silently loses the OCR routing this change exists to restore.
The merge is now `mergeHydratedDocument` rather than an inline spread, so what
hydration must carry is a stated contract with a test behind it instead of a
literal that is easy to under-specify — which is how the field was missed.1 parent 3ff91f0 commit 19230bf
13 files changed
Lines changed: 474 additions & 293 deletions
File tree
- apps/sim
- connectors
- onedrive
- lib/knowledge
- connectors
- documents
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
| 15 | + | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
| 105 | + | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
111 | 110 | | |
112 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
| |||
377 | 382 | | |
378 | 383 | | |
379 | 384 | | |
380 | | - | |
381 | | - | |
| 385 | + | |
| 386 | + | |
382 | 387 | | |
383 | 388 | | |
384 | | - | |
| 389 | + | |
385 | 390 | | |
386 | 391 | | |
387 | 392 | | |
388 | 393 | | |
389 | 394 | | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | 395 | | |
398 | 396 | | |
399 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 6 | + | |
10 | 7 | | |
11 | 8 | | |
12 | 9 | | |
13 | 10 | | |
14 | 11 | | |
15 | | - | |
16 | 12 | | |
17 | 13 | | |
18 | 14 | | |
| |||
496 | 492 | | |
497 | 493 | | |
498 | 494 | | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
505 | 502 | | |
506 | 503 | | |
507 | 504 | | |
508 | | - | |
509 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
510 | 514 | | |
511 | 515 | | |
512 | 516 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
| 517 | + | |
| 518 | + | |
523 | 519 | | |
524 | | - | |
| 520 | + | |
525 | 521 | | |
526 | | - | |
527 | | - | |
528 | | - | |
| 522 | + | |
| 523 | + | |
529 | 524 | | |
530 | 525 | | |
531 | | - | |
| 526 | + | |
532 | 527 | | |
533 | 528 | | |
534 | 529 | | |
535 | 530 | | |
536 | 531 | | |
537 | | - | |
| 532 | + | |
| 533 | + | |
538 | 534 | | |
539 | 535 | | |
540 | 536 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
| 15 | + | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
214 | 213 | | |
215 | 214 | | |
216 | 215 | | |
217 | | - | |
| 216 | + | |
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
222 | | - | |
| 221 | + | |
223 | 222 | | |
224 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
225 | 230 | | |
226 | 231 | | |
227 | 232 | | |
| |||
925 | 930 | | |
926 | 931 | | |
927 | 932 | | |
928 | | - | |
929 | | - | |
| 933 | + | |
| 934 | + | |
930 | 935 | | |
931 | 936 | | |
932 | | - | |
| 937 | + | |
933 | 938 | | |
934 | 939 | | |
935 | 940 | | |
| |||
938 | 943 | | |
939 | 944 | | |
940 | 945 | | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | 946 | | |
952 | 947 | | |
953 | 948 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
36 | 55 | | |
37 | 56 | | |
38 | 57 | | |
| |||
0 commit comments