@gmickel/gno 1.45.1 → 2.0.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/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +46 -0
- package/assets/skill/SKILL.md +7 -6
- package/assets/skill/cli-reference.md +14 -6
- package/assets/skill/mcp-reference.md +4 -1
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip.sha256 +1 -0
- package/browser-extension/dist/chunk-4tc9v0ja.js +74 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/browser-extension/dist/preview.html +1 -1
- package/browser-extension/dist/service-worker.js +32 -33
- package/bunfig.toml +2 -0
- package/package.json +40 -26
- package/spec/cli.md +30 -11
- package/spec/db/schema.sql +146 -1
- package/spec/mcp.md +26 -0
- package/src/app/context-runtime-types.ts +3 -0
- package/src/app/context-runtime.ts +2 -0
- package/src/cli/commands/ask.ts +6 -1
- package/src/cli/commands/daemon.ts +21 -8
- package/src/cli/commands/embed.ts +77 -41
- package/src/cli/commands/mcp/install.ts +20 -0
- package/src/cli/commands/mcp/paths.ts +25 -0
- package/src/cli/commands/mcp/status.ts +6 -0
- package/src/cli/detach.ts +3 -2
- package/src/cli/program.ts +6 -0
- package/src/config/types.ts +3 -3
- package/src/converters/adapters/markitdownTs/adapter.ts +1 -2
- package/src/converters/adapters/officeparser/adapter.ts +1 -2
- package/src/converters/versions.ts +6 -8
- package/src/core/context-evidence.ts +8 -4
- package/src/core/job-manager.ts +95 -13
- package/src/core/network-boundary-inventory.ts +10 -0
- package/src/core/shutdown-budget.ts +45 -0
- package/src/embed/backlog.ts +107 -4
- package/src/embed/batch.ts +42 -2
- package/src/embed/fingerprint.ts +16 -0
- package/src/embed/retry.ts +113 -5
- package/src/embed/variant-backlog.ts +105 -0
- package/src/embed/variant-plan.ts +62 -0
- package/src/embed/variant-retry.ts +113 -0
- package/src/ingestion/graph-reconciliation.ts +327 -0
- package/src/ingestion/sync.ts +9 -272
- package/src/llm/http-inference.ts +6 -0
- package/src/llm/httpEmbedding.ts +37 -6
- package/src/llm/httpGeneration.ts +18 -3
- package/src/llm/httpRerank.ts +23 -5
- package/src/llm/inference-cancellation.ts +168 -0
- package/src/llm/inference-scope.ts +202 -0
- package/src/llm/lazy-ports.ts +115 -0
- package/src/llm/native-worker/client.ts +541 -0
- package/src/llm/native-worker/dispatcher.ts +228 -0
- package/src/llm/native-worker/embedding-identity.ts +33 -0
- package/src/llm/native-worker/entry.ts +173 -0
- package/src/llm/native-worker/errors.ts +32 -0
- package/src/llm/native-worker/evaluation.ts +16 -0
- package/src/llm/native-worker/owned-exit.ts +108 -0
- package/src/llm/native-worker/owner.ts +141 -0
- package/src/llm/native-worker/ports.ts +317 -0
- package/src/llm/native-worker/protocol.ts +442 -0
- package/src/llm/native-worker/runtime-config.ts +92 -0
- package/src/llm/nodeLlamaCpp/adapter.ts +77 -20
- package/src/llm/nodeLlamaCpp/embedding.ts +130 -46
- package/src/llm/nodeLlamaCpp/generation.ts +34 -5
- package/src/llm/nodeLlamaCpp/lifecycle-options.ts +99 -0
- package/src/llm/nodeLlamaCpp/lifecycle.ts +209 -204
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +111 -0
- package/src/llm/nodeLlamaCpp/rerank.ts +118 -27
- package/src/llm/nodeLlamaCpp/simulator-handle.ts +73 -0
- package/src/llm/nodeLlamaCpp/simulator-install.ts +124 -0
- package/src/llm/nodeLlamaCpp/simulator-session.ts +240 -0
- package/src/llm/nodeLlamaCpp/simulator-types.ts +80 -0
- package/src/llm/types.ts +35 -5
- package/src/mcp/context.ts +27 -0
- package/src/mcp/http-transport.ts +12 -10
- package/src/mcp/server.ts +3 -0
- package/src/mcp/tool-profile.ts +30 -8
- package/src/mcp/tools/context.ts +8 -11
- package/src/mcp/tools/embed.ts +1 -1
- package/src/mcp/tools/index-cmd.ts +1 -1
- package/src/mcp/tools/index.ts +10 -8
- package/src/mcp/tools/query.ts +14 -30
- package/src/mcp/tools/vsearch.ts +1 -1
- package/src/pipeline/answer.ts +23 -3
- package/src/pipeline/claim-verifier.ts +6 -0
- package/src/pipeline/expansion.ts +43 -40
- package/src/pipeline/explain.ts +6 -2
- package/src/pipeline/filters.ts +63 -0
- package/src/pipeline/fusion.ts +29 -9
- package/src/pipeline/graph-retrieval.ts +29 -9
- package/src/pipeline/hybrid.ts +198 -55
- package/src/pipeline/hydration.ts +161 -0
- package/src/pipeline/owner-fusion.ts +87 -0
- package/src/pipeline/rerank.ts +35 -11
- package/src/pipeline/search.ts +13 -2
- package/src/pipeline/types.ts +5 -3
- package/src/pipeline/vsearch.ts +87 -7
- package/src/sdk/client.ts +47 -3
- package/src/sdk/embed.ts +63 -39
- package/src/serve/background-runtime.ts +1 -1
- package/src/serve/context.ts +41 -56
- package/src/serve/embed-scheduler.ts +58 -35
- package/src/serve/public/components/IndexingProgress.tsx +46 -60
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/lib/shiki-language-ids.ts +14 -0
- package/src/serve/resident-admission.ts +36 -36
- package/src/serve/resident-background-work.ts +20 -2
- package/src/serve/resident-request.ts +11 -5
- package/src/serve/resident-runtime.ts +97 -61
- package/src/serve/resident-shutdown.ts +153 -0
- package/src/serve/routes/api.ts +3 -1
- package/src/serve/server.ts +47 -26
- package/src/store/migrations/028-vector-variants.ts +54 -0
- package/src/store/migrations/029-graph-reference-state.ts +77 -0
- package/src/store/migrations/index.ts +4 -0
- package/src/store/sqlite/adapter.ts +251 -183
- package/src/store/sqlite/eligibility.ts +174 -0
- package/src/store/sqlite/graph-edge-application.ts +66 -0
- package/src/store/sqlite/graph-reference-state.ts +194 -0
- package/src/store/sqlite/legacy-vector-ownership.ts +79 -0
- package/src/store/types.ts +80 -12
- package/src/store/vector/eligibility.ts +36 -0
- package/src/store/vector/freshness.ts +33 -6
- package/src/store/vector/lazy.ts +81 -0
- package/src/store/vector/sqlite-vec.ts +106 -54
- package/src/store/vector/stats.ts +14 -3
- package/src/store/vector/types.ts +35 -2
- package/src/store/vector/variant-search.ts +192 -0
- package/src/store/vector/variants.ts +451 -0
- package/vendor/converters/markitdown-ts/LICENSE +21 -0
- package/vendor/converters/markitdown-ts/dist/index.cjs +1180 -0
- package/vendor/converters/markitdown-ts/dist/index.d.cts +46 -0
- package/vendor/converters/markitdown-ts/dist/index.d.mts +46 -0
- package/vendor/converters/markitdown-ts/dist/index.d.ts +46 -0
- package/vendor/converters/markitdown-ts/dist/index.mjs +1152 -0
- package/vendor/converters/markitdown-ts/package.json +77 -0
- package/vendor/converters/officeparser/LICENSE +21 -0
- package/vendor/converters/officeparser/dist/OfficeConverter.d.ts +47 -0
- package/vendor/converters/officeparser/dist/OfficeConverter.js +76 -0
- package/vendor/converters/officeparser/dist/OfficeGenerator.d.ts +23 -0
- package/vendor/converters/officeparser/dist/OfficeGenerator.js +73 -0
- package/vendor/converters/officeparser/dist/OfficeParser.d.ts +106 -0
- package/vendor/converters/officeparser/dist/OfficeParser.js +332 -0
- package/vendor/converters/officeparser/dist/cli.d.ts +28 -0
- package/vendor/converters/officeparser/dist/cli.js +381 -0
- package/vendor/converters/officeparser/dist/defaults.d.ts +41 -0
- package/vendor/converters/officeparser/dist/defaults.js +218 -0
- package/vendor/converters/officeparser/dist/generators/BaseGenerator.d.ts +107 -0
- package/vendor/converters/officeparser/dist/generators/BaseGenerator.js +248 -0
- package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.d.ts +82 -0
- package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.js +797 -0
- package/vendor/converters/officeparser/dist/generators/CsvGenerator.d.ts +38 -0
- package/vendor/converters/officeparser/dist/generators/CsvGenerator.js +245 -0
- package/vendor/converters/officeparser/dist/generators/EpubGenerator.d.ts +43 -0
- package/vendor/converters/officeparser/dist/generators/EpubGenerator.js +315 -0
- package/vendor/converters/officeparser/dist/generators/HtmlGenerator.d.ts +59 -0
- package/vendor/converters/officeparser/dist/generators/HtmlGenerator.js +1942 -0
- package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.d.ts +96 -0
- package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.js +1175 -0
- package/vendor/converters/officeparser/dist/generators/PdfGenerator.d.ts +22 -0
- package/vendor/converters/officeparser/dist/generators/PdfGenerator.js +194 -0
- package/vendor/converters/officeparser/dist/generators/RtfGenerator.d.ts +29 -0
- package/vendor/converters/officeparser/dist/generators/RtfGenerator.js +316 -0
- package/vendor/converters/officeparser/dist/generators/TextGenerator.d.ts +13 -0
- package/vendor/converters/officeparser/dist/generators/TextGenerator.js +201 -0
- package/vendor/converters/officeparser/dist/index.d.ts +60 -0
- package/vendor/converters/officeparser/dist/index.js +72 -0
- package/vendor/converters/officeparser/dist/index.mjs +18 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.d.ts +2621 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.iife.js +1336 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.mjs +1335 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.slim.d.ts +2621 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.slim.iife.js +1336 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.slim.mjs +1335 -0
- package/vendor/converters/officeparser/dist/parsers/CsvParser.d.ts +9 -0
- package/vendor/converters/officeparser/dist/parsers/CsvParser.js +115 -0
- package/vendor/converters/officeparser/dist/parsers/EpubParser.d.ts +8 -0
- package/vendor/converters/officeparser/dist/parsers/EpubParser.js +217 -0
- package/vendor/converters/officeparser/dist/parsers/ExcelParser.d.ts +32 -0
- package/vendor/converters/officeparser/dist/parsers/ExcelParser.js +736 -0
- package/vendor/converters/officeparser/dist/parsers/HtmlParser.d.ts +2 -0
- package/vendor/converters/officeparser/dist/parsers/HtmlParser.js +1287 -0
- package/vendor/converters/officeparser/dist/parsers/MarkdownParser.d.ts +2 -0
- package/vendor/converters/officeparser/dist/parsers/MarkdownParser.js +1272 -0
- package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.d.ts +31 -0
- package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.js +1819 -0
- package/vendor/converters/officeparser/dist/parsers/PdfParser.d.ts +67 -0
- package/vendor/converters/officeparser/dist/parsers/PdfParser.js +848 -0
- package/vendor/converters/officeparser/dist/parsers/PowerPointParser.d.ts +32 -0
- package/vendor/converters/officeparser/dist/parsers/PowerPointParser.js +950 -0
- package/vendor/converters/officeparser/dist/parsers/RtfParser.d.ts +187 -0
- package/vendor/converters/officeparser/dist/parsers/RtfParser.js +1801 -0
- package/vendor/converters/officeparser/dist/parsers/WordParser.d.ts +79 -0
- package/vendor/converters/officeparser/dist/parsers/WordParser.js +1177 -0
- package/vendor/converters/officeparser/dist/sbom.cdx.json +1763 -0
- package/vendor/converters/officeparser/dist/types.d.ts +2507 -0
- package/vendor/converters/officeparser/dist/types.js +107 -0
- package/vendor/converters/officeparser/dist/utils/astUtils.d.ts +16 -0
- package/vendor/converters/officeparser/dist/utils/astUtils.js +33 -0
- package/vendor/converters/officeparser/dist/utils/chartUtils.d.ts +6 -0
- package/vendor/converters/officeparser/dist/utils/chartUtils.js +257 -0
- package/vendor/converters/officeparser/dist/utils/configUtils.d.ts +44 -0
- package/vendor/converters/officeparser/dist/utils/configUtils.js +315 -0
- package/vendor/converters/officeparser/dist/utils/dateUtils.d.ts +17 -0
- package/vendor/converters/officeparser/dist/utils/dateUtils.js +69 -0
- package/vendor/converters/officeparser/dist/utils/envUtils.d.ts +29 -0
- package/vendor/converters/officeparser/dist/utils/envUtils.js +152 -0
- package/vendor/converters/officeparser/dist/utils/errorUtils.d.ts +72 -0
- package/vendor/converters/officeparser/dist/utils/errorUtils.js +245 -0
- package/vendor/converters/officeparser/dist/utils/imageUtils.d.ts +66 -0
- package/vendor/converters/officeparser/dist/utils/imageUtils.js +133 -0
- package/vendor/converters/officeparser/dist/utils/mathUtils.d.ts +42 -0
- package/vendor/converters/officeparser/dist/utils/mathUtils.js +385 -0
- package/vendor/converters/officeparser/dist/utils/moduleLoader.d.ts +18 -0
- package/vendor/converters/officeparser/dist/utils/moduleLoader.js +106 -0
- package/vendor/converters/officeparser/dist/utils/ocrUtils.d.ts +42 -0
- package/vendor/converters/officeparser/dist/utils/ocrUtils.js +428 -0
- package/vendor/converters/officeparser/dist/utils/sanitize.d.ts +148 -0
- package/vendor/converters/officeparser/dist/utils/sanitize.js +344 -0
- package/vendor/converters/officeparser/dist/utils/sheetUtils.d.ts +7 -0
- package/vendor/converters/officeparser/dist/utils/sheetUtils.js +35 -0
- package/vendor/converters/officeparser/dist/utils/styleMapper.d.ts +36 -0
- package/vendor/converters/officeparser/dist/utils/styleMapper.js +224 -0
- package/vendor/converters/officeparser/dist/utils/xmlUtils.d.ts +163 -0
- package/vendor/converters/officeparser/dist/utils/xmlUtils.js +461 -0
- package/vendor/converters/officeparser/dist/utils/zipUtils.d.ts +134 -0
- package/vendor/converters/officeparser/dist/utils/zipUtils.js +337 -0
- package/vendor/converters/officeparser/package.json +147 -0
- package/vendor/converters/upstream-manifest.json +124 -0
- package/vendor/dependency-fixes/README.md +77 -0
- package/vendor/dependency-fixes/vendor-converters.py +83 -0
- package/browser-extension/artifacts/gno-browser-clipper-v1.45.1.zip +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v1.45.1.zip.sha256 +0 -1
- package/browser-extension/dist/chunk-627emwpj.js +0 -75
- /package/browser-extension/dist/{chunk-ydfx5d7p.css → chunk-z74y8n8c.css} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markitdown-ts",
|
|
3
|
+
"version": "0.0.10",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"homepage": "https://github.com/dead8309/markitdown-ts#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/dead8309/markitdown-ts/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/dead8309/markitdown-ts.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Vaibhav Raj",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/index.cjs",
|
|
25
|
+
"module": "dist/index.mjs",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@ai-sdk/openai": "^3.0.2",
|
|
32
|
+
"@types/jsdom": "^21.1.7",
|
|
33
|
+
"@types/mime-types": "^2.1.4",
|
|
34
|
+
"@types/node": "^22.10.2",
|
|
35
|
+
"@types/turndown": "^5.0.5",
|
|
36
|
+
"@types/unzipper": "^0.10.10",
|
|
37
|
+
"bumpp": "^9.9.1",
|
|
38
|
+
"is-ci": "^4.1.0",
|
|
39
|
+
"prettier": "^3.4.2",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"unbuild": "^3.0.1",
|
|
42
|
+
"vite": "^6.0.4",
|
|
43
|
+
"vitest": "^2.1.8",
|
|
44
|
+
"zod": "^4.1.8"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@joplin/turndown-plugin-gfm": "^1.0.60",
|
|
48
|
+
"@xmldom/xmldom": "^0.9.6",
|
|
49
|
+
"ai": "^6.0.6",
|
|
50
|
+
"jsdom": "^25.0.1",
|
|
51
|
+
"mammoth": "^1.8.0",
|
|
52
|
+
"mime-types": "^2.1.35",
|
|
53
|
+
"pdf-parse": "^2.4.5",
|
|
54
|
+
"turndown": "^7.2.0",
|
|
55
|
+
"xlsx": "^0.18.5"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"unzipper": "^0.12.3",
|
|
59
|
+
"youtube-transcript": "^1.2.1"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"youtube-transcript": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"unzipper": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "unbuild",
|
|
71
|
+
"format": "prettier --write src/**/*.ts",
|
|
72
|
+
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
73
|
+
"preversion": "pnpm typecheck && pnpm build",
|
|
74
|
+
"test": "vitest",
|
|
75
|
+
"typecheck": "tsc --noEmit"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Harsh Ankur
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BlobLike, ConversionResult, OfficeConverterConfig, SupportedDestination, SupportedFileType } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Utility type to infer the file type from a file path string literal.
|
|
4
|
+
*/
|
|
5
|
+
type InferFileTypeFromPath<T> = T extends `${string}.${infer E}` ? (Lowercase<E> extends SupportedFileType ? Lowercase<E> : SupportedFileType) : SupportedFileType;
|
|
6
|
+
/**
|
|
7
|
+
* Main converter class providing a streamlined one-step API for document conversion.
|
|
8
|
+
*
|
|
9
|
+
* This class coordinates the `OfficeParser` and `OfficeGenerator` to transform
|
|
10
|
+
* documents from one format to another (e.g., DOCX to Markdown, PDF to HTML).
|
|
11
|
+
*/
|
|
12
|
+
export declare class OfficeConverter {
|
|
13
|
+
/**
|
|
14
|
+
* Converts an office document from its source format to a specified destination format.
|
|
15
|
+
*
|
|
16
|
+
* This method:
|
|
17
|
+
* 1. Detects the source file type and parses it into a unified AST using `OfficeParser`.
|
|
18
|
+
* 2. Automatically configures the parser based on the generator requirements (e.g., enabling
|
|
19
|
+
* attachment extraction if images are requested in the output).
|
|
20
|
+
* 3. Generates the destination document from the AST using `OfficeGenerator`.
|
|
21
|
+
*
|
|
22
|
+
* @template F The inferred type of the input file (path string or buffer).
|
|
23
|
+
* @template T The authoritative source file type (inferred from path or config).
|
|
24
|
+
*
|
|
25
|
+
* @param file - File path (string), Buffer, or ArrayBuffer containing the source document.
|
|
26
|
+
* @param destination - The target format (e.g., 'md', 'html', 'pdf', 'text', 'chunks').
|
|
27
|
+
* @param config - Optional unified configuration for both the parser and generator phases.
|
|
28
|
+
*
|
|
29
|
+
* @returns A promise resolving to the ConversionResult containing the value and messages.
|
|
30
|
+
* @throws {Error} If the source format is unsupported or parsing/generation fails.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Convert Word to Markdown with a single call
|
|
35
|
+
* const { value: markdown } = await OfficeConverter.convert('report.docx', 'md');
|
|
36
|
+
*
|
|
37
|
+
* // Convert PDF to HTML (Note: OCR is disabled in this one-step API)
|
|
38
|
+
* const { value: html } = await OfficeConverter.convert(buffer, 'html', {
|
|
39
|
+
* generatorConfig: {
|
|
40
|
+
* includeImages: true
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
static convert<F extends string | Buffer | ArrayBuffer | Uint8Array | BlobLike, T extends SupportedFileType = InferFileTypeFromPath<F>, D extends SupportedDestination<T> = SupportedDestination<T>>(file: F, destination: D, config?: OfficeConverterConfig<D, T>): Promise<ConversionResult<D>>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OfficeConverter = void 0;
|
|
4
|
+
const OfficeGenerator_js_1 = require("./OfficeGenerator.js");
|
|
5
|
+
const OfficeParser_js_1 = require("./OfficeParser.js");
|
|
6
|
+
/**
|
|
7
|
+
* Main converter class providing a streamlined one-step API for document conversion.
|
|
8
|
+
*
|
|
9
|
+
* This class coordinates the `OfficeParser` and `OfficeGenerator` to transform
|
|
10
|
+
* documents from one format to another (e.g., DOCX to Markdown, PDF to HTML).
|
|
11
|
+
*/
|
|
12
|
+
class OfficeConverter {
|
|
13
|
+
/**
|
|
14
|
+
* Converts an office document from its source format to a specified destination format.
|
|
15
|
+
*
|
|
16
|
+
* This method:
|
|
17
|
+
* 1. Detects the source file type and parses it into a unified AST using `OfficeParser`.
|
|
18
|
+
* 2. Automatically configures the parser based on the generator requirements (e.g., enabling
|
|
19
|
+
* attachment extraction if images are requested in the output).
|
|
20
|
+
* 3. Generates the destination document from the AST using `OfficeGenerator`.
|
|
21
|
+
*
|
|
22
|
+
* @template F The inferred type of the input file (path string or buffer).
|
|
23
|
+
* @template T The authoritative source file type (inferred from path or config).
|
|
24
|
+
*
|
|
25
|
+
* @param file - File path (string), Buffer, or ArrayBuffer containing the source document.
|
|
26
|
+
* @param destination - The target format (e.g., 'md', 'html', 'pdf', 'text', 'chunks').
|
|
27
|
+
* @param config - Optional unified configuration for both the parser and generator phases.
|
|
28
|
+
*
|
|
29
|
+
* @returns A promise resolving to the ConversionResult containing the value and messages.
|
|
30
|
+
* @throws {Error} If the source format is unsupported or parsing/generation fails.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Convert Word to Markdown with a single call
|
|
35
|
+
* const { value: markdown } = await OfficeConverter.convert('report.docx', 'md');
|
|
36
|
+
*
|
|
37
|
+
* // Convert PDF to HTML (Note: OCR is disabled in this one-step API)
|
|
38
|
+
* const { value: html } = await OfficeConverter.convert(buffer, 'html', {
|
|
39
|
+
* generatorConfig: {
|
|
40
|
+
* includeImages: true
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
static async convert(file, destination, config) {
|
|
46
|
+
// 1. Prepare Parser Configuration
|
|
47
|
+
// We prioritize the top-level onWarning if provided.
|
|
48
|
+
const parserConfig = {
|
|
49
|
+
...config?.parseConfig,
|
|
50
|
+
onWarning: config?.onWarning || config?.parseConfig?.onWarning,
|
|
51
|
+
};
|
|
52
|
+
// Remove OCR settings for the streamlined converter as requested
|
|
53
|
+
parserConfig.ocr = false;
|
|
54
|
+
// Remove undefined keys to prevent overwriting defaults in resolveParserConfig
|
|
55
|
+
Object.keys(parserConfig).forEach((key) => parserConfig[key] === undefined && delete parserConfig[key]);
|
|
56
|
+
/**
|
|
57
|
+
* AUTOMATIC CONFIGURATION SYNC
|
|
58
|
+
* We sync extractAttachments from the generator configuration.
|
|
59
|
+
*/
|
|
60
|
+
parserConfig.extractAttachments = (config?.generatorConfig?.includeImages !== false) || (config?.generatorConfig?.includeCharts !== false);
|
|
61
|
+
// 2. Parse the source document into the universal AST
|
|
62
|
+
const ast = await OfficeParser_js_1.OfficeParser.parseOffice(file, parserConfig);
|
|
63
|
+
// 3. Generate the destination document from the AST
|
|
64
|
+
const generatorConfig = {
|
|
65
|
+
...config?.generatorConfig,
|
|
66
|
+
onWarning: config?.onWarning || config?.generatorConfig?.onWarning,
|
|
67
|
+
};
|
|
68
|
+
// The spread widens the object to an inferred literal; it is a `GeneratorConfig<D>` by
|
|
69
|
+
// construction (config.generatorConfig is already typed for D, and onWarning is common to
|
|
70
|
+
// every destination), so the cast restates what the types otherwise lose.
|
|
71
|
+
const result = await OfficeGenerator_js_1.OfficeGenerator.generate(ast, destination, generatorConfig);
|
|
72
|
+
result.messages = [...(ast.warnings || []), ...result.messages];
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.OfficeConverter = OfficeConverter;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ConversionResult, GeneratorConfig, OfficeParserAST, SupportedDestination, SupportedFileType, UniversalGeneratorFormat } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Main generator class providing document conversion functionality.
|
|
4
|
+
*/
|
|
5
|
+
export declare class OfficeGenerator {
|
|
6
|
+
/**
|
|
7
|
+
* Normalizes format aliases (e.g., 'txt' to 'text', 'markdown' to 'md') to standard internal formats.
|
|
8
|
+
*/
|
|
9
|
+
static normalizeDestination(dest: string): UniversalGeneratorFormat;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a file of the specified type from an AST.
|
|
12
|
+
* This is the single source of truth for generation logic.
|
|
13
|
+
*
|
|
14
|
+
* @param ast - The OfficeParserAST to generate from
|
|
15
|
+
* @param destination - The target format (e.g., 'text', 'md', 'html', 'pdf')
|
|
16
|
+
* @param config - Optional configuration for the generator
|
|
17
|
+
* @returns A promise resolving to the ConversionResult containing the value and messages
|
|
18
|
+
* @throws {Error} If the destination format is unsupported
|
|
19
|
+
*/
|
|
20
|
+
static generate<T extends SupportedFileType, D extends SupportedDestination<T>>(ast: OfficeParserAST & {
|
|
21
|
+
type: T;
|
|
22
|
+
}, destination: D, config?: GeneratorConfig<D>): Promise<ConversionResult<D>>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OfficeGenerator = void 0;
|
|
4
|
+
const ChunkingGenerator_js_1 = require("./generators/ChunkingGenerator.js");
|
|
5
|
+
const CsvGenerator_js_1 = require("./generators/CsvGenerator.js");
|
|
6
|
+
const EpubGenerator_js_1 = require("./generators/EpubGenerator.js");
|
|
7
|
+
const HtmlGenerator_js_1 = require("./generators/HtmlGenerator.js");
|
|
8
|
+
const MarkdownGenerator_js_1 = require("./generators/MarkdownGenerator.js");
|
|
9
|
+
const PdfGenerator_js_1 = require("./generators/PdfGenerator.js");
|
|
10
|
+
const RtfGenerator_js_1 = require("./generators/RtfGenerator.js");
|
|
11
|
+
const TextGenerator_js_1 = require("./generators/TextGenerator.js");
|
|
12
|
+
const types_js_1 = require("./types.js");
|
|
13
|
+
const errorUtils_js_1 = require("./utils/errorUtils.js");
|
|
14
|
+
/**
|
|
15
|
+
* Main generator class providing document conversion functionality.
|
|
16
|
+
*/
|
|
17
|
+
class OfficeGenerator {
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes format aliases (e.g., 'txt' to 'text', 'markdown' to 'md') to standard internal formats.
|
|
20
|
+
*/
|
|
21
|
+
static normalizeDestination(dest) {
|
|
22
|
+
const d = dest?.toLowerCase();
|
|
23
|
+
if (d === 'txt')
|
|
24
|
+
return 'text';
|
|
25
|
+
if (d === 'markdown')
|
|
26
|
+
return 'md';
|
|
27
|
+
return d;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generates a file of the specified type from an AST.
|
|
31
|
+
* This is the single source of truth for generation logic.
|
|
32
|
+
*
|
|
33
|
+
* @param ast - The OfficeParserAST to generate from
|
|
34
|
+
* @param destination - The target format (e.g., 'text', 'md', 'html', 'pdf')
|
|
35
|
+
* @param config - Optional configuration for the generator
|
|
36
|
+
* @returns A promise resolving to the ConversionResult containing the value and messages
|
|
37
|
+
* @throws {Error} If the destination format is unsupported
|
|
38
|
+
*/
|
|
39
|
+
static async generate(ast, destination, config) {
|
|
40
|
+
let generator;
|
|
41
|
+
const normalizedDestination = OfficeGenerator.normalizeDestination(destination);
|
|
42
|
+
switch (normalizedDestination) {
|
|
43
|
+
case 'text':
|
|
44
|
+
generator = new TextGenerator_js_1.TextGenerator(ast, config);
|
|
45
|
+
break;
|
|
46
|
+
case 'md':
|
|
47
|
+
generator = new MarkdownGenerator_js_1.MarkdownGenerator(ast, config);
|
|
48
|
+
break;
|
|
49
|
+
case 'html':
|
|
50
|
+
generator = new HtmlGenerator_js_1.HtmlGenerator(ast, config);
|
|
51
|
+
break;
|
|
52
|
+
case 'pdf':
|
|
53
|
+
generator = new PdfGenerator_js_1.PdfGenerator(ast, config);
|
|
54
|
+
break;
|
|
55
|
+
case 'csv':
|
|
56
|
+
generator = new CsvGenerator_js_1.CsvGenerator(ast, config);
|
|
57
|
+
break;
|
|
58
|
+
case 'rtf':
|
|
59
|
+
generator = new RtfGenerator_js_1.RtfGenerator(ast, config);
|
|
60
|
+
break;
|
|
61
|
+
case 'chunks':
|
|
62
|
+
generator = new ChunkingGenerator_js_1.ChunkingGenerator(ast, config);
|
|
63
|
+
break;
|
|
64
|
+
case 'epub':
|
|
65
|
+
generator = new EpubGenerator_js_1.EpubGenerator(ast, config);
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
throw (0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.FORMAT_UNSUPPORTED, undefined, destination);
|
|
69
|
+
}
|
|
70
|
+
return generator.generate();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.OfficeGenerator = OfficeGenerator;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Office Parser - Main Entry Point
|
|
3
|
+
*
|
|
4
|
+
* This module provides the main `OfficeParser` class with a single static method
|
|
5
|
+
* that automatically detects file types and routes to the appropriate parser.
|
|
6
|
+
*
|
|
7
|
+
* **Supported Formats:**
|
|
8
|
+
* - DOCX (Word documents)
|
|
9
|
+
* - XLSX (Excel spreadsheets)
|
|
10
|
+
* - PPTX (PowerPoint presentations)
|
|
11
|
+
* - ODT, ODP, ODS (OpenDocument formats)
|
|
12
|
+
* - PDF (Portable Document Format)
|
|
13
|
+
* - RTF (Rich Text Format)
|
|
14
|
+
* - CSV (Comma-Separated Values)
|
|
15
|
+
* - MD (Markdown)
|
|
16
|
+
* - HTML (HyperText Markup Language)
|
|
17
|
+
* - EPUB (E-book format)
|
|
18
|
+
*
|
|
19
|
+
* **Usage:**
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { OfficeParser } from 'officeparser';
|
|
22
|
+
*
|
|
23
|
+
* // Parse from file path
|
|
24
|
+
* const ast = await OfficeParser.parseOffice('document.docx', {
|
|
25
|
+
* extractAttachments: true,
|
|
26
|
+
* ocr: true
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Parse from Buffer
|
|
30
|
+
* const buffer = fs.readFileSync('document.pdf');
|
|
31
|
+
* const ast = await OfficeParser.parseOffice(buffer);
|
|
32
|
+
*
|
|
33
|
+
* // Get plain text
|
|
34
|
+
* console.log((await ast.to('text')).value);
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @module OfficeParser
|
|
38
|
+
*/
|
|
39
|
+
import { BlobLike, OfficeParserAST, OfficeParserConfig } from './types.js';
|
|
40
|
+
/**
|
|
41
|
+
* Main parser class providing office document parsing functionality.
|
|
42
|
+
*
|
|
43
|
+
* This class contains a single static method `parseOffice` that serves as the
|
|
44
|
+
* universal entry point for parsing any supported office document format.
|
|
45
|
+
*/
|
|
46
|
+
export declare class OfficeParser {
|
|
47
|
+
/**
|
|
48
|
+
* Parses an office document and returns a structured AST.
|
|
49
|
+
*
|
|
50
|
+
* This method:
|
|
51
|
+
* 1. Accepts a file path, Buffer, or ArrayBuffer
|
|
52
|
+
* 2. Detects the file type (from extension or content)
|
|
53
|
+
* 3. Routes to the appropriate format-specific parser
|
|
54
|
+
* 4. Returns a unified AST structure
|
|
55
|
+
*
|
|
56
|
+
* **File Type Detection:**
|
|
57
|
+
* - If a file path is provided, uses the file extension
|
|
58
|
+
* - If a Buffer is provided, uses magic bytes detection (file-type library)
|
|
59
|
+
*
|
|
60
|
+
* **Supported Formats and Routes:**
|
|
61
|
+
* - `.docx` → WordParser (OOXML)
|
|
62
|
+
* - `.xlsx` → ExcelParser (OOXML)
|
|
63
|
+
* - `.pptx` → PowerPointParser (OOXML)
|
|
64
|
+
* - `.odt`, `.odp`, `.ods` → OpenOfficeParser (ODF)
|
|
65
|
+
* - `.pdf` → PdfParser (PDF.js)
|
|
66
|
+
* - `.rtf` → RtfParser (custom RTF parser)
|
|
67
|
+
* - `.csv` → CsvParser
|
|
68
|
+
* - `.md` → MarkdownParser
|
|
69
|
+
* - `.html` → HtmlParser
|
|
70
|
+
* - `.epub` → EpubParser
|
|
71
|
+
*
|
|
72
|
+
* @param file - File path (string), Buffer, or ArrayBuffer containing the document
|
|
73
|
+
* @param config - Optional configuration object (defaults applied for all omitted options)
|
|
74
|
+
* @returns A promise resolving to the parsed OfficeParserAST
|
|
75
|
+
* @throws {Error} If file doesn't exist, format is unsupported, or parsing fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Parse a DOCX file
|
|
80
|
+
* const ast = await OfficeParser.parseOffice('report.docx', {
|
|
81
|
+
* extractAttachments: true,
|
|
82
|
+
* includeRawContent: false
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Parse a Buffer with OCR enabled
|
|
86
|
+
* const buffer = await retrieveData('document.pdf').then(r => r.arrayBuffer());
|
|
87
|
+
* const ast = await OfficeParser.parseOffice(buffer, {
|
|
88
|
+
* ocr: true,
|
|
89
|
+
* ocrLanguage: 'eng+fra'
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // Extract text
|
|
93
|
+
* const text = ast.toText();
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
static parseOffice(file: string | Buffer | ArrayBuffer | Uint8Array | BlobLike, configOrCallback?: OfficeParserConfig | ((ast: OfficeParserAST, err?: any) => void), config?: OfficeParserConfig): Promise<OfficeParserAST>;
|
|
97
|
+
/**
|
|
98
|
+
* Terminates all active OCR workers and cleans up resources.
|
|
99
|
+
*
|
|
100
|
+
* This should be called when the application is shutting down or when OCR
|
|
101
|
+
* is no longer needed to prevent memory leaks and orphaned worker processes.
|
|
102
|
+
*
|
|
103
|
+
* @returns A promise that resolves when all workers have been terminated
|
|
104
|
+
*/
|
|
105
|
+
static terminateOcr(): Promise<void>;
|
|
106
|
+
}
|