@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
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// A pane set to "Run in its own Worker" runs here in a Worker of its own (the
|
|
2
|
+
// page makes one per such pane: src/runtime/runtime.js). Its inputs come in as
|
|
3
|
+
// copies of the shared sandbox's values and its value goes back as a copy (the
|
|
4
|
+
// shared sandbox keeps it, so readers, exports and previews work as for any
|
|
5
|
+
// pane). Copies are structured clones: plain data, Maps, Sets, Dates, typed
|
|
6
|
+
// arrays and Blobs cross; functions, modules and class instances don't, and
|
|
7
|
+
// say so. What needs the shared sandbox is forwarded to it by copy:
|
|
8
|
+
// live values (yield, emit), events (emit.event, values keyed by event
|
|
9
|
+
// outputs), send() on a channel and state setters. Each goes to the page as a
|
|
10
|
+
// copy, which stores it in the shared sandbox, so it behaves as it does from a
|
|
11
|
+
// pane there; a value that can't be copied is refused, naming the part.
|
|
12
|
+
let ownMode = false;
|
|
13
|
+
const OWN_OFF = 'turn off "Run in its own Worker" to use it';
|
|
14
|
+
/** What a pane in its own Worker sends has to be copied: `what` (its words) can't be, and this says which part. */
|
|
15
|
+
function ownCopyError(what, problem) {
|
|
16
|
+
return new Error(`${what}: this pane runs in its own Worker, so it is copied to the shared sandbox, and it holds ${problem}, which can't be copied. Send plain data (objects, arrays, Maps, Dates, Blobs…), or ${OWN_OFF.replace(" to use it", "")}.`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// The direct channel. In the browser the page hands the shared sandbox
|
|
20
|
+
// and each pane's own Worker the two ends of a MessageChannel (linkOwn here,
|
|
21
|
+
// linkShared there; src/runtime/runtime.js `linked`), so a copy goes straight
|
|
22
|
+
// from one Worker to the other: one structured clone each way instead of two
|
|
23
|
+
// (Worker to page, page to Worker). Each copy is posted with a ticket, and the
|
|
24
|
+
// page names the ticket in the call that takes it (fromShared, fromOwn). The
|
|
25
|
+
// copy and that call travel on different channels, so a take waits briefly
|
|
26
|
+
// for its copy. Node's Workers can't take a port: there, copies go through the
|
|
27
|
+
// page as before.
|
|
28
|
+
const ownLinks = new Map(); // the shared sandbox: pane id -> the channel to its own Worker
|
|
29
|
+
let sharedLink = null; // a pane's own Worker: the channel to the shared sandbox
|
|
30
|
+
const LINK_KEEP_MS = 60000; // a copy nobody took (the call that would have failed first) goes after this
|
|
31
|
+
const LINK_GONE = "Stopped: the channel between this pane's own Worker and the shared sandbox was replaced while this ran.";
|
|
32
|
+
function makeLink(port) {
|
|
33
|
+
const link = { port, inbox: new Map(), waiters: new Map(), seq: 0 };
|
|
34
|
+
port.onmessage = ({ data }) => {
|
|
35
|
+
const waiter = link.waiters.get(data?.ticket);
|
|
36
|
+
if (waiter) {
|
|
37
|
+
link.waiters.delete(data.ticket);
|
|
38
|
+
waiter.resolve(data.value);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
link.inbox.set(data?.ticket, { value: data?.value, at: Date.now() });
|
|
42
|
+
if (link.inbox.size > 16) for (const [ticket, entry] of link.inbox) if (entry.at < Date.now() - LINK_KEEP_MS) link.inbox.delete(ticket);
|
|
43
|
+
};
|
|
44
|
+
return link;
|
|
45
|
+
}
|
|
46
|
+
function closeLink(link) {
|
|
47
|
+
if (!link) return;
|
|
48
|
+
link.port.onmessage = null;
|
|
49
|
+
link.port.close();
|
|
50
|
+
link.inbox.clear();
|
|
51
|
+
for (const waiter of link.waiters.values()) waiter.reject(new Error(LINK_GONE));
|
|
52
|
+
link.waiters.clear();
|
|
53
|
+
}
|
|
54
|
+
/** The copy posted on `link` with `ticket`: at once, or when it arrives (at most `waitMs` later). */
|
|
55
|
+
function takeFrom(link, ticket, waitMs) {
|
|
56
|
+
if (!link) return Promise.reject(new Error(LINK_GONE));
|
|
57
|
+
const entry = link.inbox.get(ticket);
|
|
58
|
+
if (entry) {
|
|
59
|
+
link.inbox.delete(ticket);
|
|
60
|
+
return Promise.resolve(entry.value);
|
|
61
|
+
}
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const timer = setTimeout(() => {
|
|
64
|
+
link.waiters.delete(ticket);
|
|
65
|
+
reject(new Error("A copy sent between this pane's own Worker and the shared sandbox didn't arrive."));
|
|
66
|
+
}, Math.max(1, Number(waitMs) || 0));
|
|
67
|
+
link.waiters.set(ticket, {
|
|
68
|
+
resolve: (value) => (clearTimeout(timer), resolve(value)),
|
|
69
|
+
reject: (error) => (clearTimeout(timer), reject(error)),
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** A pane's own Worker: `map` (a copy for the shared sandbox) goes straight there when there is a channel; the page gets its ticket instead. */
|
|
74
|
+
function viaLink(map) {
|
|
75
|
+
if (!sharedLink) return map;
|
|
76
|
+
const ticket = ++sharedLink.seq;
|
|
77
|
+
sharedLink.port.postMessage({ ticket, value: map });
|
|
78
|
+
return new Map([["ticket", ticket]]);
|
|
79
|
+
}
|
|
80
|
+
// What a pane in its own Worker sent to the shared sandbox and the page hasn't
|
|
81
|
+
// stored yet (setters' changes): a run, an item or a live step replies only
|
|
82
|
+
// once they have landed, as a run's events do (afterEvents).
|
|
83
|
+
const ownForwards = new Set();
|
|
84
|
+
function forward(name, ...args) {
|
|
85
|
+
const sent = hostRef.call(name, ...args);
|
|
86
|
+
ownForwards.add(sent);
|
|
87
|
+
const done = () => ownForwards.delete(sent);
|
|
88
|
+
sent.then(done, done);
|
|
89
|
+
return sent;
|
|
90
|
+
}
|
|
91
|
+
async function forwarded() {
|
|
92
|
+
while (ownForwards.size) await Promise.allSettled([...ownForwards]);
|
|
93
|
+
}
|
|
94
|
+
/** How runtime.js ownReads labels the state pane a setter writes to, in copyOut's names. */
|
|
95
|
+
const SETTER_STATE = "()'s state";
|
|
96
|
+
/**
|
|
97
|
+
* setX in a pane in its own Worker: the change is made to its copy of
|
|
98
|
+
* the state pane's value (so the rest of the run sees it, as in the shared
|
|
99
|
+
* sandbox) and sent, as a copy, to the state pane, which then reruns its
|
|
100
|
+
* readers. Keyed setters send their request; the state pane applies it.
|
|
101
|
+
*/
|
|
102
|
+
function ownSetter(source, name, key, forwardingConsole) {
|
|
103
|
+
const check = (value, what) => {
|
|
104
|
+
const budget = { left: 200000 };
|
|
105
|
+
const problem = copyProblem(value, "", budget);
|
|
106
|
+
if (problem) throw ownCopyError(what, problem);
|
|
107
|
+
return budget.binary;
|
|
108
|
+
};
|
|
109
|
+
const send = (kind, entries) => void forward(kind, source, viaLink(new Map(Object.entries(entries)))).catch((error) => forwardingConsole?.error?.(`${name}():`, error?.message ?? error));
|
|
110
|
+
const set = (next) => {
|
|
111
|
+
const current = values.get(source);
|
|
112
|
+
const value = typeof next === "function" ? next(current) : next;
|
|
113
|
+
if (Object.is(value, current)) return value;
|
|
114
|
+
const binary = check(value, `${name}(…)`);
|
|
115
|
+
values.set(source, value);
|
|
116
|
+
send("ownSetState", { value: toCopy(value), ...(binary ? { binary } : {}) });
|
|
117
|
+
return value;
|
|
118
|
+
};
|
|
119
|
+
for (const op of KEYED_OPS) {
|
|
120
|
+
set[op] = (...args) => {
|
|
121
|
+
const request = keyedRequest(op, args);
|
|
122
|
+
const list = values.get(source);
|
|
123
|
+
const out = applyKeyed(list, request, { spec: stateKeyOf(key), name, has: values.has(source) });
|
|
124
|
+
if (!out.change) return list;
|
|
125
|
+
check(request, `${name}.${op}(…)`);
|
|
126
|
+
values.set(source, out.value);
|
|
127
|
+
send("ownChangeState", { request, label: name, ...(key !== undefined ? { spec: key } : {}) });
|
|
128
|
+
return out.value;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return Object.freeze(set);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A value a pane in its own Worker hands to the shared sandbox (its run's
|
|
135
|
+
* value, a live value, an emitter's): a Map, which crosses whole by structured
|
|
136
|
+
* clone (andbox checks a reply with JSON.stringify, which a Map always passes),
|
|
137
|
+
* `{ value }` or `{ skip, reason }`. Throws when it can't be copied.
|
|
138
|
+
*/
|
|
139
|
+
function ownOut(value, what) {
|
|
140
|
+
if (isSkip(value)) return new Map([["skip", true], ["reason", skipReason(value)]]);
|
|
141
|
+
const budget = { left: 200000 };
|
|
142
|
+
const problem = copyProblem(value, "", budget);
|
|
143
|
+
if (problem) throw ownCopyError(what, problem);
|
|
144
|
+
return viaLink(new Map([["value", toCopy(value)], ...(budget.binary ? [["binary", true]] : [])]));
|
|
145
|
+
}
|
|
146
|
+
const COPY_PROTOS = new Set(
|
|
147
|
+
[Object.prototype, Array.prototype, null, Date.prototype, RegExp.prototype, Map.prototype, Set.prototype, ArrayBuffer.prototype, DataView.prototype, Boolean.prototype, Number.prototype, String.prototype, globalThis.SharedArrayBuffer?.prototype].filter(
|
|
148
|
+
(p) => p !== undefined,
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
const OWN_HTML = "mallory:html"; // html`…` crosses as { "mallory:html": text } (its toString is a function)
|
|
152
|
+
const memberPath = (path, key) => (/^[A-Za-z_$][\w$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`);
|
|
153
|
+
/**
|
|
154
|
+
* Why a value can't be copied to or from a pane's own Worker ("a function at
|
|
155
|
+
* .add", "a Point (a class instance) at .p"), or null. A structured clone
|
|
156
|
+
* would throw on some of these and quietly turn class instances into plain
|
|
157
|
+
* objects; this says which part it is. Big values are walked only so far:
|
|
158
|
+
* past that, the copy itself fails on what it can't carry.
|
|
159
|
+
*/
|
|
160
|
+
function copyProblem(value, path = "", budget = { left: 200000 }, seen = new Set()) {
|
|
161
|
+
if (budget.left-- <= 0) return null;
|
|
162
|
+
const at = path ? ` at ${path}` : "";
|
|
163
|
+
const type = typeof value;
|
|
164
|
+
if (type === "function") return `a function${value.name ? ` (${value.name})` : ""}${at}`;
|
|
165
|
+
if (type === "symbol") return `a symbol${at}`;
|
|
166
|
+
if (value === null || type !== "object") return null;
|
|
167
|
+
if (seen.has(value)) return null;
|
|
168
|
+
seen.add(value);
|
|
169
|
+
if (path === "" && value[HTML]) return null; // html`…`: crosses as its text (toCopy)
|
|
170
|
+
if (Object.prototype.toString.call(value) === "[object Module]") return `a module${at}`;
|
|
171
|
+
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
|
|
172
|
+
budget.binary = true; // its buffers can move rather than be copied twice (src/runtime/transfer.js)
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
if ((typeof Blob === "function" && value instanceof Blob) || value instanceof Error) return null;
|
|
176
|
+
const proto = Object.getPrototypeOf(value);
|
|
177
|
+
if (!COPY_PROTOS.has(proto)) {
|
|
178
|
+
const name = proto?.constructor?.name;
|
|
179
|
+
return `${name ? `a ${name}` : "an object"} (a class instance)${at}`;
|
|
180
|
+
}
|
|
181
|
+
if (value instanceof Map) {
|
|
182
|
+
let i = 0;
|
|
183
|
+
for (const [k, v] of value) {
|
|
184
|
+
const problem = copyProblem(k, `${path}[key ${i}]`, budget, seen) ?? copyProblem(v, `${path}.get(${typeof k === "string" ? JSON.stringify(k) : i})`, budget, seen);
|
|
185
|
+
if (problem) return problem;
|
|
186
|
+
i++;
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
if (value instanceof Set) {
|
|
191
|
+
let i = 0;
|
|
192
|
+
for (const v of value) {
|
|
193
|
+
const problem = copyProblem(v, `${path}[${i++}]`, budget, seen);
|
|
194
|
+
if (problem) return problem;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
for (const key of Object.keys(value)) {
|
|
199
|
+
const problem = copyProblem(value[key], Array.isArray(value) ? `${path}[${key}]` : memberPath(path, key), budget, seen);
|
|
200
|
+
if (problem) return problem;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const toCopy = (value) => (value && typeof value === "object" && value[HTML] ? { [OWN_HTML]: String(value.html) } : value);
|
|
205
|
+
function fromCopy(value) {
|
|
206
|
+
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype) return value;
|
|
207
|
+
const keys = Object.keys(value);
|
|
208
|
+
return keys.length === 1 && keys[0] === OWN_HTML && typeof value[OWN_HTML] === "string" ? html([value[OWN_HTML]]) : value;
|
|
209
|
+
}
|
|
210
|
+
// What crosses to the page is wrapped in a Map: andbox sends a call's result by structured clone after
|
|
211
|
+
// checking it with JSON.stringify, which a Map always passes (a BigInt or a cycle inside would make it a string).
|
|
212
|
+
const wrapped = (entries) => new Map(Object.entries(entries));
|
|
213
|
+
/** A copy as it arrives (`fromCopy`), with a skip marker (ownOut's) back to skip(…). */
|
|
214
|
+
function fromOwn(payload) {
|
|
215
|
+
if (payload?.get?.("skip")) return skip(payload.get("reason"));
|
|
216
|
+
return fromCopy(payload?.get?.("value"));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A pane's own Worker takes its inputs: `payload` (a Map from the page)
|
|
220
|
+
* has `keys` and `values` (copies, in order: its inputs and the state panes its
|
|
221
|
+
* setters write to), and `event` (`{ key, event }`) for a reader of events.
|
|
222
|
+
* The last run's inputs go.
|
|
223
|
+
*/
|
|
224
|
+
function loadOwn(payload) {
|
|
225
|
+
const keys = payload?.get?.("keys") ?? [];
|
|
226
|
+
const copies = payload?.get?.("values") ?? [];
|
|
227
|
+
for (const key of [...values.keys()]) if (!keys.includes(key)) values.delete(key);
|
|
228
|
+
keys.forEach((key, i) => values.set(key, fromCopy(copies[i])));
|
|
229
|
+
eventStore.clear();
|
|
230
|
+
const read = payload?.get?.("event");
|
|
231
|
+
if (read) eventStore.set(read.key, Object.freeze({ ...read.event, payload: fromCopy(read.event.payload) }));
|
|
232
|
+
}
|
|
233
|
+
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Timers pane code starts. A restart can't bring a timer back (its
|
|
2
|
+
// callback lives only in the Worker), so a pane that left one pending runs
|
|
3
|
+
// again after a restart instead of having its value put back (finish), which
|
|
4
|
+
// starts its timer again.
|
|
5
|
+
//
|
|
6
|
+
// Every timer counts, however it was started: the Worker's global setTimeout
|
|
7
|
+
// and setInterval are wrapped, so `globalThis.setTimeout`, a library's
|
|
8
|
+
// own timers and a timer a callback starts later are seen as well as the
|
|
9
|
+
// setTimeout in a pane's scope. Each pending timer has owners, the panes it
|
|
10
|
+
// counts against:
|
|
11
|
+
// - one started through the names in a pane's scope (timersFor): that pane;
|
|
12
|
+
// - one started in a timer's callback: that timer's owners, so a timer that
|
|
13
|
+
// re-arms itself stays its pane's;
|
|
14
|
+
// - any other (globalThis.setTimeout, a library's own) started while a pane's
|
|
15
|
+
// code runs up to its first `await` (`syncOwners`): that pane;
|
|
16
|
+
// - later on: the panes whose code is on the stack (each pane's code is
|
|
17
|
+
// compiled with a sourceURL naming it, mallory://<name>), which finds pane
|
|
18
|
+
// code that goes on after an `await`. Panes with the same name (a
|
|
19
|
+
// repeater's instances) can't be told apart that way: of them, the ones
|
|
20
|
+
// whose code is running count;
|
|
21
|
+
// - when no pane's code is on the stack (a library's own promise chain): every
|
|
22
|
+
// pane whose code is running here then (`running`: a run's code, from its
|
|
23
|
+
// call until its promise settles, and a live pane's step).
|
|
24
|
+
// With no async context in JavaScript, the last two can't always say which
|
|
25
|
+
// pane started a timer, so it counts against each that may have: they run
|
|
26
|
+
// again after a restart rather than one being put back without its timer.
|
|
27
|
+
// One started while no pane's code runs (by work a pane didn't wait for, after
|
|
28
|
+
// its run ended) has no owner, and isn't seen.
|
|
29
|
+
const timerOwners = new Map(); // a pending timer's handle -> the pane ids it counts against
|
|
30
|
+
const paneTimers = new Map(); // pane id -> how many pending timers count against it
|
|
31
|
+
const running = new Map(); // pane id -> runs of its code in progress here
|
|
32
|
+
let callbackOwners = null; // while a timer's callback (or a pane's scoped setTimeout) runs: whom new timers count against
|
|
33
|
+
let syncOwners = null; // while a pane's code runs up to its first await: that pane
|
|
34
|
+
const codeNames = new Map(); // a pane's code's name (its sourceURL, mallory://<name>) -> the pane ids whose code has it
|
|
35
|
+
const CODE_FRAME = /mallory:\/\/(\S+?):\d+:\d+/g;
|
|
36
|
+
/** Pane `id`'s code is compiled under `name` (compile's sourceURL): a timer started with it on the stack is that pane's. */
|
|
37
|
+
function nameCode(id, name) {
|
|
38
|
+
let ids = codeNames.get(name);
|
|
39
|
+
if (!ids) codeNames.set(name, (ids = new Set()));
|
|
40
|
+
ids.add(id);
|
|
41
|
+
}
|
|
42
|
+
/** The panes whose code is on the stack now. */
|
|
43
|
+
function panesOnStack() {
|
|
44
|
+
const limit = Error.stackTraceLimit;
|
|
45
|
+
Error.stackTraceLimit = 100;
|
|
46
|
+
const stack = String(new Error().stack ?? "");
|
|
47
|
+
Error.stackTraceLimit = limit;
|
|
48
|
+
const ids = new Set();
|
|
49
|
+
for (const [, name] of stack.matchAll(CODE_FRAME)) {
|
|
50
|
+
let decoded;
|
|
51
|
+
try {
|
|
52
|
+
decoded = decodeURIComponent(name);
|
|
53
|
+
} catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
for (const id of codeNames.get(decoded) ?? []) ids.add(id);
|
|
57
|
+
}
|
|
58
|
+
return [...ids];
|
|
59
|
+
}
|
|
60
|
+
function ownersNow() {
|
|
61
|
+
if (callbackOwners) return callbackOwners;
|
|
62
|
+
if (syncOwners) return syncOwners;
|
|
63
|
+
const found = panesOnStack();
|
|
64
|
+
if (found.length > 1) {
|
|
65
|
+
const now = found.filter((id) => running.has(id));
|
|
66
|
+
if (now.length) return now;
|
|
67
|
+
}
|
|
68
|
+
return found.length ? found : [...running.keys()];
|
|
69
|
+
}
|
|
70
|
+
/** `fn()`, the start of pane `id`'s code, up to its first await: timers started meanwhile are its own. */
|
|
71
|
+
function startsCode(id, fn) {
|
|
72
|
+
const before = syncOwners;
|
|
73
|
+
syncOwners = [id];
|
|
74
|
+
try {
|
|
75
|
+
return fn();
|
|
76
|
+
} finally {
|
|
77
|
+
syncOwners = before;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function ownTimer(handle, owners) {
|
|
81
|
+
if (!owners.length) return;
|
|
82
|
+
timerOwners.set(handle, owners);
|
|
83
|
+
for (const id of owners) paneTimers.set(id, (paneTimers.get(id) ?? 0) + 1);
|
|
84
|
+
}
|
|
85
|
+
function disownTimer(handle) {
|
|
86
|
+
const owners = timerOwners.get(handle);
|
|
87
|
+
if (!owners) return;
|
|
88
|
+
timerOwners.delete(handle);
|
|
89
|
+
for (const id of owners) {
|
|
90
|
+
const n = (paneTimers.get(id) ?? 0) - 1;
|
|
91
|
+
if (n > 0) paneTimers.set(id, n);
|
|
92
|
+
else paneTimers.delete(id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** `fn` (a timer's callback) with `owners` as whom the timers it starts count against. */
|
|
96
|
+
function withOwners(owners, fn, args) {
|
|
97
|
+
const before = callbackOwners;
|
|
98
|
+
callbackOwners = owners;
|
|
99
|
+
try {
|
|
100
|
+
return typeof fn === "function" ? fn(...args) : (0, eval)(String(fn));
|
|
101
|
+
} finally {
|
|
102
|
+
callbackOwners = before;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Pane `id`'s code runs here until the returned function is called (a run, a live step): new timers count against it. */
|
|
106
|
+
function codeRuns(id) {
|
|
107
|
+
running.set(id, (running.get(id) ?? 0) + 1);
|
|
108
|
+
let done = false;
|
|
109
|
+
return () => {
|
|
110
|
+
if (done) return;
|
|
111
|
+
done = true;
|
|
112
|
+
const n = running.get(id) - 1;
|
|
113
|
+
if (n > 0) running.set(id, n);
|
|
114
|
+
else running.delete(id);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const globalTimers = {
|
|
118
|
+
setTimeout(fn, ms, ...args) {
|
|
119
|
+
const owners = ownersNow();
|
|
120
|
+
const handle = setTimeout(() => {
|
|
121
|
+
disownTimer(handle);
|
|
122
|
+
withOwners(owners, fn, args);
|
|
123
|
+
}, ms);
|
|
124
|
+
ownTimer(handle, owners);
|
|
125
|
+
return handle;
|
|
126
|
+
},
|
|
127
|
+
setInterval(fn, ms, ...args) {
|
|
128
|
+
const owners = ownersNow();
|
|
129
|
+
const handle = setInterval(() => withOwners(owners, fn, args), ms);
|
|
130
|
+
ownTimer(handle, owners);
|
|
131
|
+
return handle;
|
|
132
|
+
},
|
|
133
|
+
clearTimeout(handle) {
|
|
134
|
+
disownTimer(handle);
|
|
135
|
+
clearTimeout(handle);
|
|
136
|
+
},
|
|
137
|
+
clearInterval(handle) {
|
|
138
|
+
disownTimer(handle);
|
|
139
|
+
clearInterval(handle);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
for (const [name, fn] of Object.entries(globalTimers)) {
|
|
143
|
+
Object.defineProperty(fn, "name", { value: name });
|
|
144
|
+
globalThis[name] = fn;
|
|
145
|
+
}
|
|
146
|
+
/** setTimeout & co. in pane `id`'s scope: what they start counts against it alone, as does what their callbacks start. */
|
|
147
|
+
function timersFor(id) {
|
|
148
|
+
const mine = [id];
|
|
149
|
+
return {
|
|
150
|
+
setTimeout: (fn, ms, ...args) => withOwners(mine, () => globalTimers.setTimeout(fn, ms, ...args), []),
|
|
151
|
+
setInterval: (fn, ms, ...args) => withOwners(mine, () => globalTimers.setInterval(fn, ms, ...args), []),
|
|
152
|
+
clearTimeout: globalTimers.clearTimeout,
|
|
153
|
+
clearInterval: globalTimers.clearInterval,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const TIMER_HELPERS = ["setTimeout", "setInterval", "clearTimeout", "clearInterval"];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* An eval pane's `state` as JSON that comes back exactly, to put back
|
|
160
|
+
* after a restart: `{ text }`, `{ none: true }` (its code doesn't use state),
|
|
161
|
+
* or `{ lost: true }` (it can't be: it isn't plain JSON, or it is bigger than
|
|
162
|
+
* `maxLength`; then its value isn't put back either, since it would come back
|
|
163
|
+
* without the state it was made with).
|
|
164
|
+
*/
|
|
165
|
+
function stateJSON(id, maxLength) {
|
|
166
|
+
if (!paneStates.has(id)) return { none: true };
|
|
167
|
+
const kept = exporter?.storableJSON ? exporter.storableJSON(paneStates.get(id).value, { maxLength }) : null;
|
|
168
|
+
return kept?.ok ? { text: kept.text } : { lost: true };
|
|
169
|
+
}
|
|
170
|
+
/** Did pane `id`'s runs leave something here a restart would lose (an onCleanup, a live run, event outputs, a pending timer, however it was started)? */
|
|
171
|
+
const leftBehind = (id) => cleanups.has(id) || liveRuns.has(id) || eventOutputs.has(id) || paneTimers.has(id);
|
|
172
|
+
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// State panes: a value that other panes can replace through a setter. Setting
|
|
2
|
+
// it tells the page, which reruns everything downstream of the state pane.
|
|
3
|
+
// Keyed setters: setTodos.update(key, patch), .insert(item, at?),
|
|
4
|
+
// .remove(key) and .move(key, to) change one item of a list (applyKeyed,
|
|
5
|
+
// src/runtime/keys.js) by the state pane's key (`key`, default "id": the rule
|
|
6
|
+
// `each.key` uses). Each makes a new array that shares the items it didn't
|
|
7
|
+
// touch, and tells the page what changed ({ op, key, at?, to? }), for the run
|
|
8
|
+
// log; keyed for-each readers learn which items changed from keyedLog.
|
|
9
|
+
const setters = new Map(); // state pane id -> setter
|
|
10
|
+
const stateKeys = new Map(); // state pane id -> its key spec, as the page last said (a reader's setters, changeState)
|
|
11
|
+
const setterLabels = new Map(); // state pane id -> "setTodos", for messages
|
|
12
|
+
function setterFor(id) {
|
|
13
|
+
if (!setters.has(id)) {
|
|
14
|
+
const set = (next) => {
|
|
15
|
+
const value = typeof next === "function" ? next(values.get(id)) : next;
|
|
16
|
+
if (Object.is(value, values.get(id))) return value;
|
|
17
|
+
values.set(id, value);
|
|
18
|
+
hostRef.call("stateChanged", id).catch(() => {});
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
for (const op of KEYED_OPS) set[op] = (...args) => changeState(id, keyedRequest(op, args)).value;
|
|
22
|
+
setters.set(id, set);
|
|
23
|
+
}
|
|
24
|
+
return setters.get(id);
|
|
25
|
+
}
|
|
26
|
+
/** A keyed change to state pane `id` (a request as applyKeyed takes it): `{ value, change? }` (no change: the same list). Throws a readable error. */
|
|
27
|
+
function changeState(id, request, spec = stateKeys.get(id)) {
|
|
28
|
+
const list = values.get(id);
|
|
29
|
+
const out = applyKeyed(list, request, { spec: stateKeyOf(spec), name: setterLabels.get(id) ?? "set", has: values.has(id) });
|
|
30
|
+
if (!out.change) return { value: list };
|
|
31
|
+
values.set(id, out.value);
|
|
32
|
+
noteKeyed(list, out.value, out.items);
|
|
33
|
+
tellChanged(id, out.change);
|
|
34
|
+
return { value: out.value, change: out.change };
|
|
35
|
+
}
|
|
36
|
+
// Keyed changes made in one go (a loop of updates) reach the page as one message, so the page reruns
|
|
37
|
+
// the readers once and its feedback-loop guard counts one change, not one per item.
|
|
38
|
+
const changesToSend = new Map(); // state pane id -> [change…]
|
|
39
|
+
function tellChanged(id, change) {
|
|
40
|
+
const queued = changesToSend.get(id);
|
|
41
|
+
if (queued) return void queued.push(change);
|
|
42
|
+
changesToSend.set(id, [change]);
|
|
43
|
+
queueMicrotask(() => {
|
|
44
|
+
const changes = changesToSend.get(id) ?? [];
|
|
45
|
+
changesToSend.delete(id);
|
|
46
|
+
hostRef.call("stateChanged", id, changes).catch(() => {});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The keyed hint: which lists came from which by keyed changes, so a
|
|
51
|
+
// keyed for-each pane over one (eachPlan) needn't fingerprint every item again:
|
|
52
|
+
// an item that no keyed change since its last run touched, and that is the
|
|
53
|
+
// same object it ran with, is reused at once. Any other way of making a list
|
|
54
|
+
// (a plain setter, a run, a restore, a pin) starts no chain, so its readers
|
|
55
|
+
// fingerprint every item as before. Lists are numbered on first sight (held
|
|
56
|
+
// weakly); the log keeps the newest KEYED_LOG_MAX links.
|
|
57
|
+
const KEYED_LOG_MAX = 1024;
|
|
58
|
+
const keyedSeqs = new WeakMap(); // list -> its number
|
|
59
|
+
const keyedLog = new Map(); // number -> { prev: number, items: the items the change touched }
|
|
60
|
+
let keyedNext = 0;
|
|
61
|
+
let keyedHints = true; // off: keyed readers fingerprint every item (setKeyedHints, for measuring)
|
|
62
|
+
function seqOf(list) {
|
|
63
|
+
let seq = keyedSeqs.get(list);
|
|
64
|
+
if (seq === undefined) keyedSeqs.set(list, (seq = ++keyedNext));
|
|
65
|
+
return seq;
|
|
66
|
+
}
|
|
67
|
+
function noteKeyed(before, after, items) {
|
|
68
|
+
const prev = seqOf(before);
|
|
69
|
+
keyedLog.set(seqOf(after), { prev, items });
|
|
70
|
+
while (keyedLog.size > KEYED_LOG_MAX) keyedLog.delete(keyedLog.keys().next().value);
|
|
71
|
+
}
|
|
72
|
+
/** The items keyed changes touched on the way from list number `from` to `list`, or null when `list` didn't come from it that way. */
|
|
73
|
+
function keyedSince(from, list) {
|
|
74
|
+
if (!keyedHints || from === undefined || !Array.isArray(list)) return null;
|
|
75
|
+
const touched = [];
|
|
76
|
+
let seq = keyedSeqs.get(list);
|
|
77
|
+
for (let steps = 0; seq !== from; steps++) {
|
|
78
|
+
const link = seq === undefined ? undefined : keyedLog.get(seq);
|
|
79
|
+
if (!link || steps > KEYED_LOG_MAX) return null;
|
|
80
|
+
touched.push(...link.items);
|
|
81
|
+
seq = link.prev;
|
|
82
|
+
}
|
|
83
|
+
return touched;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The equality cut-off (src/model/rate.js): after a run, a value's
|
|
87
|
+
// fingerprint is compared with the one recorded for the run the page says
|
|
88
|
+
// its readers last saw. JSON-like values (primitives, arrays, plain objects,
|
|
89
|
+
// dates) compare by content: a hash of canonical JSON (sorted keys) and its
|
|
90
|
+
// length. Anything else (functions, modules, class instances, Maps, Blobs, a
|
|
91
|
+
// value too big to walk) compares by identity.
|
|
92
|
+
const FP_BUDGET = 4_000_000; // characters of canonical JSON walked before giving up (identity)
|
|
93
|
+
// canonical(value, budget) and NOT_PLAIN are src/runtime/keys.js's (mallory:keys), shared with item keys.
|
|
94
|
+
/** cyrb53: a fast 53-bit string hash (not cryptographic). */
|
|
95
|
+
function hash53(text) {
|
|
96
|
+
let h1 = 0xdeadbeef;
|
|
97
|
+
let h2 = 0x41c6ce57;
|
|
98
|
+
for (let i = 0; i < text.length; i++) {
|
|
99
|
+
const c = text.charCodeAt(i);
|
|
100
|
+
h1 = Math.imul(h1 ^ c, 2654435761);
|
|
101
|
+
h2 = Math.imul(h2 ^ c, 1597334677);
|
|
102
|
+
}
|
|
103
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
104
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
105
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
106
|
+
}
|
|
107
|
+
// A tensor compares by content too (shape, dtype and bytes), up to this many bytes; a bigger one compares by identity.
|
|
108
|
+
const FP_TENSOR_BYTES = 16 * 1024 * 1024;
|
|
109
|
+
function tensorFingerprint(value) {
|
|
110
|
+
const bytes = new Uint8Array(value.data.buffer, value.data.byteOffset, value.data.byteLength);
|
|
111
|
+
let h1 = 0xdeadbeef;
|
|
112
|
+
let h2 = 0x41c6ce57;
|
|
113
|
+
const mix = (c) => {
|
|
114
|
+
h1 = Math.imul(h1 ^ c, 2654435761);
|
|
115
|
+
h2 = Math.imul(h2 ^ c, 1597334677);
|
|
116
|
+
};
|
|
117
|
+
for (const c of `${value.dtype}[${value.shape}]`) mix(c.charCodeAt(0));
|
|
118
|
+
for (let i = 0; i < bytes.length; i++) mix(bytes[i]);
|
|
119
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
120
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
121
|
+
return { hash: `tensor:${4294967296 * (2097151 & h2) + (h1 >>> 0)}:${bytes.length}` };
|
|
122
|
+
}
|
|
123
|
+
function fingerprintOf(value) {
|
|
124
|
+
try {
|
|
125
|
+
const text = canonical(value, { left: FP_BUDGET });
|
|
126
|
+
return { hash: `${hash53(text)}:${text.length}` };
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error !== NOT_PLAIN) throw error;
|
|
129
|
+
if (tensorLib?.isTensor(value) && value.data.byteLength <= FP_TENSOR_BYTES) return tensorFingerprint(value);
|
|
130
|
+
// Held weakly: the cut-off mustn't keep a big old value alive. (A symbol never compares equal.)
|
|
131
|
+
return typeof value === "object" || typeof value === "function" ? { ref: new WeakRef(value) } : { hash: `${typeof value}:${Math.random()}` };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const sameFingerprint = (a, b) => ("hash" in a ? a.hash === b.hash : "ref" in b && a.ref.deref() !== undefined && a.ref.deref() === b.ref.deref());
|
|
135
|
+
const FP_RUNS = 8; // fingerprints kept per pane (runs newer than its readers' base: superseded ones, until the base moves past them)
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The cut-off's answer for run `runId` of pane `id`: is the value it stored
|
|
139
|
+
* the same as the one run `base` stored (the run whose value the readers last
|
|
140
|
+
* saw)? Records this run's fingerprint either way. Each run's is kept under
|
|
141
|
+
* its run id, so recording one twice (in a run's reply, then a compare)
|
|
142
|
+
* or recording a run that was then superseded doesn't change what a later run
|
|
143
|
+
* is compared with: always the base's. A live run records each value
|
|
144
|
+
* under the same run id, and its base is that run: each value is compared
|
|
145
|
+
* with the one before.
|
|
146
|
+
*/
|
|
147
|
+
function cutoffAnswer(id, runId, base) {
|
|
148
|
+
if (latest.get(id) !== runId) return { superseded: true };
|
|
149
|
+
if (!values.has(id)) {
|
|
150
|
+
fingerprints.delete(id);
|
|
151
|
+
return { unchanged: false };
|
|
152
|
+
}
|
|
153
|
+
const fp = fingerprintOf(values.get(id));
|
|
154
|
+
const runs = fingerprints.get(id) ?? new Map();
|
|
155
|
+
const prev = base == null ? undefined : runs.get(base);
|
|
156
|
+
// Runs older than the base are never a base again (it only moves on to newer runs).
|
|
157
|
+
for (const r of [...runs.keys()]) if (base == null || r < base) runs.delete(r);
|
|
158
|
+
runs.set(runId, fp);
|
|
159
|
+
for (const r of [...runs.keys()]) if (runs.size > FP_RUNS && r !== runId && r !== base) runs.delete(r);
|
|
160
|
+
fingerprints.set(id, runs);
|
|
161
|
+
return { unchanged: Boolean(prev && sameFingerprint(prev, fp)) };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The run log's full value of a pane's run (src/model/runlog.js fullValue):
|
|
166
|
+
* its JSON text when at most `maxBytes` long, `{ tooBig }`, or `{ error }`
|
|
167
|
+
* (it can't be written as JSON). A preview that is plainly too big isn't
|
|
168
|
+
* written out at all (the run log decides the same from the preview).
|
|
169
|
+
*/
|
|
170
|
+
function runValueJSON(id, preview, { maxBytes, maxPreviewEntries } = {}) {
|
|
171
|
+
if (maxBytes && preview?.type === "string" && preview.size > maxBytes) return { tooBig: preview.size + 2 };
|
|
172
|
+
if (maxPreviewEntries && typeof preview?.size === "number" && preview.size > maxPreviewEntries) return { tooBig: true };
|
|
173
|
+
if (!exporter) return { error: "Exporting isn't available in this sandbox." };
|
|
174
|
+
try {
|
|
175
|
+
const { text } = exporter.exportText(values.get(id), "json", { scalars: false });
|
|
176
|
+
return maxBytes && text.length > maxBytes ? { tooBig: text.length } : { text };
|
|
177
|
+
} catch (error) {
|
|
178
|
+
return { error: String(error?.message ?? error) };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** sameValue(a, b) in pane code: are two values equal the way the cut-off compares them (JSON-like ones by content, anything else by identity)? */
|
|
182
|
+
const sameValue = (a, b) => Object.is(a, b) || sameFingerprint(fingerprintOf(a), fingerprintOf(b));
|
|
183
|
+
/** A JSON-like value's content hash (as the cut-off's), or null for anything else (it never compares equal). */
|
|
184
|
+
function contentHash(value) {
|
|
185
|
+
try {
|
|
186
|
+
const text = canonical(value, { left: FP_BUDGET });
|
|
187
|
+
return `${hash53(text)}:${text.length}`;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error !== NOT_PLAIN) throw error;
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|