@belboy47/brc-agent 0.0.0-stage → 2.0.17-lab.1
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 +30 -0
- package/LICENSE-desktop-commander +21 -0
- package/NOTICE +13 -0
- package/README.md +58 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +354 -0
- package/dist/cli.js.map +1 -0
- package/dist/context.d.ts +31 -0
- package/dist/context.js +11 -0
- package/dist/context.js.map +1 -0
- package/dist/core/command-manager.d.ts +8 -0
- package/dist/core/command-manager.js +242 -0
- package/dist/core/command-manager.js.map +1 -0
- package/dist/core/config-field-definitions.d.ts +41 -0
- package/dist/core/config-field-definitions.js +38 -0
- package/dist/core/config-field-definitions.js.map +1 -0
- package/dist/core/config-manager.d.ts +102 -0
- package/dist/core/config-manager.js +451 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/config.d.ts +6 -0
- package/dist/core/config.js +20 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/custom-stdio.d.ts +9 -0
- package/dist/core/custom-stdio.js +2 -0
- package/dist/core/custom-stdio.js.map +1 -0
- package/dist/core/error-handlers.d.ts +7 -0
- package/dist/core/error-handlers.js +16 -0
- package/dist/core/error-handlers.js.map +1 -0
- package/dist/core/file-transfer.d.ts +16 -0
- package/dist/core/file-transfer.js +316 -0
- package/dist/core/file-transfer.js.map +1 -0
- package/dist/core/handlers/edit-search-handlers.d.ts +6 -0
- package/dist/core/handlers/edit-search-handlers.js +7 -0
- package/dist/core/handlers/edit-search-handlers.js.map +1 -0
- package/dist/core/handlers/filesystem-handlers.d.ts +38 -0
- package/dist/core/handlers/filesystem-handlers.js +535 -0
- package/dist/core/handlers/filesystem-handlers.js.map +1 -0
- package/dist/core/handlers/history-handlers.d.ts +12 -0
- package/dist/core/handlers/history-handlers.js +68 -0
- package/dist/core/handlers/history-handlers.js.map +1 -0
- package/dist/core/handlers/index.d.ts +7 -0
- package/dist/core/handlers/index.js +9 -0
- package/dist/core/handlers/index.js.map +1 -0
- package/dist/core/handlers/process-handlers.d.ts +9 -0
- package/dist/core/handlers/process-handlers.js +16 -0
- package/dist/core/handlers/process-handlers.js.map +1 -0
- package/dist/core/handlers/search-handlers.d.ts +17 -0
- package/dist/core/handlers/search-handlers.js +336 -0
- package/dist/core/handlers/search-handlers.js.map +1 -0
- package/dist/core/handlers/terminal-handlers.d.ts +21 -0
- package/dist/core/handlers/terminal-handlers.js +36 -0
- package/dist/core/handlers/terminal-handlers.js.map +1 -0
- package/dist/core/handlers/transfer-handlers.d.ts +4 -0
- package/dist/core/handlers/transfer-handlers.js +76 -0
- package/dist/core/handlers/transfer-handlers.js.map +1 -0
- package/dist/core/search-manager.d.ts +162 -0
- package/dist/core/search-manager.js +929 -0
- package/dist/core/search-manager.js.map +1 -0
- package/dist/core/terminal-manager.d.ts +126 -0
- package/dist/core/terminal-manager.js +671 -0
- package/dist/core/terminal-manager.js.map +1 -0
- package/dist/core/tool-definitions.d.ts +9 -0
- package/dist/core/tool-definitions.js +1020 -0
- package/dist/core/tool-definitions.js.map +1 -0
- package/dist/core/tools/config.d.ts +97 -0
- package/dist/core/tools/config.js +265 -0
- package/dist/core/tools/config.js.map +1 -0
- package/dist/core/tools/edit.d.ts +49 -0
- package/dist/core/tools/edit.js +540 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/feedback.d.ts +8 -0
- package/dist/core/tools/feedback.js +133 -0
- package/dist/core/tools/feedback.js.map +1 -0
- package/dist/core/tools/filesystem.d.ts +84 -0
- package/dist/core/tools/filesystem.js +991 -0
- package/dist/core/tools/filesystem.js.map +1 -0
- package/dist/core/tools/fuzzySearch.d.ts +14 -0
- package/dist/core/tools/fuzzySearch.js +141 -0
- package/dist/core/tools/fuzzySearch.js.map +1 -0
- package/dist/core/tools/fuzzySearchCore.d.ts +52 -0
- package/dist/core/tools/fuzzySearchCore.js +126 -0
- package/dist/core/tools/fuzzySearchCore.js.map +1 -0
- package/dist/core/tools/improved-process-tools.d.ts +24 -0
- package/dist/core/tools/improved-process-tools.js +645 -0
- package/dist/core/tools/improved-process-tools.js.map +1 -0
- package/dist/core/tools/mime-types.d.ts +3 -0
- package/dist/core/tools/mime-types.js +29 -0
- package/dist/core/tools/mime-types.js.map +1 -0
- package/dist/core/tools/pdf/extract-images.d.ts +34 -0
- package/dist/core/tools/pdf/extract-images.js +133 -0
- package/dist/core/tools/pdf/extract-images.js.map +1 -0
- package/dist/core/tools/pdf/index.d.ts +6 -0
- package/dist/core/tools/pdf/index.js +4 -0
- package/dist/core/tools/pdf/index.js.map +1 -0
- package/dist/core/tools/pdf/lib/pdf2md.d.ts +36 -0
- package/dist/core/tools/pdf/lib/pdf2md.js +77 -0
- package/dist/core/tools/pdf/lib/pdf2md.js.map +1 -0
- package/dist/core/tools/pdf/manipulations.d.ts +13 -0
- package/dist/core/tools/pdf/manipulations.js +100 -0
- package/dist/core/tools/pdf/manipulations.js.map +1 -0
- package/dist/core/tools/pdf/markdown.d.ts +26 -0
- package/dist/core/tools/pdf/markdown.js +276 -0
- package/dist/core/tools/pdf/markdown.js.map +1 -0
- package/dist/core/tools/pdf/utils.d.ts +12 -0
- package/dist/core/tools/pdf/utils.js +35 -0
- package/dist/core/tools/pdf/utils.js.map +1 -0
- package/dist/core/tools/process.d.ts +17 -0
- package/dist/core/tools/process.js +88 -0
- package/dist/core/tools/process.js.map +1 -0
- package/dist/core/tools/prompts.d.ts +28 -0
- package/dist/core/tools/prompts.js +260 -0
- package/dist/core/tools/prompts.js.map +1 -0
- package/dist/core/tools/schemas.d.ts +594 -0
- package/dist/core/tools/schemas.js +282 -0
- package/dist/core/tools/schemas.js.map +1 -0
- package/dist/core/tools/usage.d.ts +5 -0
- package/dist/core/tools/usage.js +25 -0
- package/dist/core/tools/usage.js.map +1 -0
- package/dist/core/types.d.ts +83 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/ui/file-preview/shared/preview-file-types.d.ts +5 -0
- package/dist/core/ui/file-preview/shared/preview-file-types.js +60 -0
- package/dist/core/ui/file-preview/shared/preview-file-types.js.map +1 -0
- package/dist/core/utils/ab-test.d.ts +12 -0
- package/dist/core/utils/ab-test.js +105 -0
- package/dist/core/utils/ab-test.js.map +1 -0
- package/dist/core/utils/capture.d.ts +12 -0
- package/dist/core/utils/capture.js +38 -0
- package/dist/core/utils/capture.js.map +1 -0
- package/dist/core/utils/dockerPrompt.d.ts +17 -0
- package/dist/core/utils/dockerPrompt.js +54 -0
- package/dist/core/utils/dockerPrompt.js.map +1 -0
- package/dist/core/utils/feature-flags.d.ts +59 -0
- package/dist/core/utils/feature-flags.js +218 -0
- package/dist/core/utils/feature-flags.js.map +1 -0
- package/dist/core/utils/files/base.d.ts +173 -0
- package/dist/core/utils/files/base.js +6 -0
- package/dist/core/utils/files/base.js.map +1 -0
- package/dist/core/utils/files/binary.d.ts +21 -0
- package/dist/core/utils/files/binary.js +66 -0
- package/dist/core/utils/files/binary.js.map +1 -0
- package/dist/core/utils/files/docx.d.ts +47 -0
- package/dist/core/utils/files/docx.js +678 -0
- package/dist/core/utils/files/docx.js.map +1 -0
- package/dist/core/utils/files/excel.d.ts +24 -0
- package/dist/core/utils/files/excel.js +438 -0
- package/dist/core/utils/files/excel.js.map +1 -0
- package/dist/core/utils/files/factory.d.ts +29 -0
- package/dist/core/utils/files/factory.js +103 -0
- package/dist/core/utils/files/factory.js.map +1 -0
- package/dist/core/utils/files/image.d.ts +21 -0
- package/dist/core/utils/files/image.js +79 -0
- package/dist/core/utils/files/image.js.map +1 -0
- package/dist/core/utils/files/index.d.ts +9 -0
- package/dist/core/utils/files/index.js +15 -0
- package/dist/core/utils/files/index.js.map +1 -0
- package/dist/core/utils/files/pdf.d.ts +32 -0
- package/dist/core/utils/files/pdf.js +141 -0
- package/dist/core/utils/files/pdf.js.map +1 -0
- package/dist/core/utils/files/text.d.ts +70 -0
- package/dist/core/utils/files/text.js +552 -0
- package/dist/core/utils/files/text.js.map +1 -0
- package/dist/core/utils/fuzzySearchLogger.d.ts +26 -0
- package/dist/core/utils/fuzzySearchLogger.js +9 -0
- package/dist/core/utils/fuzzySearchLogger.js.map +1 -0
- package/dist/core/utils/lineEndingHandler.d.ts +21 -0
- package/dist/core/utils/lineEndingHandler.js +78 -0
- package/dist/core/utils/lineEndingHandler.js.map +1 -0
- package/dist/core/utils/logger.d.ts +17 -0
- package/dist/core/utils/logger.js +5 -0
- package/dist/core/utils/logger.js.map +1 -0
- package/dist/core/utils/mcp-ui-ab-test.d.ts +13 -0
- package/dist/core/utils/mcp-ui-ab-test.js +63 -0
- package/dist/core/utils/mcp-ui-ab-test.js.map +1 -0
- package/dist/core/utils/open-browser.d.ts +9 -0
- package/dist/core/utils/open-browser.js +47 -0
- package/dist/core/utils/open-browser.js.map +1 -0
- package/dist/core/utils/process-detection.d.ts +23 -0
- package/dist/core/utils/process-detection.js +151 -0
- package/dist/core/utils/process-detection.js.map +1 -0
- package/dist/core/utils/ripgrep-resolver.d.ts +9 -0
- package/dist/core/utils/ripgrep-resolver.js +96 -0
- package/dist/core/utils/ripgrep-resolver.js.map +1 -0
- package/dist/core/utils/system-info.d.ts +72 -0
- package/dist/core/utils/system-info.js +723 -0
- package/dist/core/utils/system-info.js.map +1 -0
- package/dist/core/utils/toolHistory.d.ts +31 -0
- package/dist/core/utils/toolHistory.js +17 -0
- package/dist/core/utils/toolHistory.js.map +1 -0
- package/dist/core/utils/trackTools.d.ts +1 -0
- package/dist/core/utils/trackTools.js +3 -0
- package/dist/core/utils/trackTools.js.map +1 -0
- package/dist/core/utils/unsupportedParams.d.ts +24 -0
- package/dist/core/utils/unsupportedParams.js +67 -0
- package/dist/core/utils/unsupportedParams.js.map +1 -0
- package/dist/core/utils/usageTracker.d.ts +125 -0
- package/dist/core/utils/usageTracker.js +475 -0
- package/dist/core/utils/usageTracker.js.map +1 -0
- package/dist/core/utils/welcome-onboarding.d.ts +11 -0
- package/dist/core/utils/welcome-onboarding.js +100 -0
- package/dist/core/utils/welcome-onboarding.js.map +1 -0
- package/dist/core/utils/withTimeout.d.ts +28 -0
- package/dist/core/utils/withTimeout.js +86 -0
- package/dist/core/utils/withTimeout.js.map +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +2 -0
- package/dist/core/version.js.map +1 -0
- package/dist/dispatcher.d.ts +7 -0
- package/dist/dispatcher.js +179 -0
- package/dist/dispatcher.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/cli-commands.d.ts +5 -0
- package/dist/plugins/cli-commands.js +240 -0
- package/dist/plugins/cli-commands.js.map +1 -0
- package/dist/plugins/defaults.d.ts +62 -0
- package/dist/plugins/defaults.js +260 -0
- package/dist/plugins/defaults.js.map +1 -0
- package/dist/plugins/first-run.d.ts +16 -0
- package/dist/plugins/first-run.js +89 -0
- package/dist/plugins/first-run.js.map +1 -0
- package/dist/plugins/host.d.ts +20 -0
- package/dist/plugins/host.js +175 -0
- package/dist/plugins/host.js.map +1 -0
- package/dist/plugins/installer.d.ts +21 -0
- package/dist/plugins/installer.js +350 -0
- package/dist/plugins/installer.js.map +1 -0
- package/dist/plugins/locate.d.ts +15 -0
- package/dist/plugins/locate.js +99 -0
- package/dist/plugins/locate.js.map +1 -0
- package/dist/plugins/manager.d.ts +32 -0
- package/dist/plugins/manager.js +139 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/paths.d.ts +32 -0
- package/dist/plugins/paths.js +49 -0
- package/dist/plugins/paths.js.map +1 -0
- package/dist/plugins/python.d.ts +55 -0
- package/dist/plugins/python.js +234 -0
- package/dist/plugins/python.js.map +1 -0
- package/dist/plugins/store.d.ts +12 -0
- package/dist/plugins/store.js +76 -0
- package/dist/plugins/store.js.map +1 -0
- package/dist/plugins/types.d.ts +112 -0
- package/dist/plugins/types.js +9 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/util.d.ts +37 -0
- package/dist/plugins/util.js +283 -0
- package/dist/plugins/util.js.map +1 -0
- package/dist/runtime/activity.d.ts +49 -0
- package/dist/runtime/activity.js +158 -0
- package/dist/runtime/activity.js.map +1 -0
- package/dist/runtime/browser-workflow.d.ts +21 -0
- package/dist/runtime/browser-workflow.js +51 -0
- package/dist/runtime/browser-workflow.js.map +1 -0
- package/dist/runtime/code-graph.d.ts +156 -0
- package/dist/runtime/code-graph.js +330 -0
- package/dist/runtime/code-graph.js.map +1 -0
- package/dist/runtime/code-structure.d.ts +53 -0
- package/dist/runtime/code-structure.js +152 -0
- package/dist/runtime/code-structure.js.map +1 -0
- package/dist/runtime/coding-session.d.ts +97 -0
- package/dist/runtime/coding-session.js +142 -0
- package/dist/runtime/coding-session.js.map +1 -0
- package/dist/runtime/docker-client.d.ts +47 -0
- package/dist/runtime/docker-client.js +40 -0
- package/dist/runtime/docker-client.js.map +1 -0
- package/dist/runtime/errors.d.ts +9 -0
- package/dist/runtime/errors.js +56 -0
- package/dist/runtime/errors.js.map +1 -0
- package/dist/runtime/failure-log.d.ts +22 -0
- package/dist/runtime/failure-log.js +112 -0
- package/dist/runtime/failure-log.js.map +1 -0
- package/dist/runtime/fast-batch.d.ts +55 -0
- package/dist/runtime/fast-batch.js +104 -0
- package/dist/runtime/fast-batch.js.map +1 -0
- package/dist/runtime/file-safety.d.ts +7 -0
- package/dist/runtime/file-safety.js +134 -0
- package/dist/runtime/file-safety.js.map +1 -0
- package/dist/runtime/generic-code.d.ts +9 -0
- package/dist/runtime/generic-code.js +123 -0
- package/dist/runtime/generic-code.js.map +1 -0
- package/dist/runtime/graph-outline.d.ts +54 -0
- package/dist/runtime/graph-outline.js +118 -0
- package/dist/runtime/graph-outline.js.map +1 -0
- package/dist/runtime/harness.d.ts +61 -0
- package/dist/runtime/harness.js +102 -0
- package/dist/runtime/harness.js.map +1 -0
- package/dist/runtime/instruction-context.d.ts +23 -0
- package/dist/runtime/instruction-context.js +136 -0
- package/dist/runtime/instruction-context.js.map +1 -0
- package/dist/runtime/lab-mode.d.ts +4 -0
- package/dist/runtime/lab-mode.js +18 -0
- package/dist/runtime/lab-mode.js.map +1 -0
- package/dist/runtime/languages.d.ts +30 -0
- package/dist/runtime/languages.js +59 -0
- package/dist/runtime/languages.js.map +1 -0
- package/dist/runtime/nav-cache.d.ts +2 -0
- package/dist/runtime/nav-cache.js +12 -0
- package/dist/runtime/nav-cache.js.map +1 -0
- package/dist/runtime/operations.d.ts +40 -0
- package/dist/runtime/operations.js +86 -0
- package/dist/runtime/operations.js.map +1 -0
- package/dist/runtime/platform-capabilities.d.ts +20 -0
- package/dist/runtime/platform-capabilities.js +36 -0
- package/dist/runtime/platform-capabilities.js.map +1 -0
- package/dist/runtime/program-runner.d.ts +4 -0
- package/dist/runtime/program-runner.js +73 -0
- package/dist/runtime/program-runner.js.map +1 -0
- package/dist/runtime/project-context.d.ts +53 -0
- package/dist/runtime/project-context.js +90 -0
- package/dist/runtime/project-context.js.map +1 -0
- package/dist/runtime/project-files.d.ts +2 -0
- package/dist/runtime/project-files.js +3 -0
- package/dist/runtime/project-files.js.map +1 -0
- package/dist/runtime/project-index.d.ts +40 -0
- package/dist/runtime/project-index.js +158 -0
- package/dist/runtime/project-index.js.map +1 -0
- package/dist/runtime/resource-limits.d.ts +42 -0
- package/dist/runtime/resource-limits.js +50 -0
- package/dist/runtime/resource-limits.js.map +1 -0
- package/dist/runtime/scratch-budget.d.ts +11 -0
- package/dist/runtime/scratch-budget.js +107 -0
- package/dist/runtime/scratch-budget.js.map +1 -0
- package/dist/runtime/search-diagnostics.d.ts +3 -0
- package/dist/runtime/search-diagnostics.js +45 -0
- package/dist/runtime/search-diagnostics.js.map +1 -0
- package/dist/runtime/toolchains.d.ts +25 -0
- package/dist/runtime/toolchains.js +70 -0
- package/dist/runtime/toolchains.js.map +1 -0
- package/dist/runtime/worker-coordination.d.ts +314 -0
- package/dist/runtime/worker-coordination.js +564 -0
- package/dist/runtime/worker-coordination.js.map +1 -0
- package/dist/runtime/workspace.d.ts +151 -0
- package/dist/runtime/workspace.js +267 -0
- package/dist/runtime/workspace.js.map +1 -0
- package/dist/service.d.ts +3 -0
- package/dist/service.js +102 -0
- package/dist/service.js.map +1 -0
- package/dist/terminal-setup.d.ts +33 -0
- package/dist/terminal-setup.js +219 -0
- package/dist/terminal-setup.js.map +1 -0
- package/dist/terminal-shortcuts.d.ts +22 -0
- package/dist/terminal-shortcuts.js +145 -0
- package/dist/terminal-shortcuts.js.map +1 -0
- package/dist/terminal-ui.d.ts +20 -0
- package/dist/terminal-ui.js +53 -0
- package/dist/terminal-ui.js.map +1 -0
- package/dist/tools/ast-grep.d.ts +132 -0
- package/dist/tools/ast-grep.js +625 -0
- package/dist/tools/ast-grep.js.map +1 -0
- package/dist/tools/brc-tools.d.ts +112 -0
- package/dist/tools/brc-tools.js +599 -0
- package/dist/tools/brc-tools.js.map +1 -0
- package/dist/tools/check-tools.d.ts +4 -0
- package/dist/tools/check-tools.js +29 -0
- package/dist/tools/check-tools.js.map +1 -0
- package/dist/tools/coding-tools.d.ts +33 -0
- package/dist/tools/coding-tools.js +190 -0
- package/dist/tools/coding-tools.js.map +1 -0
- package/dist/tools/command-shell.d.ts +17 -0
- package/dist/tools/command-shell.js +84 -0
- package/dist/tools/command-shell.js.map +1 -0
- package/dist/tools/dev-extras.d.ts +42 -0
- package/dist/tools/dev-extras.js +135 -0
- package/dist/tools/dev-extras.js.map +1 -0
- package/dist/tools/edit-tools.d.ts +4 -0
- package/dist/tools/edit-tools.js +293 -0
- package/dist/tools/edit-tools.js.map +1 -0
- package/dist/tools/fast-exec.d.ts +11 -0
- package/dist/tools/fast-exec.js +202 -0
- package/dist/tools/fast-exec.js.map +1 -0
- package/dist/tools/image-tools.d.ts +37 -0
- package/dist/tools/image-tools.js +293 -0
- package/dist/tools/image-tools.js.map +1 -0
- package/dist/tools/jobs.d.ts +227 -0
- package/dist/tools/jobs.js +608 -0
- package/dist/tools/jobs.js.map +1 -0
- package/dist/tools/ops-tools.d.ts +8 -0
- package/dist/tools/ops-tools.js +58 -0
- package/dist/tools/ops-tools.js.map +1 -0
- package/dist/tools/plugin-tools.d.ts +38 -0
- package/dist/tools/plugin-tools.js +133 -0
- package/dist/tools/plugin-tools.js.map +1 -0
- package/dist/tools/rtk.d.ts +60 -0
- package/dist/tools/rtk.js +245 -0
- package/dist/tools/rtk.js.map +1 -0
- package/dist/tools/sandbox-tools.d.ts +41 -0
- package/dist/tools/sandbox-tools.js +146 -0
- package/dist/tools/sandbox-tools.js.map +1 -0
- package/dist/tools/worker-tools.d.ts +231 -0
- package/dist/tools/worker-tools.js +55 -0
- package/dist/tools/worker-tools.js.map +1 -0
- package/dist/tools/workspace-batch.d.ts +262 -0
- package/dist/tools/workspace-batch.js +188 -0
- package/dist/tools/workspace-batch.js.map +1 -0
- package/dist/transport/pairing.d.ts +22 -0
- package/dist/transport/pairing.js +154 -0
- package/dist/transport/pairing.js.map +1 -0
- package/dist/transport/plugin-admin.d.ts +33 -0
- package/dist/transport/plugin-admin.js +156 -0
- package/dist/transport/plugin-admin.js.map +1 -0
- package/dist/transport/relay-url.d.ts +3 -0
- package/dist/transport/relay-url.js +38 -0
- package/dist/transport/relay-url.js.map +1 -0
- package/dist/transport/result-budget.d.ts +11 -0
- package/dist/transport/result-budget.js +45 -0
- package/dist/transport/result-budget.js.map +1 -0
- package/dist/transport/ws-client.d.ts +64 -0
- package/dist/transport/ws-client.js +242 -0
- package/dist/transport/ws-client.js.map +1 -0
- package/package.json +70 -5
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory pattern for creating appropriate file handlers
|
|
3
|
+
* Routes file operations to the correct handler based on file type
|
|
4
|
+
*
|
|
5
|
+
* Each handler implements canHandle() which can be sync (extension-based)
|
|
6
|
+
* or async (content-based like BinaryFileHandler using isBinaryFile)
|
|
7
|
+
*
|
|
8
|
+
* BRC: Excel/PDF/DOCX handlers pull in heavy libraries (exceljs, pdf-lib,
|
|
9
|
+
* md-to-pdf/puppeteer, unpdf, pizzip). They are loaded with dynamic import()
|
|
10
|
+
* only when a file of that type is actually touched, which keeps agent startup
|
|
11
|
+
* fast and memory low. Type routing is done by extension here.
|
|
12
|
+
*/
|
|
13
|
+
import { TextFileHandler } from './text.js';
|
|
14
|
+
import { ImageFileHandler } from './image.js';
|
|
15
|
+
import { BinaryFileHandler } from './binary.js';
|
|
16
|
+
const EXCEL_EXTENSIONS = ['.xlsx', '.xls', '.xlsm'];
|
|
17
|
+
const PDF_EXTENSIONS = ['.pdf'];
|
|
18
|
+
const DOCX_EXTENSIONS = ['.docx'];
|
|
19
|
+
function hasExt(filePath, exts) {
|
|
20
|
+
const lower = filePath.toLowerCase();
|
|
21
|
+
return exts.some(e => lower.endsWith(e));
|
|
22
|
+
}
|
|
23
|
+
// Singleton instances of each handler
|
|
24
|
+
let excelHandler = null;
|
|
25
|
+
let imageHandler = null;
|
|
26
|
+
let textHandler = null;
|
|
27
|
+
let binaryHandler = null;
|
|
28
|
+
let pdfHandler = null;
|
|
29
|
+
let docxHandler = null;
|
|
30
|
+
async function getExcelHandler() {
|
|
31
|
+
if (!excelHandler) {
|
|
32
|
+
const { ExcelFileHandler } = await import('./excel.js');
|
|
33
|
+
excelHandler = new ExcelFileHandler();
|
|
34
|
+
}
|
|
35
|
+
return excelHandler;
|
|
36
|
+
}
|
|
37
|
+
async function getPdfHandler() {
|
|
38
|
+
if (!pdfHandler) {
|
|
39
|
+
const { PdfFileHandler } = await import('./pdf.js');
|
|
40
|
+
pdfHandler = new PdfFileHandler();
|
|
41
|
+
}
|
|
42
|
+
return pdfHandler;
|
|
43
|
+
}
|
|
44
|
+
async function getDocxHandler() {
|
|
45
|
+
if (!docxHandler) {
|
|
46
|
+
const { DocxFileHandler } = await import('./docx.js');
|
|
47
|
+
docxHandler = new DocxFileHandler();
|
|
48
|
+
}
|
|
49
|
+
return docxHandler;
|
|
50
|
+
}
|
|
51
|
+
function getImageHandler() {
|
|
52
|
+
if (!imageHandler)
|
|
53
|
+
imageHandler = new ImageFileHandler();
|
|
54
|
+
return imageHandler;
|
|
55
|
+
}
|
|
56
|
+
function getTextHandler() {
|
|
57
|
+
if (!textHandler)
|
|
58
|
+
textHandler = new TextFileHandler();
|
|
59
|
+
return textHandler;
|
|
60
|
+
}
|
|
61
|
+
function getBinaryHandler() {
|
|
62
|
+
if (!binaryHandler)
|
|
63
|
+
binaryHandler = new BinaryFileHandler();
|
|
64
|
+
return binaryHandler;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the appropriate file handler for a given file path
|
|
68
|
+
*
|
|
69
|
+
* Priority order:
|
|
70
|
+
* 1. DOCX files (extension based)
|
|
71
|
+
* 2. PDF files (extension based)
|
|
72
|
+
* 3. Excel files (xlsx, xls, xlsm) - extension based
|
|
73
|
+
* 4. Image files (png, jpg, gif, webp) - extension based
|
|
74
|
+
* 5. Binary files - content-based detection via isBinaryFile
|
|
75
|
+
* 6. Text files (default)
|
|
76
|
+
*/
|
|
77
|
+
export async function getFileHandler(filePath) {
|
|
78
|
+
if (hasExt(filePath, DOCX_EXTENSIONS))
|
|
79
|
+
return getDocxHandler();
|
|
80
|
+
if (hasExt(filePath, PDF_EXTENSIONS))
|
|
81
|
+
return getPdfHandler();
|
|
82
|
+
if (hasExt(filePath, EXCEL_EXTENSIONS))
|
|
83
|
+
return getExcelHandler();
|
|
84
|
+
// Check Image (extension-based, sync - images are binary but handled specially)
|
|
85
|
+
if (getImageHandler().canHandle(filePath)) {
|
|
86
|
+
return getImageHandler();
|
|
87
|
+
}
|
|
88
|
+
// Check Binary (content-based, async via isBinaryFile)
|
|
89
|
+
if (await getBinaryHandler().canHandle(filePath)) {
|
|
90
|
+
return getBinaryHandler();
|
|
91
|
+
}
|
|
92
|
+
// Default to text handler
|
|
93
|
+
return getTextHandler();
|
|
94
|
+
}
|
|
95
|
+
/** Check if a file path is an Excel file (extension based, no heavy import). */
|
|
96
|
+
export function isExcelFile(path) {
|
|
97
|
+
return hasExt(path, EXCEL_EXTENSIONS);
|
|
98
|
+
}
|
|
99
|
+
/** Check if a file path is an image file. */
|
|
100
|
+
export function isImageFile(path) {
|
|
101
|
+
return getImageHandler().canHandle(path);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../packages/agent/src/core/utils/files/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACpD,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,CAAC;AAChC,MAAM,eAAe,GAAG,CAAC,OAAO,CAAC,CAAC;AAElC,SAAS,MAAM,CAAC,QAAgB,EAAE,IAAc;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,sCAAsC;AACtC,IAAI,YAAY,GAAuB,IAAI,CAAC;AAC5C,IAAI,YAAY,GAA4B,IAAI,CAAC;AACjD,IAAI,WAAW,GAA2B,IAAI,CAAC;AAC/C,IAAI,aAAa,GAA6B,IAAI,CAAC;AACnD,IAAI,UAAU,GAAuB,IAAI,CAAC;AAC1C,IAAI,WAAW,GAAuB,IAAI,CAAC;AAE3C,KAAK,UAAU,eAAe;IAC1B,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAA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,IAAI,eAAe,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxC,OAAO,eAAe,EAAE,CAAC;IAC7B,CAAC;IAED,uDAAuD;IACvD,IAAI,MAAM,gBAAgB,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/C,OAAO,gBAAgB,EAAE,CAAC;IAC9B,CAAC;IAED,0BAA0B;IAC1B,OAAO,cAAc,EAAE,CAAC;AAC5B,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,OAAO,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,OAAO,eAAe,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image file handler
|
|
3
|
+
* Handles reading image files and converting to base64
|
|
4
|
+
*/
|
|
5
|
+
import { FileHandler, ReadOptions, FileResult, FileInfo } from './base.js';
|
|
6
|
+
/**
|
|
7
|
+
* Image file handler implementation
|
|
8
|
+
* Supports: PNG, JPEG, GIF, WebP, BMP, SVG
|
|
9
|
+
*/
|
|
10
|
+
export declare class ImageFileHandler implements FileHandler {
|
|
11
|
+
private static readonly IMAGE_EXTENSIONS;
|
|
12
|
+
private static readonly IMAGE_MIME_TYPES;
|
|
13
|
+
canHandle(path: string): boolean;
|
|
14
|
+
read(path: string, options?: ReadOptions): Promise<FileResult>;
|
|
15
|
+
write(path: string, content: Buffer | string): Promise<void>;
|
|
16
|
+
getInfo(path: string): Promise<FileInfo>;
|
|
17
|
+
/**
|
|
18
|
+
* Get MIME type for image based on file extension
|
|
19
|
+
*/
|
|
20
|
+
private getMimeType;
|
|
21
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image file handler
|
|
3
|
+
* Handles reading image files and converting to base64
|
|
4
|
+
*/
|
|
5
|
+
import fs from "fs/promises";
|
|
6
|
+
/**
|
|
7
|
+
* Image file handler implementation
|
|
8
|
+
* Supports: PNG, JPEG, GIF, WebP, BMP, SVG
|
|
9
|
+
*/
|
|
10
|
+
export class ImageFileHandler {
|
|
11
|
+
static IMAGE_EXTENSIONS = [
|
|
12
|
+
'.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.svg'
|
|
13
|
+
];
|
|
14
|
+
static IMAGE_MIME_TYPES = {
|
|
15
|
+
'.png': 'image/png',
|
|
16
|
+
'.jpg': 'image/jpeg',
|
|
17
|
+
'.jpeg': 'image/jpeg',
|
|
18
|
+
'.gif': 'image/gif',
|
|
19
|
+
'.webp': 'image/webp',
|
|
20
|
+
'.bmp': 'image/bmp',
|
|
21
|
+
'.svg': 'image/svg+xml'
|
|
22
|
+
};
|
|
23
|
+
canHandle(path) {
|
|
24
|
+
const lowerPath = path.toLowerCase();
|
|
25
|
+
return ImageFileHandler.IMAGE_EXTENSIONS.some(ext => lowerPath.endsWith(ext));
|
|
26
|
+
}
|
|
27
|
+
async read(path, options) {
|
|
28
|
+
// Images are always read in full, ignoring offset and length
|
|
29
|
+
const buffer = await fs.readFile(path, { signal: options?.signal });
|
|
30
|
+
const content = buffer.toString('base64');
|
|
31
|
+
const mimeType = this.getMimeType(path);
|
|
32
|
+
return {
|
|
33
|
+
content,
|
|
34
|
+
mimeType,
|
|
35
|
+
metadata: {
|
|
36
|
+
isImage: true
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async write(path, content) {
|
|
41
|
+
// If content is base64 string, convert to buffer
|
|
42
|
+
if (typeof content === 'string') {
|
|
43
|
+
const buffer = Buffer.from(content, 'base64');
|
|
44
|
+
await fs.writeFile(path, buffer);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
await fs.writeFile(path, content);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async getInfo(path) {
|
|
51
|
+
const stats = await fs.stat(path);
|
|
52
|
+
return {
|
|
53
|
+
size: stats.size,
|
|
54
|
+
created: stats.birthtime,
|
|
55
|
+
modified: stats.mtime,
|
|
56
|
+
accessed: stats.atime,
|
|
57
|
+
isDirectory: stats.isDirectory(),
|
|
58
|
+
isFile: stats.isFile(),
|
|
59
|
+
permissions: stats.mode.toString(8).slice(-3),
|
|
60
|
+
fileType: 'image',
|
|
61
|
+
metadata: {
|
|
62
|
+
isImage: true
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get MIME type for image based on file extension
|
|
68
|
+
*/
|
|
69
|
+
getMimeType(path) {
|
|
70
|
+
const lowerPath = path.toLowerCase();
|
|
71
|
+
for (const [ext, mimeType] of Object.entries(ImageFileHandler.IMAGE_MIME_TYPES)) {
|
|
72
|
+
if (lowerPath.endsWith(ext)) {
|
|
73
|
+
return mimeType;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return 'application/octet-stream'; // Fallback
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../../packages/agent/src/core/utils/files/image.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ7B;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACjB,MAAM,CAAU,gBAAgB,GAAG;QACvC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;KAC3D,CAAC;IAEM,MAAM,CAAU,gBAAgB,GAA8B;QAClE,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,YAAY;QACpB,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,YAAY;QACrB,MAAM,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AO,EAAE,KAAK,CAAC,SAAS;YACxB,QAAQ,EAAE,KAAK,CAAC,KAAK;YACrB,QAAQ,EAAE,KAAK,CAAC,KAAK;YACrB,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE;YAChC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;YACtB,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC7C,QAAQ,EAAE,OAAO;YACjB,QAAQ,EAAE;gBACN,OAAO,EAAE,IAAI;aAChB;SACJ,CAAC;IACN,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,IAAY;QAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACrC,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC9E,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1B,OAAO,QAAQ,CAAC;YACpB,CAAC;QACL,CAAC;QACD,OAAO,0BAA0B,CAAC,CAAC,WAAW;IAClD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File handling system
|
|
3
|
+
* Exports all file handlers, interfaces, and utilities
|
|
4
|
+
*/
|
|
5
|
+
export * from './base.js';
|
|
6
|
+
export { getFileHandler, isExcelFile, isImageFile } from './factory.js';
|
|
7
|
+
export { TextFileHandler } from './text.js';
|
|
8
|
+
export { ImageFileHandler } from './image.js';
|
|
9
|
+
export { BinaryFileHandler } from './binary.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File handling system
|
|
3
|
+
* Exports all file handlers, interfaces, and utilities
|
|
4
|
+
*/
|
|
5
|
+
// Base interfaces and types
|
|
6
|
+
export * from './base.js';
|
|
7
|
+
// Factory function
|
|
8
|
+
export { getFileHandler, isExcelFile, isImageFile } from './factory.js';
|
|
9
|
+
// File handlers
|
|
10
|
+
export { TextFileHandler } from './text.js';
|
|
11
|
+
export { ImageFileHandler } from './image.js';
|
|
12
|
+
export { BinaryFileHandler } from './binary.js';
|
|
13
|
+
// ExcelFileHandler / PdfFileHandler / DocxFileHandler are intentionally NOT
|
|
14
|
+
// re-exported: they are loaded lazily by factory.ts (heavy dependencies).
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/agent/src/core/utils/files/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4BAA4B;AAC5B,cAAc,WAAW,CAAC;AAE1B,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAExE,gBAAgB;AAChB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,4EAA4E;AAC5E,0EAA0E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF File Handler
|
|
3
|
+
* Implements FileHandler interface for PDF documents
|
|
4
|
+
*/
|
|
5
|
+
import { FileHandler, FileResult, FileInfo, ReadOptions, EditResult } from './base.js';
|
|
6
|
+
/**
|
|
7
|
+
* File handler for PDF documents
|
|
8
|
+
* Extracts text and images, supports page-based pagination
|
|
9
|
+
*/
|
|
10
|
+
export declare class PdfFileHandler implements FileHandler {
|
|
11
|
+
private readonly extensions;
|
|
12
|
+
/**
|
|
13
|
+
* Check if this handler can handle the given file
|
|
14
|
+
*/
|
|
15
|
+
canHandle(path: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Read PDF content - extracts text as markdown with images
|
|
18
|
+
*/
|
|
19
|
+
read(path: string, options?: ReadOptions): Promise<FileResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Write PDF - creates from markdown or operations
|
|
22
|
+
*/
|
|
23
|
+
write(path: string, content: any, mode?: 'rewrite' | 'append'): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Edit PDF by range/operations
|
|
26
|
+
*/
|
|
27
|
+
editRange(path: string, range: string, content: any, options?: Record<string, any>): Promise<EditResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Get PDF file information
|
|
30
|
+
*/
|
|
31
|
+
getInfo(path: string): Promise<FileInfo>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF File Handler
|
|
3
|
+
* Implements FileHandler interface for PDF documents
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'fs/promises';
|
|
6
|
+
import { parsePdfToMarkdown, parseMarkdownToPdf, editPdf } from '../../tools/pdf/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* File handler for PDF documents
|
|
9
|
+
* Extracts text and images, supports page-based pagination
|
|
10
|
+
*/
|
|
11
|
+
export class PdfFileHandler {
|
|
12
|
+
extensions = ['.pdf'];
|
|
13
|
+
/**
|
|
14
|
+
* Check if this handler can handle the given file
|
|
15
|
+
*/
|
|
16
|
+
canHandle(path) {
|
|
17
|
+
const ext = path.toLowerCase();
|
|
18
|
+
return this.extensions.some(e => ext.endsWith(e));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read PDF content - extracts text as markdown with images
|
|
22
|
+
*/
|
|
23
|
+
async read(path, options) {
|
|
24
|
+
const { offset = 0, length } = options ?? {};
|
|
25
|
+
try {
|
|
26
|
+
// Use existing PDF parser
|
|
27
|
+
// Ensure we pass a valid PageRange or number array
|
|
28
|
+
// If length is undefined, we assume "rest of file" which requires careful handling.
|
|
29
|
+
// If length is defined, we pass { offset, length }.
|
|
30
|
+
// If neither, we pass empty array (all pages).
|
|
31
|
+
// Note: offset defaults to 0 if undefined.
|
|
32
|
+
let range;
|
|
33
|
+
if (length !== undefined) {
|
|
34
|
+
range = { offset, length };
|
|
35
|
+
}
|
|
36
|
+
else if (offset > 0) {
|
|
37
|
+
// If offset provided but no length, try to read reasonable amount or all?
|
|
38
|
+
// PageRange requires length. Let's assume 0 means "all" or use a large number?
|
|
39
|
+
// Looking at pdf2md implementation, it uses generatePageNumbers(offset, length, total).
|
|
40
|
+
// We'll pass 0 for length to imply "rest" if supported, or just undefined length if valid.
|
|
41
|
+
// But typescript requires length.
|
|
42
|
+
range = { offset, length: 0 };
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
range = [];
|
|
46
|
+
}
|
|
47
|
+
const pdfResult = await parsePdfToMarkdown(path, range);
|
|
48
|
+
return {
|
|
49
|
+
content: '', // Main content is in metadata.pages
|
|
50
|
+
mimeType: 'application/pdf',
|
|
51
|
+
metadata: {
|
|
52
|
+
isPdf: true,
|
|
53
|
+
author: pdfResult.metadata.author,
|
|
54
|
+
title: pdfResult.metadata.title,
|
|
55
|
+
totalPages: pdfResult.metadata.totalPages,
|
|
56
|
+
pages: pdfResult.pages
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
62
|
+
return {
|
|
63
|
+
content: `Error reading PDF: ${errorMessage}`,
|
|
64
|
+
mimeType: 'text/plain',
|
|
65
|
+
metadata: {
|
|
66
|
+
error: true,
|
|
67
|
+
errorMessage
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Write PDF - creates from markdown or operations
|
|
74
|
+
*/
|
|
75
|
+
async write(path, content, mode) {
|
|
76
|
+
// If content is string, treat as markdown to convert
|
|
77
|
+
if (typeof content === 'string') {
|
|
78
|
+
await parseMarkdownToPdf(content, path);
|
|
79
|
+
}
|
|
80
|
+
else if (Array.isArray(content)) {
|
|
81
|
+
// Array of operations - use editPdf
|
|
82
|
+
const resultBuffer = await editPdf(path, content);
|
|
83
|
+
await fs.writeFile(path, resultBuffer);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error('PDF write requires markdown string or array of operations');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Edit PDF by range/operations
|
|
91
|
+
*/
|
|
92
|
+
async editRange(path, range, content, options) {
|
|
93
|
+
try {
|
|
94
|
+
// For PDF, range editing isn't directly supported
|
|
95
|
+
// Could interpret range as page numbers in future
|
|
96
|
+
const resultBuffer = await editPdf(path, content);
|
|
97
|
+
await fs.writeFile(options?.outputPath || path, resultBuffer);
|
|
98
|
+
return { success: true, editsApplied: 1 };
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
editsApplied: 0,
|
|
105
|
+
errors: [{ location: range, error: errorMessage }]
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get PDF file information
|
|
111
|
+
*/
|
|
112
|
+
async getInfo(path) {
|
|
113
|
+
const stats = await fs.stat(path);
|
|
114
|
+
// Get basic PDF metadata
|
|
115
|
+
let metadata = { isPdf: true };
|
|
116
|
+
try {
|
|
117
|
+
const pdfResult = await parsePdfToMarkdown(path, { offset: 0, length: 0 }); // Just metadata
|
|
118
|
+
metadata = {
|
|
119
|
+
isPdf: true,
|
|
120
|
+
title: pdfResult.metadata.title,
|
|
121
|
+
author: pdfResult.metadata.author,
|
|
122
|
+
totalPages: pdfResult.metadata.totalPages
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// If we can't parse, just return basic info
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
size: stats.size,
|
|
130
|
+
created: stats.birthtime,
|
|
131
|
+
modified: stats.mtime,
|
|
132
|
+
accessed: stats.atime,
|
|
133
|
+
isDirectory: false,
|
|
134
|
+
isFile: true,
|
|
135
|
+
permissions: (stats.mode & 0o777).toString(8),
|
|
136
|
+
fileType: 'binary',
|
|
137
|
+
metadata
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=pdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf.js","sourceRoot":"","sources":["../../../../../packages/agent/src/core/utils/files/pdf.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAE3F;;;GAGG;AACH,MAAM,OAAO,cAAc;IACN,UAAU,GAAG,CAAC,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,SAAS,CAAC,IAAY;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,OAAqB;QAC1C,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAE7C,IAAI,CAAC;YACD,0BAA0B;YAC1B,mDAAmD;YACnD,oFAAoF;YACpF,oDAAoD;YACpD,+CAA+C;YAC/C,2CAA2C;YAE3C,IAAI,KAAU,CAAC;YACf,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,KAAK,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YAC/B,CAAC;iBAAM,IAAI,MAAM,GAAG,CAAC,EAAE,CAA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,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB;YAC5F,QAAQ,GAAG;gBACP,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,KAAK;gBAC/B,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM;gBACjC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,UAAU;aAC5C,CAAC;QACN,CAAC;QAAC,MAAM,CAAC;YACL,4CAA4C;QAChD,CAAC;QAED,OAAO;YACH,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,SAAS;YACxB,QAAQ,EAAE,KAAK,CAAC,KAAK;YACrB,QAAQ,EAAE,KAAK,CAAC,KAAK;YACrB,WAAW,EAAE,KAAK;YAClB,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC7C,QAAQ,EAAE,QAAQ;YAClB,QAAQ;SACX,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text file handler
|
|
3
|
+
* Handles reading, writing, and editing text files
|
|
4
|
+
*
|
|
5
|
+
* Binary detection is handled at the factory level (factory.ts) using isBinaryFile.
|
|
6
|
+
* This handler only receives files that have been confirmed as text.
|
|
7
|
+
*
|
|
8
|
+
* TECHNICAL DEBT:
|
|
9
|
+
* This handler is missing editRange() - text search/replace logic currently lives in
|
|
10
|
+
* src/tools/edit.ts (performSearchReplace function) instead of here.
|
|
11
|
+
*
|
|
12
|
+
* For architectural consistency with ExcelFileHandler.editRange(), the fuzzy
|
|
13
|
+
* search/replace logic should be moved here. See comment in src/tools/edit.ts.
|
|
14
|
+
*/
|
|
15
|
+
import { FileHandler, ReadOptions, FileResult, FileInfo } from './base.js';
|
|
16
|
+
/**
|
|
17
|
+
* Text file handler implementation
|
|
18
|
+
* Binary detection is done at the factory level - this handler assumes file is text
|
|
19
|
+
*/
|
|
20
|
+
export declare class TextFileHandler implements FileHandler {
|
|
21
|
+
canHandle(_path: string): boolean;
|
|
22
|
+
private detectTextEncoding;
|
|
23
|
+
read(filePath: string, options?: ReadOptions): Promise<FileResult>;
|
|
24
|
+
write(path: string, content: string, mode?: 'rewrite' | 'append'): Promise<void>;
|
|
25
|
+
getInfo(path: string): Promise<FileInfo>;
|
|
26
|
+
/**
|
|
27
|
+
* Count lines in text content
|
|
28
|
+
* Made static and public for use by other modules (e.g., writeFile telemetry in filesystem.ts)
|
|
29
|
+
*/
|
|
30
|
+
static countLines(content: string): number;
|
|
31
|
+
/**
|
|
32
|
+
* Get file line count (for files under size limit)
|
|
33
|
+
*/
|
|
34
|
+
private getFileLineCount;
|
|
35
|
+
/**
|
|
36
|
+
* Generate enhanced status message
|
|
37
|
+
*/
|
|
38
|
+
private generateEnhancedStatusMessage;
|
|
39
|
+
/**
|
|
40
|
+
* Split text into lines while preserving line endings
|
|
41
|
+
* Made static and public for use by other modules (e.g., readFileInternal in filesystem.ts)
|
|
42
|
+
*/
|
|
43
|
+
static splitLinesPreservingEndings(content: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Read file with smart positioning for optimal performance
|
|
46
|
+
*/
|
|
47
|
+
private readFileWithSmartPositioning;
|
|
48
|
+
/**
|
|
49
|
+
* BRC: lines [offset, offset+length) of a large UTF-8 file, found by scanning 1 MB chunks for
|
|
50
|
+
* newline bytes; only the requested window is decoded. Returns null (caller falls back to the
|
|
51
|
+
* original readers) if a lone \r is seen before the window is complete.
|
|
52
|
+
*/
|
|
53
|
+
private readWindowByScanning;
|
|
54
|
+
/**
|
|
55
|
+
* Read last N lines efficiently by reading file backwards
|
|
56
|
+
*/
|
|
57
|
+
private readLastNLinesReverse;
|
|
58
|
+
/**
|
|
59
|
+
* Read from end using readline with circular buffer
|
|
60
|
+
*/
|
|
61
|
+
private readFromEndWithReadline;
|
|
62
|
+
/**
|
|
63
|
+
* Read from start/middle using readline
|
|
64
|
+
*/
|
|
65
|
+
private readFromStartWithReadline;
|
|
66
|
+
/**
|
|
67
|
+
* Read from estimated byte position for very large files
|
|
68
|
+
*/
|
|
69
|
+
private readFromEstimatedPosition;
|
|
70
|
+
}
|