@johnhenry/mallory-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -2
- package/bin/mallory.mjs +51 -0
- package/package.json +51 -4
- package/src/a2a/client.js +511 -0
- package/src/a2a/demo-agent.js +396 -0
- package/src/a2a/hub.js +578 -0
- package/src/a2a/settings.js +88 -0
- package/src/a2a/task.js +358 -0
- package/src/acp/client.js +573 -0
- package/src/acp/demo-agent.js +332 -0
- package/src/acp/hub.js +632 -0
- package/src/acp/settings.js +78 -0
- package/src/actions/map.js +524 -0
- package/src/agent/cloud.js +77 -0
- package/src/agent/compact.js +84 -0
- package/src/agent/constants.js +39 -0
- package/src/agent/diff.js +101 -0
- package/src/agent/fork.js +159 -0
- package/src/agent/grounding.js +73 -0
- package/src/agent/guards.js +129 -0
- package/src/agent/local-transport.js +152 -0
- package/src/agent/loop.js +479 -0
- package/src/agent/park-store.js +77 -0
- package/src/agent/park.js +76 -0
- package/src/agent/ports.js +28 -0
- package/src/agent/providers.js +591 -0
- package/src/agent/restart.js +51 -0
- package/src/agent/router.js +380 -0
- package/src/agent/run.js +861 -0
- package/src/agent/tools.js +247 -0
- package/src/agent-library/engine.js +43 -0
- package/src/ai/bridge.js +155 -0
- package/src/ai/policy.js +131 -0
- package/src/aimatey/vendor.js +18 -0
- package/src/audio/container-duration.js +35 -0
- package/src/audio/instruments.js +776 -0
- package/src/audio/lanes.js +230 -0
- package/src/audio/patch.js +1410 -0
- package/src/audio/plan.js +276 -0
- package/src/audio/rack.js +1006 -0
- package/src/audio/sample-trim.js +293 -0
- package/src/audio/soundfont.js +243 -0
- package/src/audio/take-store.js +87 -0
- package/src/audio/takes.js +129 -0
- package/src/audio/wav.js +170 -0
- package/src/audio/zzfx.js +333 -0
- package/src/autonomy/bundle.js +207 -0
- package/src/autonomy/confine.js +61 -0
- package/src/autonomy/enforce.js +155 -0
- package/src/autonomy/file-kv.js +88 -0
- package/src/autonomy/ledger.js +203 -0
- package/src/autonomy/pins.js +50 -0
- package/src/autonomy/psl/index.js +32 -0
- package/src/autonomy/psl/suffixes.json +1 -0
- package/src/autonomy/record.js +28 -0
- package/src/autonomy/routines.js +107 -0
- package/src/autonomy/server.js +175 -0
- package/src/autonomy/signer-node.js +167 -0
- package/src/autonomy/store.js +43 -0
- package/src/autonomy/unattended.js +13 -0
- package/src/bytes/bytes.js +378 -0
- package/src/calc/syntax.js +125 -0
- package/src/calc/tex.js +28 -0
- package/src/calendar/vendor.js +2 -0
- package/src/clipboard.js +130 -0
- package/src/clsh/clsh.js +3417 -0
- package/src/codec/capnp.js +1804 -0
- package/src/codec/core.js +2043 -0
- package/src/codec/vendor/avro.js +136 -0
- package/src/codec/vendor/cbor.js +25 -0
- package/src/codec/vendor/flatbuffers.js +206 -0
- package/src/codec/vendor/msgpack.js +9 -0
- package/src/codec/vendor/protobuf.js +53 -0
- package/src/delegation/caps.js +60 -0
- package/src/delegation/config.js +32 -0
- package/src/device/model.js +246 -0
- package/src/device/recording.js +198 -0
- package/src/device/stream-model.js +151 -0
- package/src/documents/documents.js +1224 -0
- package/src/effects/catalog.js +63 -0
- package/src/effects/extras.js +133 -0
- package/src/effects/parse.js +339 -0
- package/src/embed/protocol.js +131 -0
- package/src/env/env.js +159 -0
- package/src/exact/vendor.js +45 -0
- package/src/example-meta.js +164 -0
- package/src/examples.js +94 -0
- package/src/export/canvas-image.js +217 -0
- package/src/export/expr-latex-lazy.js +8 -0
- package/src/export/formats.js +322 -0
- package/src/export/latex.js +183 -0
- package/src/export/pane.js +184 -0
- package/src/export/value.js +452 -0
- package/src/export/zip.js +214 -0
- package/src/ext/access.js +58 -0
- package/src/ext/btasks.js +225 -0
- package/src/ext/client.js +209 -0
- package/src/ext/tools.js +69 -0
- package/src/ext/view.js +105 -0
- package/src/ext/webmcp-tabs.js +299 -0
- package/src/files/archive.js +232 -0
- package/src/files/files.js +317 -0
- package/src/formats/json.js +24 -0
- package/src/formats/jupyter.js +188 -0
- package/src/formats/markdown.js +254 -0
- package/src/formats/n8n.js +276 -0
- package/src/formats/node-red.js +363 -0
- package/src/formats/registry.js +177 -0
- package/src/formats/rivet.js +259 -0
- package/src/formats/shared.js +98 -0
- package/src/formats/structure.js +182 -0
- package/src/formats/yaml.js +127 -0
- package/src/frame/frame.js +962 -0
- package/src/frame/vendor.js +1484 -0
- package/src/gate/audit.js +116 -0
- package/src/gate/gate.js +365 -0
- package/src/gate/policy.js +295 -0
- package/src/gate/scripted.js +110 -0
- package/src/gate/seams.js +32 -0
- package/src/gate/store.js +66 -0
- package/src/geometry/model.js +533 -0
- package/src/grant-key.js +149 -0
- package/src/graph/model.js +381 -0
- package/src/headless/a2a-push.js +123 -0
- package/src/headless/channels/config.js +142 -0
- package/src/headless/channels/connectors.js +283 -0
- package/src/headless/channels/index.js +257 -0
- package/src/headless/channels/mail.js +197 -0
- package/src/headless/channels/mailnet.js +223 -0
- package/src/headless/channels/platforms.js +194 -0
- package/src/headless/channels/replay.js +49 -0
- package/src/headless/cli.js +1397 -0
- package/src/headless/companion-client.js +182 -0
- package/src/headless/cost-cli.js +177 -0
- package/src/headless/deprecations-cli.js +102 -0
- package/src/headless/examples.js +48 -0
- package/src/headless/ffmpeg-exec.js +217 -0
- package/src/headless/gateways/config.js +213 -0
- package/src/headless/gateways/homeassistant.js +159 -0
- package/src/headless/gateways/index.js +121 -0
- package/src/headless/gateways/matter.js +150 -0
- package/src/headless/gateways/mqtt-client.js +177 -0
- package/src/headless/gateways/mqtt.js +70 -0
- package/src/headless/gateways/netway.js +226 -0
- package/src/headless/gateways/serverpod-worker.mjs +16 -0
- package/src/headless/gateways/serverpod.js +71 -0
- package/src/headless/gateways/util.js +27 -0
- package/src/headless/grant-cli.js +208 -0
- package/src/headless/guard.js +125 -0
- package/src/headless/guards.js +124 -0
- package/src/headless/machine-cli.js +853 -0
- package/src/headless/mcp-endpoint.js +287 -0
- package/src/headless/mcp-roots.js +38 -0
- package/src/headless/model-endpoint.js +88 -0
- package/src/headless/net.js +151 -0
- package/src/headless/node.js +263 -0
- package/src/headless/npm-tarball.js +29 -0
- package/src/headless/operator-page.js +112 -0
- package/src/headless/operator.js +242 -0
- package/src/headless/people.js +34 -0
- package/src/headless/pkg-cli.js +1103 -0
- package/src/headless/pkg-serve.js +138 -0
- package/src/headless/process-worker.js +88 -0
- package/src/headless/runner-remote.js +477 -0
- package/src/headless/sandbox-child.mjs +21 -0
- package/src/headless/scheduled.js +557 -0
- package/src/headless/serve-stream.js +97 -0
- package/src/headless/serve.js +2238 -0
- package/src/headless/short-links.js +158 -0
- package/src/headless/static-dirs.js +207 -0
- package/src/headless/trust-file.js +51 -0
- package/src/headless/watch.js +291 -0
- package/src/headless/ws-connect.js +65 -0
- package/src/headless/ws-connections.js +44 -0
- package/src/headless/ws-echo.js +150 -0
- package/src/headless/ws-proxy.js +354 -0
- package/src/headless/ws-ticket.js +48 -0
- package/src/hooks/config.js +50 -0
- package/src/hooks/engine.js +189 -0
- package/src/input/log.js +613 -0
- package/src/input/player.js +217 -0
- package/src/input/replay.js +209 -0
- package/src/jth/vendor.js +28 -0
- package/src/ledger/tx.js +94 -0
- package/src/machine/apply.js +193 -0
- package/src/machine/diff.js +168 -0
- package/src/machine/drive.js +296 -0
- package/src/machine/engine.js +478 -0
- package/src/machine/files-tool.js +76 -0
- package/src/machine/lint.js +139 -0
- package/src/machine/llmtm-trace.js +117 -0
- package/src/machine/llmtm.js +475 -0
- package/src/machine/otel.js +80 -0
- package/src/machine/pane-provider.js +51 -0
- package/src/machine/propose.js +159 -0
- package/src/machine/random.js +52 -0
- package/src/machine/risk.js +107 -0
- package/src/machine/session.js +1017 -0
- package/src/machine/shell-tool.js +45 -0
- package/src/machine/tape.js +349 -0
- package/src/machine/templates.js +104 -0
- package/src/machine/trace.js +664 -0
- package/src/machine/view.js +73 -0
- package/src/machine/vm-tool.js +47 -0
- package/src/machine/watchdog.js +46 -0
- package/src/mcp/app-args.js +51 -0
- package/src/mcp/app-run.js +56 -0
- package/src/mcp/apps.js +468 -0
- package/src/mcp/cache.js +232 -0
- package/src/mcp/client.js +507 -0
- package/src/mcp/demo-app.js +183 -0
- package/src/mcp/demo-server.js +602 -0
- package/src/mcp/elicitation.js +116 -0
- package/src/mcp/hub.js +1326 -0
- package/src/mcp/roots.js +139 -0
- package/src/mcp/sampling.js +105 -0
- package/src/mcp/settings.js +125 -0
- package/src/mcp/tape.js +292 -0
- package/src/mcp/uri-template.js +156 -0
- package/src/mcp/wsh-client.js +164 -0
- package/src/media/animated-codec.js +7 -0
- package/src/media/animated.js +623 -0
- package/src/media/compare-agent.js +70 -0
- package/src/media/compare-job.js +63 -0
- package/src/media/compare-page.js +296 -0
- package/src/media/compare-worker.js +14 -0
- package/src/media/compare.js +600 -0
- package/src/media/contract.js +62 -0
- package/src/media/decode-frame.js +57 -0
- package/src/media/decode-pool.js +188 -0
- package/src/media/ffmpeg-edit.js +344 -0
- package/src/media/ffmpeg-wasm-client.js +121 -0
- package/src/media/ffmpeg-wasm-session.js +79 -0
- package/src/media/ffmpeg-wasm.js +139 -0
- package/src/media/ffmpeg-worker.js +23 -0
- package/src/media/ffmpeg.js +903 -0
- package/src/media/helpers.js +419 -0
- package/src/media/keep.js +108 -0
- package/src/media/metadata-worker.js +16 -0
- package/src/media/metadata.js +2518 -0
- package/src/media/mime.js +102 -0
- package/src/media/page-decode.js +74 -0
- package/src/media/persist.js +114 -0
- package/src/media/png.js +226 -0
- package/src/media/sample-input.js +67 -0
- package/src/media/store.js +86 -0
- package/src/media/wav.js +109 -0
- package/src/midi/mappings.js +250 -0
- package/src/midi/message.js +125 -0
- package/src/model/action-hub.js +143 -0
- package/src/model/adapters.js +284 -0
- package/src/model/agent-runs.js +12 -0
- package/src/model/arrange.js +308 -0
- package/src/model/automation-clock.js +494 -0
- package/src/model/automation.js +653 -0
- package/src/model/batches.js +78 -0
- package/src/model/binary-view.js +195 -0
- package/src/model/breakpoints.js +392 -0
- package/src/model/calc-settings.js +65 -0
- package/src/model/calendar.js +254 -0
- package/src/model/canvas-id.js +5 -0
- package/src/model/canvas.js +5048 -0
- package/src/model/channel-names.js +29 -0
- package/src/model/channels.js +692 -0
- package/src/model/chart-clock.js +631 -0
- package/src/model/chart-code.js +69 -0
- package/src/model/codecs.js +60 -0
- package/src/model/companion-access.js +271 -0
- package/src/model/companion-pane.js +50 -0
- package/src/model/composite.js +324 -0
- package/src/model/context.js +380 -0
- package/src/model/controls.js +231 -0
- package/src/model/converter-presets.js +368 -0
- package/src/model/cost.js +580 -0
- package/src/model/curve-transform.js +122 -0
- package/src/model/cycles.js +176 -0
- package/src/model/debug-log.js +168 -0
- package/src/model/decision-clock.js +100 -0
- package/src/model/decisions.js +265 -0
- package/src/model/desk.js +87 -0
- package/src/model/device-hub.js +400 -0
- package/src/model/diff.js +445 -0
- package/src/model/emit-events.js +179 -0
- package/src/model/errors.js +238 -0
- package/src/model/event-presets.js +297 -0
- package/src/model/events.js +1303 -0
- package/src/model/explicit-setters.js +139 -0
- package/src/model/field-mapping.js +623 -0
- package/src/model/files-pane.js +263 -0
- package/src/model/flow-idle.js +89 -0
- package/src/model/foreach.js +549 -0
- package/src/model/frame-loop.js +71 -0
- package/src/model/frame-pressure.js +180 -0
- package/src/model/function-scaffold.js +1000 -0
- package/src/model/geometry-settings.js +54 -0
- package/src/model/goals.js +176 -0
- package/src/model/graph-settings.js +76 -0
- package/src/model/grid-widget.js +175 -0
- package/src/model/groups.js +332 -0
- package/src/model/hash.js +21 -0
- package/src/model/history.js +259 -0
- package/src/model/http-copy.js +88 -0
- package/src/model/http-send-companion.js +110 -0
- package/src/model/http-send.js +163 -0
- package/src/model/http-tap.js +521 -0
- package/src/model/http-tools.js +1138 -0
- package/src/model/import-lock.js +78 -0
- package/src/model/imports.js +258 -0
- package/src/model/infer-outputs.js +822 -0
- package/src/model/ink-connect.js +150 -0
- package/src/model/ink-diff.js +75 -0
- package/src/model/ink-gone.js +71 -0
- package/src/model/ink-route.js +120 -0
- package/src/model/ink-svg.js +206 -0
- package/src/model/ink.js +739 -0
- package/src/model/input-log-hub.js +456 -0
- package/src/model/input-split.js +69 -0
- package/src/model/json-schema-host.js +9 -0
- package/src/model/json-schema.js +368 -0
- package/src/model/jth.js +78 -0
- package/src/model/latex-expr.js +528 -0
- package/src/model/layout-history.js +120 -0
- package/src/model/lazy-map.js +88 -0
- package/src/model/ledger-pane.js +101 -0
- package/src/model/legacy-viaframe.js +90 -0
- package/src/model/lessons.js +448 -0
- package/src/model/links.js +981 -0
- package/src/model/live.js +411 -0
- package/src/model/math-widget.js +53 -0
- package/src/model/memory-settings.js +33 -0
- package/src/model/midi-controls.js +350 -0
- package/src/model/nl-time.js +408 -0
- package/src/model/notebook.js +137 -0
- package/src/model/pane-view-store.js +15 -0
- package/src/model/partial.js +115 -0
- package/src/model/pause-clock.js +53 -0
- package/src/model/peer-pane.js +32 -0
- package/src/model/persist-state.js +290 -0
- package/src/model/person-only.js +122 -0
- package/src/model/pin.js +209 -0
- package/src/model/plot-3d.js +213 -0
- package/src/model/plot-series.js +157 -0
- package/src/model/plot-settings.js +531 -0
- package/src/model/ports.js +312 -0
- package/src/model/presentation.js +222 -0
- package/src/model/preset-apply.js +316 -0
- package/src/model/preset-banks.js +335 -0
- package/src/model/preset-morph.js +263 -0
- package/src/model/preset-ops.js +205 -0
- package/src/model/preset-player.js +283 -0
- package/src/model/preset-states.js +172 -0
- package/src/model/profile-settings.js +109 -0
- package/src/model/promote.js +103 -0
- package/src/model/protected.js +10 -0
- package/src/model/proxy-log.js +230 -0
- package/src/model/proxy.js +367 -0
- package/src/model/quantity-widget.js +61 -0
- package/src/model/queue-book.js +359 -0
- package/src/model/quick-add.js +224 -0
- package/src/model/rate-limit.js +313 -0
- package/src/model/rate.js +95 -0
- package/src/model/recovery.js +216 -0
- package/src/model/rename-follow.js +113 -0
- package/src/model/repeater.js +1126 -0
- package/src/model/retention.js +664 -0
- package/src/model/route-edit.js +132 -0
- package/src/model/router.js +155 -0
- package/src/model/runaway.js +232 -0
- package/src/model/runlog.js +1033 -0
- package/src/model/runners/a2a.js +2 -0
- package/src/model/runners/acp.js +2 -0
- package/src/model/runners/actions.js +4 -0
- package/src/model/runners/agent.js +4 -0
- package/src/model/runners/audio.js +21 -0
- package/src/model/runners/automation.js +2 -0
- package/src/model/runners/calc.js +23 -0
- package/src/model/runners/catch.js +10 -0
- package/src/model/runners/codec.js +24 -0
- package/src/model/runners/companion-run.js +2 -0
- package/src/model/runners/device.js +7 -0
- package/src/model/runners/dom.js +13 -0
- package/src/model/runners/effects.js +2 -0
- package/src/model/runners/embed.js +11 -0
- package/src/model/runners/eval.js +2 -0
- package/src/model/runners/files.js +19 -0
- package/src/model/runners/geometry.js +23 -0
- package/src/model/runners/goals.js +18 -0
- package/src/model/runners/graph.js +23 -0
- package/src/model/runners/html.js +2 -0
- package/src/model/runners/http-proxy.js +185 -0
- package/src/model/runners/http-send.js +61 -0
- package/src/model/runners/http-static.js +83 -0
- package/src/model/runners/http-tap.js +26 -0
- package/src/model/runners/http.js +40 -0
- package/src/model/runners/import.js +2 -0
- package/src/model/runners/index.js +74 -0
- package/src/model/runners/input.js +14 -0
- package/src/model/runners/inputlog.js +7 -0
- package/src/model/runners/ledger.js +15 -0
- package/src/model/runners/machine.js +4 -0
- package/src/model/runners/mcp.js +2 -0
- package/src/model/runners/mcpapp.js +2 -0
- package/src/model/runners/media.js +18 -0
- package/src/model/runners/memory.js +28 -0
- package/src/model/runners/mesh-inspect.js +13 -0
- package/src/model/runners/peer.js +14 -0
- package/src/model/runners/plot.js +22 -0
- package/src/model/runners/render.js +14 -0
- package/src/model/runners/respond.js +2 -0
- package/src/model/runners/sample-soundfont.js +85 -0
- package/src/model/runners/sample.js +159 -0
- package/src/model/runners/scene.js +8 -0
- package/src/model/runners/score.js +24 -0
- package/src/model/runners/secret.js +10 -0
- package/src/model/runners/select.js +2 -0
- package/src/model/runners/shared.js +4 -0
- package/src/model/runners/shares.js +15 -0
- package/src/model/runners/shell.js +7 -0
- package/src/model/runners/skill.js +26 -0
- package/src/model/runners/state.js +2 -0
- package/src/model/runners/statechart.js +4 -0
- package/src/model/runners/subgraph.js +9 -0
- package/src/model/runners/tabs.js +25 -0
- package/src/model/runners/terminal.js +5 -0
- package/src/model/runners/text.js +4 -0
- package/src/model/runners/timer.js +7 -0
- package/src/model/runners/traffic.js +65 -0
- package/src/model/runners/trigger.js +2 -0
- package/src/model/runners/verdict.js +29 -0
- package/src/model/runners/vm.js +7 -0
- package/src/model/runners/wait.js +4 -0
- package/src/model/runners/ws-client.js +57 -0
- package/src/model/safe-regex.js +719 -0
- package/src/model/sample-settings.js +43 -0
- package/src/model/sample-source.js +47 -0
- package/src/model/saved-mapping.js +153 -0
- package/src/model/score-controllers.js +87 -0
- package/src/model/score-edit.js +399 -0
- package/src/model/score-instruments.js +300 -0
- package/src/model/score-library.js +407 -0
- package/src/model/score-markup.js +235 -0
- package/src/model/score-mix.js +248 -0
- package/src/model/score-patterns.js +276 -0
- package/src/model/score-selection.js +34 -0
- package/src/model/score-time.js +139 -0
- package/src/model/score-transforms.js +336 -0
- package/src/model/score-transport.js +192 -0
- package/src/model/selection.js +351 -0
- package/src/model/serial-controls.js +328 -0
- package/src/model/shares-pane.js +17 -0
- package/src/model/shell-pane.js +106 -0
- package/src/model/signature.js +1122 -0
- package/src/model/size-hints.js +106 -0
- package/src/model/size-ratio.js +12 -0
- package/src/model/skill-settings.js +23 -0
- package/src/model/snapping.js +466 -0
- package/src/model/split.js +375 -0
- package/src/model/spring-player.js +222 -0
- package/src/model/statecharts.js +1369 -0
- package/src/model/states-preset.js +208 -0
- package/src/model/static-route.js +100 -0
- package/src/model/step-words.js +45 -0
- package/src/model/subgraph.js +1042 -0
- package/src/model/switch.js +98 -0
- package/src/model/tabs-store.js +10 -0
- package/src/model/tensor-view.js +146 -0
- package/src/model/timer-clock.js +361 -0
- package/src/model/timers.js +422 -0
- package/src/model/timing.js +212 -0
- package/src/model/traffic-agent.js +111 -0
- package/src/model/traffic-store.js +20 -0
- package/src/model/traffic.js +665 -0
- package/src/model/transport.js +364 -0
- package/src/model/turns.js +86 -0
- package/src/model/types.js +425 -0
- package/src/model/value-path.js +138 -0
- package/src/model/versions.js +535 -0
- package/src/model/view-outputs.js +144 -0
- package/src/model/viewport-bookmarks.js +194 -0
- package/src/model/virtual-clock.js +85 -0
- package/src/model/vm-pane.js +258 -0
- package/src/model/wait-clock.js +715 -0
- package/src/model/wait-persist.js +248 -0
- package/src/model/waits.js +431 -0
- package/src/model/watch.js +80 -0
- package/src/model/webhook.js +496 -0
- package/src/model/when.js +48 -0
- package/src/model/widget-values.js +392 -0
- package/src/model/window-commands.js +278 -0
- package/src/model/windows.js +348 -0
- package/src/model/wire-inspect.js +343 -0
- package/src/model/wire-ops.js +324 -0
- package/src/model/wire-pipeline.js +378 -0
- package/src/model/wire-route.js +637 -0
- package/src/model/workspaces.js +122 -0
- package/src/model/ws-client.js +155 -0
- package/src/model/ws-demo.js +31 -0
- package/src/model/ws-frames.js +141 -0
- package/src/model/ws-hub.js +219 -0
- package/src/model/ws-served.js +13 -0
- package/src/model/xstate.js +374 -0
- package/src/narrative/narrative.js +1557 -0
- package/src/network/auth.js +224 -0
- package/src/network/csp-frame.js +197 -0
- package/src/network/declarative-shadow.js +27 -0
- package/src/network/frame-net-shim.js +962 -0
- package/src/network/hosts.js +157 -0
- package/src/network/policy.js +520 -0
- package/src/network/rtc-shim.js +418 -0
- package/src/network/secret-gate.js +78 -0
- package/src/network/secrets.js +261 -0
- package/src/network/sockets.js +287 -0
- package/src/network/store.js +186 -0
- package/src/network/streams.js +99 -0
- package/src/packages/asset-values.js +50 -0
- package/src/packages/assets.js +99 -0
- package/src/packages/deprecation.js +203 -0
- package/src/packages/fetch.js +152 -0
- package/src/packages/function-canvas.js +73 -0
- package/src/packages/module.js +120 -0
- package/src/packages/package.js +474 -0
- package/src/packages/published.js +27 -0
- package/src/packages/requires.js +83 -0
- package/src/packages/signing.js +145 -0
- package/src/packages/trust.js +107 -0
- package/src/panes/a2a.js +51 -0
- package/src/panes/acp.js +60 -0
- package/src/panes/actions.js +54 -0
- package/src/panes/agent.js +83 -0
- package/src/panes/audio.js +103 -0
- package/src/panes/automation.js +112 -0
- package/src/panes/calc.js +67 -0
- package/src/panes/catch.js +52 -0
- package/src/panes/codec.js +59 -0
- package/src/panes/colors.js +12 -0
- package/src/panes/companion.js +54 -0
- package/src/panes/decision.js +65 -0
- package/src/panes/device.js +56 -0
- package/src/panes/dom.js +37 -0
- package/src/panes/effects.js +118 -0
- package/src/panes/embed.js +30 -0
- package/src/panes/eval.js +186 -0
- package/src/panes/fields.js +299 -0
- package/src/panes/files.js +45 -0
- package/src/panes/gate.js +70 -0
- package/src/panes/geometry.js +64 -0
- package/src/panes/goals.js +75 -0
- package/src/panes/graph.js +66 -0
- package/src/panes/html.js +54 -0
- package/src/panes/http.js +82 -0
- package/src/panes/import.js +38 -0
- package/src/panes/input.js +124 -0
- package/src/panes/inputlog.js +66 -0
- package/src/panes/ledger.js +56 -0
- package/src/panes/machine.js +138 -0
- package/src/panes/mcp.js +85 -0
- package/src/panes/mcpapp.js +64 -0
- package/src/panes/media.js +38 -0
- package/src/panes/memory.js +46 -0
- package/src/panes/mesh-inspect.js +49 -0
- package/src/panes/note.js +38 -0
- package/src/panes/peer.js +44 -0
- package/src/panes/plot.js +196 -0
- package/src/panes/registry.js +475 -0
- package/src/panes/render.js +87 -0
- package/src/panes/respond.js +44 -0
- package/src/panes/router.js +84 -0
- package/src/panes/sample.js +75 -0
- package/src/panes/scene.js +55 -0
- package/src/panes/score.js +87 -0
- package/src/panes/secret.js +38 -0
- package/src/panes/select.js +67 -0
- package/src/panes/shader.js +166 -0
- package/src/panes/shared.js +33 -0
- package/src/panes/shares.js +43 -0
- package/src/panes/shell.js +47 -0
- package/src/panes/skill.js +44 -0
- package/src/panes/state.js +91 -0
- package/src/panes/statechart.js +63 -0
- package/src/panes/story.js +33 -0
- package/src/panes/subgraph.js +94 -0
- package/src/panes/tabs.js +52 -0
- package/src/panes/terminal.js +57 -0
- package/src/panes/text.js +36 -0
- package/src/panes/timer.js +55 -0
- package/src/panes/traffic.js +59 -0
- package/src/panes/verdict.js +62 -0
- package/src/panes/vm.js +46 -0
- package/src/panes/wait.js +61 -0
- package/src/panes/watch.js +57 -0
- package/src/panes/webhook.js +67 -0
- package/src/panes/ws-client.js +67 -0
- package/src/persist.js +281 -0
- package/src/plot/tex.js +19 -0
- package/src/plot/vendor.js +59 -0
- package/src/plot/view-vendor.js +5 -0
- package/src/privacy/levels.js +108 -0
- package/src/protocol/devtools.js +116 -0
- package/src/protocol/inspector.js +368 -0
- package/src/render/time.js +381 -0
- package/src/rooms/mesh-metrics.js +162 -0
- package/src/run/companion.js +355 -0
- package/src/run/describe.js +114 -0
- package/src/run/local-model.js +150 -0
- package/src/run/monitor.js +208 -0
- package/src/run/publish.js +360 -0
- package/src/run/respond-outcome.js +12 -0
- package/src/run/run.js +820 -0
- package/src/run/runner-pairing.js +243 -0
- package/src/run/values.js +122 -0
- package/src/runtime/compile.js +122 -0
- package/src/runtime/console-tag.js +64 -0
- package/src/runtime/frame-signals.js +126 -0
- package/src/runtime/iteration-push.js +19 -0
- package/src/runtime/keys.js +474 -0
- package/src/runtime/midi-input.js +170 -0
- package/src/runtime/person-waits.js +140 -0
- package/src/runtime/resource-timing.js +56 -0
- package/src/runtime/runtime.js +2150 -0
- package/src/runtime/sandbox-modules.js +163 -0
- package/src/runtime/spring.js +246 -0
- package/src/runtime/strict.js +215 -0
- package/src/runtime/transfer.js +75 -0
- package/src/runtime/tween.js +158 -0
- package/src/runtime/wasm-fuel.js +596 -0
- package/src/runtime/worker/00-prelude.js +88 -0
- package/src/runtime/worker/10-helpers.js +295 -0
- package/src/runtime/worker/20-io.js +645 -0
- package/src/runtime/worker/30-previews.js +210 -0
- package/src/runtime/worker/40-profile-lineage.js +278 -0
- package/src/runtime/worker/50-own-worker.js +233 -0
- package/src/runtime/worker/60-timers.js +172 -0
- package/src/runtime/worker/70-state-keyed.js +193 -0
- package/src/runtime/worker/80-each-compile-generators.js +619 -0
- package/src/runtime/worker/90-events-operators.js +655 -0
- package/src/runtime/worker/95-agents-batches.js +1820 -0
- package/src/runtime/worker/96-plot.js +47 -0
- package/src/runtime/worker/97-calc.js +28 -0
- package/src/runtime/worker/98-geometry.js +24 -0
- package/src/runtime/worker/99-graph.js +30 -0
- package/src/runtime/worker/99-shell.js +30 -0
- package/src/safety/config.js +57 -0
- package/src/safety/engine.js +324 -0
- package/src/scene/pixi-scene.js +806 -0
- package/src/scene/scene-assets.js +241 -0
- package/src/scene/scene-edit.js +319 -0
- package/src/secret/settings.js +41 -0
- package/src/security/multipart.js +257 -0
- package/src/security/redact.js +261 -0
- package/src/serial/broker.js +473 -0
- package/src/serial/config.js +185 -0
- package/src/serial/framers.js +389 -0
- package/src/serial/packets.js +64 -0
- package/src/shader/audio-texture.js +87 -0
- package/src/shader/channels.js +496 -0
- package/src/shader/common.js +90 -0
- package/src/shader/model.js +867 -0
- package/src/shader/passes.js +150 -0
- package/src/shader/shadertoy.js +198 -0
- package/src/shell/hub.js +287 -0
- package/src/sim/checkpoints.js +850 -0
- package/src/sim/compile.js +37 -0
- package/src/sim/fixed.js +377 -0
- package/src/sim/headless.js +205 -0
- package/src/sim/physics.js +399 -0
- package/src/smf-helper/vendor.js +2 -0
- package/src/sources/config.js +435 -0
- package/src/storage.js +153 -0
- package/src/table/table-geo.js +2344 -0
- package/src/table/table-lineage.js +808 -0
- package/src/table/table-quality.js +355 -0
- package/src/table/table-schema.js +392 -0
- package/src/table/table-sql.js +1650 -0
- package/src/table/table-stats.js +480 -0
- package/src/table/table.js +2102 -0
- package/src/tensor/tensor.js +1153 -0
- package/src/terminal/hub.js +715 -0
- package/src/terminal/screen.js +516 -0
- package/src/tests/capture.js +88 -0
- package/src/tests/compare.js +480 -0
- package/src/tests/dataset.js +170 -0
- package/src/tests/evaluate.js +286 -0
- package/src/tests/from-runs.js +99 -0
- package/src/tests/judge.js +134 -0
- package/src/tests/matchers.js +263 -0
- package/src/tests/matrix-spec.js +87 -0
- package/src/tests/matrix.js +397 -0
- package/src/tests/metrics.js +369 -0
- package/src/tests/no-value.js +42 -0
- package/src/tests/pane-check.js +45 -0
- package/src/tests/report.js +124 -0
- package/src/tests/reporters.js +140 -0
- package/src/tests/run.js +155 -0
- package/src/tilemap/tilemap.js +1122 -0
- package/src/units/units.js +3 -0
- package/src/util/bytes-text.js +21 -0
- package/src/util/num.js +10 -0
- package/src/util/regexp.js +2 -0
- package/src/util/text.js +38 -0
- package/src/verdict/engine.js +154 -0
- package/src/vm/guest-wsh.js +108 -0
- package/src/vm/hub.js +457 -0
- package/src/vm/image-files.js +4 -0
- package/src/vm/image.js +33 -0
- package/src/vm/image.lock.json +13 -0
- package/src/vm/link.js +266 -0
- package/src/vm/mount.js +212 -0
- package/src/vm/net.js +85 -0
- package/src/vm/pipe-ws.js +187 -0
- package/src/vm/v86-loader.js +11 -0
- package/src/webmcp/args.js +212 -0
- package/src/webmcp/hidden.js +218 -0
- package/src/webmcp/text.js +250 -0
- package/src/webmcp/tools/bookmark-tools.js +106 -0
- package/src/webmcp/tools/breakpoint-tools.js +48 -0
- package/src/webmcp/tools/canvases.js +208 -0
- package/src/webmcp/tools/context-tools.js +84 -0
- package/src/webmcp/tools/core.js +170 -0
- package/src/webmcp/tools/devices.js +41 -0
- package/src/webmcp/tools/edit.js +357 -0
- package/src/webmcp/tools/event-tools.js +145 -0
- package/src/webmcp/tools/image-tools.js +173 -0
- package/src/webmcp/tools/ink-tools.js +247 -0
- package/src/webmcp/tools/input-log-tools.js +163 -0
- package/src/webmcp/tools/live.js +166 -0
- package/src/webmcp/tools/machine-tools.js +74 -0
- package/src/webmcp/tools/media.js +161 -0
- package/src/webmcp/tools/midi-tools.js +32 -0
- package/src/webmcp/tools/preset-tools.js +184 -0
- package/src/webmcp/tools/quick-add-tools.js +95 -0
- package/src/webmcp/tools/reshape.js +152 -0
- package/src/webmcp/tools/run-tools.js +309 -0
- package/src/webmcp/tools/runs.js +101 -0
- package/src/webmcp/tools/scaffold-tools.js +161 -0
- package/src/webmcp/tools/serial-tools.js +36 -0
- package/src/webmcp/tools/shared.js +338 -0
- package/src/webmcp/tools/subgraphs.js +360 -0
- package/src/webmcp/tools/tests.js +170 -0
- package/src/webmcp/tools/traffic-tools.js +70 -0
- package/src/webmcp/tools/transport-tools.js +65 -0
- package/src/webmcp/tools/version-tools.js +126 -0
- package/src/webmcp/tools/versions.js +11 -0
- package/src/webmcp/tools/wire-tools.js +90 -0
- package/src/webmcp/tools/workspace-tools.js +93 -0
- package/src/webmcp/tools.js +1323 -0
- package/src/wsh/connect.js +347 -0
- package/src/wsh/demo-host.js +361 -0
- package/src/wsh/e2e.js +27 -0
- package/src/wsh/keys.js +154 -0
- package/src/wsh/known-hosts.js +39 -0
- package/src/wsh/private-key.js +95 -0
- package/src/wsh/reverse.js +34 -0
- package/src/wsh/settings.js +118 -0
- package/src/wsh/transfer.js +62 -0
- package/src/wsh/vendor.js +5 -0
- package/src/x402/challenge.js +171 -0
- package/src/x402/demo-server.js +127 -0
- package/src/x402/pay.js +125 -0
- package/src/x402/retry.js +95 -0
- package/src/x402/store.js +76 -0
package/src/model/pin.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Pinned values (n8n's "pin data"): a pane can hold a value still. A
|
|
2
|
+
// pinned pane doesn't run: its pin goes downstream as if the pane had just
|
|
3
|
+
// computed it, so everything below an expensive or flaky step (a model call, a
|
|
4
|
+
// paged API, a camera) can be iterated on offline and repeatably. A pin typed
|
|
5
|
+
// by hand on a pane that never ran is sample data.
|
|
6
|
+
//
|
|
7
|
+
// The saved form is an optional pane field (format version 2 stays: an older
|
|
8
|
+
// mallory ignores the field and runs the pane):
|
|
9
|
+
//
|
|
10
|
+
// pin: {
|
|
11
|
+
// value?, // plain JSON (what the Worker's JSON export makes of the value)
|
|
12
|
+
// skip?, // present instead: a pinned skip(reason) (reason text, or null)
|
|
13
|
+
// media?, // instead: a media value whose bytes are inline (<= 256 KB):
|
|
14
|
+
// // { kind, type, size, name?, width?, …, data } (src/media/persist.js)
|
|
15
|
+
// at, // when it was pinned (ms since the epoch)
|
|
16
|
+
// source, // "run" (the pane's value then) or "edited" (typed in the editor)
|
|
17
|
+
// codeHash, // which code and inputs it came from ("pinned · code changed since")
|
|
18
|
+
// }
|
|
19
|
+
//
|
|
20
|
+
// Pure (no DOM): the canvas model, the headless runner and the tests use it.
|
|
21
|
+
// capturePin reads a pane's live value through the canvas's runtime.
|
|
22
|
+
import { describeForContent, toBase64, INLINE_LIMIT, metaFromContent } from "../media/persist.js";
|
|
23
|
+
import { isMedia } from "../media/contract.js";
|
|
24
|
+
import { typesWhere } from "../panes/registry.js";
|
|
25
|
+
|
|
26
|
+
/** Pane types that can be pinned: their records' `pinnable` (src/panes/). Import panes hold modules (never JSON); text panes already are their value; frame panes other than html would stop drawing. */
|
|
27
|
+
export const PINNABLE = typesWhere((r) => r.pinnable);
|
|
28
|
+
|
|
29
|
+
export const PIN_LIMITS = {
|
|
30
|
+
pane: 1024 * 1024, // one pin's JSON
|
|
31
|
+
canvas: 5 * 1024 * 1024, // every pin on a canvas, subgraphs included
|
|
32
|
+
media: INLINE_LIMIT, // a media value's bytes kept in a pin (else only its description)
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const isPinnable = (type) => PINNABLE.includes(type);
|
|
36
|
+
|
|
37
|
+
/** "12.3 kB" */
|
|
38
|
+
export const kb = (bytes) => (bytes < 1024 ? `${bytes} B` : bytes < 1024 ** 2 ? `${(bytes / 1024).toFixed(1)} kB` : `${(bytes / 1024 ** 2).toFixed(1)} MB`);
|
|
39
|
+
|
|
40
|
+
/** How much room a pin takes in the saved canvas (its JSON length). */
|
|
41
|
+
export const pinBytes = (pin) => (pin ? JSON.stringify(pin).length : 0);
|
|
42
|
+
|
|
43
|
+
/** A short, stable hash (FNV-1a, 32 bits, hex) of text. */
|
|
44
|
+
export function hashText(text) {
|
|
45
|
+
let h = 0x811c9dc5;
|
|
46
|
+
const s = String(text);
|
|
47
|
+
for (let i = 0; i < s.length; i++) {
|
|
48
|
+
h ^= s.charCodeAt(i);
|
|
49
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
50
|
+
}
|
|
51
|
+
return h.toString(16).padStart(8, "0");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const withoutPins = (panes = []) => panes.map(({ rect, pin, ...p }) => (p.type === "subgraph" ? { ...p, graph: { panes: withoutPins(p.graph?.panes ?? []) } } : p));
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Which code and inputs a pane's value came from: its own content (code,
|
|
58
|
+
* text, widget, module, media, graph) and its wiring, without geometry, its
|
|
59
|
+
* name, a pin or the saved field mappings (they say how the code was
|
|
60
|
+
* written, not what runs). A pin records it, so the pane can say when it
|
|
61
|
+
* changed since.
|
|
62
|
+
*/
|
|
63
|
+
export function codeHash(pane) {
|
|
64
|
+
const { id, name, rect, width, height, collapsed, pin, pinned, sticky, stashed, layer, mappings, inputs = [], ...content } = pane ?? {};
|
|
65
|
+
if (content.graph) content.graph = { panes: withoutPins(content.graph.panes ?? []) };
|
|
66
|
+
if (content.media) {
|
|
67
|
+
const { data, ...about } = content.media; // the description is enough (and the bytes may be in the browser's store)
|
|
68
|
+
content.media = about;
|
|
69
|
+
}
|
|
70
|
+
// A wire's output (format 3) is part of its wiring; wires without one hash as they always have.
|
|
71
|
+
return hashText(JSON.stringify([content, inputs.map((i) => (i.output ? [i.name, i.source, i.output] : [i.name, i.source]))]));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Has a pinned pane's code or wiring changed since it was pinned? */
|
|
75
|
+
export const pinStale = (pane) => Boolean(pane?.pin?.codeHash) && pane.pin.codeHash !== codeHash(pane);
|
|
76
|
+
|
|
77
|
+
/** A pin record. `held` is `{ value }`, `{ skip }` or `{ media }`. */
|
|
78
|
+
export function makePin(held, { pane, source = "run", now = Date.now() } = {}) {
|
|
79
|
+
const pin = {};
|
|
80
|
+
if ("skip" in held) pin.skip = held.skip === undefined || held.skip === null ? null : String(held.skip);
|
|
81
|
+
else if (held.media) pin.media = held.media;
|
|
82
|
+
else pin.value = held.value === undefined ? null : held.value;
|
|
83
|
+
return { ...pin, at: now, source, ...(pane ? { codeHash: codeHash(pane) } : {}) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Throws a readable error when a pin is over a limit (`others`: the bytes of the canvas's other pins). */
|
|
87
|
+
export function checkPinSize(pin, others = 0) {
|
|
88
|
+
const bytes = pinBytes(pin);
|
|
89
|
+
if (bytes > PIN_LIMITS.pane) throw new Error(`That value is too big to pin: ${kb(bytes)}, and a pin holds at most ${kb(PIN_LIMITS.pane)}.`);
|
|
90
|
+
if (bytes + others > PIN_LIMITS.canvas) throw new Error(`Pinning it would put ${kb(bytes + others)} of pinned values on this canvas; the limit is ${kb(PIN_LIMITS.canvas)}. Unpin something first.`);
|
|
91
|
+
return bytes;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Every pane with a pin (subgraphs' panes included), as [pane, path] pairs. */
|
|
95
|
+
export function pinnedPanes(panes = [], path = [], out = []) {
|
|
96
|
+
for (const p of panes) {
|
|
97
|
+
if (p?.pin) out.push([p, [...path, p.id]]);
|
|
98
|
+
if (p?.type === "subgraph") pinnedPanes(p.graph?.panes ?? [], [...path, p.id], out);
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The bytes of every pin in `panes` (except pane `except`'s own). */
|
|
104
|
+
export const pinsBytes = (panes, except) => pinnedPanes(panes).filter(([p]) => p.id !== except).reduce((n, [p]) => n + pinBytes(p.pin), 0);
|
|
105
|
+
|
|
106
|
+
/** A copy of panes without pins (a share link without "include pinned values", a headless run without --use-pins). */
|
|
107
|
+
export function stripPins(panes = []) {
|
|
108
|
+
return panes.map((p) => {
|
|
109
|
+
const { pin, ...rest } = p;
|
|
110
|
+
return rest.type === "subgraph" && rest.graph ? { ...rest, graph: { ...rest.graph, panes: stripPins(rest.graph.panes ?? []) } } : rest;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Throws a readable error unless every pin in a canvas's panes is well formed and within the limits. */
|
|
115
|
+
export function validatePins(panes = []) {
|
|
116
|
+
let total = 0;
|
|
117
|
+
for (const [pane] of pinnedPanes(panes)) {
|
|
118
|
+
const pin = pane.pin;
|
|
119
|
+
const where = `The pinned value of pane "${pane.name || pane.id}"`;
|
|
120
|
+
if (!pin || typeof pin !== "object" || Array.isArray(pin)) throw new Error(`${where} in that canvas is malformed.`);
|
|
121
|
+
const held = ["value", "skip", "media"].filter((k) => k in pin);
|
|
122
|
+
if (held.length !== 1) throw new Error(`${where} needs exactly one of value, skip or media.`);
|
|
123
|
+
if ("skip" in pin && pin.skip !== null && typeof pin.skip !== "string") throw new Error(`${where}: its skip reason isn't text.`);
|
|
124
|
+
if ("media" in pin && !(pin.media && typeof pin.media.data === "string" && typeof pin.media.kind === "string")) throw new Error(`${where}: its media has no inline bytes.`);
|
|
125
|
+
if (pin.source !== undefined && !["run", "edited"].includes(pin.source)) throw new Error(`${where}: source must be "run" or "edited".`);
|
|
126
|
+
if (pin.at !== undefined && !Number.isFinite(pin.at)) throw new Error(`${where}: "at" isn't a time.`);
|
|
127
|
+
const bytes = pinBytes(pin);
|
|
128
|
+
if (bytes > PIN_LIMITS.pane) throw new Error(`${where} is ${kb(bytes)}, over the ${kb(PIN_LIMITS.pane)} limit.`);
|
|
129
|
+
total += bytes;
|
|
130
|
+
}
|
|
131
|
+
if (total > PIN_LIMITS.canvas) throw new Error(`That canvas's pinned values take ${kb(total)}, over the ${kb(PIN_LIMITS.canvas)} limit.`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ── the editor ────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
const isSkipObject = (v) => v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 1 && "$skip" in v;
|
|
137
|
+
|
|
138
|
+
/** A pin as editor text: its JSON, `{ "$skip": reason }` for a pinned skip, a media value's description (read only). */
|
|
139
|
+
export function pinEditorText(pin) {
|
|
140
|
+
if (!pin) return "";
|
|
141
|
+
if ("skip" in pin) return JSON.stringify({ $skip: pin.skip }, null, 2);
|
|
142
|
+
if (pin.media) {
|
|
143
|
+
const { data, ...about } = pin.media;
|
|
144
|
+
return JSON.stringify({ $media: about.kind, ...about }, null, 2);
|
|
145
|
+
}
|
|
146
|
+
return JSON.stringify(pin.value, null, 2) ?? "null";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* What the editor's text pins: `{ value }`, or `{ skip }` for `{ "$skip": reason }`.
|
|
151
|
+
* Throws a SyntaxError with the parse error for invalid JSON.
|
|
152
|
+
*/
|
|
153
|
+
export function parsePinText(text) {
|
|
154
|
+
const source = String(text ?? "").trim();
|
|
155
|
+
if (!source) throw new SyntaxError("Type a JSON value (for example 42, \"text\", [1, 2] or {\"a\": 1}).");
|
|
156
|
+
const value = JSON.parse(source);
|
|
157
|
+
if (isSkipObject(value)) return { skip: value.$skip === null || value.$skip === undefined ? null : String(value.$skip) };
|
|
158
|
+
return { value };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** What a pane's run returns while it is pinned: `{ skip }`, `{ media: { blob, meta } }` or `{ value }`. */
|
|
162
|
+
export function pinnedOutput(pin) {
|
|
163
|
+
if ("skip" in pin) return { skip: pin.skip ?? "pinned skip" };
|
|
164
|
+
if (pin.media) return { media: { data: pin.media.data, type: pin.media.type, meta: metaFromContent(pin.media) } };
|
|
165
|
+
return { value: pin.value };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A one-line description of what a pin holds, for badges and agents. */
|
|
169
|
+
export function describePin(pin) {
|
|
170
|
+
if (!pin) return "";
|
|
171
|
+
if ("skip" in pin) return `a skip${pin.skip ? ` (${pin.skip})` : ""}`;
|
|
172
|
+
if (pin.media) return `${pin.media.type || pin.media.kind}, ${kb(pin.media.size ?? 0)}`;
|
|
173
|
+
const text = JSON.stringify(pin.value) ?? "null";
|
|
174
|
+
return text.length > 60 ? `${text.slice(0, 59)}…` : text;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The pin for a pane's current value, read from the sandbox: its JSON (through
|
|
179
|
+
* the Worker's JSON export, so a value JSON can't hold is refused with the
|
|
180
|
+
* reason: "it contains a function (add) at .add"), a media value's bytes when
|
|
181
|
+
* they are small enough (else its description), or a skip. Throws a readable
|
|
182
|
+
* error when there is nothing to pin.
|
|
183
|
+
*/
|
|
184
|
+
export async function capturePin(canvas, id, { now = Date.now() } = {}) {
|
|
185
|
+
const pane = canvas.panes.get(id);
|
|
186
|
+
if (!pane) throw new Error("There is no such pane.");
|
|
187
|
+
if (!isPinnable(pane.type)) throw new Error(`${pane.type === "import" ? "An import pane holds a module, which can't be pinned" : `A ${pane.type} pane can't be pinned`}.`);
|
|
188
|
+
const state = canvas.stateValue(id);
|
|
189
|
+
if (state.status === "skipped" && (!state.skip?.source || state.skip.source === id)) return makePin({ skip: state.skip?.reason ?? null }, { pane, now });
|
|
190
|
+
if (state.status !== "done") throw new Error(`"${pane.name || id}" has no value to pin yet (it is ${state.stale ? "stale" : state.status}). Run it first, or use "Edit pinned value…" to type one.`);
|
|
191
|
+
const key = canvas.homeOf?.(id)?.key ?? id;
|
|
192
|
+
if (state.result?.mediaFound?.top) {
|
|
193
|
+
const [value] = await canvas.runtime.clone([key]);
|
|
194
|
+
if (isMedia(value)) {
|
|
195
|
+
const about = describeForContent(value, { source: "pin" });
|
|
196
|
+
delete about.source;
|
|
197
|
+
delete about.stored;
|
|
198
|
+
if (value.blob.size <= PIN_LIMITS.media) return makePin({ media: { ...about, data: toBase64(new Uint8Array(await value.blob.arrayBuffer())) } }, { pane, now });
|
|
199
|
+
return makePin({ value: { $media: about.kind, ...about } }, { pane, now }); // too big to keep: its description only
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
let text;
|
|
203
|
+
try {
|
|
204
|
+
({ text } = await canvas.runtime.exportValue(key, "json"));
|
|
205
|
+
} catch (error) {
|
|
206
|
+
throw new Error(String(error?.message ?? error).replace(/^This value can't be written as JSON/, "This value can't be pinned"));
|
|
207
|
+
}
|
|
208
|
+
return makePin({ value: JSON.parse(text) }, { pane, now });
|
|
209
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// The plot pane's 3D helpers: pure maths with no DOM and no Three.js, so they are tested in Node. The view that draws is src/ui/plot-3d.js
|
|
2
|
+
// (a lazily loaded Three.js scene); the Worker samples the meshes (src/plot/source.js).
|
|
3
|
+
//
|
|
4
|
+
// camera { azimuth, elevation, distance, target: [x, y, z] }: an orbit around `target`; z is up. Ephemeral: it is the person's view in this
|
|
5
|
+
// tab (not in the canvas file, not an output), like a hover; "reset the plot's view" puts the default back.
|
|
6
|
+
// axisTicks nice tick values per axis for the labels the view prints (CSS2D-style text, never HTML from data)
|
|
7
|
+
// upgrade a 2D row becomes a surface row (MAL-PLOT-24)
|
|
8
|
+
import { formatTick, niceTicks, tickStep } from "../plot/view-vendor.js";
|
|
9
|
+
|
|
10
|
+
export const CAMERA_LIMITS = Object.freeze({ min: 0.4, max: 40, elevation: Math.PI / 2 - 0.01 });
|
|
11
|
+
export const defaultCamera = () => ({ azimuth: -Math.PI / 4, elevation: Math.PI / 6, distance: 2.4, target: [0, 0, 0] });
|
|
12
|
+
|
|
13
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
14
|
+
|
|
15
|
+
/** The camera turned by (dAzimuth, dElevation) radians; the elevation stays short of the poles. */
|
|
16
|
+
export function orbit(camera, dAzimuth, dElevation) {
|
|
17
|
+
return { ...camera, azimuth: camera.azimuth + dAzimuth, elevation: clamp(camera.elevation + dElevation, -CAMERA_LIMITS.elevation, CAMERA_LIMITS.elevation) };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The camera moved nearer by `factor` (2 = twice as near; below 1 away), between the limits. */
|
|
21
|
+
export function zoom(camera, factor) {
|
|
22
|
+
const f = Number.isFinite(factor) && factor > 0 ? factor : 1;
|
|
23
|
+
return { ...camera, distance: clamp(camera.distance / f, CAMERA_LIMITS.min, CAMERA_LIMITS.max) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The target moved across the view by (dx, dy) in view widths (right and up on the screen). */
|
|
27
|
+
export function panCamera(camera, dx, dy) {
|
|
28
|
+
const { azimuth: a, elevation: e, distance: d } = camera;
|
|
29
|
+
const right = [Math.cos(a), -Math.sin(a), 0]; // screen-right in the ground plane (the camera looks along (sin a, cos a) toward the target)
|
|
30
|
+
const up = [Math.sin(a) * Math.sin(e), Math.cos(a) * Math.sin(e), Math.cos(e)];
|
|
31
|
+
const k = d * 0.6;
|
|
32
|
+
return { ...camera, target: camera.target.map((v, i) => v + (right[i] * dx + up[i] * dy) * k) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const STEP = 0.1;
|
|
36
|
+
/**
|
|
37
|
+
* The camera after a key: arrows orbit, + and - zoom, W A S D (or Shift+arrows through `shift`) pan, Home resets. null for a key it does not use,
|
|
38
|
+
* so the page's own key handling goes on.
|
|
39
|
+
*/
|
|
40
|
+
export function keyToCamera(camera, key, shift = false) {
|
|
41
|
+
if (shift) {
|
|
42
|
+
if (key === "ArrowLeft") return panCamera(camera, -STEP, 0);
|
|
43
|
+
if (key === "ArrowRight") return panCamera(camera, STEP, 0);
|
|
44
|
+
if (key === "ArrowUp") return panCamera(camera, 0, STEP);
|
|
45
|
+
if (key === "ArrowDown") return panCamera(camera, 0, -STEP);
|
|
46
|
+
}
|
|
47
|
+
switch (key) {
|
|
48
|
+
case "ArrowLeft": return orbit(camera, -STEP * 2, 0);
|
|
49
|
+
case "ArrowRight": return orbit(camera, STEP * 2, 0);
|
|
50
|
+
case "ArrowUp": return orbit(camera, 0, STEP);
|
|
51
|
+
case "ArrowDown": return orbit(camera, 0, -STEP);
|
|
52
|
+
case "+": case "=": return zoom(camera, 1.15);
|
|
53
|
+
case "-": case "_": return zoom(camera, 1 / 1.15);
|
|
54
|
+
case "Home": case "0": return defaultCamera();
|
|
55
|
+
default: return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const finiteBounds = (b) => b && b.min?.every(Number.isFinite) && b.max?.every(Number.isFinite);
|
|
60
|
+
|
|
61
|
+
/** The bounds of several items united; an axis that is NaN in an item (a hole-only mesh, a flat axis without data) does not count. */
|
|
62
|
+
export function unionBounds(list) {
|
|
63
|
+
const min = [Infinity, Infinity, Infinity];
|
|
64
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
65
|
+
for (const b of list) {
|
|
66
|
+
if (!b?.min || !b?.max) continue;
|
|
67
|
+
for (let k = 0; k < 3; k++) {
|
|
68
|
+
if (Number.isFinite(b.min[k])) min[k] = Math.min(min[k], b.min[k]);
|
|
69
|
+
if (Number.isFinite(b.max[k])) max[k] = Math.max(max[k], b.max[k]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { min: min.map((v) => (v === Infinity ? NaN : v)), max: max.map((v) => (v === -Infinity ? NaN : v)) };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** { x: [{ value, label }], y, z }: nice ticks inside the bounds, each with the label that is printed (no ticks for an axis with no bounds). */
|
|
76
|
+
export function axisTicks(bounds, count = 5) {
|
|
77
|
+
const out = {};
|
|
78
|
+
["x", "y", "z"].forEach((axis, k) => {
|
|
79
|
+
const lo = bounds?.min?.[k];
|
|
80
|
+
const hi = bounds?.max?.[k];
|
|
81
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void (out[axis] = []);
|
|
82
|
+
const [a, b] = hi > lo ? [lo, hi] : [lo - 0.5, hi + 0.5];
|
|
83
|
+
const step = tickStep(a, b, count);
|
|
84
|
+
out[axis] = niceTicks(a, b, count).map((value) => ({ value, label: formatTick(value, step) }));
|
|
85
|
+
});
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The scene's frame: the centre and the half-size that the view fits into a unit cube, from the united bounds (a flat or empty axis gets a
|
|
91
|
+
* small span so nothing divides by 0). scale = 1 / the longest span.
|
|
92
|
+
*/
|
|
93
|
+
export function sceneFrame(bounds) {
|
|
94
|
+
const b = finiteBounds(bounds) ? bounds : { min: [-1, -1, -1], max: [1, 1, 1] };
|
|
95
|
+
const span = b.max.map((v, k) => Math.max(v - b.min[k], 1e-9));
|
|
96
|
+
const longest = Math.max(...span);
|
|
97
|
+
return { center: b.min.map((v, k) => (v + b.max[k]) / 2), span, scale: 1 / longest };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Parametric-surface presets (MAL-3D-04): the formulas of x, y, z in u and v, and the parameter ranges. */
|
|
101
|
+
export const SURFACE_PRESETS = Object.freeze({
|
|
102
|
+
torus: { label: "torus", expr: "(2 + cos(v))*cos(u)", expr2: "(2 + cos(v))*sin(u)", expr3: "sin(v)", min: 0, max: "2*pi", min2: 0, max2: "2*pi" },
|
|
103
|
+
sphere: { label: "sphere", expr: "sin(v)*cos(u)", expr2: "sin(v)*sin(u)", expr3: "cos(v)", min: 0, max: "2*pi", min2: 0, max2: "pi" },
|
|
104
|
+
mobius: { label: "Möbius strip", expr: "(1 + v/2*cos(u/2))*cos(u)", expr2: "(1 + v/2*cos(u/2))*sin(u)", expr3: "v/2*sin(u/2)", min: 0, max: "2*pi", min2: -1, max2: 1 },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A 2D row as a surface row (MAL-PLOT-24, the upgrade): a contour or gradient of f(x, y) and a y = f(x) formula keep their text as z = f(x, y).
|
|
109
|
+
* Anything with its own parameter fields (levels, robust, modulus) leaves them behind.
|
|
110
|
+
*/
|
|
111
|
+
export function upgradeTo3D(curve) {
|
|
112
|
+
const { id, expr, label, color, visible, grid } = curve;
|
|
113
|
+
return { id, kind: "surface", expr: expr ?? "x*y", min: -3, max: 3, min2: -3, max2: 3, ...(label ? { label } : {}), ...(color ? { color } : {}), ...(visible === false ? { visible: false } : {}), ...(Number.isInteger(grid) && grid >= 2 && grid <= 256 ? { grid } : {}) };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A summary of the 3D items of a plot's last answer, for an agent: counts, bounds, and whether the budget stopped one. */
|
|
117
|
+
export function summarize3D(items = []) {
|
|
118
|
+
return items
|
|
119
|
+
.filter((i) => i.mesh || i.curve3 || i.field3)
|
|
120
|
+
.map((i) => ({
|
|
121
|
+
id: i.id,
|
|
122
|
+
kind: i.kind,
|
|
123
|
+
...(i.mesh ? { vertices: i.mesh.vertexCount, triangles: i.mesh.indices.length / 3, holes: i.mesh.valid.reduce((n, v) => n + (v ? 0 : 1), 0) } : {}),
|
|
124
|
+
...(i.curve3 ? { points: i.curve3.count, runs: i.curve3.runs.length } : {}),
|
|
125
|
+
...(i.field3 ? { arrows: i.field3.count, skipped: i.field3.skipped } : {}),
|
|
126
|
+
bounds: i.bounds,
|
|
127
|
+
complete: i.progress?.complete ?? true,
|
|
128
|
+
...(i.progress && !i.progress.complete ? { stopped: i.progress.reason } : {}),
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A constant-size summary of the complex items of a plot's last answer, for an agent: counts of what was found, and why a formula has no shader form. */
|
|
133
|
+
export function complexStatus(items = []) {
|
|
134
|
+
return items
|
|
135
|
+
.filter((i) => i.complex)
|
|
136
|
+
.map((i) => ({
|
|
137
|
+
id: i.id,
|
|
138
|
+
...(i.complex.zeros ? { zeros: i.complex.zeros.filter((z) => z.kind === "zero").length, poles: i.complex.zeros.filter((z) => z.kind === "pole").length } : {}),
|
|
139
|
+
...(i.complex.unity ? { unity: i.complex.unity.length } : {}),
|
|
140
|
+
...(i.complex.conformal ? { conformalLines: i.complex.conformal.length } : {}),
|
|
141
|
+
picture: i.complex.raster?.progress?.complete === false ? `stopped at row ${i.complex.raster.progress.rows} of ${i.complex.raster.progress.of}` : "complete",
|
|
142
|
+
...(i.complex.shaderReason ? { noShader: String(i.complex.shaderReason).slice(0, 120) } : {}),
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const CLEAR_3D = { expr3: undefined, min2: undefined, max2: undefined, zMin: undefined, zMax: undefined };
|
|
147
|
+
/** The settings only a complex curve (or surface) has: they are refused on every other kind, so a change of kind drops them. */
|
|
148
|
+
const CLEAR_COMPLEX = { zeros: undefined, unity: undefined, conformal: undefined, engine: undefined, degrees: undefined, part: undefined };
|
|
149
|
+
const KINDS_WITH_3D = ["surface", "psurface", "curve3", "field3", "complex3"];
|
|
150
|
+
/**
|
|
151
|
+
* The fields a curve gets when its kind changes to `kind` (a 3D one or back): what the kind needs is filled in (sensible formulas and ranges,
|
|
152
|
+
* kept when the row already is a 3D kind with them), what it does not have is cleared. A y = f(x) or f(x, y) formula carries over to a surface.
|
|
153
|
+
*/
|
|
154
|
+
export function kindDefaults3D(kind, cv) {
|
|
155
|
+
const was3D = KINDS_WITH_3D.includes(cv.kind);
|
|
156
|
+
const wasComplex = cv.kind === "complex" || cv.kind === "complex3";
|
|
157
|
+
if (kind === "complex") return { ...CLEAR_3D, ...CLEAR_COMPLEX, expr2: undefined, expr: wasComplex ? cv.expr : "(z^2 - 1)/(z^2 + 1)", min: undefined, max: undefined, grid: undefined, zeros: true };
|
|
158
|
+
if (kind === "complex3") return { ...CLEAR_3D, ...CLEAR_COMPLEX, expr2: undefined, expr: wasComplex ? cv.expr : "z^2 - 1", min: -2, max: 2, min2: -2, max2: 2, part: "abs", grid: undefined };
|
|
159
|
+
if (kind === "surface") return { ...CLEAR_3D, ...CLEAR_COMPLEX, expr2: undefined, expr: cv.kind === "param" || was3D || wasComplex ? (cv.kind === "surface" ? cv.expr : "sin(x)*cos(y)") : cv.expr, min: -3, max: 3, min2: -3, max2: 3, grid: undefined };
|
|
160
|
+
if (kind === "psurface") return { ...CLEAR_3D, ...CLEAR_COMPLEX, ...(({ label, ...p }) => p)(SURFACE_PRESETS.sphere), grid: undefined };
|
|
161
|
+
if (kind === "curve3") return { ...CLEAR_3D, ...CLEAR_COMPLEX, expr: "cos(t)", expr2: "sin(t)", expr3: "t/6", min: 0, max: "4*pi", grid: undefined };
|
|
162
|
+
if (kind === "field3") return { ...CLEAR_3D, ...CLEAR_COMPLEX, expr: "-y", expr2: "x", expr3: "0.3", min: -2, max: 2, min2: -2, max2: 2, zMin: -2, zMax: 2, grid: 5 };
|
|
163
|
+
return was3D || wasComplex ? { ...CLEAR_3D, ...CLEAR_COMPLEX, expr3: undefined, min: undefined, max: undefined, grid: undefined, ...(kind === "y" || kind === "implicit" || kind === "contour" || kind === "gradient" || kind === "finite" ? { expr: "x" } : {}) } : {};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The most pixels a 3D picture's drawing buffer may hold (16 M, a 4096-pixel square): a shared canvas with a very wide pane can't ask for more. */
|
|
167
|
+
export const PICTURE_PIXELS = 4096 * 4096;
|
|
168
|
+
/** The pixel ratio to draw a w × h (CSS pixels) 3D view at for a picture: the screen's ratio times `scale`, cut down to stay within PICTURE_PIXELS. */
|
|
169
|
+
export function pictureRatio(w, h, ratio, scale) {
|
|
170
|
+
if (!(w > 0 && h > 0)) return 0;
|
|
171
|
+
const want = ratio * scale;
|
|
172
|
+
return Math.min(want, Math.sqrt(PICTURE_PIXELS / (w * h)));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ── the slice plane (MAL-3D-03): dragging it, and moving it by key ──
|
|
176
|
+
|
|
177
|
+
const AXES = { x: 0, y: 1, z: 2 };
|
|
178
|
+
const finite3 = (v) => Array.isArray(v) && v.length === 3 && v.every(Number.isFinite);
|
|
179
|
+
|
|
180
|
+
/** The extent of the data box along the plane's axis: [low, high]. */
|
|
181
|
+
export function sliceRange(bounds, axis) {
|
|
182
|
+
const i = AXES[axis];
|
|
183
|
+
return i === undefined || !finite3(bounds?.min) || !finite3(bounds?.max) ? null : [bounds.min[i], bounds.max[i]];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Where the plane goes when it is dragged: the point of its axis line (through `center`, along `axis`) nearest the pointer's ray
|
|
188
|
+
* `{ origin, direction }` in the data's own coordinates, held inside the data box. null when there is no answer (a ray along the axis, a
|
|
189
|
+
* bad number, an unknown axis): the plane then stays where it is.
|
|
190
|
+
*/
|
|
191
|
+
export function sliceFromRay(ray, axis, center, bounds) {
|
|
192
|
+
const i = AXES[axis];
|
|
193
|
+
const range = sliceRange(bounds, axis);
|
|
194
|
+
if (i === undefined || !range || !finite3(ray?.origin) || !finite3(ray?.direction) || !finite3(center)) return null;
|
|
195
|
+
const v = ray.direction;
|
|
196
|
+
const c = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
|
197
|
+
if (!(c > 1e-12)) return null;
|
|
198
|
+
const b = v[i]; // u is the unit vector of the axis
|
|
199
|
+
const w0 = center.map((value, k) => value - ray.origin[k]);
|
|
200
|
+
const d = w0[i];
|
|
201
|
+
const e = v[0] * w0[0] + v[1] * w0[1] + v[2] * w0[2];
|
|
202
|
+
const denom = c - b * b;
|
|
203
|
+
if (!(Math.abs(denom) > 1e-9 * c)) return null;
|
|
204
|
+
const s = center[i] + (b * e - c * d) / denom;
|
|
205
|
+
return Number.isFinite(s) ? Math.min(range[1], Math.max(range[0], s)) : null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The plane moved by a key: [ and PageDown down, ] and PageUp up, a fiftieth of the box (a tenth with Shift). null for any other key or a box with no depth. */
|
|
209
|
+
export function sliceKey(at, range, key, shift = false) {
|
|
210
|
+
const dir = key === "]" || key === "PageUp" ? 1 : key === "[" || key === "PageDown" ? -1 : 0;
|
|
211
|
+
if (!dir || !Number.isFinite(at) || !Array.isArray(range) || !(range[1] > range[0])) return null;
|
|
212
|
+
return Math.min(range[1], Math.max(range[0], at + (dir * (range[1] - range[0])) / (shift ? 10 : 50)));
|
|
213
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// The series of the plot view: x is the first column, and every later column that holds a number is one
|
|
2
|
+
// series. One series keeps the plain two-column table the view always had; several become a long table
|
|
3
|
+
// (x, value, series) that <plot-line color="series"> and <plot-marks color="series"> draw one line and one color each.
|
|
4
|
+
// Pure, so the page and the tests read a table the same way.
|
|
5
|
+
//
|
|
6
|
+
// A pane's `plot` setting also chooses the `kind` it is drawn as (PLOT_KINDS: the line, bars, a heatmap, …). It chooses which numeric columns are the series (`series`, in that order; none chosen is
|
|
7
|
+
// every numeric column) and which of them go on a secondary y axis on the right (`secondary`). The chart has one y
|
|
8
|
+
// scale, so a secondary series is drawn scaled onto the left axis' range (`plotRows`) while the table behind it keeps
|
|
9
|
+
// the true values (`rows`), and `axis2` says how to label the right-hand ticks. `marks: false` draws the line alone,
|
|
10
|
+
// without a dot at each point (a spectrum has hundreds).
|
|
11
|
+
import { nice, ticks } from "@johnhenry/data-plot/scale.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What the plot view can draw. `line` (the default) is a line through the points, with the points; `marks` the points alone;
|
|
15
|
+
* `bar` bars from zero (grouped when there are several series); `heatmap` a cell per x and series, colored by its value;
|
|
16
|
+
* `range` a bar from a low to a high per x (low, high), or those with the value between them (value, low, high), for error bars;
|
|
17
|
+
* `gantt` a bar from a start to an end per row; `dumbbell` two dots joined by a line per row; `sparkline` one small line per series;
|
|
18
|
+
* `faces` a Chernoff face per row, a column to each feature;
|
|
19
|
+
* `fit` a scatter with the fit drawn over it: the first series is the data (dots only), every later series a line through its own points (a
|
|
20
|
+
* fitted curve, with a cell left empty where a row belongs to the data alone), and a column called `outlier` (1 or true: the row's dot is drawn
|
|
21
|
+
* as an outlier) is a flag and not a series.
|
|
22
|
+
*/
|
|
23
|
+
export const PLOT_KINDS = ["line", "marks", "bar", "heatmap", "range", "gantt", "dumbbell", "sparkline", "faces", "fit"];
|
|
24
|
+
|
|
25
|
+
/** The numeric columns a kind cannot be drawn without. */
|
|
26
|
+
export const KIND_NEEDS = { range: 2, gantt: 2, dumbbell: 2, fit: 2 };
|
|
27
|
+
|
|
28
|
+
/** The most numeric columns a kind reads; a table with more draws the first ones and says so. */
|
|
29
|
+
export const KIND_USES = { range: 3, gantt: 2, dumbbell: 2, faces: 8 };
|
|
30
|
+
|
|
31
|
+
/** More series than this can't be told apart by color; the rest are counted, not drawn. */
|
|
32
|
+
export const MAX_SERIES = 8;
|
|
33
|
+
|
|
34
|
+
const isNumber = (v) => typeof v === "number" && Number.isFinite(v);
|
|
35
|
+
|
|
36
|
+
/** The most column names a plot setting lists. */
|
|
37
|
+
export const MAX_CHOSEN = 40;
|
|
38
|
+
|
|
39
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
40
|
+
const names = (v) => Array.isArray(v) && v.every((n) => typeof n === "string" && n.length > 0 && n.length <= 200);
|
|
41
|
+
|
|
42
|
+
/** What is wrong with a plot setting, as sentences (empty when it can be used). The agent tool and the dialog show these. */
|
|
43
|
+
export function plotProblems(raw) {
|
|
44
|
+
if (raw === undefined || raw === null) return [];
|
|
45
|
+
if (!isObject(raw)) return ["plot should be an object (kind, series, secondary, marks)."];
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const k of Object.keys(raw)) if (k !== "kind" && k !== "series" && k !== "secondary" && k !== "marks") out.push(`plot.${k} isn't a plot setting (use kind, series, secondary, marks).`);
|
|
48
|
+
if (raw.kind !== undefined && raw.kind !== null && !PLOT_KINDS.includes(raw.kind)) out.push(`plot.kind is one of ${PLOT_KINDS.join(", ")}.`);
|
|
49
|
+
if (raw.marks !== undefined && typeof raw.marks !== "boolean") out.push("plot.marks should be true or false.");
|
|
50
|
+
for (const k of ["series", "secondary"]) {
|
|
51
|
+
if (raw[k] === undefined) continue;
|
|
52
|
+
if (!names(raw[k])) out.push(`plot.${k} should be a list of column names.`);
|
|
53
|
+
else if (raw[k].length > MAX_CHOSEN) out.push(`plot.${k} names more than ${MAX_CHOSEN} columns (at most ${MAX_CHOSEN}).`);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The usable part of a pane's `plot` setting: `undefined` when nothing is set. Never throws. */
|
|
59
|
+
export function cleanPlotSettings(raw) {
|
|
60
|
+
if (!isObject(raw)) return undefined;
|
|
61
|
+
const list = (v) => (Array.isArray(v) ? [...new Set(v.filter((n) => typeof n === "string" && n.length > 0 && n.length <= 200))].slice(0, MAX_CHOSEN) : []);
|
|
62
|
+
const out = {};
|
|
63
|
+
if (PLOT_KINDS.includes(raw.kind) && raw.kind !== "line") out.kind = raw.kind; // line is what no kind means
|
|
64
|
+
const series = list(raw.series);
|
|
65
|
+
const secondary = list(raw.secondary);
|
|
66
|
+
if (series.length) out.series = series;
|
|
67
|
+
if (secondary.length) out.secondary = secondary;
|
|
68
|
+
if (raw.marks === false) out.marks = false; // true is the default and isn't kept
|
|
69
|
+
return Object.keys(out).length ? out : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The kind a pane's settings ask for (line when none, or one that isn't known). */
|
|
73
|
+
export const plotKind = (settings) => (PLOT_KINDS.includes(settings?.kind) ? settings.kind : "line");
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The y domain of a bar chart: it takes in zero and rounds out to ticks. `zero` is where zero sits in it, 0 (the bottom) to 1.
|
|
77
|
+
* Nothing (or nothing but zeros) is 0 to 1.
|
|
78
|
+
*/
|
|
79
|
+
export function zeroDomain(values) {
|
|
80
|
+
const nums = values.filter(isNumber);
|
|
81
|
+
const [lo, hi] = nums.length ? nice([Math.min(0, ...nums), Math.max(0, ...nums)]) : [0, 1];
|
|
82
|
+
const [a, b] = lo === hi ? [0, 1] : [lo, hi];
|
|
83
|
+
return { lo: a, hi: b, zero: (0 - a) / (b - a) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const extentOf = (values) => values.reduce(([lo, hi], v) => [Math.min(lo, v), Math.max(hi, v)], [Infinity, -Infinity]);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `table` is `{ columns, rows }` (rows are arrays); `settings` the pane's `plot` setting. Returns `{ problem }`, or
|
|
90
|
+
* `{ kind, x, y, series, columns, ignored, secondary, axis2, omitted, long, header, rows, plotRows, wide, lineish, marks }` (plus a `problem` when the kind needs more series than are drawn): `header` names
|
|
91
|
+
* the columns of `rows`, `y` the column to draw ("value" for several series), `columns` the numeric columns to choose from,
|
|
92
|
+
* `ignored` chosen names that are not one, `lineish` whether x is a number line in order (a line joins the points), `marks` whether to draw a dot at each point (false only when the setting says so; without a line the dots are all there is).
|
|
93
|
+
* `rows` are the table (true values); `plotRows` the same rows with the secondary series scaled onto the left axis;
|
|
94
|
+
* `axis2`, when there is a secondary axis, is `{ label, lo, hi, ticks: [{ value }], toPlot(value) }`.
|
|
95
|
+
*/
|
|
96
|
+
export function plotSeries(table, settings) {
|
|
97
|
+
const columns = table?.columns ?? [];
|
|
98
|
+
const source = table?.rows ?? [];
|
|
99
|
+
const xi = 0;
|
|
100
|
+
const numeric = [];
|
|
101
|
+
columns.forEach((_, i) => {
|
|
102
|
+
if (i !== xi && source.some((r) => isNumber(r[i]))) numeric.push(i);
|
|
103
|
+
});
|
|
104
|
+
if (!numeric.length) return { problem: "plot: no numeric column to put on y" };
|
|
105
|
+
const chosen = settings?.series?.length ? settings.series : undefined;
|
|
106
|
+
const picked = chosen ? [...new Set(chosen)].map((name) => [name, numeric.find((i) => columns[i] === name)]) : [];
|
|
107
|
+
const ignored = picked.filter(([, i]) => i === undefined).map(([name]) => name);
|
|
108
|
+
const wanted = chosen ? picked.filter(([, i]) => i !== undefined).map(([, i]) => i) : numeric;
|
|
109
|
+
if (!wanted.length) return { problem: "plot: none of the chosen columns holds a number" };
|
|
110
|
+
const used = wanted.slice(0, MAX_SERIES);
|
|
111
|
+
const omitted = wanted.length - used.length;
|
|
112
|
+
const x = columns[xi];
|
|
113
|
+
const long = used.length > 1;
|
|
114
|
+
// The secondary axis needs a series left on the primary one to share the chart with.
|
|
115
|
+
let right = used.filter((i) => settings?.secondary?.includes(columns[i]));
|
|
116
|
+
if (right.length === used.length) right = [];
|
|
117
|
+
const left = used.filter((i) => !right.includes(i));
|
|
118
|
+
const tag = (i) => (right.includes(i) ? `${columns[i]} (right)` : columns[i]);
|
|
119
|
+
let axis2;
|
|
120
|
+
let scaleOf = (v) => v;
|
|
121
|
+
if (right.length) {
|
|
122
|
+
const [p0, p1] = nice(extentOf(source.flatMap((r) => left.map((i) => r[i]).filter(isNumber))));
|
|
123
|
+
let [lo, hi] = extentOf(source.flatMap((r) => right.map((i) => r[i]).filter(isNumber)));
|
|
124
|
+
if (lo === hi) (lo -= 1), (hi += 1);
|
|
125
|
+
[lo, hi] = nice([lo, hi]);
|
|
126
|
+
const toPlot = (v) => p0 + ((v - lo) / (hi - lo)) * (p1 - p0);
|
|
127
|
+
scaleOf = toPlot;
|
|
128
|
+
axis2 = { label: right.map((i) => columns[i]).join(", "), lo, hi, ticks: ticks([lo, hi], 5).map((value) => ({ value })), toPlot };
|
|
129
|
+
}
|
|
130
|
+
const longRows = (convert) => used.flatMap((i) => source.filter((r) => isNumber(r[i])).map((r) => [r[xi], right.includes(i) ? convert(r[i]) : r[i], tag(i)]));
|
|
131
|
+
const rows = long ? longRows((v) => v) : source.map((r) => [r[xi], r[used[0]]]);
|
|
132
|
+
const plotRows = long && right.length ? longRows(scaleOf) : rows;
|
|
133
|
+
const xs = source.map((r) => r[xi]);
|
|
134
|
+
const wide = { header: [x, ...used.map((i) => columns[i])], rows: source.map((r) => [r[xi], ...used.map((i) => r[i])]) };
|
|
135
|
+
const lineish = xs.some(isNumber) && xs.every((v, i) => isNumber(v) && (i === 0 || v >= xs[i - 1]));
|
|
136
|
+
const kind = plotKind(settings);
|
|
137
|
+
const need = KIND_NEEDS[kind];
|
|
138
|
+
return {
|
|
139
|
+
kind,
|
|
140
|
+
...(need && used.length < need ? { problem: `${kind}: needs at least two numeric columns (the first is x), and this table has ${used.length === 1 ? "one" : "none"} to draw` } : {}),
|
|
141
|
+
x,
|
|
142
|
+
y: long ? "value" : columns[used[0]],
|
|
143
|
+
series: used.map((i) => columns[i]),
|
|
144
|
+
columns: numeric.map((i) => columns[i]),
|
|
145
|
+
ignored,
|
|
146
|
+
secondary: right.map((i) => columns[i]),
|
|
147
|
+
...(axis2 ? { axis2 } : {}),
|
|
148
|
+
omitted,
|
|
149
|
+
long,
|
|
150
|
+
header: long ? [x, "value", "series"] : [x, columns[used[0]]],
|
|
151
|
+
rows,
|
|
152
|
+
plotRows,
|
|
153
|
+
wide,
|
|
154
|
+
lineish,
|
|
155
|
+
marks: settings?.marks !== false,
|
|
156
|
+
};
|
|
157
|
+
}
|