@qvac/harness 1.0.0-rc.9 → 1.0.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/CHANGELOG.md +701 -7
- package/NOTICE.md +0 -16
- package/README.md +46 -5
- package/dist-lib/index.d.ts +23 -16
- package/dist-lib/index.js +127 -23
- package/dist-lib/lib/agent/delegate.d.ts +1 -0
- package/dist-lib/lib/agent/delegate.js +10 -9
- package/dist-lib/lib/agent/follow.d.ts +1 -0
- package/dist-lib/lib/agent/follow.js +12 -2
- package/dist-lib/lib/agent/resolve.js +11 -3
- package/dist-lib/lib/agent/tools.d.ts +1 -0
- package/dist-lib/lib/agent/tools.js +1 -1
- package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
- package/dist-lib/lib/capabilities/agent-ports.js +8 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +79 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +12 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +47 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +5 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +19 -11
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +38 -23
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +31 -10
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -7
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +41 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +26 -10
- package/dist-lib/lib/capabilities/completion-engine/actors.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors.js +8 -8
- package/dist-lib/lib/capabilities/completion-engine/driver.d.ts +0 -1
- package/dist-lib/lib/capabilities/completion-engine/driver.js +30 -6
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/engine.js +35 -15
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +0 -1
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +13 -3
- package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -2
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +29 -9
- package/dist-lib/lib/capabilities/completion-engine/ports.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -4
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +14 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +102 -47
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -1
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -41
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +21 -135
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +40 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
- package/dist-lib/lib/capabilities/completion-engine/transition-log.d.ts +14 -0
- package/dist-lib/lib/capabilities/completion-engine/transition-log.js +44 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +36 -8
- package/dist-lib/lib/capabilities/enhance.js +3 -3
- package/dist-lib/lib/capabilities/kv-cache.js +11 -3
- package/dist-lib/lib/capabilities/prefix-template.d.ts +34 -0
- package/dist-lib/lib/capabilities/prefix-template.js +175 -0
- package/dist-lib/lib/capabilities/prompt-prefix.d.ts +2 -0
- package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +4 -4
- package/dist-lib/lib/capabilities/sdk-tool.js +22 -6
- package/dist-lib/lib/capabilities/skill-entry.d.ts +13 -1
- package/dist-lib/lib/capabilities/skill-entry.js +33 -2
- package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
- package/dist-lib/lib/capabilities/tool-turns/answered.d.ts +15 -0
- package/dist-lib/lib/capabilities/tool-turns/answered.js +16 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +10 -43
- package/dist-lib/lib/capabilities/tool-turns.js +7 -262
- package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
- package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
- package/dist-lib/lib/client/index.js +6 -5
- package/dist-lib/lib/connect/abort.d.ts +6 -0
- package/dist-lib/lib/connect/abort.js +52 -0
- package/dist-lib/lib/connect/bridges.d.ts +21 -0
- package/dist-lib/lib/connect/bridges.js +185 -0
- package/dist-lib/lib/connect/decode.d.ts +31 -0
- package/dist-lib/lib/connect/decode.js +114 -0
- package/dist-lib/lib/connect/host-run-log.d.ts +20 -0
- package/dist-lib/lib/connect/host-run-log.js +89 -0
- package/dist-lib/lib/connect/round-log.d.ts +8 -0
- package/dist-lib/lib/connect/round-log.js +33 -0
- package/dist-lib/lib/connect/served.d.ts +7 -0
- package/dist-lib/lib/connect/served.js +45 -0
- package/dist-lib/lib/connect.d.ts +5 -1
- package/dist-lib/lib/connect.js +102 -444
- package/dist-lib/lib/context-window.d.ts +13 -6
- package/dist-lib/lib/context-window.js +18 -5
- package/dist-lib/lib/contract/agent.d.ts +18 -1
- package/dist-lib/lib/contract/completion.d.ts +35 -3
- package/dist-lib/lib/contract/drive.d.ts +154 -4
- package/dist-lib/lib/contract/exec.d.ts +1 -0
- package/dist-lib/lib/contract/index.d.ts +1 -0
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/contract/media.d.ts +58 -0
- package/dist-lib/lib/contract/models.d.ts +6 -2
- package/dist-lib/lib/contract/ocr.d.ts +17 -0
- package/dist-lib/lib/contract/ocr.js +1 -0
- package/dist-lib/lib/contract/root-search.d.ts +34 -0
- package/dist-lib/lib/contract/root-search.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +13 -0
- package/dist-lib/lib/contract-types.d.ts +10 -2
- package/dist-lib/lib/docx/index.js +1 -1
- package/dist-lib/lib/errors.d.ts +8 -4
- package/dist-lib/lib/errors.js +12 -8
- package/dist-lib/lib/fold/index.d.ts +4 -2
- package/dist-lib/lib/fold/index.js +15 -7
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
- package/dist-lib/lib/helpers/completion-params.js +18 -2
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- package/dist-lib/lib/helpers/drain.d.ts +1 -1
- package/dist-lib/lib/helpers/drain.js +1 -1
- package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
- package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
- package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
- package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
- package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
- package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
- package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
- package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
- package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
- package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +36 -6
- package/dist-lib/lib/helpers/goal-check.js +34 -98
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
- package/dist-lib/lib/helpers/recent-map.js +23 -0
- package/dist-lib/lib/helpers/repeated-reply.js +9 -2
- package/dist-lib/lib/helpers/root-search.d.ts +3 -0
- package/dist-lib/lib/helpers/root-search.js +74 -0
- package/dist-lib/lib/helpers/run-latency.d.ts +14 -0
- package/dist-lib/lib/helpers/run-latency.js +63 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
- package/dist-lib/lib/helpers/run-outcome.js +6 -2
- package/dist-lib/lib/helpers/spawn-path.d.ts +1 -0
- package/dist-lib/lib/helpers/spawn-path.js +2 -1
- package/dist-lib/lib/helpers/stable-stringify.js +10 -2
- package/dist-lib/lib/helpers/text-coalescer.d.ts +6 -0
- package/dist-lib/lib/helpers/text-coalescer.js +44 -4
- package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
- package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.js +157 -0
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
- package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
- package/dist-lib/lib/lifecycle/completion-run.js +2 -2
- package/dist-lib/lib/log.d.ts +3 -0
- package/dist-lib/lib/log.js +17 -1
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +13 -16
- package/dist-lib/lib/machine/completion/actions/completion.js +110 -138
- package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
- package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
- package/dist-lib/lib/machine/completion/actions/prepare.js +2 -1
- package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
- package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
- package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
- package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
- package/dist-lib/lib/machine/completion/actions/tools.js +73 -151
- package/dist-lib/lib/machine/completion/context.js +6 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +2 -1
- package/dist-lib/lib/machine/completion/guards/retry.js +4 -3
- package/dist-lib/lib/machine/completion/implementations.d.ts +8 -5
- package/dist-lib/lib/machine/completion/implementations.js +22 -7
- package/dist-lib/lib/machine/completion/machine.d.ts +15 -6
- package/dist-lib/lib/machine/completion/machine.js +25 -5
- package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
- package/dist-lib/lib/machine/completion/metrics.js +70 -0
- package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
- package/dist-lib/lib/machine/completion/nudges.js +33 -0
- package/dist-lib/lib/machine/completion/rules.d.ts +10 -33
- package/dist-lib/lib/machine/completion/rules.js +27 -103
- package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
- package/dist-lib/lib/machine/completion/splice.js +19 -0
- package/dist-lib/lib/machine/completion/types.d.ts +37 -13
- package/dist-lib/lib/machine/index.d.ts +21 -7
- package/dist-lib/lib/machine/index.js +7 -2
- package/dist-lib/lib/media-host.d.ts +12 -0
- package/dist-lib/lib/media-host.js +52 -0
- package/dist-lib/lib/media-port.d.ts +20 -0
- package/dist-lib/lib/media-port.js +77 -0
- package/dist-lib/lib/media-wire.d.ts +8 -0
- package/dist-lib/lib/media-wire.js +111 -0
- package/dist-lib/lib/models/context-choice.js +8 -1
- package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
- package/dist-lib/lib/models/custom-model-cache.js +3 -0
- package/dist-lib/lib/models/gguf-header.d.ts +6 -0
- package/dist-lib/lib/models/gguf-header.js +38 -1
- package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
- package/dist-lib/lib/models/gpu-selection.js +29 -5
- package/dist-lib/lib/models/kv-cache.d.ts +2 -0
- package/dist-lib/lib/models/kv-cache.js +8 -0
- package/dist-lib/lib/models/llm-presets.js +27 -1
- package/dist-lib/lib/models/load-requests.d.ts +9 -0
- package/dist-lib/lib/models/load-requests.js +42 -0
- package/dist-lib/lib/models/model-catalog-constants.d.ts +3 -2
- package/dist-lib/lib/models/model-catalog-constants.js +8 -5
- package/dist-lib/lib/models/model-catalog.d.ts +12 -3
- package/dist-lib/lib/models/model-catalog.js +40 -16
- package/dist-lib/lib/models/model-delete.js +3 -0
- package/dist-lib/lib/models/model-handle.d.ts +1 -0
- package/dist-lib/lib/models/model-list.d.ts +2 -1
- package/dist-lib/lib/models/model-list.js +5 -1
- package/dist-lib/lib/models/model-pool.d.ts +7 -1
- package/dist-lib/lib/models/model-pool.js +34 -13
- package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
- package/dist-lib/lib/models/tts-model-default.js +8 -6
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +45 -8
- package/dist-lib/lib/office/index.js +1 -1
- package/dist-lib/lib/plugins/registry.d.ts +12 -0
- package/dist-lib/lib/plugins/registry.js +71 -15
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/prompt.d.ts +7 -4
- package/dist-lib/lib/prompt.js +81 -24
- package/dist-lib/lib/residency/completion-runtime.d.ts +8 -6
- package/dist-lib/lib/residency/completion-runtime.js +53 -9
- package/dist-lib/lib/residency/index.d.ts +12 -3
- package/dist-lib/lib/residency/index.js +52 -16
- package/dist-lib/lib/round-host.js +3 -3
- package/dist-lib/lib/round-port.js +3 -3
- package/dist-lib/lib/run-log/boundary.d.ts +1 -4
- package/dist-lib/lib/run-log/boundary.js +4 -21
- package/dist-lib/lib/run-log/history-codec.d.ts +1 -1
- package/dist-lib/lib/run-log/history-codec.js +3 -3
- package/dist-lib/lib/run-log/protocol.js +17 -16
- package/dist-lib/lib/run-log/redact.d.ts +10 -1
- package/dist-lib/lib/run-log/redact.js +99 -9
- package/dist-lib/lib/run-log/request-codec.d.ts +3 -0
- package/dist-lib/lib/run-log/request-codec.js +19 -4
- package/dist-lib/lib/run-log/run-journal.js +1 -1
- package/dist-lib/lib/sdk-loader.d.ts +1 -0
- package/dist-lib/lib/sdk-loader.js +14 -0
- package/dist-lib/lib/serve/completion.d.ts +7 -0
- package/dist-lib/lib/serve/completion.js +571 -0
- package/dist-lib/lib/serve/downloads.d.ts +4 -0
- package/dist-lib/lib/serve/downloads.js +79 -0
- package/dist-lib/lib/serve/models.d.ts +5 -0
- package/dist-lib/lib/serve/models.js +120 -0
- package/dist-lib/lib/serve/noop.d.ts +1 -0
- package/dist-lib/lib/serve/noop.js +1 -0
- package/dist-lib/lib/serve/requests.d.ts +148 -0
- package/dist-lib/lib/serve/requests.js +1 -0
- package/dist-lib/lib/serve/rounds.d.ts +11 -0
- package/dist-lib/lib/serve/rounds.js +67 -0
- package/dist-lib/lib/serve/run-log-start.d.ts +37 -0
- package/dist-lib/lib/serve/run-log-start.js +253 -0
- package/dist-lib/lib/serve/skills.d.ts +32 -0
- package/dist-lib/lib/serve/skills.js +46 -0
- package/dist-lib/lib/serve.d.ts +5 -1
- package/dist-lib/lib/serve.js +23 -995
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +11 -19
- package/dist-lib/lib/sidecar/user-plugins.js +6 -4
- package/dist-lib/lib/skills-host/index.d.ts +6 -3
- package/dist-lib/lib/skills-host/index.js +39 -18
- package/dist-lib/lib/spawn.d.ts +14 -0
- package/dist-lib/lib/spawn.js +9 -5
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
- package/dist-lib/lib/tools/attachments/staging.js +18 -22
- package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
- package/dist-lib/lib/tools/exec/runner.js +20 -3
- package/dist-lib/lib/tools/exec/shell-guidance.d.ts +2 -0
- package/dist-lib/lib/tools/exec/shell-guidance.js +29 -0
- package/dist-lib/lib/tools/exec.js +4 -2
- package/dist-lib/lib/tools/files/edit-file.d.ts +4 -1
- package/dist-lib/lib/tools/files/edit-file.js +220 -28
- package/dist-lib/lib/tools/files/glob.js +72 -11
- package/dist-lib/lib/tools/files/grep.js +65 -22
- package/dist-lib/lib/tools/files/index.js +3 -1
- package/dist-lib/lib/tools/files/read-file.js +199 -36
- package/dist-lib/lib/tools/fs/document-text.d.ts +7 -1
- package/dist-lib/lib/tools/fs/document-text.js +5 -21
- package/dist-lib/lib/tools/fs/drive.d.ts +1 -17
- package/dist-lib/lib/tools/fs/edit-match.d.ts +22 -0
- package/dist-lib/lib/tools/fs/edit-match.js +337 -45
- package/dist-lib/lib/tools/fs/engine.d.ts +9 -0
- package/dist-lib/lib/tools/fs/engine.js +28 -0
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +1 -81
- package/dist-lib/lib/tools/fs/scope.d.ts +2 -17
- package/dist-lib/lib/tools/fs/search.d.ts +2 -18
- package/dist-lib/lib/tools/fs/suggest.d.ts +8 -0
- package/dist-lib/lib/tools/fs/suggest.js +110 -0
- package/dist-lib/lib/tools/fs/tool-path.d.ts +3 -0
- package/dist-lib/lib/tools/fs/tool-path.js +13 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +5 -5
- package/dist-lib/lib/tools/fs/walk.js +22 -21
- package/dist-lib/lib/tools/http-request/request.d.ts +4 -2
- package/dist-lib/lib/tools/http-request/request.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +56 -11
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +93 -14
- package/dist-lib/lib/tools/index.d.ts +3 -1
- package/dist-lib/lib/tools/index.js +6 -2
- package/dist-lib/lib/tools/office/ops.d.ts +1 -0
- package/dist-lib/lib/tools/office/ops.js +5 -1
- package/dist-lib/lib/tools/office.d.ts +3 -2
- package/dist-lib/lib/tools/office.js +200 -39
- package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
- package/dist-lib/lib/tools/operations/builders.js +41 -3
- package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
- package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
- package/dist-lib/lib/tools/operations/compile.js +8 -6
- package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
- package/dist-lib/lib/tools/pdf/build.d.ts +13 -3
- package/dist-lib/lib/tools/pdf/build.js +52 -16
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +31 -0
- package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
- package/dist-lib/lib/tools/pdf/recognize.js +55 -0
- package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
- package/dist-lib/lib/tools/pdf/request.js +4 -4
- package/dist-lib/lib/tools/pdf.d.ts +0 -1
- package/dist-lib/lib/tools/pdf.js +42 -14
- package/dist-lib/lib/tools/skill.js +13 -4
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +8 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +38 -32
- package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
- package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
- package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
- package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
- package/dist-lib/lib/tools/skills/catalog.d.ts +5 -8
- package/dist-lib/lib/tools/skills/catalog.js +1 -162
- package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/credential-check.js +3 -0
- package/dist-lib/lib/tools/skills/index.d.ts +1 -0
- package/dist-lib/lib/tools/skills/index.js +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +27 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
- package/dist-lib/lib/tools/skills/overlay-watch.d.ts +2 -2
- package/dist-lib/lib/tools/skills/overlay-watch.js +4 -3
- package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/skills/skill-tree.d.ts +5 -0
- package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
- package/dist-lib/lib/tools/tls-failure.d.ts +1 -0
- package/dist-lib/lib/tools/tls-failure.js +8 -0
- package/dist-lib/lib/tools/toolsets.d.ts +1 -1
- package/dist-lib/lib/tools/toolsets.js +2 -0
- package/dist-lib/lib/tools/web-fetch.js +46 -130
- package/dist-lib/lib/wire/download.d.ts +10 -0
- package/dist-lib/lib/wire/download.js +35 -0
- package/dist-lib/lib/wire/event.d.ts +41 -0
- package/dist-lib/lib/wire/event.js +306 -0
- package/dist-lib/lib/wire/fields.d.ts +3 -0
- package/dist-lib/lib/wire/fields.js +12 -0
- package/dist-lib/lib/wire/knowledge.d.ts +9 -0
- package/dist-lib/lib/wire/knowledge.js +68 -0
- package/dist-lib/lib/wire/round.d.ts +14 -0
- package/dist-lib/lib/wire/round.js +45 -0
- package/dist-lib/lib/wire/vectors.d.ts +6 -0
- package/dist-lib/lib/wire/vectors.js +33 -0
- package/dist-lib/lib/wire.d.ts +28 -77
- package/dist-lib/lib/wire.js +24 -463
- package/dist-lib/plugins/charts/chart-tool.d.ts +8 -0
- package/dist-lib/plugins/charts/chart-tool.js +175 -0
- package/dist-lib/plugins/charts/index.d.ts +16 -0
- package/dist-lib/plugins/charts/index.js +21 -0
- package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
- package/dist-lib/plugins/coding-guards/index.js +126 -0
- package/dist-lib/plugins/diagrams/draw.d.ts +10 -0
- package/dist-lib/plugins/diagrams/draw.js +90 -0
- package/dist-lib/plugins/diagrams/index.d.ts +13 -0
- package/dist-lib/plugins/diagrams/index.js +15 -0
- package/dist-lib/plugins/diagrams/render.d.ts +16 -0
- package/dist-lib/plugins/diagrams/render.js +285 -0
- package/dist-lib/plugins/image/edit-image.d.ts +3 -22
- package/dist-lib/plugins/image/edit-image.js +20 -44
- package/dist-lib/plugins/image/fit.d.ts +31 -0
- package/dist-lib/plugins/image/fit.js +28 -0
- package/dist-lib/plugins/image/generate-image.d.ts +24 -4
- package/dist-lib/plugins/image/generate-image.js +198 -72
- package/dist-lib/plugins/image/index.d.ts +2 -1
- package/dist-lib/plugins/image/index.js +17 -8
- package/dist-lib/plugins/knowledge/index.d.ts +3 -0
- package/dist-lib/plugins/knowledge/index.js +5 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
- package/dist-lib/plugins/knowledge/manifest.js +86 -0
- package/dist-lib/plugins/knowledge/search-tool.js +8 -8
- package/dist-lib/plugins/knowledge/store.d.ts +45 -8
- package/dist-lib/plugins/knowledge/store.js +428 -166
- package/dist-lib/plugins/mcp/call.js +15 -4
- package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
- package/dist-lib/plugins/mcp/protocol.js +13 -12
- package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
- package/dist-lib/plugins/mcp/tool-listing.js +97 -0
- package/dist-lib/plugins/music/generate-music.d.ts +21 -4
- package/dist-lib/plugins/music/generate-music.js +168 -65
- package/dist-lib/plugins/music/index.d.ts +2 -1
- package/dist-lib/plugins/music/index.js +11 -6
- package/dist-lib/plugins/obsidian/index.js +14 -4
- package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
- package/dist-lib/plugins/ocr/bmp.js +27 -0
- package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
- package/dist-lib/plugins/ocr/coverage.js +67 -0
- package/dist-lib/plugins/ocr/index.d.ts +12 -0
- package/dist-lib/plugins/ocr/index.js +20 -0
- package/dist-lib/plugins/ocr/ocr-runtime.d.ts +25 -0
- package/dist-lib/plugins/ocr/ocr-runtime.js +103 -0
- package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
- package/dist-lib/plugins/ocr/reading-order.js +218 -0
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- package/dist-lib/plugins/python/index.d.ts +4 -1
- package/dist-lib/plugins/python/index.js +5 -1
- package/dist-lib/plugins/python/language.js +11 -10
- package/dist-lib/plugins/python/python-adapter.d.ts +6 -1
- package/dist-lib/plugins/python/python-adapter.js +34 -1
- package/dist-lib/plugins/python/worker/client.js +1 -1
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- package/dist-lib/plugins/python/worker/spawn.js +1 -1
- package/dist-lib/plugins/ripgrep/index.d.ts +15 -0
- package/dist-lib/plugins/ripgrep/index.js +28 -0
- package/dist-lib/plugins/run-report/story.js +4 -1
- package/dist-lib/plugins/sandbox-linux/index.js +2 -2
- package/dist-lib/plugins/sandbox-macos/index.js +2 -2
- package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
- package/dist-lib/plugins/sandbox-vm/index.js +2 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +3 -1
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +45 -16
- package/dist-lib/plugins/sandbox-windows/index.js +2 -2
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/speech-engine.d.ts +1 -1
- package/dist-lib/plugins/speech/speech-engine.js +10 -5
- package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
- package/dist-lib/plugins/speech/speech-text.js +9 -4
- package/dist-lib/plugins/speech/voice.js +7 -2
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -0
- package/dist-lib/plugins/walkie-talkie/index.js +6 -1
- package/dist-lib/plugins/weather/lookup.js +1 -0
- package/dist-lib/schema/baseline.d.ts +2 -1
- package/dist-lib/schema/baseline.js +2 -2
- package/dist-lib/schema/generate.js +8 -1
- package/dist-lib/schema/harness.js +34 -5
- package/dist-lib/schema/release-tags.d.ts +2 -1
- package/dist-lib/schema/release-tags.js +9 -10
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +126 -13
- package/dist-lib/spec/hyperschema/index.js +126 -13
- package/dist-lib/spec/hyperschema/schema.json +86 -2
- package/dist-lib/spec/hyperschema/types.d.ts +18 -3
- package/package.json +96 -36
- package/scripts/addon-externals.cjs +7 -1
- package/worker/harness-sidecar.mjs +10 -0
- package/dist-lib/lib/helpers/buffer-burst.d.ts +0 -1
- package/dist-lib/lib/helpers/buffer-burst.js +0 -22
- package/dist-lib/lib/office/engine/codes.d.ts +0 -62
- package/dist-lib/lib/office/engine/codes.js +0 -61
- package/dist-lib/lib/office/engine/docx/document.d.ts +0 -216
- package/dist-lib/lib/office/engine/docx/document.js +0 -1152
- package/dist-lib/lib/office/engine/docx/index.d.ts +0 -7
- package/dist-lib/lib/office/engine/docx/index.js +0 -8
- package/dist-lib/lib/office/engine/docx/styles.d.ts +0 -31
- package/dist-lib/lib/office/engine/docx/styles.js +0 -173
- package/dist-lib/lib/office/engine/docx/template.d.ts +0 -18
- package/dist-lib/lib/office/engine/docx/template.js +0 -133
- package/dist-lib/lib/office/engine/docx/text.d.ts +0 -55
- package/dist-lib/lib/office/engine/docx/text.js +0 -538
- package/dist-lib/lib/office/engine/drawingml/chart.d.ts +0 -63
- package/dist-lib/lib/office/engine/drawingml/chart.js +0 -539
- package/dist-lib/lib/office/engine/drawingml/text.d.ts +0 -35
- package/dist-lib/lib/office/engine/drawingml/text.js +0 -352
- package/dist-lib/lib/office/engine/errors.d.ts +0 -6
- package/dist-lib/lib/office/engine/errors.js +0 -12
- package/dist-lib/lib/office/engine/image.d.ts +0 -8
- package/dist-lib/lib/office/engine/image.js +0 -48
- package/dist-lib/lib/office/engine/index.d.ts +0 -12
- package/dist-lib/lib/office/engine/index.js +0 -7
- package/dist-lib/lib/office/engine/opc/content-types.d.ts +0 -17
- package/dist-lib/lib/office/engine/opc/content-types.js +0 -74
- package/dist-lib/lib/office/engine/opc/media.d.ts +0 -13
- package/dist-lib/lib/office/engine/opc/media.js +0 -11
- package/dist-lib/lib/office/engine/opc/package.d.ts +0 -51
- package/dist-lib/lib/office/engine/opc/package.js +0 -324
- package/dist-lib/lib/office/engine/opc/paths.d.ts +0 -7
- package/dist-lib/lib/office/engine/opc/paths.js +0 -46
- package/dist-lib/lib/office/engine/opc/properties.d.ts +0 -7
- package/dist-lib/lib/office/engine/opc/properties.js +0 -75
- package/dist-lib/lib/office/engine/opc/relationships.d.ts +0 -23
- package/dist-lib/lib/office/engine/opc/relationships.js +0 -65
- package/dist-lib/lib/office/engine/opc/zip.d.ts +0 -15
- package/dist-lib/lib/office/engine/opc/zip.js +0 -264
- package/dist-lib/lib/office/engine/pptx/fit.d.ts +0 -12
- package/dist-lib/lib/office/engine/pptx/fit.js +0 -37
- package/dist-lib/lib/office/engine/pptx/index.d.ts +0 -8
- package/dist-lib/lib/office/engine/pptx/index.js +0 -8
- package/dist-lib/lib/office/engine/pptx/inherit.d.ts +0 -29
- package/dist-lib/lib/office/engine/pptx/inherit.js +0 -155
- package/dist-lib/lib/office/engine/pptx/notes.d.ts +0 -5
- package/dist-lib/lib/office/engine/pptx/notes.js +0 -85
- package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +0 -23
- package/dist-lib/lib/office/engine/pptx/picture-area.js +0 -84
- package/dist-lib/lib/office/engine/pptx/presentation.d.ts +0 -56
- package/dist-lib/lib/office/engine/pptx/presentation.js +0 -787
- package/dist-lib/lib/office/engine/pptx/read.d.ts +0 -9
- package/dist-lib/lib/office/engine/pptx/read.js +0 -66
- package/dist-lib/lib/office/engine/pptx/shapes.d.ts +0 -52
- package/dist-lib/lib/office/engine/pptx/shapes.js +0 -276
- package/dist-lib/lib/office/engine/pptx/slides.d.ts +0 -27
- package/dist-lib/lib/office/engine/pptx/slides.js +0 -123
- package/dist-lib/lib/office/engine/pptx/template.d.ts +0 -20
- package/dist-lib/lib/office/engine/pptx/template.js +0 -391
- package/dist-lib/lib/office/engine/pptx/types.d.ts +0 -121
- package/dist-lib/lib/office/engine/units.d.ts +0 -3
- package/dist-lib/lib/office/engine/units.js +0 -12
- package/dist-lib/lib/office/engine/utf8.d.ts +0 -2
- package/dist-lib/lib/office/engine/utf8.js +0 -103
- package/dist-lib/lib/office/engine/xlsx/formula.d.ts +0 -49
- package/dist-lib/lib/office/engine/xlsx/formula.js +0 -381
- package/dist-lib/lib/office/engine/xlsx/index.d.ts +0 -8
- package/dist-lib/lib/office/engine/xlsx/index.js +0 -8
- package/dist-lib/lib/office/engine/xlsx/refs.d.ts +0 -22
- package/dist-lib/lib/office/engine/xlsx/refs.js +0 -82
- package/dist-lib/lib/office/engine/xlsx/reshape.d.ts +0 -21
- package/dist-lib/lib/office/engine/xlsx/reshape.js +0 -424
- package/dist-lib/lib/office/engine/xlsx/sheet.d.ts +0 -108
- package/dist-lib/lib/office/engine/xlsx/sheet.js +0 -662
- package/dist-lib/lib/office/engine/xlsx/strings.d.ts +0 -15
- package/dist-lib/lib/office/engine/xlsx/strings.js +0 -93
- package/dist-lib/lib/office/engine/xlsx/styles.d.ts +0 -38
- package/dist-lib/lib/office/engine/xlsx/styles.js +0 -369
- package/dist-lib/lib/office/engine/xlsx/template.d.ts +0 -7
- package/dist-lib/lib/office/engine/xlsx/template.js +0 -54
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +0 -162
- package/dist-lib/lib/office/engine/xlsx/workbook.js +0 -881
- package/dist-lib/lib/office/engine/xlsx/write.d.ts +0 -2
- package/dist-lib/lib/office/engine/xlsx/write.js +0 -42
- package/dist-lib/lib/office/engine/xml.d.ts +0 -45
- package/dist-lib/lib/office/engine/xml.js +0 -258
- package/patches/localwatch@1.4.3.patch +0 -13
- /package/dist-lib/lib/{office/engine/pptx/types.js → contract/media.js} +0 -0
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { HarnessError } from '../../lib/errors.js';
|
|
2
2
|
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
3
3
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
4
|
-
import { createGenerateMusicTool, createMusicRuntime } from './generate-music.js';
|
|
5
|
-
|
|
6
|
-
'@qvac/audiogen-ggml': () => import.meta.resolve('@qvac/audiogen-ggml/binding.js'),
|
|
7
|
-
'@qvac/decoder-audio': () => import.meta.resolve('@qvac/decoder-audio')
|
|
8
|
-
});
|
|
9
|
-
export { audioDurationSeconds, backendDevice, backendName, CPU_FALLBACK_NOTICE, createGenerateMusicTool, createMusicRuntime, gpuFallback, musicPercentTick, pcmToWav, presentStats } from './generate-music.js';
|
|
4
|
+
import { audioGenServer, createGenerateMusicTool, createMusicRuntime } from './generate-music.js';
|
|
5
|
+
export { audioDurationSeconds, audioGenServer, backendDevice, backendName, CPU_FALLBACK_NOTICE, createGenerateMusicTool, createMusicRuntime, gpuFallback, musicPercentTick, pcmToWav, presentStats } from './generate-music.js';
|
|
10
6
|
export class Music {
|
|
11
7
|
name = 'music';
|
|
12
8
|
api = PluginRegistry.API_VERSION;
|
|
13
9
|
needs = ['models'];
|
|
10
|
+
provides = ['music-rounds'];
|
|
14
11
|
addons = { 'audiogen-ggml': () => import('@qvac/audiogen-ggml/binding.js') };
|
|
15
12
|
read;
|
|
16
13
|
_options;
|
|
17
14
|
constructor(options) {
|
|
15
|
+
PluginRegistry.requirePeers('music', {
|
|
16
|
+
'@qvac/audiogen-ggml': () => import.meta.resolve('@qvac/audiogen-ggml/binding.js'),
|
|
17
|
+
'@qvac/decoder-audio': () => import.meta.resolve('@qvac/decoder-audio')
|
|
18
|
+
});
|
|
18
19
|
this._options = options;
|
|
19
20
|
this.read = options?.read;
|
|
20
21
|
}
|
|
@@ -43,11 +44,15 @@ export class Music {
|
|
|
43
44
|
loads: models,
|
|
44
45
|
loadSdk,
|
|
45
46
|
hold: models.hold,
|
|
47
|
+
requests: models.requests,
|
|
46
48
|
onProgress: (name, progress) => models.emit(models.progressState(name, progress)),
|
|
47
49
|
onBeforeLoad: (signal, srcs) => models.makeRoom(signal, new HarnessError('CHAT_MODEL_BUSY', ['music']), srcs)
|
|
48
50
|
});
|
|
49
51
|
return {
|
|
50
52
|
tools: [createGenerateMusicTool(runtime, clamps)],
|
|
53
|
+
services: {
|
|
54
|
+
'music-rounds': audioGenServer(runtime, (name, addon) => models.isCached(name, addon), clamps)
|
|
55
|
+
},
|
|
51
56
|
unload: () => runtime.unload(),
|
|
52
57
|
unloadIdle: () => runtime.unloadIdle()
|
|
53
58
|
};
|
|
@@ -4,11 +4,15 @@ import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
|
4
4
|
import { SKILL_STATE } from '../../lib/tools/skills/skill-state-constants.js';
|
|
5
5
|
import { isObsidianVaultPath, isSandboxedWorkbenchInstall, OBSIDIAN_SKILL_NAME, OBSIDIAN_VAULT_MODE_NOTE, OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY, obsidianCliState, obsidianInstallState } from './readiness.js';
|
|
6
6
|
import { capOutput, MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
|
|
7
|
-
import { runObsidianCli } from './cli.js';
|
|
8
7
|
import { normalizeObsidianCommand, parseObsidianCommand } from './command.js';
|
|
9
8
|
import { OBSIDIAN_DESKTOP_AGENT_REQUIRED, OBSIDIAN_NO_SHELL_FALLBACK, OBSIDIAN_VAULT_SETUP_REQUIRED } from './guidance.js';
|
|
10
|
-
import {
|
|
9
|
+
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
11
10
|
const DESKTOP_PLATFORMS = new Set(['darwin', 'linux', 'win32']);
|
|
11
|
+
const backends = retryMemo(() => Promise.all([import('./vault-fs.js'), import('./cli.js')]).catch((err) => {
|
|
12
|
+
throw new Error(`plugin 'obsidian' could not load its implementation: ${errorMessage(err)}`, {
|
|
13
|
+
cause: err
|
|
14
|
+
});
|
|
15
|
+
}));
|
|
12
16
|
function credentialRecord(value) {
|
|
13
17
|
if (typeof value === 'string') {
|
|
14
18
|
return value ? { token: value } : null;
|
|
@@ -27,7 +31,7 @@ function vaultFsResult(stdout, exitCode) {
|
|
|
27
31
|
? { stdout, stderr: '', exitCode: 0 }
|
|
28
32
|
: { stdout: '', stderr: `${stdout}\n\n${OBSIDIAN_NO_SHELL_FALLBACK}`, exitCode };
|
|
29
33
|
}
|
|
30
|
-
function runVaultFs(vaultPath, { action, args, maxOutputChars }) {
|
|
34
|
+
function runVaultFs(executeVaultFsAction, vaultPath, { action, args, maxOutputChars }) {
|
|
31
35
|
try {
|
|
32
36
|
return limitResult(vaultFsResult(executeVaultFsAction(vaultPath, action, args), 0), maxOutputChars);
|
|
33
37
|
}
|
|
@@ -124,11 +128,17 @@ export class ObsidianRoute {
|
|
|
124
128
|
}
|
|
125
129
|
const vaultPath = await resolveVaultPath(this._options.credentialStore, ctx);
|
|
126
130
|
if (vaultPath) {
|
|
127
|
-
|
|
131
|
+
const [{ executeVaultFsAction }] = await backends();
|
|
132
|
+
return runVaultFs(executeVaultFsAction, vaultPath, {
|
|
133
|
+
action: parsed.action,
|
|
134
|
+
args: parsed.args,
|
|
135
|
+
maxOutputChars
|
|
136
|
+
});
|
|
128
137
|
}
|
|
129
138
|
if (isSandboxedWorkbenchInstall(this._options.env ?? process.env)) {
|
|
130
139
|
return { stdout: '', stderr: OBSIDIAN_VAULT_SETUP_REQUIRED, exitCode: 1 };
|
|
131
140
|
}
|
|
141
|
+
const [, { runObsidianCli }] = await backends();
|
|
132
142
|
return runObsidianCli(normalizeObsidianCommand(command), await runtime(), {
|
|
133
143
|
timeoutMs,
|
|
134
144
|
maxOutputChars,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
const HEADER_BYTES = 54;
|
|
3
|
+
export function bmp({ width, height, data }) {
|
|
4
|
+
const row = (width * 3 + 3) & ~3;
|
|
5
|
+
const bytes = b4a.alloc(HEADER_BYTES + row * height);
|
|
6
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
7
|
+
bytes[0] = 0x42;
|
|
8
|
+
bytes[1] = 0x4d;
|
|
9
|
+
view.setUint32(2, bytes.byteLength, true);
|
|
10
|
+
view.setUint32(10, HEADER_BYTES, true);
|
|
11
|
+
view.setUint32(14, 40, true);
|
|
12
|
+
view.setInt32(18, width, true);
|
|
13
|
+
view.setInt32(22, height, true);
|
|
14
|
+
view.setUint16(26, 1, true);
|
|
15
|
+
view.setUint16(28, 24, true);
|
|
16
|
+
view.setUint32(34, row * height, true);
|
|
17
|
+
for (let y = 0; y < height; y++) {
|
|
18
|
+
const from = (height - 1 - y) * width * 4;
|
|
19
|
+
const to = HEADER_BYTES + y * row;
|
|
20
|
+
for (let x = 0; x < width; x++) {
|
|
21
|
+
bytes[to + x * 3] = data[from + x * 4 + 2] ?? 0;
|
|
22
|
+
bytes[to + x * 3 + 1] = data[from + x * 4 + 1] ?? 0;
|
|
23
|
+
bytes[to + x * 3 + 2] = data[from + x * 4] ?? 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return bytes;
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const BOX_PAD = 2;
|
|
2
|
+
export function inkCoverage(image, blocks) {
|
|
3
|
+
const lum = luminance(image);
|
|
4
|
+
const level = otsu(lum);
|
|
5
|
+
const words = wordMask(image, blocks);
|
|
6
|
+
let ink = 0;
|
|
7
|
+
let covered = 0;
|
|
8
|
+
for (let i = 0; i < lum.length; i++) {
|
|
9
|
+
if ((lum[i] ?? 0) > level)
|
|
10
|
+
continue;
|
|
11
|
+
ink++;
|
|
12
|
+
covered += words[i] ?? 0;
|
|
13
|
+
}
|
|
14
|
+
return ink === 0 ? 1 : covered / ink;
|
|
15
|
+
}
|
|
16
|
+
function luminance({ width, height, data }) {
|
|
17
|
+
const lum = new Uint8Array(width * height);
|
|
18
|
+
for (let i = 0; i < lum.length; i++) {
|
|
19
|
+
const at = i * 4;
|
|
20
|
+
lum[i] = ((data[at] ?? 0) * 299 + (data[at + 1] ?? 0) * 587 + (data[at + 2] ?? 0) * 114) / 1000;
|
|
21
|
+
}
|
|
22
|
+
return lum;
|
|
23
|
+
}
|
|
24
|
+
function otsu(lum) {
|
|
25
|
+
const counts = new Float64Array(256);
|
|
26
|
+
for (const value of lum) {
|
|
27
|
+
counts[value] = (counts[value] ?? 0) + 1;
|
|
28
|
+
}
|
|
29
|
+
let total = 0;
|
|
30
|
+
counts.forEach((count, value) => {
|
|
31
|
+
total += value * count;
|
|
32
|
+
});
|
|
33
|
+
let dark = 0;
|
|
34
|
+
let darkSum = 0;
|
|
35
|
+
let best = -1;
|
|
36
|
+
let level = 0;
|
|
37
|
+
counts.forEach((count, value) => {
|
|
38
|
+
dark += count;
|
|
39
|
+
darkSum += value * count;
|
|
40
|
+
const light = lum.length - dark;
|
|
41
|
+
if (dark === 0 || light === 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const between = dark * light * (darkSum / dark - (total - darkSum) / light) ** 2;
|
|
45
|
+
if (between > best) {
|
|
46
|
+
best = between;
|
|
47
|
+
level = value;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return level;
|
|
51
|
+
}
|
|
52
|
+
function wordMask({ width, height }, blocks) {
|
|
53
|
+
const mask = new Uint8Array(width * height);
|
|
54
|
+
for (const { bbox } of blocks) {
|
|
55
|
+
if (!bbox)
|
|
56
|
+
continue;
|
|
57
|
+
const [x0, y0, x1, y1] = bbox;
|
|
58
|
+
const left = Math.max(0, Math.floor(x0) - BOX_PAD);
|
|
59
|
+
const right = Math.min(width, Math.ceil(x1) + BOX_PAD);
|
|
60
|
+
const top = Math.max(0, Math.floor(y0) - BOX_PAD);
|
|
61
|
+
const bottom = Math.min(height, Math.ceil(y1) + BOX_PAD);
|
|
62
|
+
for (let y = top; y < bottom; y++) {
|
|
63
|
+
mask.fill(1, y * width + left, y * width + right);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return mask;
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
|
|
2
|
+
export declare class Ocr implements HarnessPlugin {
|
|
3
|
+
readonly name = "ocr";
|
|
4
|
+
readonly api = 1;
|
|
5
|
+
readonly provides: string[];
|
|
6
|
+
readonly needs: string[];
|
|
7
|
+
readonly addons: {
|
|
8
|
+
'ocr-ggml': () => Promise<(callback: (priority: number, message: string) => void) => void>;
|
|
9
|
+
};
|
|
10
|
+
constructor();
|
|
11
|
+
setup(ctx: PluginContext): PluginSetup;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
|
+
import { OcrRuntime } from './ocr-runtime.js';
|
|
3
|
+
export class Ocr {
|
|
4
|
+
name = 'ocr';
|
|
5
|
+
api = PluginRegistry.API_VERSION;
|
|
6
|
+
provides = ['ocr'];
|
|
7
|
+
needs = ['models'];
|
|
8
|
+
addons = {
|
|
9
|
+
'ocr-ggml': async () => (await import('@qvac/ocr-ggml/addonLogging')).default.setLogger
|
|
10
|
+
};
|
|
11
|
+
constructor() {
|
|
12
|
+
PluginRegistry.requirePeers('ocr', {
|
|
13
|
+
'@qvac/ocr-ggml': () => import.meta.resolve('@qvac/ocr-ggml/addonLogging')
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
setup(ctx) {
|
|
17
|
+
const runtime = new OcrRuntime(ctx.service('models'));
|
|
18
|
+
return { services: { ocr: runtime }, unloadIdle: () => runtime.unloadIdle() };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import type { ModelHost } from '../../lib/contract/models.ts';
|
|
3
|
+
import type { OcrImage, OcrPage, OcrService } from '../../lib/contract/ocr.ts';
|
|
4
|
+
import { type OcrBlock } from './reading-order.ts';
|
|
5
|
+
export interface OcrSdk {
|
|
6
|
+
ocr(params: {
|
|
7
|
+
modelId: string;
|
|
8
|
+
image: Uint8Array;
|
|
9
|
+
}): {
|
|
10
|
+
blocks: Promise<OcrBlock[]>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare class OcrRuntime implements OcrService {
|
|
14
|
+
private readonly _models;
|
|
15
|
+
private readonly _loadSdk;
|
|
16
|
+
private readonly _pool;
|
|
17
|
+
private _tail;
|
|
18
|
+
private readonly _kept;
|
|
19
|
+
constructor(models: ModelHost);
|
|
20
|
+
read(image: OcrImage, signal?: BareAbortSignal): Promise<OcrPage>;
|
|
21
|
+
unloadIdle(): Promise<void>;
|
|
22
|
+
private _recognize;
|
|
23
|
+
private _open;
|
|
24
|
+
private _serial;
|
|
25
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { OCR_DOCTR, OCR_DOCTR_1 } from '@qvac/inference/models';
|
|
3
|
+
import { errorMessage } from '../../lib/guards.js';
|
|
4
|
+
import { raceAbort } from '../../lib/helpers/race-abort.js';
|
|
5
|
+
import { RecentMap } from '../../lib/helpers/recent-map.js';
|
|
6
|
+
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
7
|
+
import { HarnessLog } from '../../lib/log.js';
|
|
8
|
+
import { bmp } from './bmp.js';
|
|
9
|
+
import { inkCoverage } from './coverage.js';
|
|
10
|
+
import { readingOrder } from './reading-order.js';
|
|
11
|
+
const OCR_MODEL_LABEL = 'OCR model';
|
|
12
|
+
const KEPT_PAGES = 1024;
|
|
13
|
+
function ocrSdk(models) {
|
|
14
|
+
return retryMemo(async () => {
|
|
15
|
+
const sdk = await models.sdk();
|
|
16
|
+
if (typeof globalThis.Bare !== 'undefined') {
|
|
17
|
+
const [{ ocrPlugin }, { registerPlugin }] = await Promise.all([
|
|
18
|
+
import('@qvac/inference/ggml-ocr/plugin'),
|
|
19
|
+
import('@qvac/inference/plugin-registry')
|
|
20
|
+
]);
|
|
21
|
+
try {
|
|
22
|
+
registerPlugin(ocrPlugin);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
HarnessLog.warn('plugin registration skipped', { plugin: 'ocr', err: errorMessage(err) });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return sdk;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export class OcrRuntime {
|
|
32
|
+
_models;
|
|
33
|
+
_loadSdk;
|
|
34
|
+
_pool;
|
|
35
|
+
_tail = Promise.resolve();
|
|
36
|
+
_kept = new RecentMap(KEPT_PAGES);
|
|
37
|
+
constructor(models) {
|
|
38
|
+
this._models = models;
|
|
39
|
+
this._loadSdk = ocrSdk(models);
|
|
40
|
+
this._pool = models.registerPool({
|
|
41
|
+
addon: 'ocr',
|
|
42
|
+
modelType: 'ggml-ocr',
|
|
43
|
+
modelConfig: { pipelineType: 'doctr', detectorModelSrc: OCR_DOCTR_1 },
|
|
44
|
+
label: OCR_MODEL_LABEL,
|
|
45
|
+
sdk: this._loadSdk
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async read(image, signal) {
|
|
49
|
+
const key = pageKey(image);
|
|
50
|
+
const kept = this._kept.get(key);
|
|
51
|
+
if (kept) {
|
|
52
|
+
return kept;
|
|
53
|
+
}
|
|
54
|
+
const page = await this._recognize(image, signal);
|
|
55
|
+
this._kept.set(key, page);
|
|
56
|
+
return page;
|
|
57
|
+
}
|
|
58
|
+
unloadIdle() {
|
|
59
|
+
return this._pool.evictIdle(() => true);
|
|
60
|
+
}
|
|
61
|
+
async _recognize(image, signal) {
|
|
62
|
+
const { held, releaseWork } = this._open();
|
|
63
|
+
let job = null;
|
|
64
|
+
try {
|
|
65
|
+
const { modelId } = await raceAbort(held.load(), signal);
|
|
66
|
+
const sdk = await this._loadSdk();
|
|
67
|
+
job = this._serial(async () => {
|
|
68
|
+
const blocks = await sdk.ocr({ modelId, image: bmp(image) }).blocks;
|
|
69
|
+
return { text: readingOrder(blocks), coverage: inkCoverage(image, blocks) };
|
|
70
|
+
});
|
|
71
|
+
return await raceAbort(job, signal);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
void Promise.allSettled([job ?? held.peek()]).then(() => {
|
|
75
|
+
try {
|
|
76
|
+
held.release();
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
releaseWork();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_open() {
|
|
85
|
+
const releaseWork = this._models.enterWork();
|
|
86
|
+
try {
|
|
87
|
+
return { held: this._pool.open(OCR_DOCTR.src), releaseWork };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
releaseWork();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_serial(job) {
|
|
95
|
+
const run = this._tail.then(job);
|
|
96
|
+
this._tail = run.catch(noop);
|
|
97
|
+
return run;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function noop() { }
|
|
101
|
+
function pageKey({ width, height, data }) {
|
|
102
|
+
return createHash('sha256').update(`${width}x${height}:`).update(data).digest('hex');
|
|
103
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const COLUMNS = { start: 'left', end: 'right' };
|
|
2
|
+
const ROWS = { start: 'top', end: 'bottom' };
|
|
3
|
+
const COLUMN_GAP = 1.5;
|
|
4
|
+
const BLOCK_GAP = 1;
|
|
5
|
+
const COLUMN_WORDS = 4;
|
|
6
|
+
const MARGIN_LINES = 0.6;
|
|
7
|
+
const MARGIN_MIN_LINES = 10;
|
|
8
|
+
const SPANNED_LINES = 0.2;
|
|
9
|
+
const MARGIN_SLACK = 0.25;
|
|
10
|
+
const SPANS = 0.5;
|
|
11
|
+
const HEADING_INSET = 0.25;
|
|
12
|
+
export function readingOrder(blocks) {
|
|
13
|
+
const words = blocks.flatMap(({ text, bbox }) => bbox ? [{ text, left: bbox[0], top: bbox[1], right: bbox[2], bottom: bbox[3] }] : []);
|
|
14
|
+
if (words.length < blocks.length) {
|
|
15
|
+
return blocks.map((block) => block.text).join('\n');
|
|
16
|
+
}
|
|
17
|
+
const level = deskewed(words);
|
|
18
|
+
return regionLines(level, medianHeight(level)).join('\n');
|
|
19
|
+
}
|
|
20
|
+
function deskewed(words) {
|
|
21
|
+
const gutter = medianHeight(words) * COLUMN_GAP;
|
|
22
|
+
const slants = chainLines(words).flatMap(({ words: line }) => segments(line, gutter).flatMap((run) => (run.length >= 3 ? [slope(run)] : [])));
|
|
23
|
+
const tilt = slants.sort((a, b) => a - b)[Math.floor(slants.length / 2)] ?? 0;
|
|
24
|
+
if (tilt === 0 || slants.length < MARGIN_MIN_LINES) {
|
|
25
|
+
return [...words];
|
|
26
|
+
}
|
|
27
|
+
return words.map((word) => {
|
|
28
|
+
const across = tilt * middle(word);
|
|
29
|
+
const down = tilt * centre(word);
|
|
30
|
+
const { text, left, top, right, bottom } = word;
|
|
31
|
+
return {
|
|
32
|
+
text,
|
|
33
|
+
left: left + across,
|
|
34
|
+
right: right + across,
|
|
35
|
+
top: top - down,
|
|
36
|
+
bottom: bottom - down
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function slope(run) {
|
|
41
|
+
const first = run[0];
|
|
42
|
+
const last = run.at(-1);
|
|
43
|
+
if (!first || !last || centre(last) === centre(first)) {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
return (middle(last) - middle(first)) / (centre(last) - centre(first));
|
|
47
|
+
}
|
|
48
|
+
function segments(line, gutter) {
|
|
49
|
+
const runs = [];
|
|
50
|
+
let reach = -Infinity;
|
|
51
|
+
for (const word of line) {
|
|
52
|
+
if (word.left - reach >= gutter) {
|
|
53
|
+
runs.push([]);
|
|
54
|
+
}
|
|
55
|
+
runs.at(-1)?.push(word);
|
|
56
|
+
reach = Math.max(reach, word.right);
|
|
57
|
+
}
|
|
58
|
+
return runs;
|
|
59
|
+
}
|
|
60
|
+
function regionLines(words, lineHeight) {
|
|
61
|
+
const columns = dense(split(words, COLUMNS, lineHeight * COLUMN_GAP)) ?? dense(marginColumns(words, lineHeight));
|
|
62
|
+
if (columns) {
|
|
63
|
+
return columns.flatMap((column) => regionLines(column, lineHeight));
|
|
64
|
+
}
|
|
65
|
+
const blocks = split(words, ROWS, lineHeight * BLOCK_GAP) ?? spannedBands(words, lineHeight);
|
|
66
|
+
if (blocks) {
|
|
67
|
+
return blocks.flatMap((block) => regionLines(block, lineHeight));
|
|
68
|
+
}
|
|
69
|
+
return chainLines(words).map((line) => line.words.map((word) => word.text).join(' '));
|
|
70
|
+
}
|
|
71
|
+
function split(words, { start, end }, gap) {
|
|
72
|
+
const parts = [];
|
|
73
|
+
let reach = -Infinity;
|
|
74
|
+
for (const word of [...words].sort((a, b) => a[start] - b[start])) {
|
|
75
|
+
if (word[start] - reach >= gap) {
|
|
76
|
+
parts.push([]);
|
|
77
|
+
}
|
|
78
|
+
parts.at(-1)?.push(word);
|
|
79
|
+
reach = Math.max(reach, word[end]);
|
|
80
|
+
}
|
|
81
|
+
return parts.length > 1 ? parts : null;
|
|
82
|
+
}
|
|
83
|
+
function dense(columns) {
|
|
84
|
+
const text = columns?.every((column) => column.length / chainLines(column).length >= COLUMN_WORDS);
|
|
85
|
+
return text ? columns : null;
|
|
86
|
+
}
|
|
87
|
+
function marginColumns(words, lineHeight) {
|
|
88
|
+
const region = regionOf(words, lineHeight);
|
|
89
|
+
const { edges } = region;
|
|
90
|
+
if (edges.length === 0 || chainLines(words).some((line) => spanning(line, region))) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const slack = lineHeight * MARGIN_SLACK;
|
|
94
|
+
const columns = edges.map(() => []);
|
|
95
|
+
columns.push([]);
|
|
96
|
+
for (const word of words) {
|
|
97
|
+
columns[edges.filter((edge) => word.left >= edge - slack).length]?.push(word);
|
|
98
|
+
}
|
|
99
|
+
return columns;
|
|
100
|
+
}
|
|
101
|
+
function spannedBands(words, lineHeight) {
|
|
102
|
+
const region = regionOf(words, lineHeight);
|
|
103
|
+
const { edges } = region;
|
|
104
|
+
const bands = [];
|
|
105
|
+
let across = true;
|
|
106
|
+
for (const line of chainLines(words)) {
|
|
107
|
+
const parts = spanning(line, region);
|
|
108
|
+
if (parts || across) {
|
|
109
|
+
bands.push([]);
|
|
110
|
+
}
|
|
111
|
+
bands.at(-1)?.push(...line.words);
|
|
112
|
+
across = parts;
|
|
113
|
+
}
|
|
114
|
+
return edges.length > 0 && bands.length > 1 ? bands : null;
|
|
115
|
+
}
|
|
116
|
+
function columnEdges(words, lineHeight) {
|
|
117
|
+
const lines = chainLines(words);
|
|
118
|
+
if (lines.length < MARGIN_MIN_LINES) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const edges = sharedEdges(words, lineHeight * MARGIN_SLACK, lines.length * MARGIN_LINES);
|
|
122
|
+
return edges.filter((edge) => {
|
|
123
|
+
const before = words.filter((word) => word.right <= edge);
|
|
124
|
+
const across = lines.filter((line) => line.words.some((word) => spans(word, [edge], lineHeight)));
|
|
125
|
+
return dense([before]) !== null && across.length <= lines.length * SPANNED_LINES;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function regionOf(words, lineHeight) {
|
|
129
|
+
const firsts = chainLines(words)
|
|
130
|
+
.map((line) => line.first.left)
|
|
131
|
+
.sort((a, b) => a - b);
|
|
132
|
+
const start = firsts[Math.floor(firsts.length / 2)] ?? 0;
|
|
133
|
+
const end = Math.max(...words.map((word) => word.right));
|
|
134
|
+
return { edges: columnEdges(words, lineHeight), start, end, lineHeight };
|
|
135
|
+
}
|
|
136
|
+
function spanning(line, region) {
|
|
137
|
+
const { edges, lineHeight } = region;
|
|
138
|
+
return line.words.some((word) => spans(word, edges, lineHeight)) || heading(line, region);
|
|
139
|
+
}
|
|
140
|
+
function heading({ words }, { edges, start, end, lineHeight }) {
|
|
141
|
+
const ordered = [...words].sort((a, b) => a.left - b.left);
|
|
142
|
+
const first = ordered[0];
|
|
143
|
+
const last = ordered.at(-1);
|
|
144
|
+
const inset = ((end - start) / (edges.length + 1)) * HEADING_INSET;
|
|
145
|
+
if (!first || !last || first.left < start + inset || last.right > end - inset) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const slack = lineHeight * MARGIN_SLACK;
|
|
149
|
+
return ordered.slice(1).some((word, at) => {
|
|
150
|
+
const before = ordered[at];
|
|
151
|
+
return (before !== undefined &&
|
|
152
|
+
word.left - before.right < lineHeight * COLUMN_GAP &&
|
|
153
|
+
edges.some((edge) => before.left < edge - slack && word.left >= edge - slack));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function spans({ left, right }, edges, lineHeight) {
|
|
157
|
+
const reach = lineHeight * SPANS;
|
|
158
|
+
return edges.some((edge) => left < edge - reach && right > edge + reach);
|
|
159
|
+
}
|
|
160
|
+
function sharedEdges(words, slack, least) {
|
|
161
|
+
const lefts = words.map((word) => word.left).sort((a, b) => a - b);
|
|
162
|
+
const windows = [];
|
|
163
|
+
let to = 0;
|
|
164
|
+
for (const [from, edge] of lefts.entries()) {
|
|
165
|
+
while (to < lefts.length && (lefts[to] ?? 0) <= edge + slack) {
|
|
166
|
+
to++;
|
|
167
|
+
}
|
|
168
|
+
if (to - from >= least) {
|
|
169
|
+
windows.push({ edge, count: to - from });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const edges = [];
|
|
173
|
+
for (const { edge } of windows.sort((a, b) => b.count - a.count)) {
|
|
174
|
+
if (edges.every((kept) => Math.abs(kept - edge) > slack)) {
|
|
175
|
+
edges.push(edge);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return edges.sort((a, b) => a - b);
|
|
179
|
+
}
|
|
180
|
+
function chainLines(words) {
|
|
181
|
+
const lines = [];
|
|
182
|
+
for (const word of [...words].sort((a, b) => a.left - b.left)) {
|
|
183
|
+
const line = levelWith(lines, word);
|
|
184
|
+
if (line) {
|
|
185
|
+
line.words.push(word);
|
|
186
|
+
line.last = word;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
lines.push({ first: word, last: word, words: [word] });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return lines.sort((a, b) => middle(a.first) - middle(b.first));
|
|
193
|
+
}
|
|
194
|
+
function levelWith(lines, word) {
|
|
195
|
+
let closest;
|
|
196
|
+
let offset = Infinity;
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
const apart = Math.abs(middle(line.last) - middle(word));
|
|
199
|
+
if (apart < height(line.last) / 2 && apart < offset) {
|
|
200
|
+
closest = line;
|
|
201
|
+
offset = apart;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return closest;
|
|
205
|
+
}
|
|
206
|
+
function middle(word) {
|
|
207
|
+
return (word.top + word.bottom) / 2;
|
|
208
|
+
}
|
|
209
|
+
function centre(word) {
|
|
210
|
+
return (word.left + word.right) / 2;
|
|
211
|
+
}
|
|
212
|
+
function height(word) {
|
|
213
|
+
return word.bottom - word.top;
|
|
214
|
+
}
|
|
215
|
+
function medianHeight(words) {
|
|
216
|
+
const heights = words.map(height).sort((a, b) => a - b);
|
|
217
|
+
return heights[Math.floor(heights.length / 2)] ?? 0;
|
|
218
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import './bare-floor.ts';
|
|
1
2
|
import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
|
|
2
3
|
import { type PythonLanguageOptions } from './language.ts';
|
|
4
|
+
import type { PythonRunResult } from './pyodide.ts';
|
|
3
5
|
import { closePythonWorker } from './worker/active.ts';
|
|
4
6
|
import { preloadPythonAddons } from './worker/client.ts';
|
|
5
7
|
export type { PythonLanguageOptions };
|
|
6
|
-
export {
|
|
8
|
+
export type { LoadPyodideFn, PythonRunResult } from './pyodide.ts';
|
|
7
9
|
export { planVendoredInstall, vendoredManifest, wheelsDir } from './wheels.ts';
|
|
8
10
|
export { closePythonWorker };
|
|
11
|
+
export declare function runPython(...args: Parameters<typeof import('./pyodide.ts').runPython>): Promise<PythonRunResult>;
|
|
9
12
|
export declare class Python implements HarnessPlugin {
|
|
10
13
|
readonly name = "python";
|
|
11
14
|
readonly api = 1;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import './bare-floor.js';
|
|
1
2
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
3
|
import { createPythonLanguage } from './language.js';
|
|
4
|
+
import { pyodideModule } from './python-adapter.js';
|
|
3
5
|
import { closePythonWorker } from './worker/active.js';
|
|
4
6
|
import { preloadPythonAddons } from './worker/client.js';
|
|
5
7
|
PluginRegistry.requirePeers('python', { pyodide: () => import.meta.resolve('pyodide') });
|
|
6
|
-
export { runPython } from './pyodide.js';
|
|
7
8
|
export { planVendoredInstall, vendoredManifest, wheelsDir } from './wheels.js';
|
|
8
9
|
export { closePythonWorker };
|
|
10
|
+
export async function runPython(...args) {
|
|
11
|
+
return (await pyodideModule()).runPython(...args);
|
|
12
|
+
}
|
|
9
13
|
export class Python {
|
|
10
14
|
name = 'python';
|
|
11
15
|
api = PluginRegistry.API_VERSION;
|