@gajae-code/coding-agent 0.17.2 → 0.17.5
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/CHANGELOG.md +267 -0
- package/dist/types/cli/daemon-cli.d.ts +3 -1
- package/dist/types/cli/github-release.d.ts +17 -0
- package/dist/types/cli/public-command-entry.d.ts +56 -0
- package/dist/types/cli/public-command-errors.d.ts +126 -0
- package/dist/types/cli/public-command-evidence.d.ts +99 -0
- package/dist/types/cli/public-command-help.d.ts +65 -0
- package/dist/types/cli/public-command-registry.d.ts +69 -0
- package/dist/types/cli/session-picker.d.ts +1 -1
- package/dist/types/cli/setup-cli.d.ts +1 -0
- package/dist/types/cli/skills-cli.d.ts +5 -0
- package/dist/types/cli.d.ts +3 -0
- package/dist/types/commands/daemon.d.ts +4 -50
- package/dist/types/commands/sdk.d.ts +20 -37
- package/dist/types/commands/setup.d.ts +3 -0
- package/dist/types/commands/skills.d.ts +9 -0
- package/dist/types/config/autorouting-tier-map.d.ts +1049 -3
- package/dist/types/config/file-lock.d.ts +13 -3
- package/dist/types/config/model-profile-activation.d.ts +45 -1
- package/dist/types/config/model-registry.d.ts +14 -3
- package/dist/types/config/model-resolver.d.ts +1 -1
- package/dist/types/config/settings-schema.d.ts +11 -0
- package/dist/types/coordinator-mcp/question-state.d.ts +6 -1
- package/dist/types/daemon/operator-contract.d.ts +5 -1
- package/dist/types/eval/js/worker-protocol.d.ts +2 -0
- package/dist/types/exec/bash-executor.d.ts +2 -0
- package/dist/types/extensibility/extensions/types.d.ts +12 -0
- package/dist/types/extensibility/gjc-plugins/registry.d.ts +4 -0
- package/dist/types/extensibility/gjc-plugins/runtime-adapters.d.ts +11 -2
- package/dist/types/extensibility/runtime-skill-discovery.d.ts +18 -0
- package/dist/types/extensibility/shared-events.d.ts +3 -1
- package/dist/types/gjc-runtime/session-state-lock.d.ts +61 -0
- package/dist/types/gjc-runtime/state-writer.d.ts +14 -1
- package/dist/types/harness-control-plane/control-endpoint.d.ts +4 -1
- package/dist/types/harness-control-plane/finalize.d.ts +14 -3
- package/dist/types/internal-urls/embedded-protocol.d.ts +9 -0
- package/dist/types/internal-urls/index.d.ts +1 -0
- package/dist/types/internal-urls/parse.d.ts +9 -1
- package/dist/types/main.d.ts +23 -1
- package/dist/types/modes/acp/acp-agent.d.ts +55 -1
- package/dist/types/modes/acp/startup-provenance.d.ts +16 -0
- package/dist/types/modes/components/custom-provider-wizard.d.ts +19 -1
- package/dist/types/modes/components/session-selector.d.ts +5 -2
- package/dist/types/modes/components/user-message-selector.d.ts +5 -2
- package/dist/types/modes/controllers/command-controller.d.ts +1 -1
- package/dist/types/modes/controllers/selector-controller.d.ts +1 -1
- package/dist/types/modes/interactive-mode.d.ts +1 -1
- package/dist/types/modes/shared/agent-wire/workflow-gate-broker.d.ts +11 -1
- package/dist/types/modes/shared/agent-wire/workflow-gate-types.d.ts +14 -1
- package/dist/types/modes/types.d.ts +2 -2
- package/dist/types/runtime/process-lifecycle.d.ts +2 -0
- package/dist/types/runtime-mcp/loader.d.ts +2 -0
- package/dist/types/runtime-mcp/manager.d.ts +69 -6
- package/dist/types/runtime-mcp/pool.d.ts +17 -0
- package/dist/types/runtime-mcp/redaction.d.ts +20 -0
- package/dist/types/runtime-mcp/startup-policy.d.ts +6 -0
- package/dist/types/runtime-mcp/tool-bridge.d.ts +9 -0
- package/dist/types/runtime-mcp/transports/http.d.ts +11 -0
- package/dist/types/sdk/broker/broker.d.ts +17 -4
- package/dist/types/sdk/broker/ensure.d.ts +3 -0
- package/dist/types/sdk/broker/identity.d.ts +5 -1
- package/dist/types/sdk/broker/lifecycle-ledger.d.ts +23 -3
- package/dist/types/sdk/broker/lifecycle.d.ts +15 -8
- package/dist/types/sdk/broker/managed-task-dag.d.ts +1335 -0
- package/dist/types/sdk/broker/managed-task-verification.d.ts +37 -0
- package/dist/types/sdk/broker/runtime.d.ts +1 -1
- package/dist/types/sdk/broker/session-index.d.ts +22 -3
- package/dist/types/sdk/broker/spawn-authority.d.ts +12 -0
- package/dist/types/sdk/broker/startup-failure.d.ts +4 -0
- package/dist/types/sdk/broker/stderr-drainer.d.ts +13 -0
- package/dist/types/sdk/bus/index.d.ts +19 -0
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +7 -1
- package/dist/types/sdk/bus/telegram-daemon.d.ts +5 -0
- package/dist/types/sdk/cli/master-cli.d.ts +6 -10
- package/dist/types/sdk/cli/rows.d.ts +19 -1
- package/dist/types/sdk/cli/session-cli.d.ts +22 -5
- package/dist/types/sdk/client/client.d.ts +2 -0
- package/dist/types/sdk/guides/cli.d.ts +3 -4
- package/dist/types/sdk/guides/verify.d.ts +2 -0
- package/dist/types/sdk/host/host.d.ts +9 -0
- package/dist/types/sdk/host/session-runtime.d.ts +31 -0
- package/dist/types/sdk/host/types.d.ts +10 -0
- package/dist/types/sdk/index.d.ts +1 -0
- package/dist/types/sdk/prompt-deadline-flush.d.ts +85 -0
- package/dist/types/sdk/prompt-deadline-manager.d.ts +37 -0
- package/dist/types/sdk/prompt-tool-boundary.d.ts +73 -0
- package/dist/types/sdk/router/session-router.d.ts +2 -0
- package/dist/types/sdk/session.d.ts +3 -3
- package/dist/types/sdk/startup-capability.d.ts +2 -0
- package/dist/types/sdk/transport/relay.d.ts +1 -0
- package/dist/types/sdk/transport/serve-cli.d.ts +48 -4
- package/dist/types/sdk/transport/stdio.d.ts +5 -1
- package/dist/types/session/agent-session.d.ts +175 -23
- package/dist/types/session/fallback-chain-controller.d.ts +6 -6
- package/dist/types/session/fold-coordinator.d.ts +17 -3
- package/dist/types/session/internal/managed-session-storage.d.ts +7 -1
- package/dist/types/session/session-manager.d.ts +64 -1
- package/dist/types/session/session-work-lease.d.ts +14 -0
- package/dist/types/setup/model-onboarding-guidance.d.ts +1 -1
- package/dist/types/setup/provider-onboarding.d.ts +81 -1
- package/dist/types/task/types.d.ts +2 -0
- package/dist/types/tools/bash-interactive.d.ts +1 -0
- package/dist/types/tools/bash.d.ts +37 -11
- package/dist/types/tools/fetch.d.ts +10 -1
- package/dist/types/tools/job.d.ts +1 -1
- package/dist/types/tools/steer-fold.d.ts +31 -0
- package/dist/types/tools/subagent.d.ts +8 -1
- package/dist/types/utils/git.d.ts +28 -2
- package/dist/types/utils/mupdf-embedded.d.ts +2 -0
- package/dist/types/utils/mupdf.d.ts +4 -0
- package/dist/types/utils/session-title-generation.d.ts +6 -0
- package/dist/types/utils/title-generator.d.ts +11 -2
- package/dist/types/web/scrapers/types.d.ts +3 -0
- package/package.json +18 -10
- package/scripts/build-binary.ts +9 -3
- package/scripts/compile-args.ts +0 -9
- package/scripts/embed-mupdf.ts +52 -0
- package/scripts/generate-sdk-operation-inventory.ts +31 -1
- package/scripts/vendor-markit.ts +196 -0
- package/src/async/job-manager.ts +22 -1
- package/src/cli/daemon-cli.ts +53 -18
- package/src/cli/github-release.ts +87 -5
- package/src/cli/mcp-cli.ts +38 -4
- package/src/cli/public-command-entry.ts +450 -0
- package/src/cli/public-command-errors.ts +581 -0
- package/src/cli/public-command-evidence.ts +717 -0
- package/src/cli/public-command-help.ts +360 -0
- package/src/cli/public-command-registry.ts +541 -0
- package/src/cli/session-picker.ts +2 -1
- package/src/cli/setup-cli.ts +10 -1
- package/src/cli/skills-cli.ts +46 -2
- package/src/cli/stats-cli.ts +11 -1
- package/src/cli.ts +61 -1
- package/src/commands/daemon.ts +65 -69
- package/src/commands/sdk.ts +175 -117
- package/src/commands/setup.ts +2 -0
- package/src/commands/skills.ts +11 -0
- package/src/config/autorouting-tier-map.ts +543 -3
- package/src/config/file-lock.ts +206 -65
- package/src/config/model-discovery-manager.ts +4 -4
- package/src/config/model-profile-activation.ts +417 -66
- package/src/config/model-registry.ts +254 -36
- package/src/config/model-resolver.ts +6 -1
- package/src/config/settings-schema.ts +26 -2
- package/src/coordinator-mcp/policy.ts +10 -5
- package/src/coordinator-mcp/question-gate-codec.ts +17 -0
- package/src/coordinator-mcp/question-state.ts +179 -9
- package/src/coordinator-mcp/server.ts +521 -87
- package/src/coordinator-mcp/session-reaper.ts +6 -4
- package/src/crash/record-loader.ts +6 -2
- package/src/daemon/operator-contract.ts +26 -12
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +1 -1
- package/src/eval/js/context-manager.ts +8 -8
- package/src/eval/js/worker-core.ts +9 -4
- package/src/eval/js/worker-protocol.ts +2 -0
- package/src/exec/bash-executor.ts +3 -0
- package/src/extensibility/extensions/runner.ts +52 -4
- package/src/extensibility/extensions/types.ts +10 -0
- package/src/extensibility/gjc-plugins/registry.ts +196 -37
- package/src/extensibility/gjc-plugins/runtime-adapters.ts +46 -8
- package/src/extensibility/runtime-skill-discovery.ts +61 -3
- package/src/extensibility/shared-events.ts +3 -1
- package/src/gjc-runtime/session-state-lock.ts +165 -24
- package/src/gjc-runtime/state-writer.ts +317 -6
- package/src/gjc-runtime/ultragoal-succession.ts +31 -3
- package/src/harness-control-plane/control-endpoint.ts +24 -6
- package/src/harness-control-plane/finalize.ts +312 -25
- package/src/harness-control-plane/owner.ts +323 -89
- package/src/internal-urls/docs-index.generated.ts +23 -20
- package/src/internal-urls/embedded-protocol.ts +83 -0
- package/src/internal-urls/index.ts +1 -0
- package/src/internal-urls/parse.ts +21 -1
- package/src/internal-urls/router.ts +4 -2
- package/src/main.ts +192 -74
- package/src/modes/acp/acp-agent.ts +973 -56
- package/src/modes/acp/startup-provenance.ts +59 -0
- package/src/modes/components/custom-provider-wizard.ts +308 -7
- package/src/modes/components/gjc-bundle-settings.ts +21 -1
- package/src/modes/components/oauth-selector.ts +9 -0
- package/src/modes/components/session-selector.ts +47 -4
- package/src/modes/components/tool-status-header.ts +72 -6
- package/src/modes/components/user-message-selector.ts +57 -15
- package/src/modes/controllers/command-controller.ts +58 -32
- package/src/modes/controllers/extension-ui-controller.ts +33 -7
- package/src/modes/controllers/input-controller.ts +4 -0
- package/src/modes/controllers/runtime-mcp-command-controller.ts +1 -1
- package/src/modes/controllers/selector-controller.ts +161 -15
- package/src/modes/interactive-mode.ts +21 -7
- package/src/modes/runtime-init.ts +1 -0
- package/src/modes/shared/agent-wire/workflow-gate-broker.ts +124 -7
- package/src/modes/shared/agent-wire/workflow-gate-types.ts +16 -2
- package/src/modes/types.ts +2 -2
- package/src/prompts/agent-fragments/browser-aside.md +1 -0
- package/src/prompts/system/title-system.md +1 -1
- package/src/prompts/tools/bash.md +1 -1
- package/src/prompts/tools/job.md +1 -1
- package/src/prompts/tools/read.md +2 -0
- package/src/runtime/network-prewarm-service.test.ts +36 -1
- package/src/runtime/network-prewarm-service.ts +28 -3
- package/src/runtime/process-lifecycle.ts +22 -11
- package/src/runtime-mcp/config.ts +16 -1
- package/src/runtime-mcp/loader.ts +6 -3
- package/src/runtime-mcp/manager.ts +845 -109
- package/src/runtime-mcp/pool.test.ts +31 -0
- package/src/runtime-mcp/pool.ts +304 -28
- package/src/runtime-mcp/redaction.ts +42 -0
- package/src/runtime-mcp/startup-policy.ts +7 -0
- package/src/runtime-mcp/tool-bridge.ts +71 -0
- package/src/runtime-mcp/transports/http.ts +108 -25
- package/src/sdk/acp/adapter.ts +27 -8
- package/src/sdk/broker/broker.ts +1431 -198
- package/src/sdk/broker/ensure.ts +21 -3
- package/src/sdk/broker/identity.ts +22 -1
- package/src/sdk/broker/lifecycle-ledger.ts +95 -31
- package/src/sdk/broker/lifecycle.ts +690 -141
- package/src/sdk/broker/managed-task-dag.ts +1927 -0
- package/src/sdk/broker/managed-task-verification.ts +642 -0
- package/src/sdk/broker/runtime.ts +1 -1
- package/src/sdk/broker/session-index.ts +97 -4
- package/src/sdk/broker/spawn-authority.ts +175 -14
- package/src/sdk/broker/startup-failure.ts +80 -1
- package/src/sdk/broker/stderr-drainer.ts +59 -0
- package/src/sdk/broker/transport.ts +1 -0
- package/src/sdk/bus/chat-daemon-control.ts +2 -2
- package/src/sdk/bus/chat-daemon-runtime.ts +1 -0
- package/src/sdk/bus/index.ts +707 -81
- package/src/sdk/bus/telegram-daemon-cli.ts +31 -2
- package/src/sdk/bus/telegram-daemon-contract.ts +7 -1
- package/src/sdk/bus/telegram-daemon.ts +10 -3
- package/src/sdk/cli/master-cli.ts +47 -36
- package/src/sdk/cli/rows.ts +30 -7
- package/src/sdk/cli/session-cli.ts +705 -184
- package/src/sdk/client/client.ts +18 -0
- package/src/sdk/guides/catalog.ts +2 -2
- package/src/sdk/guides/cli.ts +20 -62
- package/src/sdk/guides/verify.ts +14 -0
- package/src/sdk/host/host.ts +49 -5
- package/src/sdk/host/session-runtime.test.ts +184 -2
- package/src/sdk/host/session-runtime.ts +322 -101
- package/src/sdk/host/types.ts +12 -1
- package/src/sdk/host/websocket-transport.lifecycle.test.ts +84 -0
- package/src/sdk/host/websocket-transport.ts +40 -6
- package/src/sdk/index.ts +11 -0
- package/src/sdk/lifecycle/service.ts +2 -0
- package/src/sdk/prompt-deadline-flush.ts +356 -0
- package/src/sdk/prompt-deadline-manager.ts +133 -1
- package/src/sdk/prompt-tool-boundary.ts +121 -0
- package/src/sdk/protocol/operation-inventory.generated.json +106 -0
- package/src/sdk/router/session-router.ts +9 -1
- package/src/sdk/session.ts +763 -116
- package/src/sdk/startup-capability.ts +1 -1
- package/src/sdk/transport/relay.ts +71 -6
- package/src/sdk/transport/serve-cli.ts +397 -42
- package/src/sdk/transport/socket.ts +12 -11
- package/src/sdk/transport/stdio.ts +7 -3
- package/src/session/agent-session.ts +2472 -407
- package/src/session/fallback-chain-controller.ts +6 -7
- package/src/session/fold-coordinator.ts +24 -5
- package/src/session/internal/managed-session-scope.ts +68 -18
- package/src/session/internal/managed-session-storage.ts +334 -12
- package/src/session/session-manager.ts +382 -44
- package/src/session/session-work-lease.ts +34 -0
- package/src/setup/model-onboarding-guidance.ts +1 -1
- package/src/setup/provider-onboarding.ts +397 -24
- package/src/setup/provider-presets.json +2 -1
- package/src/slash-commands/builtin-registry.ts +259 -15
- package/src/task/executor.ts +46 -17
- package/src/task/index.ts +14 -2
- package/src/task/types.ts +2 -0
- package/src/tools/bash-interactive.ts +2 -0
- package/src/tools/bash.ts +118 -78
- package/src/tools/fetch.ts +140 -25
- package/src/tools/job.ts +151 -25
- package/src/tools/output-meta.ts +15 -2
- package/src/tools/path-utils.ts +27 -3
- package/src/tools/read.ts +3 -3
- package/src/tools/steer-fold.ts +107 -0
- package/src/tools/subagent-render.ts +24 -1
- package/src/tools/subagent.ts +27 -1
- package/src/tools/tool-catalog.generated.ts +29 -2
- package/src/tools/tool-errors.ts +4 -0
- package/src/utils/git.ts +53 -3
- package/src/utils/markit.ts +55 -41
- package/src/utils/mupdf-assets.d.ts +4 -0
- package/src/utils/mupdf-embedded.ts +4 -0
- package/src/utils/mupdf.ts +136 -0
- package/src/utils/session-title-generation.ts +29 -0
- package/src/utils/title-generator.ts +46 -2
- package/src/web/scrapers/types.ts +24 -3
- package/vendor/markit-ai/LICENSE +21 -0
- package/vendor/markit-ai/MANIFEST.json +412 -0
- package/vendor/markit-ai/dist/commands/config.d.ts +4 -0
- package/vendor/markit-ai/dist/commands/config.js +139 -0
- package/vendor/markit-ai/dist/commands/convert.d.ts +6 -0
- package/vendor/markit-ai/dist/commands/convert.js +113 -0
- package/vendor/markit-ai/dist/commands/formats.d.ts +2 -0
- package/vendor/markit-ai/dist/commands/formats.js +92 -0
- package/vendor/markit-ai/dist/commands/init.d.ts +2 -0
- package/vendor/markit-ai/dist/commands/init.js +29 -0
- package/vendor/markit-ai/dist/commands/onboard.d.ts +2 -0
- package/vendor/markit-ai/dist/commands/onboard.js +61 -0
- package/vendor/markit-ai/dist/commands/plugin.d.ts +4 -0
- package/vendor/markit-ai/dist/commands/plugin.js +58 -0
- package/vendor/markit-ai/dist/config.d.ts +26 -0
- package/vendor/markit-ai/dist/config.js +42 -0
- package/vendor/markit-ai/dist/converters/audio.d.ts +7 -0
- package/vendor/markit-ai/dist/converters/audio.js +104 -0
- package/vendor/markit-ai/dist/converters/csv.d.ts +7 -0
- package/vendor/markit-ai/dist/converters/csv.js +83 -0
- package/vendor/markit-ai/dist/converters/docx.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/docx.js +57 -0
- package/vendor/markit-ai/dist/converters/epub.d.ts +8 -0
- package/vendor/markit-ai/dist/converters/epub.js +128 -0
- package/vendor/markit-ai/dist/converters/github.d.ts +18 -0
- package/vendor/markit-ai/dist/converters/github.js +148 -0
- package/vendor/markit-ai/dist/converters/html.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/html.js +30 -0
- package/vendor/markit-ai/dist/converters/image.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/image.js +124 -0
- package/vendor/markit-ai/dist/converters/ipynb.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/ipynb.js +75 -0
- package/vendor/markit-ai/dist/converters/iwork.d.ts +20 -0
- package/vendor/markit-ai/dist/converters/iwork.js +391 -0
- package/vendor/markit-ai/dist/converters/json.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/json.js +21 -0
- package/vendor/markit-ai/dist/converters/pdf/columns.d.ts +35 -0
- package/vendor/markit-ai/dist/converters/pdf/columns.js +93 -0
- package/vendor/markit-ai/dist/converters/pdf/extract.d.ts +19 -0
- package/vendor/markit-ai/dist/converters/pdf/extract.js +514 -0
- package/vendor/markit-ai/dist/converters/pdf/grid.d.ts +25 -0
- package/vendor/markit-ai/dist/converters/pdf/grid.js +795 -0
- package/vendor/markit-ai/dist/converters/pdf/headers.d.ts +24 -0
- package/vendor/markit-ai/dist/converters/pdf/headers.js +108 -0
- package/vendor/markit-ai/dist/converters/pdf/index.d.ts +19 -0
- package/vendor/markit-ai/dist/converters/pdf/index.js +136 -0
- package/vendor/markit-ai/dist/converters/pdf/mupdf-loader.js +9 -0
- package/vendor/markit-ai/dist/converters/pdf/render.d.ts +24 -0
- package/vendor/markit-ai/dist/converters/pdf/render.js +513 -0
- package/vendor/markit-ai/dist/converters/pdf/types.d.ts +75 -0
- package/vendor/markit-ai/dist/converters/pdf/types.js +1 -0
- package/vendor/markit-ai/dist/converters/plain-text.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/plain-text.js +87 -0
- package/vendor/markit-ai/dist/converters/pptx.d.ts +8 -0
- package/vendor/markit-ai/dist/converters/pptx.js +289 -0
- package/vendor/markit-ai/dist/converters/rss.d.ts +11 -0
- package/vendor/markit-ai/dist/converters/rss.js +138 -0
- package/vendor/markit-ai/dist/converters/wikipedia.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/wikipedia.js +33 -0
- package/vendor/markit-ai/dist/converters/xlsx.d.ts +8 -0
- package/vendor/markit-ai/dist/converters/xlsx.js +147 -0
- package/vendor/markit-ai/dist/converters/xml.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/xml.js +18 -0
- package/vendor/markit-ai/dist/converters/yaml.d.ts +6 -0
- package/vendor/markit-ai/dist/converters/yaml.js +17 -0
- package/vendor/markit-ai/dist/converters/zip.d.ts +8 -0
- package/vendor/markit-ai/dist/converters/zip.js +57 -0
- package/vendor/markit-ai/dist/index.d.ts +30 -0
- package/vendor/markit-ai/dist/index.js +26 -0
- package/vendor/markit-ai/dist/main.d.ts +2 -0
- package/vendor/markit-ai/dist/main.js +191 -0
- package/vendor/markit-ai/dist/markit.d.ts +45 -0
- package/vendor/markit-ai/dist/markit.js +267 -0
- package/vendor/markit-ai/dist/plugins/api.d.ts +7 -0
- package/vendor/markit-ai/dist/plugins/api.js +42 -0
- package/vendor/markit-ai/dist/plugins/index.d.ts +4 -0
- package/vendor/markit-ai/dist/plugins/index.js +3 -0
- package/vendor/markit-ai/dist/plugins/installer.d.ts +25 -0
- package/vendor/markit-ai/dist/plugins/installer.js +176 -0
- package/vendor/markit-ai/dist/plugins/loader.d.ts +6 -0
- package/vendor/markit-ai/dist/plugins/loader.js +61 -0
- package/vendor/markit-ai/dist/plugins/types.d.ts +25 -0
- package/vendor/markit-ai/dist/plugins/types.js +1 -0
- package/vendor/markit-ai/dist/providers/anthropic.d.ts +2 -0
- package/vendor/markit-ai/dist/providers/anthropic.js +47 -0
- package/vendor/markit-ai/dist/providers/index.d.ts +21 -0
- package/vendor/markit-ai/dist/providers/index.js +56 -0
- package/vendor/markit-ai/dist/providers/openai.d.ts +2 -0
- package/vendor/markit-ai/dist/providers/openai.js +76 -0
- package/vendor/markit-ai/dist/providers/types.d.ts +26 -0
- package/vendor/markit-ai/dist/providers/types.js +1 -0
- package/vendor/markit-ai/dist/types.d.ts +36 -0
- package/vendor/markit-ai/dist/types.js +1 -0
- package/vendor/markit-ai/dist/utils/exit-codes.d.ts +4 -0
- package/vendor/markit-ai/dist/utils/exit-codes.js +4 -0
- package/vendor/markit-ai/dist/utils/output.d.ts +22 -0
- package/vendor/markit-ai/dist/utils/output.js +31 -0
- package/vendor/markit-ai/dist/utils/turndown.d.ts +8 -0
- package/vendor/markit-ai/dist/utils/turndown.js +70 -0
- package/vendor/markit-ai/package.json +74 -0
- package/vendor/markit-ai.patch +49 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function createPluginAPI(pluginId) {
|
|
2
|
+
let name = pluginId;
|
|
3
|
+
let version = "0.0.0";
|
|
4
|
+
const converters = [];
|
|
5
|
+
const providers = [];
|
|
6
|
+
const formats = [];
|
|
7
|
+
const api = {
|
|
8
|
+
setName(n) {
|
|
9
|
+
name = n;
|
|
10
|
+
},
|
|
11
|
+
setVersion(v) {
|
|
12
|
+
version = v;
|
|
13
|
+
},
|
|
14
|
+
registerConverter(converter, format) {
|
|
15
|
+
converters.push(converter);
|
|
16
|
+
if (format) {
|
|
17
|
+
formats.push(format);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
registerProvider(provider) {
|
|
21
|
+
providers.push(provider);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
function resolve() {
|
|
25
|
+
return { name, version, converters, providers, formats };
|
|
26
|
+
}
|
|
27
|
+
return { api, resolve };
|
|
28
|
+
}
|
|
29
|
+
export function isPluginFunction(val) {
|
|
30
|
+
return typeof val === "function";
|
|
31
|
+
}
|
|
32
|
+
export function resolvePluginExport(exported, pluginId) {
|
|
33
|
+
if (isPluginFunction(exported)) {
|
|
34
|
+
const { api, resolve } = createPluginAPI(pluginId);
|
|
35
|
+
exported(api);
|
|
36
|
+
return resolve();
|
|
37
|
+
}
|
|
38
|
+
if (exported && typeof exported === "object" && "converters" in exported) {
|
|
39
|
+
return exported;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Invalid plugin export from "${pluginId}": expected a function or { name, converters } object`);
|
|
42
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createPluginAPI, resolvePluginExport } from "./api.js";
|
|
2
|
+
export { installPlugin, listInstalled, parsePluginSource, removePlugin, } from "./installer.js";
|
|
3
|
+
export { loadAllPlugins, loadPluginFromPath } from "./loader.js";
|
|
4
|
+
export type { MarkitPluginAPI, PluginDef, PluginFunction } from "./types.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface PluginSource {
|
|
2
|
+
type: "npm" | "git" | "local";
|
|
3
|
+
name: string;
|
|
4
|
+
ref?: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
subpath?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface InstalledPlugin {
|
|
10
|
+
source: string;
|
|
11
|
+
path: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function parsePluginSource(source: string): PluginSource;
|
|
15
|
+
export declare function installPlugin(source: string): Promise<{
|
|
16
|
+
path: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function removePlugin(name: string): boolean;
|
|
20
|
+
export declare function listInstalled(): Array<{
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
source: string;
|
|
24
|
+
path: string;
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import { basename, join, resolve } from "node:path";
|
|
4
|
+
import { findConfigDir } from "../config.js";
|
|
5
|
+
const PLUGINS_FILE = "plugins.json";
|
|
6
|
+
export function parsePluginSource(source) {
|
|
7
|
+
// npm:package@version
|
|
8
|
+
if (source.startsWith("npm:")) {
|
|
9
|
+
const rest = source.slice(4);
|
|
10
|
+
let name;
|
|
11
|
+
let ref;
|
|
12
|
+
if (rest.startsWith("@")) {
|
|
13
|
+
const lastAt = rest.lastIndexOf("@");
|
|
14
|
+
if (lastAt > 0 && lastAt !== rest.indexOf("@")) {
|
|
15
|
+
name = rest.slice(0, lastAt);
|
|
16
|
+
ref = rest.slice(lastAt + 1);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
name = rest;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const atIdx = rest.indexOf("@");
|
|
24
|
+
if (atIdx > 0) {
|
|
25
|
+
name = rest.slice(0, atIdx);
|
|
26
|
+
ref = rest.slice(atIdx + 1);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
name = rest;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { type: "npm", name, ref };
|
|
33
|
+
}
|
|
34
|
+
// git:url or https://...
|
|
35
|
+
if (source.startsWith("git:") ||
|
|
36
|
+
source.startsWith("https://") ||
|
|
37
|
+
source.startsWith("http://") ||
|
|
38
|
+
source.startsWith("ssh://")) {
|
|
39
|
+
let raw = source;
|
|
40
|
+
if (raw.startsWith("git:"))
|
|
41
|
+
raw = raw.slice(4);
|
|
42
|
+
let subpath;
|
|
43
|
+
const hashIdx = raw.indexOf("#");
|
|
44
|
+
if (hashIdx > 0) {
|
|
45
|
+
subpath = raw.slice(hashIdx + 1);
|
|
46
|
+
raw = raw.slice(0, hashIdx);
|
|
47
|
+
}
|
|
48
|
+
let ref;
|
|
49
|
+
const atIdx = raw.lastIndexOf("@");
|
|
50
|
+
if (atIdx > 0 && !raw.slice(atIdx).includes("/")) {
|
|
51
|
+
ref = raw.slice(atIdx + 1);
|
|
52
|
+
raw = raw.slice(0, atIdx);
|
|
53
|
+
}
|
|
54
|
+
let url = raw;
|
|
55
|
+
if (!url.startsWith("http://") &&
|
|
56
|
+
!url.startsWith("https://") &&
|
|
57
|
+
!url.startsWith("ssh://")) {
|
|
58
|
+
url = `https://${url}`;
|
|
59
|
+
}
|
|
60
|
+
if (!url.endsWith(".git"))
|
|
61
|
+
url += ".git";
|
|
62
|
+
const name = subpath ? basename(subpath) : basename(url, ".git");
|
|
63
|
+
return { type: "git", name, url, ref, subpath };
|
|
64
|
+
}
|
|
65
|
+
// Local path
|
|
66
|
+
const absPath = resolve(source);
|
|
67
|
+
const name = basename(absPath).replace(/\.(ts|js)$/, "");
|
|
68
|
+
return { type: "local", name, path: absPath };
|
|
69
|
+
}
|
|
70
|
+
function getPluginsDir() {
|
|
71
|
+
const configDir = findConfigDir();
|
|
72
|
+
const dir = configDir
|
|
73
|
+
? join(configDir, "plugins")
|
|
74
|
+
: join(process.cwd(), ".markit", "plugins");
|
|
75
|
+
mkdirSync(dir, { recursive: true });
|
|
76
|
+
return dir;
|
|
77
|
+
}
|
|
78
|
+
function getPluginsJsonPath() {
|
|
79
|
+
const configDir = findConfigDir();
|
|
80
|
+
return configDir
|
|
81
|
+
? join(configDir, PLUGINS_FILE)
|
|
82
|
+
: join(process.cwd(), ".markit", PLUGINS_FILE);
|
|
83
|
+
}
|
|
84
|
+
function readPluginsJson() {
|
|
85
|
+
const path = getPluginsJsonPath();
|
|
86
|
+
if (!existsSync(path))
|
|
87
|
+
return { plugins: [] };
|
|
88
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
89
|
+
}
|
|
90
|
+
function writePluginsJson(data) {
|
|
91
|
+
const path = getPluginsJsonPath();
|
|
92
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
93
|
+
writeFileSync(path, `${JSON.stringify(data, null, 2)}\n`);
|
|
94
|
+
}
|
|
95
|
+
export async function installPlugin(source) {
|
|
96
|
+
const parsed = parsePluginSource(source);
|
|
97
|
+
const pluginsDir = getPluginsDir();
|
|
98
|
+
let installPath;
|
|
99
|
+
switch (parsed.type) {
|
|
100
|
+
case "npm": {
|
|
101
|
+
const npmDir = join(pluginsDir, "npm");
|
|
102
|
+
mkdirSync(npmDir, { recursive: true });
|
|
103
|
+
const spec = parsed.ref ? `${parsed.name}@${parsed.ref}` : parsed.name;
|
|
104
|
+
execSync(`npm install ${spec}`, { cwd: npmDir, stdio: "pipe" });
|
|
105
|
+
installPath = join(npmDir, "node_modules", parsed.name);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case "git": {
|
|
109
|
+
const url = new URL(parsed.url || "");
|
|
110
|
+
const gitDir = join(pluginsDir, "git", url.hostname, url.pathname.replace(/\.git$/, ""));
|
|
111
|
+
if (existsSync(gitDir)) {
|
|
112
|
+
execSync("git pull", { cwd: gitDir, stdio: "pipe" });
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
mkdirSync(join(gitDir, ".."), { recursive: true });
|
|
116
|
+
const refArg = parsed.ref ? `--branch ${parsed.ref}` : "";
|
|
117
|
+
execSync(`git clone ${refArg} ${parsed.url} ${gitDir}`, {
|
|
118
|
+
stdio: "pipe",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (existsSync(join(gitDir, "package.json"))) {
|
|
122
|
+
execSync("npm install", { cwd: gitDir, stdio: "pipe" });
|
|
123
|
+
}
|
|
124
|
+
installPath = parsed.subpath ? join(gitDir, parsed.subpath) : gitDir;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case "local": {
|
|
128
|
+
if (!parsed.path || !existsSync(parsed.path)) {
|
|
129
|
+
throw new Error(`Path does not exist: ${parsed.path}`);
|
|
130
|
+
}
|
|
131
|
+
installPath = parsed.path;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const data = readPluginsJson();
|
|
136
|
+
const existing = data.plugins.findIndex((p) => p.source === source);
|
|
137
|
+
const entry = {
|
|
138
|
+
source,
|
|
139
|
+
path: installPath,
|
|
140
|
+
name: parsed.name,
|
|
141
|
+
};
|
|
142
|
+
if (existing >= 0) {
|
|
143
|
+
data.plugins[existing] = entry;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
data.plugins.push(entry);
|
|
147
|
+
}
|
|
148
|
+
writePluginsJson(data);
|
|
149
|
+
return { path: installPath, name: parsed.name };
|
|
150
|
+
}
|
|
151
|
+
export function removePlugin(name) {
|
|
152
|
+
const data = readPluginsJson();
|
|
153
|
+
const idx = data.plugins.findIndex((p) => p.name === name || p.source.includes(name));
|
|
154
|
+
if (idx < 0)
|
|
155
|
+
return false;
|
|
156
|
+
const plugin = data.plugins[idx];
|
|
157
|
+
const parsed = parsePluginSource(plugin.source);
|
|
158
|
+
if (parsed.type !== "local" && existsSync(plugin.path)) {
|
|
159
|
+
rmSync(plugin.path, { recursive: true, force: true });
|
|
160
|
+
}
|
|
161
|
+
data.plugins.splice(idx, 1);
|
|
162
|
+
writePluginsJson(data);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
export function listInstalled() {
|
|
166
|
+
const data = readPluginsJson();
|
|
167
|
+
return data.plugins.map((p) => {
|
|
168
|
+
const parsed = parsePluginSource(p.source);
|
|
169
|
+
return {
|
|
170
|
+
name: p.name || parsed.name,
|
|
171
|
+
type: parsed.type,
|
|
172
|
+
source: p.source,
|
|
173
|
+
path: p.path,
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { findConfigDir } from "../config.js";
|
|
5
|
+
import { resolvePluginExport } from "./api.js";
|
|
6
|
+
export async function loadPluginFromPath(path) {
|
|
7
|
+
let absPath = resolve(path);
|
|
8
|
+
// Directory → find entry point
|
|
9
|
+
if (existsSync(absPath) && statSync(absPath).isDirectory()) {
|
|
10
|
+
const candidates = [
|
|
11
|
+
join(absPath, "src", "index.ts"),
|
|
12
|
+
join(absPath, "src", "index.js"),
|
|
13
|
+
join(absPath, "index.ts"),
|
|
14
|
+
join(absPath, "index.js"),
|
|
15
|
+
];
|
|
16
|
+
const pkgPath = join(absPath, "package.json");
|
|
17
|
+
if (existsSync(pkgPath)) {
|
|
18
|
+
try {
|
|
19
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
20
|
+
if (pkg.main)
|
|
21
|
+
candidates.unshift(join(absPath, pkg.main));
|
|
22
|
+
}
|
|
23
|
+
catch { }
|
|
24
|
+
}
|
|
25
|
+
const found = candidates.find((c) => existsSync(c));
|
|
26
|
+
if (found) {
|
|
27
|
+
absPath = found;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error(`No entry point found in ${absPath}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const mod = await import(pathToFileURL(absPath).href);
|
|
34
|
+
const pluginId = absPath.replace(/.*\//, "").replace(/\.(ts|js)$/, "");
|
|
35
|
+
return resolvePluginExport(mod.default, pluginId);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Load all plugins from .markit/plugins.json
|
|
39
|
+
*/
|
|
40
|
+
export async function loadAllPlugins() {
|
|
41
|
+
const plugins = [];
|
|
42
|
+
const configDir = findConfigDir();
|
|
43
|
+
if (!configDir)
|
|
44
|
+
return plugins;
|
|
45
|
+
const pluginsFile = join(configDir, "plugins.json");
|
|
46
|
+
if (!existsSync(pluginsFile))
|
|
47
|
+
return plugins;
|
|
48
|
+
try {
|
|
49
|
+
const data = JSON.parse(readFileSync(pluginsFile, "utf-8"));
|
|
50
|
+
const entries = data.plugins ?? [];
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const p = typeof entry === "string" ? entry : entry.path;
|
|
53
|
+
try {
|
|
54
|
+
plugins.push(await loadPluginFromPath(p));
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch { }
|
|
60
|
+
return plugins;
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Provider } from "../providers/types.js";
|
|
2
|
+
import type { Converter } from "../types.js";
|
|
3
|
+
export interface FormatDef {
|
|
4
|
+
name: string;
|
|
5
|
+
extensions: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface MarkitPluginAPI {
|
|
8
|
+
setName(name: string): void;
|
|
9
|
+
setVersion(version: string): void;
|
|
10
|
+
registerConverter(converter: Converter, format?: FormatDef): void;
|
|
11
|
+
registerProvider(provider: Provider): void;
|
|
12
|
+
}
|
|
13
|
+
export type PluginFunction = (api: MarkitPluginAPI) => void;
|
|
14
|
+
export interface PluginDef {
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
converters: Converter[];
|
|
18
|
+
providers: Provider[];
|
|
19
|
+
formats: FormatDef[];
|
|
20
|
+
}
|
|
21
|
+
export interface InstalledPlugin {
|
|
22
|
+
source: string;
|
|
23
|
+
path: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const anthropic = {
|
|
2
|
+
name: "anthropic",
|
|
3
|
+
envKeys: ["ANTHROPIC_API_KEY", "MARKIT_API_KEY"],
|
|
4
|
+
defaultBase: "https://api.anthropic.com",
|
|
5
|
+
defaultModel: "claude-haiku-4-5",
|
|
6
|
+
create(config, prompt) {
|
|
7
|
+
return {
|
|
8
|
+
describe: async (image, mimetype) => {
|
|
9
|
+
const res = await fetch(`${config.apiBase}/v1/messages`, {
|
|
10
|
+
method: "POST",
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"x-api-key": config.apiKey,
|
|
14
|
+
"anthropic-version": "2023-06-01",
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
model: config.model,
|
|
18
|
+
max_tokens: 1024,
|
|
19
|
+
messages: [
|
|
20
|
+
{
|
|
21
|
+
role: "user",
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: "image",
|
|
25
|
+
source: {
|
|
26
|
+
type: "base64",
|
|
27
|
+
media_type: mimetype,
|
|
28
|
+
data: image.toString("base64"),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{ type: "text", text: prompt },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const body = await res.text();
|
|
39
|
+
throw new Error(`Anthropic API error ${res.status}: ${body}`);
|
|
40
|
+
}
|
|
41
|
+
const data = await res.json();
|
|
42
|
+
return data.content?.[0]?.text ?? "";
|
|
43
|
+
},
|
|
44
|
+
// Anthropic doesn't have a transcription API
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { MarkitConfig } from "../config.js";
|
|
2
|
+
import type { MarkitOptions } from "../types.js";
|
|
3
|
+
import type { Provider } from "./types.js";
|
|
4
|
+
export type { Provider, ProviderConfig, ResolvedConfig } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Register a custom provider.
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerProvider(provider: Provider): void;
|
|
9
|
+
/**
|
|
10
|
+
* Get a provider by name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getProvider(name: string): Provider | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* List all registered provider names.
|
|
15
|
+
*/
|
|
16
|
+
export declare function listProviders(): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Build describe/transcribe functions from config.
|
|
19
|
+
* Resolves provider, API key, model, and base URL automatically.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createLlmFunctions(config: MarkitConfig, prompt?: string): MarkitOptions;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { anthropic } from "./anthropic.js";
|
|
2
|
+
import { openai } from "./openai.js";
|
|
3
|
+
const providers = {
|
|
4
|
+
openai,
|
|
5
|
+
anthropic,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Register a custom provider.
|
|
9
|
+
*/
|
|
10
|
+
export function registerProvider(provider) {
|
|
11
|
+
providers[provider.name] = provider;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get a provider by name.
|
|
15
|
+
*/
|
|
16
|
+
export function getProvider(name) {
|
|
17
|
+
return providers[name];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* List all registered provider names.
|
|
21
|
+
*/
|
|
22
|
+
export function listProviders() {
|
|
23
|
+
return Object.keys(providers);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve config + env vars into a ResolvedConfig for a provider.
|
|
27
|
+
*/
|
|
28
|
+
function resolve(provider, config) {
|
|
29
|
+
// API key: env vars (in provider priority order) > config file
|
|
30
|
+
const apiKey = provider.envKeys.reduce((found, key) => found || process.env[key], undefined) || config.llm?.apiKey;
|
|
31
|
+
if (!apiKey)
|
|
32
|
+
return null;
|
|
33
|
+
return {
|
|
34
|
+
apiKey,
|
|
35
|
+
apiBase: (config.llm?.apiBase || provider.defaultBase).replace(/\/+$/, ""),
|
|
36
|
+
model: process.env.MARKIT_MODEL || config.llm?.model || provider.defaultModel,
|
|
37
|
+
transcriptionModel: config.llm?.transcriptionModel || provider.defaultTranscriptionModel,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const BASE_PROMPT = "Describe this image in detail.";
|
|
41
|
+
/**
|
|
42
|
+
* Build describe/transcribe functions from config.
|
|
43
|
+
* Resolves provider, API key, model, and base URL automatically.
|
|
44
|
+
*/
|
|
45
|
+
export function createLlmFunctions(config, prompt) {
|
|
46
|
+
const providerName = config.llm?.provider || "openai";
|
|
47
|
+
const provider = providers[providerName];
|
|
48
|
+
if (!provider) {
|
|
49
|
+
throw new Error(`Unknown provider '${providerName}'. Available: ${Object.keys(providers).join(", ")}`);
|
|
50
|
+
}
|
|
51
|
+
const resolved = resolve(provider, config);
|
|
52
|
+
if (!resolved)
|
|
53
|
+
return {};
|
|
54
|
+
const fullPrompt = prompt ? `${BASE_PROMPT}\n\n${prompt}` : BASE_PROMPT;
|
|
55
|
+
return provider.create(resolved, fullPrompt);
|
|
56
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const openai = {
|
|
2
|
+
name: "openai",
|
|
3
|
+
envKeys: ["OPENAI_API_KEY", "MARKIT_API_KEY"],
|
|
4
|
+
defaultBase: "https://api.openai.com/v1",
|
|
5
|
+
defaultModel: "gpt-4.1-nano",
|
|
6
|
+
defaultTranscriptionModel: "gpt-4o-mini-transcribe",
|
|
7
|
+
create(config, prompt) {
|
|
8
|
+
return {
|
|
9
|
+
describe: async (image, mimetype) => {
|
|
10
|
+
const res = await fetch(`${config.apiBase}/chat/completions`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
model: config.model,
|
|
18
|
+
messages: [
|
|
19
|
+
{
|
|
20
|
+
role: "user",
|
|
21
|
+
content: [
|
|
22
|
+
{ type: "text", text: prompt },
|
|
23
|
+
{
|
|
24
|
+
type: "image_url",
|
|
25
|
+
image_url: {
|
|
26
|
+
url: `data:${mimetype};base64,${image.toString("base64")}`,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
max_tokens: 1024,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
const body = await res.text();
|
|
37
|
+
throw new Error(`OpenAI API error ${res.status}: ${body}`);
|
|
38
|
+
}
|
|
39
|
+
const data = await res.json();
|
|
40
|
+
return data.choices?.[0]?.message?.content ?? "";
|
|
41
|
+
},
|
|
42
|
+
transcribe: async (audio, mimetype) => {
|
|
43
|
+
const ext = mimeToExt(mimetype);
|
|
44
|
+
const file = new File([new Uint8Array(audio)], `audio${ext}`, {
|
|
45
|
+
type: mimetype,
|
|
46
|
+
});
|
|
47
|
+
const formData = new FormData();
|
|
48
|
+
formData.append("model", config.transcriptionModel || "gpt-4o-mini-transcribe");
|
|
49
|
+
formData.append("file", file);
|
|
50
|
+
const res = await fetch(`${config.apiBase}/audio/transcriptions`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { Authorization: `Bearer ${config.apiKey}` },
|
|
53
|
+
body: formData,
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const body = await res.text();
|
|
57
|
+
throw new Error(`Transcription API error ${res.status}: ${body}`);
|
|
58
|
+
}
|
|
59
|
+
const data = await res.json();
|
|
60
|
+
return data.text ?? "";
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
function mimeToExt(mime) {
|
|
66
|
+
const map = {
|
|
67
|
+
"audio/mpeg": ".mp3",
|
|
68
|
+
"audio/wav": ".wav",
|
|
69
|
+
"audio/mp4": ".m4a",
|
|
70
|
+
"video/mp4": ".mp4",
|
|
71
|
+
"audio/ogg": ".ogg",
|
|
72
|
+
"audio/flac": ".flac",
|
|
73
|
+
"audio/aac": ".aac",
|
|
74
|
+
};
|
|
75
|
+
return map[mime] || ".mp3";
|
|
76
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MarkitOptions } from "../types.js";
|
|
2
|
+
export interface ProviderConfig {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
apiBase?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
transcriptionModel?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Provider {
|
|
9
|
+
name: string;
|
|
10
|
+
/** Env vars to check for API key, in priority order */
|
|
11
|
+
envKeys: string[];
|
|
12
|
+
/** Default API base URL */
|
|
13
|
+
defaultBase: string;
|
|
14
|
+
/** Default model for image description */
|
|
15
|
+
defaultModel: string;
|
|
16
|
+
/** Default model for audio transcription (if supported) */
|
|
17
|
+
defaultTranscriptionModel?: string;
|
|
18
|
+
/** Build describe/transcribe functions from resolved config */
|
|
19
|
+
create(config: ResolvedConfig, prompt: string): MarkitOptions;
|
|
20
|
+
}
|
|
21
|
+
export interface ResolvedConfig {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
apiBase: string;
|
|
24
|
+
model: string;
|
|
25
|
+
transcriptionModel?: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface StreamInfo {
|
|
2
|
+
mimetype?: string;
|
|
3
|
+
extension?: string;
|
|
4
|
+
charset?: string;
|
|
5
|
+
filename?: string;
|
|
6
|
+
localPath?: string;
|
|
7
|
+
url?: string;
|
|
8
|
+
/** Directory to write extracted images/diagrams. */
|
|
9
|
+
imageDir?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ConversionResult {
|
|
12
|
+
markdown: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MarkitOptions {
|
|
16
|
+
/** Describe an image, return markdown. Receives raw bytes and mimetype. */
|
|
17
|
+
describe?: (image: Buffer, mimetype: string) => Promise<string>;
|
|
18
|
+
/** Transcribe audio, return text. Receives raw bytes and mimetype. */
|
|
19
|
+
transcribe?: (audio: Buffer, mimetype: string) => Promise<string>;
|
|
20
|
+
/** Extra instructions appended to the image description prompt. */
|
|
21
|
+
prompt?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Converter {
|
|
24
|
+
/** Human-readable name for error messages */
|
|
25
|
+
name: string;
|
|
26
|
+
/** Quick check: can this converter handle the given stream? */
|
|
27
|
+
accepts(streamInfo: StreamInfo): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Optional URL-first hook. When present, called before the default fetch
|
|
30
|
+
* so the converter can handle URL fetching itself (e.g. rewrite to a raw
|
|
31
|
+
* content URL or call an API).
|
|
32
|
+
*/
|
|
33
|
+
convertUrl?(url: string, options?: MarkitOptions): Promise<ConversionResult>;
|
|
34
|
+
/** Convert the source to markdown */
|
|
35
|
+
convert(input: Buffer, streamInfo: StreamInfo, options?: MarkitOptions): Promise<ConversionResult>;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface OutputOptions {
|
|
2
|
+
json?: boolean;
|
|
3
|
+
quiet?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const success: (msg: string) => void;
|
|
6
|
+
export declare const info: (msg: string) => void;
|
|
7
|
+
export declare const warn: (msg: string) => void;
|
|
8
|
+
export declare const error: (msg: string) => void;
|
|
9
|
+
export declare const bold: (s: string) => string;
|
|
10
|
+
export declare const dim: (s: string) => string;
|
|
11
|
+
export declare const cmd: (s: string) => string;
|
|
12
|
+
export declare const bullet: (msg: string) => void;
|
|
13
|
+
export declare const bulletDim: (msg: string) => void;
|
|
14
|
+
export declare const hint: (msg: string) => void;
|
|
15
|
+
export declare const nextStep: (command: string) => void;
|
|
16
|
+
export declare const header: (title: string) => void;
|
|
17
|
+
export declare function jsonOutput(data: object): void;
|
|
18
|
+
export declare function output(options: OutputOptions, handlers: {
|
|
19
|
+
json?: () => object;
|
|
20
|
+
quiet?: () => void;
|
|
21
|
+
human: () => void;
|
|
22
|
+
}): void;
|