@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,77 @@
|
|
|
1
|
+
// Cloud model providers (CLW-SET-01, wave R-4): AWS Bedrock, Azure OpenAI and Cloudflare Workers AI. Each is reached over HTTPS
|
|
2
|
+
// through the same OpenAI chat-completions request an `openai` pane makes, so the network policy, the secret() placeholder
|
|
3
|
+
// and the streaming all stay as they are; only the URL and where the key goes differ. Pure, no imports.
|
|
4
|
+
//
|
|
5
|
+
// bedrock https://bedrock-runtime.<region>.amazonaws.com/openai/v1 Authorization: Bearer <Bedrock API key>; model = the model id
|
|
6
|
+
// azure <endpoint>/openai/deployments/<deployment>?api-version=… api-key: <key>; the model is the deployment
|
|
7
|
+
// cloudflare https://api.cloudflare.com/client/v4/accounts/<id>/ai/v1 Authorization: Bearer <API token>; model = e.g. @cf/meta/llama-3.1-8b-instruct
|
|
8
|
+
//
|
|
9
|
+
// The settings are `cloud` ({ region, endpoint, deployment, apiVersion, accountId }); a key is only ever a NAME (keyName). Not
|
|
10
|
+
// supported: AWS SigV4 (access key and secret key pairs): a Bedrock API key (bearer) is what reaches Bedrock from a page.
|
|
11
|
+
|
|
12
|
+
import { CLOUD_PROVIDERS } from "./constants.js";
|
|
13
|
+
export { CLOUD_PROVIDERS };
|
|
14
|
+
|
|
15
|
+
/** The fields each cloud provider takes, for the forms: `[key, label, placeholder]`. */
|
|
16
|
+
export const CLOUD_FIELDS = Object.freeze({
|
|
17
|
+
bedrock: [["region", "region", "us-east-1"]],
|
|
18
|
+
azure: [
|
|
19
|
+
["endpoint", "endpoint", "https://my-resource.openai.azure.com"],
|
|
20
|
+
["deployment", "deployment", "gpt-4o"],
|
|
21
|
+
["apiVersion", "api-version", "2024-10-21"],
|
|
22
|
+
],
|
|
23
|
+
cloudflare: [["accountId", "account id", "32 hex characters"]],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const REGION = /^[a-z]{2,4}(?:-[a-z]+)+-\d{1,2}$/;
|
|
27
|
+
const TOKEN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
28
|
+
const ACCOUNT = /^[0-9a-f]{32}$/i;
|
|
29
|
+
const str = (v) => (typeof v === "string" ? v.trim() : "");
|
|
30
|
+
|
|
31
|
+
/** The cloud settings of `kind`, checked: only its own fields, trimmed. Throws a sentence a person can act on. */
|
|
32
|
+
export function cleanCloud(kind, cloud) {
|
|
33
|
+
const c = cloud && typeof cloud === "object" ? cloud : {};
|
|
34
|
+
if (kind === "bedrock") {
|
|
35
|
+
const region = str(c.region).toLowerCase();
|
|
36
|
+
if (!REGION.test(region)) throw new Error('Bedrock needs a region, like "us-east-1".');
|
|
37
|
+
return { region };
|
|
38
|
+
}
|
|
39
|
+
if (kind === "cloudflare") {
|
|
40
|
+
const accountId = str(c.accountId).toLowerCase();
|
|
41
|
+
if (!ACCOUNT.test(accountId)) throw new Error("Cloudflare Workers AI needs the account id: 32 hexadecimal characters (the dashboard shows it).");
|
|
42
|
+
return { accountId };
|
|
43
|
+
}
|
|
44
|
+
if (kind === "azure") {
|
|
45
|
+
let url;
|
|
46
|
+
try {
|
|
47
|
+
url = new URL(str(c.endpoint));
|
|
48
|
+
} catch {
|
|
49
|
+
throw new Error('Azure OpenAI needs the resource endpoint, like "https://my-resource.openai.azure.com".');
|
|
50
|
+
}
|
|
51
|
+
if (url.protocol !== "https:") throw new Error("The Azure OpenAI endpoint must be https.");
|
|
52
|
+
if (url.username || url.password || url.search || url.hash || (url.pathname !== "/" && url.pathname !== "")) throw new Error("The Azure OpenAI endpoint is the resource's address only (no path, query or login).");
|
|
53
|
+
const deployment = str(c.deployment);
|
|
54
|
+
const apiVersion = str(c.apiVersion);
|
|
55
|
+
if (!TOKEN.test(deployment)) throw new Error("Azure OpenAI needs the deployment name (letters, digits, . _ -).");
|
|
56
|
+
if (!TOKEN.test(apiVersion)) throw new Error('Azure OpenAI needs an api-version, like "2024-10-21".');
|
|
57
|
+
return { endpoint: url.origin, deployment, apiVersion };
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`"${kind}" is not a cloud provider (one of ${CLOUD_PROVIDERS.join(", ")}).`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Where a cloud provider's chat completions go: `{ url, model, authHeader }`. `model` is what the request body names (Azure
|
|
64
|
+
* answers from its deployment, so it sends the deployment). Throws when the settings don't hold up.
|
|
65
|
+
*/
|
|
66
|
+
export function cloudTarget(kind, { model = "", cloud } = {}) {
|
|
67
|
+
const c = cleanCloud(kind, cloud);
|
|
68
|
+
if (kind === "bedrock") {
|
|
69
|
+
if (!TOKEN.test(str(model).replace(/[:/]/g, "-"))) throw new Error('Bedrock needs a model id, like "openai.gpt-oss-120b-1:0".');
|
|
70
|
+
return { url: `https://bedrock-runtime.${c.region}.amazonaws.com/openai/v1/chat/completions`, model: str(model), authHeader: "authorization" };
|
|
71
|
+
}
|
|
72
|
+
if (kind === "cloudflare") {
|
|
73
|
+
if (!str(model)) throw new Error('Cloudflare Workers AI needs a model, like "@cf/meta/llama-3.1-8b-instruct".');
|
|
74
|
+
return { url: `https://api.cloudflare.com/client/v4/accounts/${c.accountId}/ai/v1/chat/completions`, model: str(model), authHeader: "authorization" };
|
|
75
|
+
}
|
|
76
|
+
return { url: `${c.endpoint}/openai/deployments/${encodeURIComponent(c.deployment)}/chat/completions?api-version=${encodeURIComponent(c.apiVersion)}`, model: c.deployment, authHeader: "api-key" };
|
|
77
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Context compaction (CLW-AGT-01): when the conversation sent to the model grows past a limit, the OLDEST tool results the model has already answered are
|
|
2
|
+
// replaced by a one-line note, then (if still over) old long notes of the model's own are shortened. Pure: it returns a new history and never touches the one
|
|
3
|
+
// it was given, so the loop's live history, a fork's replay and a parked run still hold everything.
|
|
4
|
+
//
|
|
5
|
+
// What it will not touch:
|
|
6
|
+
// - the first message (the task) and the last `keepRecent` messages;
|
|
7
|
+
// - a tool message with no assistant message after it: the model has not answered it yet, so it hasn't been seen (the newest results always go whole);
|
|
8
|
+
// - an assistant message whose calls have no tool message after them: calls still waiting on a person's approval or on a tool;
|
|
9
|
+
// - the structure: no message is dropped and every call keeps its id, name and arguments, so a provider's call/result pairing stays valid.
|
|
10
|
+
import { brief } from "../util/text.js";
|
|
11
|
+
|
|
12
|
+
export const COMPACT_DEFAULT_CHARS = 120_000;
|
|
13
|
+
export const COMPACT_KEEP_RECENT = 6;
|
|
14
|
+
const NOTE_CHARS = 400;
|
|
15
|
+
|
|
16
|
+
const textLen = (v) => {
|
|
17
|
+
if (v === undefined || v === null) return 0;
|
|
18
|
+
if (typeof v === "string") return v.length;
|
|
19
|
+
try {
|
|
20
|
+
return JSON.stringify(v)?.length ?? 0;
|
|
21
|
+
} catch {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** How many characters a history weighs, as the model is sent it (text, call arguments, results). */
|
|
27
|
+
export function historyChars(history) {
|
|
28
|
+
let n = 0;
|
|
29
|
+
for (const m of history) {
|
|
30
|
+
n += textLen(m.text);
|
|
31
|
+
for (const c of m.calls ?? []) n += textLen(c.args) + String(c.name ?? "").length;
|
|
32
|
+
for (const r of m.results ?? []) n += textLen(r.value) + textLen(r.error);
|
|
33
|
+
}
|
|
34
|
+
return n;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const note = (what, n) => `[compacted: ${what} of ${n} characters, already used by the model and dropped to save context]`;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @returns {{ history: object[], compacted: number, savedChars: number }} `history` is the same array when nothing needed compacting.
|
|
41
|
+
*/
|
|
42
|
+
export function compactHistory(history, { maxChars = COMPACT_DEFAULT_CHARS, keepRecent = COMPACT_KEEP_RECENT } = {}) {
|
|
43
|
+
const limit = Math.max(1, Math.floor(Number(maxChars) || COMPACT_DEFAULT_CHARS));
|
|
44
|
+
let size = historyChars(history);
|
|
45
|
+
if (size <= limit) return { history, compacted: 0, savedChars: 0 };
|
|
46
|
+
const out = history.slice();
|
|
47
|
+
const lastAnswer = history.findLastIndex((m) => m.role === "assistant");
|
|
48
|
+
const frontier = Math.max(1, history.length - Math.max(0, Math.floor(keepRecent)));
|
|
49
|
+
let compacted = 0;
|
|
50
|
+
const start = size;
|
|
51
|
+
// 1: tool results, oldest first.
|
|
52
|
+
for (let i = 1; i < frontier && size > limit; i++) {
|
|
53
|
+
const m = out[i];
|
|
54
|
+
if (m.role !== "tool" || i > lastAnswer) continue; // not answered yet: not seen
|
|
55
|
+
let changed = false;
|
|
56
|
+
const results = m.results.map((r) => {
|
|
57
|
+
if (r.error !== undefined) {
|
|
58
|
+
const e = String(r.error);
|
|
59
|
+
if (e.length <= NOTE_CHARS) return r;
|
|
60
|
+
changed = true;
|
|
61
|
+
return { ...r, error: `${e.slice(0, NOTE_CHARS)} ${note("an error", e.length)}` };
|
|
62
|
+
}
|
|
63
|
+
const n = textLen(r.value);
|
|
64
|
+
if (n <= NOTE_CHARS) return r;
|
|
65
|
+
changed = true;
|
|
66
|
+
return { ...r, value: `${brief(r.value, 160)} ${note("a result", n)}` };
|
|
67
|
+
});
|
|
68
|
+
if (!changed) continue;
|
|
69
|
+
size -= textLen(m.results) - textLen(results);
|
|
70
|
+
out[i] = { ...m, results };
|
|
71
|
+
compacted++;
|
|
72
|
+
}
|
|
73
|
+
// 2: still over? the model's own long notes in turns long past, oldest first. A message with calls waiting for an answer is left whole.
|
|
74
|
+
for (let i = 1; i < frontier && size > limit; i++) {
|
|
75
|
+
const m = out[i];
|
|
76
|
+
if (m.role !== "assistant" || !m.text || m.text.length <= NOTE_CHARS) continue;
|
|
77
|
+
if ((m.calls ?? []).length && out[i + 1]?.role !== "tool") continue;
|
|
78
|
+
const short = `${m.text.slice(0, NOTE_CHARS)} ${note("a note", m.text.length)}`;
|
|
79
|
+
size -= m.text.length - short.length;
|
|
80
|
+
out[i] = { ...m, text: short };
|
|
81
|
+
compacted++;
|
|
82
|
+
}
|
|
83
|
+
return compacted ? { history: out, compacted, savedChars: Math.max(0, start - size) } : { history, compacted: 0, savedChars: 0 };
|
|
84
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Agent panes (src/panes/agent.js): the names other modules need without
|
|
2
|
+
// loading the agent itself. No imports, so the pane type record (which
|
|
3
|
+
// WebMCP's tools load) can use them without an import cycle.
|
|
4
|
+
|
|
5
|
+
/** Where the model is: Chrome's on-device model, the Claude API, an OpenAI-compatible endpoint, a companion local model (#538), a recorded transcript, or an Aimatey router over those (#539). */
|
|
6
|
+
export const PROVIDERS = ["chrome", "anthropic", "openai", "local", "recorded", "router", "bedrock", "azure", "cloudflare"];
|
|
7
|
+
/** The providers that take the `cloud` settings (src/agent/cloud.js): AWS Bedrock, Azure OpenAI, Cloudflare Workers AI. */
|
|
8
|
+
export const CLOUD_PROVIDERS = ["bedrock", "azure", "cloudflare"];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Claude API as agent panes call it (raw HTTP through the network policy:
|
|
12
|
+
* the key is a secret() placeholder the page fills in for api.anthropic.com
|
|
13
|
+
* only). The default model gets an explicit effort and server-side refusal
|
|
14
|
+
* fallbacks; a model someone names gets neither (older models refuse them).
|
|
15
|
+
*/
|
|
16
|
+
export const ANTHROPIC = {
|
|
17
|
+
url: "https://api.anthropic.com/v1/messages",
|
|
18
|
+
version: "2023-06-01",
|
|
19
|
+
model: "claude-opus-5-5",
|
|
20
|
+
key: "ANTHROPIC_API_KEY",
|
|
21
|
+
effort: "medium",
|
|
22
|
+
maxTokens: 16000,
|
|
23
|
+
fallbackBeta: "server-side-fallback-2026-07-01",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* mallory's own pane tools (src/webmcp/tools.js) an agent pane may be given, by
|
|
28
|
+
* name without the mallory_ prefix. Read-only ones run when the model asks;
|
|
29
|
+
* the ones that change the canvas always wait for the person's approval.
|
|
30
|
+
* Nothing that opens another canvas (the agent's own canvas would close
|
|
31
|
+
* under it), and nothing about network rules, variables or API keys (no
|
|
32
|
+
* such tool exists; test/coverage.test.mjs checks both).
|
|
33
|
+
*/
|
|
34
|
+
export const MALLORY_READ_TOOLS = ["list_panes", "get_pane", "describe_pane_type", "get_canvas", "export_pane", "get_run_history", "get_last_run", "list_tests", "get_wire"];
|
|
35
|
+
export const MALLORY_WRITE_TOOLS = ["add_pane", "update_pane", "connect", "disconnect", "delete_pane", "run_pane", "set_input", "set_state", "duplicate_panes", "group_panes", "ungroup_pane"];
|
|
36
|
+
export const MALLORY_TOOL_NAMES = [...MALLORY_READ_TOOLS, ...MALLORY_WRITE_TOOLS];
|
|
37
|
+
|
|
38
|
+
/** The write tools that remove or overwrite what the person built: a gate policy's `denyDestructive` refuses these (src/gate/policy.js). */
|
|
39
|
+
export const MALLORY_DESTRUCTIVE_TOOLS = ["disconnect", "delete_pane", "set_state", "ungroup_pane"];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Diffing two agent runs (llmtm's diff, in small): where their traces first
|
|
2
|
+
// differ, a table of what each cost and did, and how the final values differ.
|
|
3
|
+
// Works on an agent pane's value ({ text, data?, steps, usage }, the run log
|
|
4
|
+
// keeps it as JSON) so it serves the Runs panel, the agent pane (a fork against
|
|
5
|
+
// its source) and mallory_get_run's `compareWith` alike. Pure.
|
|
6
|
+
import { jsonDiff } from "../model/runlog.js";
|
|
7
|
+
import { brief } from "./loop.js";
|
|
8
|
+
|
|
9
|
+
/** One step as a line (the trace's own words). */
|
|
10
|
+
export function stepLine(s) {
|
|
11
|
+
if (!s) return undefined;
|
|
12
|
+
if (s.type === "model") return s.calls?.length ? `model: calls ${s.calls.join(", ")}${s.text ? ` (${brief(s.text, 60)})` : ""}` : `model: ${brief(s.text, 120)}`;
|
|
13
|
+
if (s.type === "tool") return `${s.name}(${brief(s.args, 80)}) → ${s.error !== undefined ? `error: ${brief(s.error, 120)}` : brief(s.result, 120)}`;
|
|
14
|
+
if (s.type === "output") return s.decision === "amended" ? `output: edited by the person, ${brief(s.proposed, 80)} → ${brief(s.landed, 80)}` : `output: ${s.decision}${s.reason ? ` (${brief(s.reason, 80)})` : ""}`;
|
|
15
|
+
return `${s.type}: ${brief(s.text, 120)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// What makes two steps the same step: its content, not its timing, tokens or whether it was replayed.
|
|
19
|
+
const signature = (s) => (s.type === "output" ? JSON.stringify(["output", s.decision, s.proposed ?? "", s.landed ?? ""]) : s.type === "model" ? JSON.stringify(["model", s.text ?? "", s.calls ?? []]) : s.type === "tool" ? JSON.stringify(["tool", s.name, s.args ?? {}, s.error ?? null, s.error !== undefined ? null : (s.result ?? null)]) : JSON.stringify([s.type, s.text ?? ""]));
|
|
20
|
+
|
|
21
|
+
/** What differs between two steps in the same place. */
|
|
22
|
+
function why(a, b) {
|
|
23
|
+
if (!a) return "this run took a step the other didn't";
|
|
24
|
+
if (!b) return "the other run took a step this one didn't";
|
|
25
|
+
if (a.type !== b.type) return `a ${a.type} step in one run, a ${b.type} step in the other`;
|
|
26
|
+
if (a.type === "model") return JSON.stringify(a.calls ?? []) === JSON.stringify(b.calls ?? []) ? "the model's reply differs" : "the model asked for different tool calls";
|
|
27
|
+
if (a.type === "tool") {
|
|
28
|
+
if (a.name !== b.name || JSON.stringify(a.args ?? {}) !== JSON.stringify(b.args ?? {})) return "a different tool call";
|
|
29
|
+
return "the tool's result differs";
|
|
30
|
+
}
|
|
31
|
+
if (a.type === "output") return "the person's decision on the answer, or their edit of it, differs";
|
|
32
|
+
return `the ${a.type} step differs`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Is a value an agent pane's ({ text, steps, usage }, src/agent/run.js)? */
|
|
36
|
+
export const isAgentValue = (v) => Boolean(v) && typeof v === "object" && Array.isArray(v.steps) && typeof v.text === "string" && typeof v.usage === "object";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Where two step lists first differ (the one place agent runs and tape runs share): `shared` steps match from the start, `diverged` says
|
|
40
|
+
* whether the lists differ at all, `firstDivergent` is `{ step (1-based), why, a, b }` (the steps as `line`s; the shorter list's side is
|
|
41
|
+
* undefined). `signature(step)` is what makes two steps the same, `why(a, b)` says how two steps in the same place differ.
|
|
42
|
+
*/
|
|
43
|
+
export function diffSequences(sa, sb, { signature: sig, why: explain, line }) {
|
|
44
|
+
let shared = 0;
|
|
45
|
+
while (shared < sa.length && shared < sb.length && sig(sa[shared]) === sig(sb[shared])) shared++;
|
|
46
|
+
const diverged = shared < Math.max(sa.length, sb.length);
|
|
47
|
+
return { shared, diverged, firstDivergent: diverged ? { step: shared + 1, why: explain(sa[shared], sb[shared]), a: line(sa[shared]), b: line(sb[shared]) } : undefined };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `[[metric, a, b]]` as table rows `{ metric, a, b, changed }`. */
|
|
51
|
+
export const metricTable = (rows) => rows.map(([metric, a, b]) => ({ metric, a, b, changed: a !== b }));
|
|
52
|
+
|
|
53
|
+
const count = (steps, f) => steps.filter(f).length;
|
|
54
|
+
const sum = (steps, key) => steps.reduce((n, s) => n + (Number(s.tokens?.[key]) || 0), 0);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compare agent values `a` (the earlier or parent run) and `b`:
|
|
58
|
+
* `{ identical, steps: { a, b }, shared, firstDivergent?, table, final }`.
|
|
59
|
+
* `shared` is how many steps match from the start; `firstDivergent` is
|
|
60
|
+
* `{ step (1-based), why, a, b }` (the steps as lines; undefined when one run
|
|
61
|
+
* ended where the other went on, `why` says which). The tool-use check of a
|
|
62
|
+
* Chrome run isn't a step of the conversation and isn't compared. `table` rows
|
|
63
|
+
* are `{ metric, a, b, changed }`. `final`: `{ same: true }`, or the answers as
|
|
64
|
+
* text, or for JSON answers (`data`) their `changes` by path.
|
|
65
|
+
*/
|
|
66
|
+
export function diffAgentRuns(a = {}, b = {}) {
|
|
67
|
+
const sa = (Array.isArray(a.steps) ? a.steps : []).filter((s) => s.type !== "check");
|
|
68
|
+
const sb = (Array.isArray(b.steps) ? b.steps : []).filter((s) => s.type !== "check");
|
|
69
|
+
const { shared, diverged, firstDivergent } = diffSequences(sa, sb, { signature, why, line: stepLine });
|
|
70
|
+
|
|
71
|
+
const usage = (v, steps) => ({
|
|
72
|
+
modelCalls: v.usage?.modelCalls ?? count(steps, (s) => s.type === "model"),
|
|
73
|
+
toolCalls: v.usage?.toolCalls ?? count(steps, (s) => s.type === "tool"),
|
|
74
|
+
inputTokens: v.usage?.inputTokens ?? sum(steps, "input"),
|
|
75
|
+
outputTokens: v.usage?.outputTokens ?? sum(steps, "output"),
|
|
76
|
+
});
|
|
77
|
+
const ua = usage(a, sa);
|
|
78
|
+
const ub = usage(b, sb);
|
|
79
|
+
const rows = [
|
|
80
|
+
["steps", sa.length, sb.length],
|
|
81
|
+
["model calls", ua.modelCalls, ub.modelCalls],
|
|
82
|
+
["tool calls", ua.toolCalls, ub.toolCalls],
|
|
83
|
+
["tool errors", count(sa, (s) => s.type === "tool" && s.error !== undefined), count(sb, (s) => s.type === "tool" && s.error !== undefined)],
|
|
84
|
+
["input tokens", ua.inputTokens, ub.inputTokens],
|
|
85
|
+
["output tokens", ua.outputTokens, ub.outputTokens],
|
|
86
|
+
["answers edited", count(sa, (s) => s.type === "output" && s.decision === "amended"), count(sb, (s) => s.type === "output" && s.decision === "amended")],
|
|
87
|
+
["answer length", String(a.text ?? "").length, String(b.text ?? "").length],
|
|
88
|
+
];
|
|
89
|
+
const table = metricTable(rows);
|
|
90
|
+
|
|
91
|
+
let final;
|
|
92
|
+
if (a.data !== undefined && b.data !== undefined) {
|
|
93
|
+
const changes = jsonDiff(a.data, b.data);
|
|
94
|
+
final = changes.length ? { same: false, changes } : { same: true };
|
|
95
|
+
} else if (a.data !== undefined || b.data !== undefined) {
|
|
96
|
+
final = { same: false, a: brief(a.data !== undefined ? a.data : a.text, 300), b: brief(b.data !== undefined ? b.data : b.text, 300) };
|
|
97
|
+
} else {
|
|
98
|
+
final = String(a.text ?? "") === String(b.text ?? "") ? { same: true } : { same: false, a: brief(a.text ?? "", 300), b: brief(b.text ?? "", 300) };
|
|
99
|
+
}
|
|
100
|
+
return { identical: !diverged && final.same, steps: { a: sa.length, b: sb.length }, shared, ...(firstDivergent ? { firstDivergent } : {}), table, final };
|
|
101
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Forking an agent run (llmtm's fork, in small): take a run's trace up to one
|
|
2
|
+
// step, replay it as recorded (the model's replies and the tools' results are
|
|
3
|
+
// taken as they were, nothing is asked or run again), optionally with that
|
|
4
|
+
// step's tool result or the model's reply edited, and let the run go on live
|
|
5
|
+
// from there. Pure: no DOM, no sandbox (test/agent-fork.test.mjs).
|
|
6
|
+
//
|
|
7
|
+
// A trace step holds what a fork replays next to its brief text, in the live
|
|
8
|
+
// trace only: a model step's `reply` ({ text, calls: [{ id, name, args }],
|
|
9
|
+
// raw? }) and a tool step's `output` ({ value } or { error }); the pane's
|
|
10
|
+
// value and the run log keep the brief text alone (src/agent/run.js).
|
|
11
|
+
import { flatSteps } from "../model/runlog.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Why a trace can't be forked at step index `at`, or "" when it can. Only a
|
|
15
|
+
* model reply or a tool call that finished can be: a check, a warning or a
|
|
16
|
+
* repair isn't part of the conversation, and a trace restored from a saved
|
|
17
|
+
* value has no replies or results to replay.
|
|
18
|
+
*/
|
|
19
|
+
export function forkProblem(steps, at) {
|
|
20
|
+
if (!Array.isArray(steps) || !Number.isInteger(at) || at < 0 || at >= steps.length) return `There is no step ${Number.isInteger(at) ? at + 1 : "?"} in this trace.`;
|
|
21
|
+
if (at < attemptStart(steps)) return "This step belongs to an earlier attempt that was restarted: fork a step of the last attempt.";
|
|
22
|
+
const s = steps[at];
|
|
23
|
+
if (s.type !== "model" && s.type !== "tool") return "Only a model reply or a tool call can be forked from (this step isn't part of the conversation).";
|
|
24
|
+
if (s.type === "model" && !s.reply) return s.status === "error" ? "This model call failed, so there is no reply to continue from." : "The reply wasn't kept (a trace restored from a saved value has only its summary).";
|
|
25
|
+
if (s.type === "tool" && !s.output) return s.status === "error" ? "This tool call never finished, so there is no result to continue from." : "The result wasn't kept (a trace restored from a saved value has only its summary).";
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Where the last attempt begins: a restarted run starts again from nothing, so only the steps after its last `restart` step are one conversation. */
|
|
30
|
+
export function attemptStart(steps) {
|
|
31
|
+
for (let i = steps.length - 1; i >= 0; i--) if (steps[i]?.type === "restart") return i + 1;
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sameJSON = (a, b) => {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The recorded turns that replay steps 0..`at` of `steps`, for runLoop's
|
|
45
|
+
* `fork`: `[{ reply, results, tokens }]`, one per model reply; `results` are
|
|
46
|
+
* the tool results that go with it so far (a fork at a model step has none: its
|
|
47
|
+
* calls run live). `edit` replaces what step `at` held:
|
|
48
|
+
* a tool step: `{ result }` (any JSON) or `{ error }` (text), the tool's result as the model sees it;
|
|
49
|
+
* a model step: `{ text }` and/or `{ calls: [{ name, args }] }`, the reply.
|
|
50
|
+
* Returns `{ turns, edited }` (`edited`: the edit really changed the step);
|
|
51
|
+
* throws an Error saying why when the fork or the edit can't be made.
|
|
52
|
+
*/
|
|
53
|
+
export function forkTurns(steps, at, edit = {}) {
|
|
54
|
+
const problem = forkProblem(steps, at);
|
|
55
|
+
if (problem) throw new Error(problem);
|
|
56
|
+
const target = steps[at];
|
|
57
|
+
const wants = (key) => edit && Object.hasOwn(edit, key) && edit[key] !== undefined;
|
|
58
|
+
if (target.type === "tool" && (wants("text") || wants("calls"))) throw new Error("A tool call's result (or an error) is what a tool step's edit changes, not a reply.");
|
|
59
|
+
if (target.type === "model" && (wants("result") || wants("error"))) throw new Error("A model reply's text and calls are what a model step's edit changes, not a tool call's result.");
|
|
60
|
+
if (wants("result") && wants("error")) throw new Error("Edit the tool call's result or give it an error, not both.");
|
|
61
|
+
const turns = [];
|
|
62
|
+
for (const s of steps.slice(attemptStart(steps), at + 1)) {
|
|
63
|
+
if (s.type === "model") {
|
|
64
|
+
if (!s.reply) throw new Error("A model reply before this step wasn't kept, so the run can't be replayed up to it.");
|
|
65
|
+
turns.push({ reply: { ...s.reply, calls: (s.reply.calls ?? []).map((c) => ({ ...c })) }, results: [], tokens: s.tokens });
|
|
66
|
+
} else if (s.type === "tool") {
|
|
67
|
+
const turn = turns.at(-1);
|
|
68
|
+
if (!turn) throw new Error("A tool call comes before any model reply in this trace.");
|
|
69
|
+
if (!s.output) throw new Error("A tool call before this step never finished, so the run can't be replayed up to it.");
|
|
70
|
+
turn.results.push({ ...s.output });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const turn = turns.at(-1);
|
|
74
|
+
let edited = false;
|
|
75
|
+
if (target.type === "tool") {
|
|
76
|
+
const was = turn.results.at(-1);
|
|
77
|
+
if (wants("error")) {
|
|
78
|
+
const error = String(edit.error);
|
|
79
|
+
edited = was.error !== error;
|
|
80
|
+
turn.results[turn.results.length - 1] = { error };
|
|
81
|
+
} else if (wants("result")) {
|
|
82
|
+
edited = was.error !== undefined || !sameJSON(was.value, edit.result);
|
|
83
|
+
turn.results[turn.results.length - 1] = { value: edit.result };
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
const reply = turn.reply;
|
|
87
|
+
if (wants("text") && String(edit.text) !== reply.text) {
|
|
88
|
+
reply.text = String(edit.text);
|
|
89
|
+
edited = true;
|
|
90
|
+
}
|
|
91
|
+
if (wants("calls")) {
|
|
92
|
+
if (!Array.isArray(edit.calls)) throw new Error("`calls` is a list of { name, args }.");
|
|
93
|
+
const next = edit.calls.map((c, i) => {
|
|
94
|
+
if (!c || typeof c.name !== "string" || !c.name.trim()) throw new Error(`Call ${i + 1} needs a tool name.`);
|
|
95
|
+
if (c.args !== undefined && (typeof c.args !== "object" || c.args === null || Array.isArray(c.args))) throw new Error(`Call ${i + 1}'s arguments must be an object.`);
|
|
96
|
+
return { name: c.name.trim(), args: c.args ?? {} };
|
|
97
|
+
});
|
|
98
|
+
const was = reply.calls.map(({ name, args }) => ({ name, args }));
|
|
99
|
+
if (!sameJSON(was, next)) {
|
|
100
|
+
reply.calls = next.map((c, i) => ({ id: `fork-${i + 1}`, ...c }));
|
|
101
|
+
edited = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (edited) delete reply.raw; // the provider's own copy of the reply (thinking blocks and all) no longer says what it says
|
|
105
|
+
}
|
|
106
|
+
return { turns, edited };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Does a provider keep its own session, so a recorded conversation can't be put into it? (Chrome's: only the first turn takes earlier turns.) */
|
|
110
|
+
export const cannotReplayInto = (kind) => (kind === "chrome" ? "Chrome's on-device session keeps its own conversation and takes earlier tool results only as they happen, so a run can't be forked onto it: pick the Claude API, an OpenAI-compatible endpoint or recorded replies." : "");
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The forks in a run log as a tree: `[{ run, step, children, orphan? }]`, the
|
|
114
|
+
* roots first. A node is one agent pane's run (a step of a canvas run); a fork
|
|
115
|
+
* hangs under the run it was made from (`step.fork.of` is that run's id, in the
|
|
116
|
+
* same pane). Only runs that are part of a fork are listed: the first run a
|
|
117
|
+
* fork came from, and every fork. A fork whose source left the log is a root
|
|
118
|
+
* with `orphan` set.
|
|
119
|
+
*/
|
|
120
|
+
export function forkTree(runs) {
|
|
121
|
+
const nodes = new Map(); // "pane|runId" -> node
|
|
122
|
+
for (const run of runs ?? []) {
|
|
123
|
+
for (const step of flatSteps(run.steps)) {
|
|
124
|
+
if (step.depth || step.status === "superseded" || step.status === "cancelled") continue;
|
|
125
|
+
nodes.set(`${step.pane}|${step.runId}`, { run, step, children: [] });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const roots = [];
|
|
129
|
+
const inFamily = new Set();
|
|
130
|
+
for (const node of nodes.values()) {
|
|
131
|
+
const fork = node.step.fork;
|
|
132
|
+
if (!fork) continue;
|
|
133
|
+
inFamily.add(node);
|
|
134
|
+
const parent = nodes.get(`${node.step.pane}|${fork.of}`);
|
|
135
|
+
if (parent) {
|
|
136
|
+
parent.children.push(node);
|
|
137
|
+
inFamily.add(parent);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const node of inFamily) {
|
|
141
|
+
const parent = node.step.fork ? nodes.get(`${node.step.pane}|${node.step.fork.of}`) : undefined;
|
|
142
|
+
if (!parent) roots.push(node.step.fork ? Object.assign(node, { orphan: true }) : node);
|
|
143
|
+
}
|
|
144
|
+
const order = (list) => list.sort((a, b) => a.step.start - b.step.start).forEach((n) => order(n.children));
|
|
145
|
+
order(roots);
|
|
146
|
+
return roots;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** "step 3 (edited)" for a fork's source. */
|
|
150
|
+
export const forkWords = (fork) => `step ${fork.at + 1}${fork.edited ? " edited" : ""}`;
|
|
151
|
+
|
|
152
|
+
/** The run in `runs` that agent pane `pane`'s run-log step `step` was forked from (its `fork.of` run id), or undefined (not a fork, or that run left the log). */
|
|
153
|
+
export const forkSource = (runs, pane, step) => (step?.fork ? (runs ?? []).find((r) => flatSteps(r.steps).some((s) => s.pane === pane && s.runId === step.fork.of)) : undefined);
|
|
154
|
+
|
|
155
|
+
/** The last step of a live trace that can be forked from (its index), or -1: what "Fork this agent's run…" opens on. */
|
|
156
|
+
export function lastForkable(steps) {
|
|
157
|
+
for (let i = (steps?.length ?? 0) - 1; i >= 0; i--) if (!forkProblem(steps, i)) return i;
|
|
158
|
+
return -1;
|
|
159
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Composer mode (#545): "tools as input, not agent output". A person runs an
|
|
2
|
+
// MCP server's tools (or reads a resource, gets a prompt) by hand in the MCP
|
|
3
|
+
// server pane's forms, and picks answers to attach to an agent pane's next
|
|
4
|
+
// message (the agent pane's `attach`). That run's user turn carries them as
|
|
5
|
+
// grounding, after the message, and they are used up: the run that sent them
|
|
6
|
+
// clears `attach` (a change that reruns nothing). The run's value says what it
|
|
7
|
+
// was grounded with (`grounding`), and its trace shows the whole message.
|
|
8
|
+
//
|
|
9
|
+
// The person attaches, never the model: no WebMCP tool sets `attach`
|
|
10
|
+
// (it isn't one of the agent pane's agent fields) and the MCP calls were the
|
|
11
|
+
// person's own, through the gate. Pure.
|
|
12
|
+
|
|
13
|
+
/** At most this many answers wait on one agent pane, and this much of each answer's text goes into the message. */
|
|
14
|
+
export const ATTACH_LIMITS = Object.freeze({ items: 8, chars: 6000 });
|
|
15
|
+
|
|
16
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
17
|
+
const str = (v, max) => (typeof v === "string" ? v.slice(0, max) : "");
|
|
18
|
+
|
|
19
|
+
/** One attached answer, cleaned: `{ server, kind, name, args, value, at }` (kind: tool, resource or prompt), or null. */
|
|
20
|
+
export function attachEntry(e) {
|
|
21
|
+
if (!isObject(e) || typeof e.name !== "string" || !e.name || e.error !== undefined) return null;
|
|
22
|
+
const kind = ["tool", "resource", "prompt"].includes(e.kind) ? e.kind : "tool";
|
|
23
|
+
return { server: str(e.server, 200), kind, name: e.name.slice(0, 500), args: isObject(e.args) ? e.args : {}, value: e.value === undefined ? null : e.value, at: Number.isFinite(e.at) ? e.at : 0 };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A pane's `attach`, cleaned (entries that aren't answers dropped, the newest ATTACH_LIMITS.items kept). */
|
|
27
|
+
export const cleanAttach = (list) => (Array.isArray(list) ? list.map(attachEntry).filter(Boolean).slice(-ATTACH_LIMITS.items) : []);
|
|
28
|
+
|
|
29
|
+
/** How an attached answer is named: `notes.search_notes({"query":"oslo"})`, `notes: demo://readme`. */
|
|
30
|
+
export function attachLabel(e) {
|
|
31
|
+
const where = e.server ? `${e.server}${e.kind === "resource" ? ": " : "."}` : "";
|
|
32
|
+
const args = e.kind === "resource" || !Object.keys(e.args ?? {}).length ? "" : `(${JSON.stringify(e.args)})`;
|
|
33
|
+
return `${where}${e.name}${args}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const textOf = (value) => {
|
|
37
|
+
if (typeof value === "string") return value;
|
|
38
|
+
try {
|
|
39
|
+
return JSON.stringify(value, null, 2) ?? "null";
|
|
40
|
+
} catch {
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** The user turn with its grounding after it: each attached answer, labelled, its text cut at ATTACH_LIMITS.chars. */
|
|
46
|
+
export function groundedMessage(text, attach) {
|
|
47
|
+
const items = cleanAttach(attach);
|
|
48
|
+
if (!items.length) return String(text ?? "");
|
|
49
|
+
const blocks = items.map((e, i) => {
|
|
50
|
+
const body = textOf(e.value);
|
|
51
|
+
return `[${i + 1}] ${attachLabel(e)}\n${body.length > ATTACH_LIMITS.chars ? `${body.slice(0, ATTACH_LIMITS.chars - 1)}…` : body}`;
|
|
52
|
+
});
|
|
53
|
+
return `${String(text ?? "")}\n\n---\nGrounding: answers of MCP tools the person ran by hand, attached to this message:\n\n${blocks.join("\n\n")}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What a run's value says it was grounded with: `[{ server, kind, name, args }]`. */
|
|
57
|
+
export const groundingSummary = (attach) => cleanAttach(attach).map(({ server, kind, name, args }) => ({ server, kind, name, args }));
|
|
58
|
+
|
|
59
|
+
/** The agent panes `canvas`'s MCP server panes can attach to: on it and the canvases around it, by name. */
|
|
60
|
+
export function agentTargets(canvas) {
|
|
61
|
+
const out = [];
|
|
62
|
+
for (let c = canvas; c; c = c.parent) for (const id of c.attached ?? []) if (c.panes.get(id)?.type === "agent") out.push({ canvas: c, id, name: c.panes.get(id).name || id });
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Attach `entry` (a form's answer, with `server`) to agent pane `id` of `canvas`: an undoable step. Returns false when it isn't an answer. */
|
|
67
|
+
export function attachTo(canvas, id, entry) {
|
|
68
|
+
const e = attachEntry(entry);
|
|
69
|
+
const pane = canvas.panes.get(id);
|
|
70
|
+
if (!e || pane?.type !== "agent") return false;
|
|
71
|
+
canvas.updateStep(id, { attach: [...cleanAttach(pane.attach), e].slice(-ATTACH_LIMITS.items) }, `attaching ${attachLabel(e)} to ${pane.name || id}'s next message`);
|
|
72
|
+
return true;
|
|
73
|
+
}
|