@qvac/core 0.0.0 → 0.1.0
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/LICENSE.md +198 -0
- package/NOTICE.md +13 -0
- package/README.md +694 -0
- package/SECURITY.md +6 -0
- package/dist/assistant.bundle +47256 -0
- package/dist/assistant.cjs +18 -0
- package/dist/assistant.d.ts +8 -0
- package/dist/prebuilds-manifest.json +380 -0
- package/dist-lib/client.d.ts +2 -0
- package/dist-lib/client.js +1 -0
- package/dist-lib/index.d.ts +13 -0
- package/dist-lib/index.js +10 -0
- package/dist-lib/lib/agent-icons.d.ts +3 -0
- package/dist-lib/lib/agent-icons.js +1 -0
- package/dist-lib/lib/api/agents.d.ts +5 -0
- package/dist-lib/lib/api/agents.js +38 -0
- package/dist-lib/lib/api/app-config.d.ts +5 -0
- package/dist-lib/lib/api/app-config.js +108 -0
- package/dist-lib/lib/api/approval-rules.d.ts +3 -0
- package/dist-lib/lib/api/approval-rules.js +9 -0
- package/dist-lib/lib/api/attachments.d.ts +8 -0
- package/dist-lib/lib/api/attachments.js +15 -0
- package/dist-lib/lib/api/chat-groups.d.ts +5 -0
- package/dist-lib/lib/api/chat-groups.js +12 -0
- package/dist-lib/lib/api/chat.d.ts +5 -0
- package/dist-lib/lib/api/chat.js +38 -0
- package/dist-lib/lib/api/chunks.d.ts +5 -0
- package/dist-lib/lib/api/chunks.js +61 -0
- package/dist-lib/lib/api/config.d.ts +5 -0
- package/dist-lib/lib/api/config.js +15 -0
- package/dist-lib/lib/api/current-mesh.d.ts +5 -0
- package/dist-lib/lib/api/current-mesh.js +12 -0
- package/dist-lib/lib/api/custom-models.d.ts +5 -0
- package/dist-lib/lib/api/custom-models.js +45 -0
- package/dist-lib/lib/api/devices.d.ts +8 -0
- package/dist-lib/lib/api/devices.js +125 -0
- package/dist-lib/lib/api/diagnostics.d.ts +7 -0
- package/dist-lib/lib/api/diagnostics.js +7 -0
- package/dist-lib/lib/api/effective-ctx-size.d.ts +2 -0
- package/dist-lib/lib/api/effective-ctx-size.js +10 -0
- package/dist-lib/lib/api/execution.d.ts +3 -0
- package/dist-lib/lib/api/execution.js +45 -0
- package/dist-lib/lib/api/files.d.ts +3 -0
- package/dist-lib/lib/api/files.js +48 -0
- package/dist-lib/lib/api/index.d.ts +62 -0
- package/dist-lib/lib/api/index.js +172 -0
- package/dist-lib/lib/api/instrument.d.ts +2 -0
- package/dist-lib/lib/api/instrument.js +86 -0
- package/dist-lib/lib/api/knowledge.d.ts +8 -0
- package/dist-lib/lib/api/knowledge.js +26 -0
- package/dist-lib/lib/api/logs.d.ts +14 -0
- package/dist-lib/lib/api/logs.js +116 -0
- package/dist-lib/lib/api/mesh.d.ts +13 -0
- package/dist-lib/lib/api/mesh.js +25 -0
- package/dist-lib/lib/api/model-download.d.ts +5 -0
- package/dist-lib/lib/api/model-download.js +47 -0
- package/dist-lib/lib/api/network.d.ts +8 -0
- package/dist-lib/lib/api/network.js +6 -0
- package/dist-lib/lib/api/notifications.d.ts +21 -0
- package/dist-lib/lib/api/notifications.js +108 -0
- package/dist-lib/lib/api/rag.d.ts +7 -0
- package/dist-lib/lib/api/rag.js +216 -0
- package/dist-lib/lib/api/sync.d.ts +3 -0
- package/dist-lib/lib/api/sync.js +6 -0
- package/dist-lib/lib/api/tool-activity.d.ts +5 -0
- package/dist-lib/lib/api/tool-activity.js +53 -0
- package/dist-lib/lib/api/tool-configs.d.ts +6 -0
- package/dist-lib/lib/api/tool-configs.js +27 -0
- package/dist-lib/lib/api/watchable.d.ts +12 -0
- package/dist-lib/lib/api/watchable.js +121 -0
- package/dist-lib/lib/assistant-client.d.ts +21 -0
- package/dist-lib/lib/assistant-client.js +52 -0
- package/dist-lib/lib/assistant-tree.d.ts +50 -0
- package/dist-lib/lib/assistant-tree.js +184 -0
- package/dist-lib/lib/assistant.d.ts +425 -0
- package/dist-lib/lib/assistant.js +2706 -0
- package/dist-lib/lib/audio-format.d.ts +4 -0
- package/dist-lib/lib/audio-format.js +4 -0
- package/dist-lib/lib/chat-title.d.ts +5 -0
- package/dist-lib/lib/chat-title.js +58 -0
- package/dist-lib/lib/client.d.ts +25 -0
- package/dist-lib/lib/client.js +53 -0
- package/dist-lib/lib/collabora/convert.d.ts +9 -0
- package/dist-lib/lib/collabora/convert.js +62 -0
- package/dist-lib/lib/collabora/entry.d.ts +1 -0
- package/dist-lib/lib/collabora/entry.js +44 -0
- package/dist-lib/lib/collabora/protocol.d.ts +15 -0
- package/dist-lib/lib/collabora/protocol.js +24 -0
- package/dist-lib/lib/collabora/worker.d.ts +5 -0
- package/dist-lib/lib/collabora/worker.js +111 -0
- package/dist-lib/lib/compaction.d.ts +30 -0
- package/dist-lib/lib/compaction.js +95 -0
- package/dist-lib/lib/constants.d.ts +4 -0
- package/dist-lib/lib/constants.js +4 -0
- package/dist-lib/lib/core/agent.d.ts +15 -0
- package/dist-lib/lib/core/agent.js +149 -0
- package/dist-lib/lib/core/app-build.d.ts +7 -0
- package/dist-lib/lib/core/app-build.js +1 -0
- package/dist-lib/lib/core/approval-rules.d.ts +15 -0
- package/dist-lib/lib/core/approval-rules.js +41 -0
- package/dist-lib/lib/core/async-iterable.d.ts +13 -0
- package/dist-lib/lib/core/async-iterable.js +65 -0
- package/dist-lib/lib/core/attachment-link.d.ts +7 -0
- package/dist-lib/lib/core/attachment-link.js +6 -0
- package/dist-lib/lib/core/audio-attachment.d.ts +1 -0
- package/dist-lib/lib/core/audio-attachment.js +4 -0
- package/dist-lib/lib/core/blind-peers.d.ts +6 -0
- package/dist-lib/lib/core/blind-peers.js +13 -0
- package/dist-lib/lib/core/chat-activity.d.ts +7 -0
- package/dist-lib/lib/core/chat-activity.js +244 -0
- package/dist-lib/lib/core/chat-group.d.ts +14 -0
- package/dist-lib/lib/core/chat-group.js +79 -0
- package/dist-lib/lib/core/chat-search.d.ts +17 -0
- package/dist-lib/lib/core/chat-search.js +199 -0
- package/dist-lib/lib/core/chat.d.ts +37 -0
- package/dist-lib/lib/core/chat.js +196 -0
- package/dist-lib/lib/core/chunk.d.ts +61 -0
- package/dist-lib/lib/core/chunk.js +212 -0
- package/dist-lib/lib/core/contract/activity.d.ts +11 -0
- package/dist-lib/lib/core/contract/activity.js +45 -0
- package/dist-lib/lib/core/contract/agents.d.ts +2 -0
- package/dist-lib/lib/core/contract/agents.js +29 -0
- package/dist-lib/lib/core/contract/approval-rules.d.ts +2 -0
- package/dist-lib/lib/core/contract/approval-rules.js +14 -0
- package/dist-lib/lib/core/contract/attestations.d.ts +2 -0
- package/dist-lib/lib/core/contract/attestations.js +14 -0
- package/dist-lib/lib/core/contract/chat-group.d.ts +2 -0
- package/dist-lib/lib/core/contract/chat-group.js +20 -0
- package/dist-lib/lib/core/contract/chat.d.ts +2 -0
- package/dist-lib/lib/core/contract/chat.js +18 -0
- package/dist-lib/lib/core/contract/chunks.d.ts +2 -0
- package/dist-lib/lib/core/contract/chunks.js +156 -0
- package/dist-lib/lib/core/contract/devices.d.ts +2 -0
- package/dist-lib/lib/core/contract/devices.js +110 -0
- package/dist-lib/lib/core/contract/index.d.ts +2 -0
- package/dist-lib/lib/core/contract/index.js +30 -0
- package/dist-lib/lib/core/contract/indexing.d.ts +4 -0
- package/dist-lib/lib/core/contract/indexing.js +82 -0
- package/dist-lib/lib/core/contract/knowledge.d.ts +2 -0
- package/dist-lib/lib/core/contract/knowledge.js +55 -0
- package/dist-lib/lib/core/contract/members.d.ts +2 -0
- package/dist-lib/lib/core/contract/members.js +96 -0
- package/dist-lib/lib/core/contract/seed-defaults.d.ts +2 -0
- package/dist-lib/lib/core/contract/seed-defaults.js +29 -0
- package/dist-lib/lib/core/contract/tool-activity.d.ts +2 -0
- package/dist-lib/lib/core/contract/tool-activity.js +25 -0
- package/dist-lib/lib/core/contract/tool-configs.d.ts +2 -0
- package/dist-lib/lib/core/contract/tool-configs.js +50 -0
- package/dist-lib/lib/core/contract/types.d.ts +11 -0
- package/dist-lib/lib/core/contract/types.js +1 -0
- package/dist-lib/lib/core/contract/writers.d.ts +2 -0
- package/dist-lib/lib/core/contract/writers.js +112 -0
- package/dist-lib/lib/core/cpu-info-node.d.ts +3 -0
- package/dist-lib/lib/core/cpu-info-node.js +2 -0
- package/dist-lib/lib/core/departures.d.ts +41 -0
- package/dist-lib/lib/core/departures.js +145 -0
- package/dist-lib/lib/core/device-attestation.d.ts +6 -0
- package/dist-lib/lib/core/device-attestation.js +12 -0
- package/dist-lib/lib/core/devices.d.ts +14 -0
- package/dist-lib/lib/core/devices.js +11 -0
- package/dist-lib/lib/core/document-attachment.d.ts +22 -0
- package/dist-lib/lib/core/document-attachment.js +35 -0
- package/dist-lib/lib/core/files/attachments.d.ts +8 -0
- package/dist-lib/lib/core/files/attachments.js +50 -0
- package/dist-lib/lib/core/files/index.d.ts +133 -0
- package/dist-lib/lib/core/files/index.js +585 -0
- package/dist-lib/lib/core/files/knowledge.d.ts +9 -0
- package/dist-lib/lib/core/files/knowledge.js +31 -0
- package/dist-lib/lib/core/files/preview/image.d.ts +4 -0
- package/dist-lib/lib/core/files/preview/image.js +42 -0
- package/dist-lib/lib/core/files/preview/index.d.ts +33 -0
- package/dist-lib/lib/core/files/preview/index.js +161 -0
- package/dist-lib/lib/core/files/processing/claims.d.ts +26 -0
- package/dist-lib/lib/core/files/processing/claims.js +89 -0
- package/dist-lib/lib/core/files/processing/document.d.ts +100 -0
- package/dist-lib/lib/core/files/processing/document.js +101 -0
- package/dist-lib/lib/core/files/processing/index.d.ts +75 -0
- package/dist-lib/lib/core/files/processing/index.js +295 -0
- package/dist-lib/lib/core/files/processing/ownership.d.ts +11 -0
- package/dist-lib/lib/core/files/processing/ownership.js +41 -0
- package/dist-lib/lib/core/files/processing/protocol.d.ts +29 -0
- package/dist-lib/lib/core/files/processing/protocol.js +70 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +10 -0
- package/dist-lib/lib/core/files/processing/settle.js +75 -0
- package/dist-lib/lib/core/files/processing/source.d.ts +36 -0
- package/dist-lib/lib/core/files/processing/source.js +96 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +64 -0
- package/dist-lib/lib/core/files/processing/state.js +118 -0
- package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/artifact/codec.js +172 -0
- package/dist-lib/lib/core/files/rag/artifact/id.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/artifact/id.js +39 -0
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +24 -0
- package/dist-lib/lib/core/files/rag/artifact/types.js +41 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +25 -0
- package/dist-lib/lib/core/files/rag/build.js +60 -0
- package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +12 -0
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +117 -0
- package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +30 -0
- package/dist-lib/lib/core/files/rag/chunk/metadata.js +89 -0
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +7 -0
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +18 -0
- package/dist-lib/lib/core/files/rag/document-types.d.ts +11 -0
- package/dist-lib/lib/core/files/rag/document-types.js +94 -0
- package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/csv-text.js +117 -0
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +22 -0
- package/dist-lib/lib/core/files/rag/extract/document-types.js +152 -0
- package/dist-lib/lib/core/files/rag/extract/extract.d.ts +17 -0
- package/dist-lib/lib/core/files/rag/extract/extract.js +81 -0
- package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/html-table-text.js +125 -0
- package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/html-text.js +132 -0
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +8 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +17 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +141 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +12 -0
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +43 -0
- package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/rtf-text.js +15 -0
- package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +91 -0
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +36 -0
- package/dist-lib/lib/core/files/rag/extract/types.js +12 -0
- package/dist-lib/lib/core/files/rag/extract/utf.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/extract/utf.js +18 -0
- package/dist-lib/lib/core/files/rag/index.d.ts +54 -0
- package/dist-lib/lib/core/files/rag/index.js +79 -0
- package/dist-lib/lib/core/files/rag/limits.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/limits.js +2 -0
- package/dist-lib/lib/core/files/rag/load.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/load.js +250 -0
- package/dist-lib/lib/core/files/rag/models.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/models.js +1 -0
- package/dist-lib/lib/core/files/rag/policy.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/policy.js +23 -0
- package/dist-lib/lib/core/files/rag/produce.d.ts +21 -0
- package/dist-lib/lib/core/files/rag/produce.js +214 -0
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +16 -0
- package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +4 -0
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +48 -0
- package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +37 -0
- package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +5 -0
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +21 -0
- package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/retrieval/format.js +21 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +22 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +137 -0
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +53 -0
- package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +16 -0
- package/dist-lib/lib/core/files/rag/retrieval/notices.js +27 -0
- package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +82 -0
- package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/retrieval/search.js +46 -0
- package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +10 -0
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +63 -0
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +6 -0
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +79 -0
- package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +13 -0
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +20 -0
- package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +13 -0
- package/dist-lib/lib/core/files/rag/retrieval/target.js +89 -0
- package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +70 -0
- package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/retrieval/types.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +8 -0
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +41 -0
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +96 -0
- package/dist-lib/lib/core/files/rag/vector/memory.d.ts +15 -0
- package/dist-lib/lib/core/files/rag/vector/memory.js +135 -0
- package/dist-lib/lib/core/files/rag/vector/types.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/vector/types.js +1 -0
- package/dist-lib/lib/core/files/records/chunks.d.ts +3 -0
- package/dist-lib/lib/core/files/records/chunks.js +12 -0
- package/dist-lib/lib/core/files/records/index.d.ts +10 -0
- package/dist-lib/lib/core/files/records/index.js +8 -0
- package/dist-lib/lib/core/files/records/knowledge.d.ts +22 -0
- package/dist-lib/lib/core/files/records/knowledge.js +105 -0
- package/dist-lib/lib/core/files/records/linkage.d.ts +11 -0
- package/dist-lib/lib/core/files/records/linkage.js +27 -0
- package/dist-lib/lib/core/files/records/output.d.ts +8 -0
- package/dist-lib/lib/core/files/records/output.js +38 -0
- package/dist-lib/lib/core/files/records/reclaim.d.ts +5 -0
- package/dist-lib/lib/core/files/records/reclaim.js +73 -0
- package/dist-lib/lib/core/files/records/routing.d.ts +23 -0
- package/dist-lib/lib/core/files/records/routing.js +62 -0
- package/dist-lib/lib/core/files/records/source.d.ts +16 -0
- package/dist-lib/lib/core/files/records/source.js +70 -0
- package/dist-lib/lib/core/files/records/sweep.d.ts +2 -0
- package/dist-lib/lib/core/files/records/sweep.js +30 -0
- package/dist-lib/lib/core/files/store/blob.d.ts +29 -0
- package/dist-lib/lib/core/files/store/blob.js +98 -0
- package/dist-lib/lib/core/files/store/index.d.ts +36 -0
- package/dist-lib/lib/core/files/store/index.js +89 -0
- package/dist-lib/lib/core/files/store/inline.d.ts +8 -0
- package/dist-lib/lib/core/files/store/inline.js +38 -0
- package/dist-lib/lib/core/files/store/reference.d.ts +27 -0
- package/dist-lib/lib/core/files/store/reference.js +168 -0
- package/dist-lib/lib/core/files/store/server.d.ts +27 -0
- package/dist-lib/lib/core/files/store/server.js +114 -0
- package/dist-lib/lib/core/files/store/sweep.d.ts +2 -0
- package/dist-lib/lib/core/files/store/sweep.js +45 -0
- package/dist-lib/lib/core/files/upload-input.d.ts +27 -0
- package/dist-lib/lib/core/files/upload-input.js +52 -0
- package/dist-lib/lib/core/files/upload.d.ts +32 -0
- package/dist-lib/lib/core/files/upload.js +201 -0
- package/dist-lib/lib/core/fs-drives.d.ts +18 -0
- package/dist-lib/lib/core/fs-drives.js +58 -0
- package/dist-lib/lib/core/gpu-info-node.d.ts +3 -0
- package/dist-lib/lib/core/gpu-info-node.js +2 -0
- package/dist-lib/lib/core/handoff-channel.d.ts +46 -0
- package/dist-lib/lib/core/handoff-channel.js +102 -0
- package/dist-lib/lib/core/health-assistant.d.ts +7 -0
- package/dist-lib/lib/core/health-assistant.js +24 -0
- package/dist-lib/lib/core/helpers/index.d.ts +5 -0
- package/dist-lib/lib/core/helpers/index.js +74 -0
- package/dist-lib/lib/core/hosted-agents.d.ts +36 -0
- package/dist-lib/lib/core/hosted-agents.js +127 -0
- package/dist-lib/lib/core/id.d.ts +1 -0
- package/dist-lib/lib/core/id.js +5 -0
- package/dist-lib/lib/core/identity.d.ts +14 -0
- package/dist-lib/lib/core/identity.js +45 -0
- package/dist-lib/lib/core/image/cache-sweep.d.ts +12 -0
- package/dist-lib/lib/core/image/cache-sweep.js +67 -0
- package/dist-lib/lib/core/image/normalize.d.ts +3 -0
- package/dist-lib/lib/core/image/normalize.js +49 -0
- package/dist-lib/lib/core/image/sniff.d.ts +3 -0
- package/dist-lib/lib/core/image/sniff.js +149 -0
- package/dist-lib/lib/core/invite.d.ts +14 -0
- package/dist-lib/lib/core/invite.js +36 -0
- package/dist-lib/lib/core/local/index.d.ts +71 -0
- package/dist-lib/lib/core/local/index.js +391 -0
- package/dist-lib/lib/core/membership.d.ts +15 -0
- package/dist-lib/lib/core/membership.js +40 -0
- package/dist-lib/lib/core/mesh.d.ts +153 -0
- package/dist-lib/lib/core/mesh.js +509 -0
- package/dist-lib/lib/core/migrations/agent-catalog.d.ts +6 -0
- package/dist-lib/lib/core/migrations/agent-catalog.js +17 -0
- package/dist-lib/lib/core/migrations/index.d.ts +5 -0
- package/dist-lib/lib/core/migrations/index.js +7 -0
- package/dist-lib/lib/core/migrations/membership.d.ts +11 -0
- package/dist-lib/lib/core/migrations/membership.js +26 -0
- package/dist-lib/lib/core/min-version.d.ts +6 -0
- package/dist-lib/lib/core/min-version.js +31 -0
- package/dist-lib/lib/core/next-frame.d.ts +6 -0
- package/dist-lib/lib/core/next-frame.js +27 -0
- package/dist-lib/lib/core/notification.d.ts +6 -0
- package/dist-lib/lib/core/notification.js +162 -0
- package/dist-lib/lib/core/ota-config.d.ts +19 -0
- package/dist-lib/lib/core/ota-config.js +44 -0
- package/dist-lib/lib/core/prompt-history.d.ts +12 -0
- package/dist-lib/lib/core/prompt-history.js +40 -0
- package/dist-lib/lib/core/search-fold.d.ts +1 -0
- package/dist-lib/lib/core/search-fold.js +4 -0
- package/dist-lib/lib/core/secret-handoff.d.ts +17 -0
- package/dist-lib/lib/core/secret-handoff.js +29 -0
- package/dist-lib/lib/core/send.d.ts +18 -0
- package/dist-lib/lib/core/send.js +46 -0
- package/dist-lib/lib/core/skill-overlay-handoff.d.ts +25 -0
- package/dist-lib/lib/core/skill-overlay-handoff.js +50 -0
- package/dist-lib/lib/core/skill-overlay-receiver.d.ts +8 -0
- package/dist-lib/lib/core/skill-overlay-receiver.js +20 -0
- package/dist-lib/lib/core/skill-secrets.d.ts +25 -0
- package/dist-lib/lib/core/skill-secrets.js +79 -0
- package/dist-lib/lib/core/sync/chats.d.ts +3 -0
- package/dist-lib/lib/core/sync/chats.js +5 -0
- package/dist-lib/lib/core/sync/chunks.d.ts +9 -0
- package/dist-lib/lib/core/sync/chunks.js +16 -0
- package/dist-lib/lib/core/sync/devices.d.ts +4 -0
- package/dist-lib/lib/core/sync/devices.js +12 -0
- package/dist-lib/lib/core/sync/files.d.ts +16 -0
- package/dist-lib/lib/core/sync/files.js +109 -0
- package/dist-lib/lib/core/sync/index.d.ts +5 -0
- package/dist-lib/lib/core/sync/index.js +63 -0
- package/dist-lib/lib/core/sync-status.d.ts +17 -0
- package/dist-lib/lib/core/sync-status.js +129 -0
- package/dist-lib/lib/core/system-info.d.ts +24 -0
- package/dist-lib/lib/core/system-info.js +66 -0
- package/dist-lib/lib/core/tool-activity.d.ts +22 -0
- package/dist-lib/lib/core/tool-activity.js +39 -0
- package/dist-lib/lib/core/tool-configs.d.ts +13 -0
- package/dist-lib/lib/core/tool-configs.js +141 -0
- package/dist-lib/lib/core.d.ts +291 -0
- package/dist-lib/lib/core.js +2126 -0
- package/dist-lib/lib/credential-pusher.d.ts +67 -0
- package/dist-lib/lib/credential-pusher.js +290 -0
- package/dist-lib/lib/custom-model-pusher.d.ts +9 -0
- package/dist-lib/lib/custom-model-pusher.js +42 -0
- package/dist-lib/lib/custom-model-source.d.ts +15 -0
- package/dist-lib/lib/custom-model-source.js +46 -0
- package/dist-lib/lib/deadline.d.ts +9 -0
- package/dist-lib/lib/deadline.js +31 -0
- package/dist-lib/lib/diagnostics.d.ts +35 -0
- package/dist-lib/lib/diagnostics.js +14 -0
- package/dist-lib/lib/fetch-node.d.ts +1 -0
- package/dist-lib/lib/fetch-node.js +1 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +12 -0
- package/dist-lib/lib/fs-drive-bridge.js +186 -0
- package/dist-lib/lib/fs-grant-keys.d.ts +2 -0
- package/dist-lib/lib/fs-grant-keys.js +6 -0
- package/dist-lib/lib/fs-grants.d.ts +10 -0
- package/dist-lib/lib/fs-grants.js +44 -0
- package/dist-lib/lib/image-cache-dir.d.ts +1 -0
- package/dist-lib/lib/image-cache-dir.js +5 -0
- package/dist-lib/lib/integrations/index.d.ts +4 -0
- package/dist-lib/lib/integrations/index.js +3 -0
- package/dist-lib/lib/integrations/mcp-providers.d.ts +12 -0
- package/dist-lib/lib/integrations/mcp-providers.js +22 -0
- package/dist-lib/lib/integrations/oauth-providers.d.ts +14 -0
- package/dist-lib/lib/integrations/oauth-providers.js +116 -0
- package/dist-lib/lib/integrations/setup-routes.d.ts +12 -0
- package/dist-lib/lib/integrations/setup-routes.js +114 -0
- package/dist-lib/lib/knowledge-search.d.ts +7 -0
- package/dist-lib/lib/knowledge-search.js +53 -0
- package/dist-lib/lib/kv-cache-reclaim.d.ts +5 -0
- package/dist-lib/lib/kv-cache-reclaim.js +29 -0
- package/dist-lib/lib/kv-cache.d.ts +18 -0
- package/dist-lib/lib/kv-cache.js +33 -0
- package/dist-lib/lib/legacy-core-domain.d.ts +258 -0
- package/dist-lib/lib/legacy-core-domain.js +1 -0
- package/dist-lib/lib/llm-model-names.d.ts +1 -0
- package/dist-lib/lib/llm-model-names.js +1 -0
- package/dist-lib/lib/log-buffer.d.ts +7 -0
- package/dist-lib/lib/log-buffer.js +16 -0
- package/dist-lib/lib/log-levels.d.ts +7 -0
- package/dist-lib/lib/log-levels.js +1 -0
- package/dist-lib/lib/log.d.ts +60 -0
- package/dist-lib/lib/log.js +149 -0
- package/dist-lib/lib/logger-type.d.ts +13 -0
- package/dist-lib/lib/logger-type.js +1 -0
- package/dist-lib/lib/logger.d.ts +5 -0
- package/dist-lib/lib/logger.js +18 -0
- package/dist-lib/lib/model-catalog-revision.d.ts +9 -0
- package/dist-lib/lib/model-catalog-revision.js +65 -0
- package/dist-lib/lib/model-clamp.d.ts +6 -0
- package/dist-lib/lib/model-clamp.js +20 -0
- package/dist-lib/lib/model-context.d.ts +13 -0
- package/dist-lib/lib/model-context.js +71 -0
- package/dist-lib/lib/model-download-status.d.ts +29 -0
- package/dist-lib/lib/model-download-status.js +56 -0
- package/dist-lib/lib/model-download.d.ts +191 -0
- package/dist-lib/lib/model-download.js +787 -0
- package/dist-lib/lib/oauth/asana.d.ts +35 -0
- package/dist-lib/lib/oauth/asana.js +71 -0
- package/dist-lib/lib/oauth/browser-connect.d.ts +22 -0
- package/dist-lib/lib/oauth/browser-connect.js +83 -0
- package/dist-lib/lib/oauth/client.d.ts +9 -0
- package/dist-lib/lib/oauth/client.js +9 -0
- package/dist-lib/lib/oauth/common.d.ts +38 -0
- package/dist-lib/lib/oauth/common.js +36 -0
- package/dist-lib/lib/oauth/crypto.d.ts +3 -0
- package/dist-lib/lib/oauth/crypto.js +25 -0
- package/dist-lib/lib/oauth/fetch-platform.d.ts +1 -0
- package/dist-lib/lib/oauth/fetch-platform.js +1 -0
- package/dist-lib/lib/oauth/flow-core.d.ts +6 -0
- package/dist-lib/lib/oauth/flow-core.js +37 -0
- package/dist-lib/lib/oauth/flow.d.ts +3 -0
- package/dist-lib/lib/oauth/flow.js +24 -0
- package/dist-lib/lib/oauth/google.d.ts +37 -0
- package/dist-lib/lib/oauth/google.js +77 -0
- package/dist-lib/lib/oauth/host.d.ts +5 -0
- package/dist-lib/lib/oauth/host.js +3 -0
- package/dist-lib/lib/oauth/keys.d.ts +25 -0
- package/dist-lib/lib/oauth/keys.js +93 -0
- package/dist-lib/lib/oauth/loopback.d.ts +3 -0
- package/dist-lib/lib/oauth/loopback.js +119 -0
- package/dist-lib/lib/oauth/loopback.stub.d.ts +3 -0
- package/dist-lib/lib/oauth/loopback.stub.js +6 -0
- package/dist-lib/lib/oauth/notion.d.ts +34 -0
- package/dist-lib/lib/oauth/notion.js +82 -0
- package/dist-lib/lib/oauth/pkce-runtime.d.ts +3 -0
- package/dist-lib/lib/oauth/pkce-runtime.js +5 -0
- package/dist-lib/lib/oauth/pkce.d.ts +8 -0
- package/dist-lib/lib/oauth/pkce.js +6 -0
- package/dist-lib/lib/oauth/providers.d.ts +5 -0
- package/dist-lib/lib/oauth/providers.js +73 -0
- package/dist-lib/lib/oauth/redirect-types.d.ts +19 -0
- package/dist-lib/lib/oauth/redirect-types.js +1 -0
- package/dist-lib/lib/oauth/register.d.ts +3 -0
- package/dist-lib/lib/oauth/register.js +34 -0
- package/dist-lib/lib/oauth/resolve.d.ts +17 -0
- package/dist-lib/lib/oauth/resolve.js +57 -0
- package/dist-lib/lib/oauth/spotify.d.ts +32 -0
- package/dist-lib/lib/oauth/spotify.js +73 -0
- package/dist-lib/lib/oauth/token-exchange-core.d.ts +6 -0
- package/dist-lib/lib/oauth/token-exchange-core.js +97 -0
- package/dist-lib/lib/oauth/token-exchange.d.ts +5 -0
- package/dist-lib/lib/oauth/token-exchange.js +9 -0
- package/dist-lib/lib/oauth/types.d.ts +54 -0
- package/dist-lib/lib/oauth/types.js +1 -0
- package/dist-lib/lib/oauth.client.d.ts +5 -0
- package/dist-lib/lib/oauth.client.js +2 -0
- package/dist-lib/lib/oauth.d.ts +14 -0
- package/dist-lib/lib/oauth.js +12 -0
- package/dist-lib/lib/obsidian-key.d.ts +1 -0
- package/dist-lib/lib/obsidian-key.js +1 -0
- package/dist-lib/lib/race-resource.d.ts +5 -0
- package/dist-lib/lib/race-resource.js +25 -0
- package/dist-lib/lib/reconnecting-watch.d.ts +2 -0
- package/dist-lib/lib/reconnecting-watch.js +78 -0
- package/dist-lib/lib/retry-budget.d.ts +14 -0
- package/dist-lib/lib/retry-budget.js +39 -0
- package/dist-lib/lib/run-notices.d.ts +23 -0
- package/dist-lib/lib/run-notices.js +33 -0
- package/dist-lib/lib/run-transcript.d.ts +35 -0
- package/dist-lib/lib/run-transcript.js +106 -0
- package/dist-lib/lib/skill-readiness.d.ts +2 -0
- package/dist-lib/lib/skill-readiness.js +21 -0
- package/dist-lib/lib/skill-types.d.ts +70 -0
- package/dist-lib/lib/skill-types.js +1 -0
- package/dist-lib/lib/spec-loader.d.ts +14 -0
- package/dist-lib/lib/spec-loader.js +9 -0
- package/dist-lib/lib/suspend-lifecycle.d.ts +17 -0
- package/dist-lib/lib/suspend-lifecycle.js +33 -0
- package/dist-lib/lib/task.d.ts +26 -0
- package/dist-lib/lib/task.js +69 -0
- package/dist-lib/lib/unref.d.ts +3 -0
- package/dist-lib/lib/unref.js +4 -0
- package/dist-lib/lib/wav-duration.d.ts +1 -0
- package/dist-lib/lib/wav-duration.js +53 -0
- package/dist-lib/lib/write-queue.d.ts +22 -0
- package/dist-lib/lib/write-queue.js +39 -0
- package/dist-lib/schema/build.d.ts +1 -0
- package/dist-lib/schema/build.js +120 -0
- package/dist-lib/schema/config.d.ts +4 -0
- package/dist-lib/schema/config.js +7 -0
- package/dist-lib/schema/content.d.ts +20 -0
- package/dist-lib/schema/content.js +122 -0
- package/dist-lib/schema/engine.d.ts +2 -0
- package/dist-lib/schema/engine.js +2013 -0
- package/dist-lib/schema/field-order.d.ts +1 -0
- package/dist-lib/schema/field-order.js +95 -0
- package/dist-lib/schema/local.d.ts +2 -0
- package/dist-lib/schema/local.js +133 -0
- package/dist-lib/schema/qvac.d.ts +22 -0
- package/dist-lib/schema/qvac.js +722 -0
- package/dist-lib/spec/bind.d.ts +2 -0
- package/dist-lib/spec/bind.js +520 -0
- package/dist-lib/spec/calls.d.ts +3 -0
- package/dist-lib/spec/calls.js +129 -0
- package/dist-lib/spec/capabilities.d.ts +263 -0
- package/dist-lib/spec/config/hyperconf/index.d.ts +15 -0
- package/dist-lib/spec/config/hyperconf/index.js +24 -0
- package/dist-lib/spec/config/hyperconf/package.json +3 -0
- package/dist-lib/spec/config/hyperschema/index.js +81 -0
- package/dist-lib/spec/config/hyperschema/schema.json +19 -0
- package/dist-lib/spec/hrpc/hrpc.json +1500 -0
- package/dist-lib/spec/hrpc/index.d.ts +3 -0
- package/dist-lib/spec/hrpc/index.js +1545 -0
- package/dist-lib/spec/hrpc/messages.d.ts +4 -0
- package/dist-lib/spec/hrpc/messages.js +8373 -0
- package/dist-lib/spec/hyperschema/index.d.ts +20 -0
- package/dist-lib/spec/hyperschema/index.js +8373 -0
- package/dist-lib/spec/hyperschema/schema.json +6202 -0
- package/dist-lib/spec/hyperschema/types.d.ts +1545 -0
- package/dist-lib/spec/index.d.ts +36 -0
- package/dist-lib/spec/index.js +6 -0
- package/dist-lib/spec/local/hyperdb/db.json +186 -0
- package/dist-lib/spec/local/hyperdb/index.d.ts +9 -0
- package/dist-lib/spec/local/hyperdb/index.js +855 -0
- package/dist-lib/spec/local/hyperdb/messages.js +2189 -0
- package/dist-lib/spec/local/hyperschema/index.js +1208 -0
- package/dist-lib/spec/local/hyperschema/schema.json +639 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +159 -0
- package/dist-lib/spec/mesh/hyperdb/db.json +702 -0
- package/dist-lib/spec/mesh/hyperdb/index.d.ts +9 -0
- package/dist-lib/spec/mesh/hyperdb/index.js +2260 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +7453 -0
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +174 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.d.ts +13 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +566 -0
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +5713 -0
- package/dist-lib/spec/mesh/hyperschema/index.d.ts +14 -0
- package/dist-lib/spec/mesh/hyperschema/index.js +5713 -0
- package/dist-lib/spec/mesh/hyperschema/schema.json +3142 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +754 -0
- package/ducks.png +0 -0
- package/package.json +332 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { extractCsvText } from "./csv-text.js";
|
|
2
|
+
import { classifyRagDocument, RAG_DOCUMENT_KIND } from "./document-types.js";
|
|
3
|
+
import { extractHtmlText } from "./html-text.js";
|
|
4
|
+
import { extractPdfText } from "./pdf-text.js";
|
|
5
|
+
import { extractRtfText } from "./rtf-text.js";
|
|
6
|
+
import { decodeTextBytes } from "./text-decoding.js";
|
|
7
|
+
import { RAG_EXTRACT_ERROR_CODE, RagExtractError } from "./types.js";
|
|
8
|
+
export async function extractRagDocumentFromBytes(input, opts = {}) {
|
|
9
|
+
const fileName = input.fileName ?? input.title ?? input.sourcePath ?? 'document';
|
|
10
|
+
const kind = classifyRagDocument({
|
|
11
|
+
fileName,
|
|
12
|
+
bytes: input.bytes,
|
|
13
|
+
...(input.mimeType ? { mimeType: input.mimeType } : {})
|
|
14
|
+
});
|
|
15
|
+
if (kind === RAG_DOCUMENT_KIND.unsupported) {
|
|
16
|
+
throw new RagExtractError(RAG_EXTRACT_ERROR_CODE.unsupportedFile, `Unsupported document type: ${fileName}`);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const content = await extractText(kind, input.bytes, fileName, opts);
|
|
20
|
+
return buildDocumentInput(input, fileName, content);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
if (e instanceof RagExtractError)
|
|
24
|
+
throw e;
|
|
25
|
+
throw new RagExtractError(RAG_EXTRACT_ERROR_CODE.extractionFailed, errorMessage(e));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function buildDocumentInput(input, fileName, content) {
|
|
29
|
+
return {
|
|
30
|
+
title: input.title ?? fileNameFromPath(fileName),
|
|
31
|
+
content,
|
|
32
|
+
...(input.id !== undefined ? { id: input.id } : {}),
|
|
33
|
+
...(input.blobId !== undefined ? { blobId: input.blobId } : {}),
|
|
34
|
+
...(input.sourcePath !== undefined ? { sourcePath: input.sourcePath } : {}),
|
|
35
|
+
...(input.sourceUrl !== undefined ? { sourceUrl: input.sourceUrl } : {}),
|
|
36
|
+
...(input.mimeType !== undefined ? { mimeType: input.mimeType } : {}),
|
|
37
|
+
...(input.artifactId !== undefined ? { artifactId: input.artifactId } : {}),
|
|
38
|
+
...(input.attachmentId !== undefined ? { attachmentId: input.attachmentId } : {}),
|
|
39
|
+
...(input.messageId !== undefined ? { messageId: input.messageId } : {}),
|
|
40
|
+
...(input.chatId !== undefined ? { chatId: input.chatId } : {})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function extractText(kind, bytes, fileName, opts) {
|
|
44
|
+
if (kind === RAG_DOCUMENT_KIND.pdf) {
|
|
45
|
+
const extractPdf = opts.extractors?.pdf ?? extractPdfText;
|
|
46
|
+
try {
|
|
47
|
+
return await extractPdf(bytes);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
throw new Error(`PDF extraction failed: ${errorMessage(e)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (kind === RAG_DOCUMENT_KIND.office) {
|
|
54
|
+
const extractOffice = opts.extractors?.office;
|
|
55
|
+
if (!extractOffice) {
|
|
56
|
+
throw new RagExtractError(RAG_EXTRACT_ERROR_CODE.unsupportedFile, 'Office document extraction is not available on this device');
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return await extractOffice(bytes, fileName, { signal: opts.signal });
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
throw new Error(`Office document extraction failed: ${errorMessage(e)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const text = decodeTextBytes(bytes);
|
|
66
|
+
if (kind === RAG_DOCUMENT_KIND.rtf)
|
|
67
|
+
return extractRtfText(text);
|
|
68
|
+
if (kind === RAG_DOCUMENT_KIND.html)
|
|
69
|
+
return extractHtmlText(text);
|
|
70
|
+
if (kind === RAG_DOCUMENT_KIND.csv)
|
|
71
|
+
return extractCsvText(text);
|
|
72
|
+
if (kind === RAG_DOCUMENT_KIND.tsv)
|
|
73
|
+
return extractCsvText(text, '\t');
|
|
74
|
+
return text;
|
|
75
|
+
}
|
|
76
|
+
function fileNameFromPath(path) {
|
|
77
|
+
return path.split(/[\\/]/).filter(Boolean).pop() ?? path;
|
|
78
|
+
}
|
|
79
|
+
function errorMessage(error) {
|
|
80
|
+
return error instanceof Error ? error.message : String(error);
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatHtmlTables(source: string): string;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const TABLE_BLOCK = /<table\b[^>]*>[\s\S]*?<\/table\s*>/gi;
|
|
2
|
+
const CAPTION_BLOCK = /<caption\b[^>]*>([\s\S]*?)<\/caption\s*>/i;
|
|
3
|
+
const TABLE_TAG = /<\/?(tr|th|td)\b[^>]*>/gi;
|
|
4
|
+
const DROP_BLOCKS = /<(script|style|noscript|template|svg)\b[^>]*>[\s\S]*?<\/\1\s*>/gi;
|
|
5
|
+
const COMMENT = /<!--[\s\S]*?-->/g;
|
|
6
|
+
const BREAK_TAG = /<br\s*\/?>/gi;
|
|
7
|
+
const TAG = /<[^>]*>/g;
|
|
8
|
+
export function formatHtmlTables(source) {
|
|
9
|
+
return source.replace(TABLE_BLOCK, (table) => `\n\n${formatTable(table)}\n\n`);
|
|
10
|
+
}
|
|
11
|
+
function formatTable(table) {
|
|
12
|
+
const caption = extractCaption(table);
|
|
13
|
+
const rowsText = formatTableRows(table.replace(CAPTION_BLOCK, ' '));
|
|
14
|
+
return caption ? joinTableParts(caption, rowsText) : rowsText;
|
|
15
|
+
}
|
|
16
|
+
function extractCaption(table) {
|
|
17
|
+
const caption = normalizeCell(CAPTION_BLOCK.exec(table)?.[1] ?? '');
|
|
18
|
+
return caption.length > 0 ? caption : null;
|
|
19
|
+
}
|
|
20
|
+
function joinTableParts(caption, rowsText) {
|
|
21
|
+
return rowsText.length > 0 ? `${caption}\n\n${rowsText}` : caption;
|
|
22
|
+
}
|
|
23
|
+
function formatTableRows(table) {
|
|
24
|
+
const rows = parseRows(table).filter((row) => row.some((cell) => cell.text.length > 0));
|
|
25
|
+
const first = rows[0];
|
|
26
|
+
if (!first)
|
|
27
|
+
return normalizeCell(table);
|
|
28
|
+
if (!isColumnHeaderRow(first, rows.length))
|
|
29
|
+
return formatFlatRows(rows);
|
|
30
|
+
const headers = first.map((cell, index) => cell.text || `column_${index + 1}`);
|
|
31
|
+
const dataRows = rows
|
|
32
|
+
.slice(1)
|
|
33
|
+
.map((row) => formatDataRow(headers, row))
|
|
34
|
+
.filter((line) => line.length > 0);
|
|
35
|
+
return dataRows.length > 0
|
|
36
|
+
? [`Columns: ${headers.join(', ')}`, ...dataRows].join('\n\n')
|
|
37
|
+
: formatFlatRows([first]);
|
|
38
|
+
}
|
|
39
|
+
function parseRows(table) {
|
|
40
|
+
const rows = [];
|
|
41
|
+
let row = null;
|
|
42
|
+
let cell = null;
|
|
43
|
+
let cursor = 0;
|
|
44
|
+
for (const match of table.matchAll(TABLE_TAG)) {
|
|
45
|
+
if (cell) {
|
|
46
|
+
cell.html += table.slice(cursor, match.index);
|
|
47
|
+
}
|
|
48
|
+
;
|
|
49
|
+
({ row, cell } = applyTableTag(rows, row, cell, match[0] ?? ''));
|
|
50
|
+
cursor = match.index + match[0].length;
|
|
51
|
+
}
|
|
52
|
+
if (cell) {
|
|
53
|
+
cell.html += table.slice(cursor);
|
|
54
|
+
}
|
|
55
|
+
finishRow(rows, row, cell);
|
|
56
|
+
return rows;
|
|
57
|
+
}
|
|
58
|
+
function applyTableTag(rows, row, cell, source) {
|
|
59
|
+
const tag = parseTableTag(source);
|
|
60
|
+
if (tag?.name === 'tr') {
|
|
61
|
+
return tag.closing ? finishRow(rows, row, cell) : startRow(rows, row, cell);
|
|
62
|
+
}
|
|
63
|
+
if (tag?.name === 'th' || tag?.name === 'td') {
|
|
64
|
+
return tag.closing ? finishCell(row, cell) : startCell(row, cell, tag.name === 'th');
|
|
65
|
+
}
|
|
66
|
+
return { row, cell };
|
|
67
|
+
}
|
|
68
|
+
function startRow(rows, row, cell) {
|
|
69
|
+
finishRow(rows, row, cell);
|
|
70
|
+
return { row: [], cell: null };
|
|
71
|
+
}
|
|
72
|
+
function startCell(row, cell, header) {
|
|
73
|
+
const state = finishCell(row, cell);
|
|
74
|
+
return { row: state.row ?? [], cell: { html: '', header } };
|
|
75
|
+
}
|
|
76
|
+
function finishRow(rows, row, cell) {
|
|
77
|
+
const state = finishCell(row, cell);
|
|
78
|
+
if (state.row && state.row.length > 0) {
|
|
79
|
+
rows.push(state.row);
|
|
80
|
+
}
|
|
81
|
+
return { row: null, cell: null };
|
|
82
|
+
}
|
|
83
|
+
function finishCell(row, cell) {
|
|
84
|
+
if (!cell)
|
|
85
|
+
return { row, cell: null };
|
|
86
|
+
const nextRow = row ?? [];
|
|
87
|
+
nextRow.push({ text: normalizeCell(cell.html), header: cell.header });
|
|
88
|
+
return { row: nextRow, cell: null };
|
|
89
|
+
}
|
|
90
|
+
function parseTableTag(tag) {
|
|
91
|
+
const match = /^<\s*(\/)?\s*(tr|th|td)\b/i.exec(tag);
|
|
92
|
+
return match ? { name: match[2] ?? '', closing: Boolean(match[1]) } : null;
|
|
93
|
+
}
|
|
94
|
+
function isColumnHeaderRow(row, rowCount) {
|
|
95
|
+
return rowCount > 1 && row.length >= 2 && row.every((cell) => cell.header);
|
|
96
|
+
}
|
|
97
|
+
function formatDataRow(headers, row) {
|
|
98
|
+
const parts = [];
|
|
99
|
+
const columnCount = Math.max(headers.length, row.length);
|
|
100
|
+
for (let index = 0; index < columnCount; index++) {
|
|
101
|
+
const value = row[index]?.text ?? '';
|
|
102
|
+
if (value.length === 0)
|
|
103
|
+
continue;
|
|
104
|
+
parts.push(`${headers[index] ?? `column_${index + 1}`}: ${value}`);
|
|
105
|
+
}
|
|
106
|
+
return parts.join(' | ');
|
|
107
|
+
}
|
|
108
|
+
function formatFlatRows(rows) {
|
|
109
|
+
return rows
|
|
110
|
+
.map((row) => row
|
|
111
|
+
.map((cell) => cell.text)
|
|
112
|
+
.filter((cell) => cell.length > 0)
|
|
113
|
+
.join(' | '))
|
|
114
|
+
.filter((line) => line.length > 0)
|
|
115
|
+
.join('\n');
|
|
116
|
+
}
|
|
117
|
+
function normalizeCell(html) {
|
|
118
|
+
return html
|
|
119
|
+
.replace(DROP_BLOCKS, ' ')
|
|
120
|
+
.replace(COMMENT, ' ')
|
|
121
|
+
.replace(BREAK_TAG, ' ')
|
|
122
|
+
.replace(TAG, ' ')
|
|
123
|
+
.replace(/\s+/g, ' ')
|
|
124
|
+
.trim();
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractHtmlText(source: string): string;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { formatHtmlTables } from "./html-table-text.js";
|
|
2
|
+
const DROP_BLOCKS = /<(script|style|noscript|template|svg|head)\b[^>]*>[\s\S]*?<\/\1\s*>/gi;
|
|
3
|
+
const COMMENT = /<!--[\s\S]*?-->/g;
|
|
4
|
+
const HEADING_OPEN = /<h([1-6])\b[^>]*>/gi;
|
|
5
|
+
const HEADING_CLOSE = /<\/h[1-6]\s*>/gi;
|
|
6
|
+
const LIST_ITEM_OPEN = /<li\b[^>]*>/gi;
|
|
7
|
+
const LIST_ITEM_CLOSE = /<\/li\s*>/gi;
|
|
8
|
+
const TABLE_CELL_OPEN = /<t[hd]\b[^>]*>/gi;
|
|
9
|
+
const TABLE_CELL_CLOSE = /<\/t[hd]\s*>/gi;
|
|
10
|
+
const TABLE_ROW_OPEN = /<tr\b[^>]*>/gi;
|
|
11
|
+
const TABLE_ROW_CLOSE = /<\/tr\s*>/gi;
|
|
12
|
+
const BREAK_TAG = /<br\s*\/?>/gi;
|
|
13
|
+
const BLOCK_CONTAINER_TAGS = 'p|div|section|article|header|footer|main|aside|nav|blockquote|pre|figure|figcaption|ul|ol|table|thead|tbody|tfoot|address|form|fieldset';
|
|
14
|
+
const BLOCK_CLOSE = new RegExp(`</(${BLOCK_CONTAINER_TAGS})\\s*>`, 'gi');
|
|
15
|
+
const BLOCK_OPEN = new RegExp(`<(${BLOCK_CONTAINER_TAGS}|hr)\\b[^>]*>`, 'gi');
|
|
16
|
+
const STRAY_CLOSE_BRACKET = />/g;
|
|
17
|
+
const NAMED_ENTITIES = new Map([
|
|
18
|
+
['amp', '&'],
|
|
19
|
+
['lt', '<'],
|
|
20
|
+
['gt', '>'],
|
|
21
|
+
['quot', '"'],
|
|
22
|
+
['apos', "'"],
|
|
23
|
+
['nbsp', ' '],
|
|
24
|
+
['copy', '©'],
|
|
25
|
+
['reg', '®'],
|
|
26
|
+
['trade', '™'],
|
|
27
|
+
['hellip', '…'],
|
|
28
|
+
['mdash', '—'],
|
|
29
|
+
['ndash', '–'],
|
|
30
|
+
['lsquo', '‘'],
|
|
31
|
+
['rsquo', '’'],
|
|
32
|
+
['ldquo', '“'],
|
|
33
|
+
['rdquo', '”'],
|
|
34
|
+
['middot', '·'],
|
|
35
|
+
['bull', '•'],
|
|
36
|
+
['deg', '°'],
|
|
37
|
+
['times', '×'],
|
|
38
|
+
['divide', '÷'],
|
|
39
|
+
['plusmn', '±'],
|
|
40
|
+
['laquo', '«'],
|
|
41
|
+
['raquo', '»'],
|
|
42
|
+
['euro', '€'],
|
|
43
|
+
['pound', '£'],
|
|
44
|
+
['yen', '¥'],
|
|
45
|
+
['cent', '¢'],
|
|
46
|
+
['sect', '§'],
|
|
47
|
+
['para', '¶'],
|
|
48
|
+
['iexcl', '¡'],
|
|
49
|
+
['iquest', '¿'],
|
|
50
|
+
['dagger', '†'],
|
|
51
|
+
['Dagger', '‡'],
|
|
52
|
+
['sbquo', '‚'],
|
|
53
|
+
['bdquo', '„'],
|
|
54
|
+
['prime', '′'],
|
|
55
|
+
['Prime', '″'],
|
|
56
|
+
['frac12', '½'],
|
|
57
|
+
['frac14', '¼'],
|
|
58
|
+
['frac34', '¾']
|
|
59
|
+
]);
|
|
60
|
+
const NUMERIC_ENTITY = /&#(x[0-9a-fA-F]+|[0-9]+);/g;
|
|
61
|
+
const NAMED_ENTITY = /&([a-zA-Z][a-zA-Z0-9]+);/g;
|
|
62
|
+
export function extractHtmlText(source) {
|
|
63
|
+
const structured = markStructure(formatHtmlTables(dropNonContent(source)));
|
|
64
|
+
const text = stripTagsFully(structured);
|
|
65
|
+
return normalizeWhitespace(decodeEntities(text));
|
|
66
|
+
}
|
|
67
|
+
function dropNonContent(source) {
|
|
68
|
+
let previous = source;
|
|
69
|
+
let current = source.replace(DROP_BLOCKS, ' ').replace(COMMENT, ' ');
|
|
70
|
+
while (current !== previous) {
|
|
71
|
+
previous = current;
|
|
72
|
+
current = current.replace(DROP_BLOCKS, ' ').replace(COMMENT, ' ');
|
|
73
|
+
}
|
|
74
|
+
return current;
|
|
75
|
+
}
|
|
76
|
+
function stripTagsFully(source) {
|
|
77
|
+
let output = '';
|
|
78
|
+
let cursor = 0;
|
|
79
|
+
while (cursor < source.length) {
|
|
80
|
+
const open = source.indexOf('<', cursor);
|
|
81
|
+
if (open === -1) {
|
|
82
|
+
return output + stripStrayCloseBrackets(source.slice(cursor));
|
|
83
|
+
}
|
|
84
|
+
output += stripStrayCloseBrackets(source.slice(cursor, open));
|
|
85
|
+
const close = source.indexOf('>', open + 1);
|
|
86
|
+
if (close === -1) {
|
|
87
|
+
return `${output} `;
|
|
88
|
+
}
|
|
89
|
+
cursor = close + 1;
|
|
90
|
+
}
|
|
91
|
+
return output;
|
|
92
|
+
}
|
|
93
|
+
function stripStrayCloseBrackets(text) {
|
|
94
|
+
return text.replace(STRAY_CLOSE_BRACKET, ' ');
|
|
95
|
+
}
|
|
96
|
+
function markStructure(html) {
|
|
97
|
+
return html
|
|
98
|
+
.replace(HEADING_OPEN, (_match, level) => `\n\n${'#'.repeat(Number(level))} `)
|
|
99
|
+
.replace(HEADING_CLOSE, '\n\n')
|
|
100
|
+
.replace(TABLE_CELL_OPEN, ' | ')
|
|
101
|
+
.replace(TABLE_CELL_CLOSE, '')
|
|
102
|
+
.replace(TABLE_ROW_OPEN, '\n')
|
|
103
|
+
.replace(TABLE_ROW_CLOSE, '')
|
|
104
|
+
.replace(LIST_ITEM_OPEN, '\n- ')
|
|
105
|
+
.replace(LIST_ITEM_CLOSE, '')
|
|
106
|
+
.replace(BREAK_TAG, '\n')
|
|
107
|
+
.replace(BLOCK_OPEN, '\n\n')
|
|
108
|
+
.replace(BLOCK_CLOSE, '\n\n');
|
|
109
|
+
}
|
|
110
|
+
function decodeEntities(text) {
|
|
111
|
+
return text
|
|
112
|
+
.replace(NUMERIC_ENTITY, (_match, code) => {
|
|
113
|
+
const codePoint = code.startsWith('x') || code.startsWith('X')
|
|
114
|
+
? Number.parseInt(code.slice(1), 16)
|
|
115
|
+
: Number.parseInt(code, 10);
|
|
116
|
+
return Number.isFinite(codePoint) && codePoint >= 0 && codePoint <= 0x10ffff
|
|
117
|
+
? String.fromCodePoint(codePoint)
|
|
118
|
+
: '';
|
|
119
|
+
})
|
|
120
|
+
.replace(NAMED_ENTITY, (match, name) => NAMED_ENTITIES.get(name) ?? match);
|
|
121
|
+
}
|
|
122
|
+
function normalizeWhitespace(text) {
|
|
123
|
+
return text
|
|
124
|
+
.replace(/\r\n?/g, '\n')
|
|
125
|
+
.replace(/[ \t\f\v]+/g, ' ')
|
|
126
|
+
.replace(/[ \t]+\n/g, '\n')
|
|
127
|
+
.replace(/\n[ \t]+/g, '\n')
|
|
128
|
+
.replace(/^\| ?/gm, '')
|
|
129
|
+
.replace(/ \|\s*$/gm, '')
|
|
130
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
131
|
+
.trim();
|
|
132
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { convertToText } from "../../../../collabora/convert.js";
|
|
2
|
+
import { MAX_OFFICE_BYTES } from "../limits.js";
|
|
3
|
+
export const extractOfficeText = (bytes, fileName, opts) => {
|
|
4
|
+
if (bytes.byteLength > MAX_OFFICE_BYTES) {
|
|
5
|
+
throw new Error(`document is too large to convert: ${bytes.byteLength} bytes, limit ${MAX_OFFICE_BYTES}`);
|
|
6
|
+
}
|
|
7
|
+
return convertToText({ bytes, fileName, to: 'md', signal: opts?.signal });
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class BareTextDecoder {
|
|
2
|
+
readonly encoding: string;
|
|
3
|
+
readonly fatal: boolean;
|
|
4
|
+
readonly ignoreBOM: boolean;
|
|
5
|
+
constructor(label?: string, options?: {
|
|
6
|
+
fatal?: boolean;
|
|
7
|
+
ignoreBOM?: boolean;
|
|
8
|
+
});
|
|
9
|
+
decode(input?: ArrayBufferView | ArrayBuffer): string;
|
|
10
|
+
}
|
|
11
|
+
export declare class BareTextEncoder {
|
|
12
|
+
encode(input?: string): Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
export declare function decodeBytes(bytes: Uint8Array, label: string, options?: {
|
|
15
|
+
fatal?: boolean;
|
|
16
|
+
ignoreBOM?: boolean;
|
|
17
|
+
}): string;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { AbortController, AbortSignal } from 'bare-abort-controller';
|
|
3
|
+
import { ReadableStream } from 'web-streams-polyfill/dist/ponyfill.mjs';
|
|
4
|
+
import { decodeLatin1, decodeUtf16 } from "./utf.js";
|
|
5
|
+
const g = globalThis;
|
|
6
|
+
if (!g.ReadableStream)
|
|
7
|
+
g.ReadableStream = ReadableStream;
|
|
8
|
+
if (!g.DOMException) {
|
|
9
|
+
g.DOMException = class DOMException extends Error {
|
|
10
|
+
constructor(message, name = 'Error') {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = name;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export class BareTextDecoder {
|
|
17
|
+
encoding;
|
|
18
|
+
fatal;
|
|
19
|
+
ignoreBOM;
|
|
20
|
+
constructor(label = 'utf-8', options = {}) {
|
|
21
|
+
this.encoding = parseEncoding(label);
|
|
22
|
+
this.fatal = options.fatal === true;
|
|
23
|
+
this.ignoreBOM = options.ignoreBOM === true;
|
|
24
|
+
}
|
|
25
|
+
decode(input) {
|
|
26
|
+
if (input === undefined)
|
|
27
|
+
return '';
|
|
28
|
+
const bytes = ArrayBuffer.isView(input)
|
|
29
|
+
? b4a.from(input.buffer, input.byteOffset, input.byteLength)
|
|
30
|
+
: b4a.from(input);
|
|
31
|
+
return decodeBytes(bytes, this.encoding, { fatal: this.fatal, ignoreBOM: this.ignoreBOM });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class BareTextEncoder {
|
|
35
|
+
encode(input = '') {
|
|
36
|
+
return b4a.from(String(input), 'utf8');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!g.TextDecoder)
|
|
40
|
+
g.TextDecoder = BareTextDecoder;
|
|
41
|
+
if (!g.TextEncoder)
|
|
42
|
+
g.TextEncoder = BareTextEncoder;
|
|
43
|
+
export function decodeBytes(bytes, label, options = {}) {
|
|
44
|
+
const fatal = options.fatal === true;
|
|
45
|
+
const encoding = parseEncoding(label);
|
|
46
|
+
const text = encoding === 'utf-16le'
|
|
47
|
+
? utf16(bytes, true, fatal)
|
|
48
|
+
: encoding === 'utf-16be'
|
|
49
|
+
? utf16(bytes, false, fatal)
|
|
50
|
+
: encoding === 'latin1'
|
|
51
|
+
? decodeLatin1(bytes)
|
|
52
|
+
: decodeUtf8(bytes, fatal);
|
|
53
|
+
return options.ignoreBOM || text.charCodeAt(0) !== 0xfeff ? text : text.slice(1);
|
|
54
|
+
}
|
|
55
|
+
function parseEncoding(label) {
|
|
56
|
+
const l = String(label).trim().toLowerCase();
|
|
57
|
+
if (l.includes('utf-16') || l.includes('utf16') || l === 'ucs-2' || l === 'ucs2') {
|
|
58
|
+
return l.includes('be') ? 'utf-16be' : 'utf-16le';
|
|
59
|
+
}
|
|
60
|
+
if (l.includes('latin1') || l.includes('8859'))
|
|
61
|
+
return 'latin1';
|
|
62
|
+
return 'utf-8';
|
|
63
|
+
}
|
|
64
|
+
function utf16(bytes, littleEndian, fatal) {
|
|
65
|
+
if (fatal && bytes.length % 2 !== 0)
|
|
66
|
+
throw new TypeError('truncated utf-16 sequence');
|
|
67
|
+
const text = decodeUtf16(bytes, littleEndian);
|
|
68
|
+
if (fatal)
|
|
69
|
+
assertPairedSurrogates(text);
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
function assertPairedSurrogates(text) {
|
|
73
|
+
for (let i = 0; i < text.length; i++) {
|
|
74
|
+
const unit = text.charCodeAt(i);
|
|
75
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
76
|
+
const low = text.charCodeAt(i + 1);
|
|
77
|
+
if (Number.isNaN(low) || low < 0xdc00 || low > 0xdfff) {
|
|
78
|
+
throw new TypeError('lone high surrogate');
|
|
79
|
+
}
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff) {
|
|
83
|
+
throw new TypeError('lone low surrogate');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function decodeUtf8(bytes, fatal) {
|
|
88
|
+
if (fatal && !isValidUtf8(bytes))
|
|
89
|
+
throw new TypeError('invalid utf-8 sequence');
|
|
90
|
+
return b4a.toString(bytes, 'utf8');
|
|
91
|
+
}
|
|
92
|
+
function isValidUtf8(bytes) {
|
|
93
|
+
for (let i = 0; i < bytes.length;) {
|
|
94
|
+
const b0 = bytes[i];
|
|
95
|
+
if (b0 < 0x80) {
|
|
96
|
+
i++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
let size;
|
|
100
|
+
let min;
|
|
101
|
+
let cp;
|
|
102
|
+
if ((b0 & 0xe0) === 0xc0) {
|
|
103
|
+
size = 2;
|
|
104
|
+
min = 0x80;
|
|
105
|
+
cp = b0 & 0x1f;
|
|
106
|
+
}
|
|
107
|
+
else if ((b0 & 0xf0) === 0xe0) {
|
|
108
|
+
size = 3;
|
|
109
|
+
min = 0x800;
|
|
110
|
+
cp = b0 & 0x0f;
|
|
111
|
+
}
|
|
112
|
+
else if ((b0 & 0xf8) === 0xf0) {
|
|
113
|
+
size = 4;
|
|
114
|
+
min = 0x10000;
|
|
115
|
+
cp = b0 & 0x07;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (i + size > bytes.length)
|
|
121
|
+
return false;
|
|
122
|
+
for (let j = 1; j < size; j++) {
|
|
123
|
+
const bj = bytes[i + j];
|
|
124
|
+
if ((bj & 0xc0) !== 0x80)
|
|
125
|
+
return false;
|
|
126
|
+
cp = (cp << 6) | (bj & 0x3f);
|
|
127
|
+
}
|
|
128
|
+
if (cp < min || cp > 0x10ffff || (cp >= 0xd800 && cp <= 0xdfff))
|
|
129
|
+
return false;
|
|
130
|
+
i += size;
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
if (!g.AbortController) {
|
|
135
|
+
g.AbortController = AbortController;
|
|
136
|
+
g.AbortSignal = AbortSignal;
|
|
137
|
+
}
|
|
138
|
+
const clone = globalThis.structuredClone;
|
|
139
|
+
if (clone) {
|
|
140
|
+
g.structuredClone = (value, options) => clone(value, (options ?? undefined));
|
|
141
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import './pdf-platform.ts';
|
|
2
|
+
export declare function extractPdfText(bytes: Uint8Array, options?: {
|
|
3
|
+
maxChars?: number;
|
|
4
|
+
}): Promise<string>;
|
|
5
|
+
export interface PdfHead {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly pagesRead: number;
|
|
8
|
+
readonly totalPages: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function extractPdfHead(bytes: Uint8Array, { maxChars }?: {
|
|
11
|
+
maxChars?: number;
|
|
12
|
+
}): Promise<PdfHead>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import "./pdf-platform.js";
|
|
2
|
+
import { getDocument } from 'unpdf/pdfjs';
|
|
3
|
+
export function extractPdfText(bytes, options = {}) {
|
|
4
|
+
return extractPdfHead(bytes, options).then((head) => head.text);
|
|
5
|
+
}
|
|
6
|
+
export async function extractPdfHead(bytes, { maxChars = Infinity } = {}) {
|
|
7
|
+
const pdf = await getDocument({
|
|
8
|
+
data: new Uint8Array(bytes),
|
|
9
|
+
disableFontFace: true,
|
|
10
|
+
isEvalSupported: false,
|
|
11
|
+
useSystemFonts: true,
|
|
12
|
+
verbosity: 0
|
|
13
|
+
}).promise;
|
|
14
|
+
try {
|
|
15
|
+
const pages = [];
|
|
16
|
+
let total = 0;
|
|
17
|
+
for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++) {
|
|
18
|
+
const page = await pdf.getPage(pageNumber);
|
|
19
|
+
const textContent = await page.getTextContent();
|
|
20
|
+
const pageText = textContent.items.map(textItem).filter(Boolean).join(' ');
|
|
21
|
+
pages.push(pageText);
|
|
22
|
+
total += pageText.length;
|
|
23
|
+
if (total > maxChars)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
const text = pages
|
|
27
|
+
.join('\n\n')
|
|
28
|
+
.replace(/[ \t]+\n/g, '\n')
|
|
29
|
+
.trim();
|
|
30
|
+
return { text, pagesRead: pages.length, totalPages: pdf.numPages };
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
await pdf.destroy();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function textItem(item) {
|
|
37
|
+
if (!isRecord(item) || typeof item.str !== 'string')
|
|
38
|
+
return '';
|
|
39
|
+
return item.str.trim();
|
|
40
|
+
}
|
|
41
|
+
function isRecord(value) {
|
|
42
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractRtfText(source: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const HEX_ESCAPE = /\\'([0-9a-fA-F]{2})/g;
|
|
2
|
+
const CONTROL_WORD = /\\[a-zA-Z]+-?\d* ?/g;
|
|
3
|
+
const CONTROL_SYMBOL = /\\[^a-zA-Z0-9]/g;
|
|
4
|
+
export function extractRtfText(source) {
|
|
5
|
+
return source
|
|
6
|
+
.replaceAll('\\par', '\n')
|
|
7
|
+
.replaceAll('\\line', '\n')
|
|
8
|
+
.replace(HEX_ESCAPE, (_match, hex) => String.fromCharCode(Number.parseInt(hex, 16)))
|
|
9
|
+
.replace(CONTROL_WORD, '')
|
|
10
|
+
.replace(CONTROL_SYMBOL, '')
|
|
11
|
+
.replace(/[{}]/g, '')
|
|
12
|
+
.replace(/[ \t]+\n/g, '\n')
|
|
13
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
14
|
+
.trim();
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function decodeTextBytes(bytes: Uint8Array): string;
|