@mostra/protocol 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/LICENSE +202 -0
- package/README.md +38 -2
- package/dist/actions.d.ts +273 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +154 -0
- package/dist/actions.js.map +1 -0
- package/dist/artifact.d.ts +113 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +79 -0
- package/dist/artifact.js.map +1 -0
- package/dist/bridge.d.ts +295 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +343 -0
- package/dist/bridge.js.map +1 -0
- package/dist/browser.d.ts +195 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +156 -0
- package/dist/browser.js.map +1 -0
- package/dist/bundle.d.ts +155 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +130 -0
- package/dist/bundle.js.map +1 -0
- package/dist/canonical.d.ts +23 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +45 -0
- package/dist/canonical.js.map +1 -0
- package/dist/capability.d.ts +38 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +61 -0
- package/dist/capability.js.map +1 -0
- package/dist/diagnostics/codes/a11y.d.ts +8 -0
- package/dist/diagnostics/codes/a11y.d.ts.map +1 -0
- package/dist/diagnostics/codes/a11y.js +30 -0
- package/dist/diagnostics/codes/a11y.js.map +1 -0
- package/dist/diagnostics/codes/action.d.ts +8 -0
- package/dist/diagnostics/codes/action.d.ts.map +1 -0
- package/dist/diagnostics/codes/action.js +110 -0
- package/dist/diagnostics/codes/action.js.map +1 -0
- package/dist/diagnostics/codes/artifact.d.ts +8 -0
- package/dist/diagnostics/codes/artifact.d.ts.map +1 -0
- package/dist/diagnostics/codes/artifact.js +121 -0
- package/dist/diagnostics/codes/artifact.js.map +1 -0
- package/dist/diagnostics/codes/build.d.ts +8 -0
- package/dist/diagnostics/codes/build.d.ts.map +1 -0
- package/dist/diagnostics/codes/build.js +55 -0
- package/dist/diagnostics/codes/build.js.map +1 -0
- package/dist/diagnostics/codes/cli.d.ts +8 -0
- package/dist/diagnostics/codes/cli.d.ts.map +1 -0
- package/dist/diagnostics/codes/cli.js +44 -0
- package/dist/diagnostics/codes/cli.js.map +1 -0
- package/dist/diagnostics/codes/console.d.ts +8 -0
- package/dist/diagnostics/codes/console.d.ts.map +1 -0
- package/dist/diagnostics/codes/console.js +30 -0
- package/dist/diagnostics/codes/console.js.map +1 -0
- package/dist/diagnostics/codes/dep.d.ts +8 -0
- package/dist/diagnostics/codes/dep.d.ts.map +1 -0
- package/dist/diagnostics/codes/dep.js +88 -0
- package/dist/diagnostics/codes/dep.js.map +1 -0
- package/dist/diagnostics/codes/env.d.ts +8 -0
- package/dist/diagnostics/codes/env.d.ts.map +1 -0
- package/dist/diagnostics/codes/env.js +132 -0
- package/dist/diagnostics/codes/env.js.map +1 -0
- package/dist/diagnostics/codes/field.d.ts +8 -0
- package/dist/diagnostics/codes/field.d.ts.map +1 -0
- package/dist/diagnostics/codes/field.js +99 -0
- package/dist/diagnostics/codes/field.js.map +1 -0
- package/dist/diagnostics/codes/home.d.ts +8 -0
- package/dist/diagnostics/codes/home.d.ts.map +1 -0
- package/dist/diagnostics/codes/home.js +132 -0
- package/dist/diagnostics/codes/home.js.map +1 -0
- package/dist/diagnostics/codes/host.d.ts +8 -0
- package/dist/diagnostics/codes/host.d.ts.map +1 -0
- package/dist/diagnostics/codes/host.js +176 -0
- package/dist/diagnostics/codes/host.js.map +1 -0
- package/dist/diagnostics/codes/hygiene.d.ts +8 -0
- package/dist/diagnostics/codes/hygiene.d.ts.map +1 -0
- package/dist/diagnostics/codes/hygiene.js +154 -0
- package/dist/diagnostics/codes/hygiene.js.map +1 -0
- package/dist/diagnostics/codes/index.d.ts +51 -0
- package/dist/diagnostics/codes/index.d.ts.map +1 -0
- package/dist/diagnostics/codes/index.js +72 -0
- package/dist/diagnostics/codes/index.js.map +1 -0
- package/dist/diagnostics/codes/live.d.ts +8 -0
- package/dist/diagnostics/codes/live.d.ts.map +1 -0
- package/dist/diagnostics/codes/live.js +30 -0
- package/dist/diagnostics/codes/live.js.map +1 -0
- package/dist/diagnostics/codes/manifest.d.ts +8 -0
- package/dist/diagnostics/codes/manifest.d.ts.map +1 -0
- package/dist/diagnostics/codes/manifest.js +44 -0
- package/dist/diagnostics/codes/manifest.js.map +1 -0
- package/dist/diagnostics/codes/network.d.ts +8 -0
- package/dist/diagnostics/codes/network.d.ts.map +1 -0
- package/dist/diagnostics/codes/network.js +30 -0
- package/dist/diagnostics/codes/network.js.map +1 -0
- package/dist/diagnostics/codes/platform.d.ts +8 -0
- package/dist/diagnostics/codes/platform.d.ts.map +1 -0
- package/dist/diagnostics/codes/platform.js +18 -0
- package/dist/diagnostics/codes/platform.js.map +1 -0
- package/dist/diagnostics/codes/publish.d.ts +8 -0
- package/dist/diagnostics/codes/publish.d.ts.map +1 -0
- package/dist/diagnostics/codes/publish.js +44 -0
- package/dist/diagnostics/codes/publish.js.map +1 -0
- package/dist/diagnostics/codes/regression.d.ts +8 -0
- package/dist/diagnostics/codes/regression.d.ts.map +1 -0
- package/dist/diagnostics/codes/regression.js +77 -0
- package/dist/diagnostics/codes/regression.js.map +1 -0
- package/dist/diagnostics/codes/runtime.d.ts +8 -0
- package/dist/diagnostics/codes/runtime.d.ts.map +1 -0
- package/dist/diagnostics/codes/runtime.js +66 -0
- package/dist/diagnostics/codes/runtime.js.map +1 -0
- package/dist/diagnostics/codes/secret.d.ts +8 -0
- package/dist/diagnostics/codes/secret.d.ts.map +1 -0
- package/dist/diagnostics/codes/secret.js +18 -0
- package/dist/diagnostics/codes/secret.js.map +1 -0
- package/dist/diagnostics/codes/smoke.d.ts +8 -0
- package/dist/diagnostics/codes/smoke.d.ts.map +1 -0
- package/dist/diagnostics/codes/smoke.js +30 -0
- package/dist/diagnostics/codes/smoke.js.map +1 -0
- package/dist/diagnostics/codes/submit.d.ts +8 -0
- package/dist/diagnostics/codes/submit.d.ts.map +1 -0
- package/dist/diagnostics/codes/submit.js +99 -0
- package/dist/diagnostics/codes/submit.js.map +1 -0
- package/dist/diagnostics/codes/target.d.ts +8 -0
- package/dist/diagnostics/codes/target.d.ts.map +1 -0
- package/dist/diagnostics/codes/target.js +18 -0
- package/dist/diagnostics/codes/target.js.map +1 -0
- package/dist/diagnostics/codes/type.d.ts +8 -0
- package/dist/diagnostics/codes/type.d.ts.map +1 -0
- package/dist/diagnostics/codes/type.js +30 -0
- package/dist/diagnostics/codes/type.js.map +1 -0
- package/dist/diagnostics/codes/verify.d.ts +8 -0
- package/dist/diagnostics/codes/verify.d.ts.map +1 -0
- package/dist/diagnostics/codes/verify.js +99 -0
- package/dist/diagnostics/codes/verify.js.map +1 -0
- package/dist/diagnostics/diagnostic.d.ts +79 -0
- package/dist/diagnostics/diagnostic.d.ts.map +1 -0
- package/dist/diagnostics/diagnostic.js +131 -0
- package/dist/diagnostics/diagnostic.js.map +1 -0
- package/dist/diagnostics/spec.d.ts +49 -0
- package/dist/diagnostics/spec.d.ts.map +1 -0
- package/dist/diagnostics/spec.js +31 -0
- package/dist/diagnostics/spec.js.map +1 -0
- package/dist/hygiene.d.ts +66 -0
- package/dist/hygiene.d.ts.map +1 -0
- package/dist/hygiene.js +134 -0
- package/dist/hygiene.js.map +1 -0
- package/dist/ids.d.ts +119 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +135 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +86 -0
- package/dist/interaction.d.ts +391 -0
- package/dist/interaction.d.ts.map +1 -0
- package/dist/interaction.js +306 -0
- package/dist/interaction.js.map +1 -0
- package/dist/manifest.d.ts +97 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +101 -0
- package/dist/manifest.js.map +1 -0
- package/dist/method.d.ts +26 -0
- package/dist/method.d.ts.map +1 -0
- package/dist/method.js +10 -0
- package/dist/method.js.map +1 -0
- package/dist/methods/artifact/create.d.ts +29 -0
- package/dist/methods/artifact/create.d.ts.map +1 -0
- package/dist/methods/artifact/create.js +31 -0
- package/dist/methods/artifact/create.js.map +1 -0
- package/dist/methods/artifact/get.d.ts +17 -0
- package/dist/methods/artifact/get.d.ts.map +1 -0
- package/dist/methods/artifact/get.js +21 -0
- package/dist/methods/artifact/get.js.map +1 -0
- package/dist/methods/artifact/list.d.ts +22 -0
- package/dist/methods/artifact/list.d.ts.map +1 -0
- package/dist/methods/artifact/list.js +19 -0
- package/dist/methods/artifact/list.js.map +1 -0
- package/dist/methods/artifact/publish.d.ts +28 -0
- package/dist/methods/artifact/publish.d.ts.map +1 -0
- package/dist/methods/artifact/publish.js +28 -0
- package/dist/methods/artifact/publish.js.map +1 -0
- package/dist/methods/artifact/verify.d.ts +29 -0
- package/dist/methods/artifact/verify.d.ts.map +1 -0
- package/dist/methods/artifact/verify.js +27 -0
- package/dist/methods/artifact/verify.js.map +1 -0
- package/dist/methods/deps/add.d.ts +43 -0
- package/dist/methods/deps/add.d.ts.map +1 -0
- package/dist/methods/deps/add.js +40 -0
- package/dist/methods/deps/add.js.map +1 -0
- package/dist/methods/dev/start.d.ts +52 -0
- package/dist/methods/dev/start.d.ts.map +1 -0
- package/dist/methods/dev/start.js +56 -0
- package/dist/methods/dev/start.js.map +1 -0
- package/dist/methods/dev/stop.d.ts +16 -0
- package/dist/methods/dev/stop.d.ts.map +1 -0
- package/dist/methods/dev/stop.js +21 -0
- package/dist/methods/dev/stop.js.map +1 -0
- package/dist/methods/events/ack.d.ts +20 -0
- package/dist/methods/events/ack.d.ts.map +1 -0
- package/dist/methods/events/ack.js +26 -0
- package/dist/methods/events/ack.js.map +1 -0
- package/dist/methods/events/read.d.ts +40 -0
- package/dist/methods/events/read.d.ts.map +1 -0
- package/dist/methods/events/read.js +35 -0
- package/dist/methods/events/read.js.map +1 -0
- package/dist/methods/events/subscribe.d.ts +54 -0
- package/dist/methods/events/subscribe.d.ts.map +1 -0
- package/dist/methods/events/subscribe.js +44 -0
- package/dist/methods/events/subscribe.js.map +1 -0
- package/dist/methods/events/unsubscribe.d.ts +16 -0
- package/dist/methods/events/unsubscribe.d.ts.map +1 -0
- package/dist/methods/events/unsubscribe.js +21 -0
- package/dist/methods/events/unsubscribe.js.map +1 -0
- package/dist/methods/gc/run.d.ts +76 -0
- package/dist/methods/gc/run.d.ts.map +1 -0
- package/dist/methods/gc/run.js +56 -0
- package/dist/methods/gc/run.js.map +1 -0
- package/dist/methods/index.d.ts +6 -0
- package/dist/methods/index.d.ts.map +1 -0
- package/dist/methods/index.js +78 -0
- package/dist/methods/index.js.map +1 -0
- package/dist/methods/instance/check.d.ts +30 -0
- package/dist/methods/instance/check.d.ts.map +1 -0
- package/dist/methods/instance/check.js +34 -0
- package/dist/methods/instance/check.js.map +1 -0
- package/dist/methods/instance/status.d.ts +102 -0
- package/dist/methods/instance/status.d.ts.map +1 -0
- package/dist/methods/instance/status.js +83 -0
- package/dist/methods/instance/status.js.map +1 -0
- package/dist/methods/live/push.d.ts +28 -0
- package/dist/methods/live/push.d.ts.map +1 -0
- package/dist/methods/live/push.js +35 -0
- package/dist/methods/live/push.js.map +1 -0
- package/dist/methods/mostra/initialize.d.ts +143 -0
- package/dist/methods/mostra/initialize.d.ts.map +1 -0
- package/dist/methods/mostra/initialize.js +97 -0
- package/dist/methods/mostra/initialize.js.map +1 -0
- package/dist/methods/mostra/shutdown.d.ts +14 -0
- package/dist/methods/mostra/shutdown.d.ts.map +1 -0
- package/dist/methods/mostra/shutdown.js +22 -0
- package/dist/methods/mostra/shutdown.js.map +1 -0
- package/dist/methods/port/drafts-mirror.d.ts +30 -0
- package/dist/methods/port/drafts-mirror.d.ts.map +1 -0
- package/dist/methods/port/drafts-mirror.js +33 -0
- package/dist/methods/port/drafts-mirror.js.map +1 -0
- package/dist/methods/port/secrets-get.d.ts +19 -0
- package/dist/methods/port/secrets-get.d.ts.map +1 -0
- package/dist/methods/port/secrets-get.js +31 -0
- package/dist/methods/port/secrets-get.js.map +1 -0
- package/dist/methods/port/submissions-deliver.d.ts +38 -0
- package/dist/methods/port/submissions-deliver.d.ts.map +1 -0
- package/dist/methods/port/submissions-deliver.js +38 -0
- package/dist/methods/port/submissions-deliver.js.map +1 -0
- package/dist/methods/port/trusted-controls-activated.d.ts +27 -0
- package/dist/methods/port/trusted-controls-activated.d.ts.map +1 -0
- package/dist/methods/port/trusted-controls-activated.js +33 -0
- package/dist/methods/port/trusted-controls-activated.js.map +1 -0
- package/dist/methods/port/trusted-controls-policy.d.ts +21 -0
- package/dist/methods/port/trusted-controls-policy.d.ts.map +1 -0
- package/dist/methods/port/trusted-controls-policy.js +27 -0
- package/dist/methods/port/trusted-controls-policy.js.map +1 -0
- package/dist/methods/results/get.d.ts +32 -0
- package/dist/methods/results/get.d.ts.map +1 -0
- package/dist/methods/results/get.js +36 -0
- package/dist/methods/results/get.js.map +1 -0
- package/dist/methods/secret/delete.d.ts +22 -0
- package/dist/methods/secret/delete.d.ts.map +1 -0
- package/dist/methods/secret/delete.js +32 -0
- package/dist/methods/secret/delete.js.map +1 -0
- package/dist/methods/secret/list.d.ts +21 -0
- package/dist/methods/secret/list.d.ts.map +1 -0
- package/dist/methods/secret/list.js +29 -0
- package/dist/methods/secret/list.js.map +1 -0
- package/dist/methods/secret/set.d.ts +37 -0
- package/dist/methods/secret/set.d.ts.map +1 -0
- package/dist/methods/secret/set.js +41 -0
- package/dist/methods/secret/set.js.map +1 -0
- package/dist/methods/state/get.d.ts +25 -0
- package/dist/methods/state/get.d.ts.map +1 -0
- package/dist/methods/state/get.js +29 -0
- package/dist/methods/state/get.js.map +1 -0
- package/dist/methods/state/patch.d.ts +32 -0
- package/dist/methods/state/patch.d.ts.map +1 -0
- package/dist/methods/state/patch.js +29 -0
- package/dist/methods/state/patch.js.map +1 -0
- package/dist/methods/view/default.d.ts +19 -0
- package/dist/methods/view/default.d.ts.map +1 -0
- package/dist/methods/view/default.js +23 -0
- package/dist/methods/view/default.js.map +1 -0
- package/dist/methods/view/launch.d.ts +27 -0
- package/dist/methods/view/launch.d.ts.map +1 -0
- package/dist/methods/view/launch.js +30 -0
- package/dist/methods/view/launch.js.map +1 -0
- package/dist/methods/view/revoke.d.ts +19 -0
- package/dist/methods/view/revoke.d.ts.map +1 -0
- package/dist/methods/view/revoke.js +26 -0
- package/dist/methods/view/revoke.js.map +1 -0
- package/dist/methods/view/rotate.d.ts +21 -0
- package/dist/methods/view/rotate.d.ts.map +1 -0
- package/dist/methods/view/rotate.js +27 -0
- package/dist/methods/view/rotate.js.map +1 -0
- package/dist/methods/view/url.d.ts +52 -0
- package/dist/methods/view/url.d.ts.map +1 -0
- package/dist/methods/view/url.js +43 -0
- package/dist/methods/view/url.js.map +1 -0
- package/dist/methods/wait/wait.d.ts +37 -0
- package/dist/methods/wait/wait.d.ts.map +1 -0
- package/dist/methods/wait/wait.js +39 -0
- package/dist/methods/wait/wait.js.map +1 -0
- package/dist/revision.d.ts +43 -0
- package/dist/revision.d.ts.map +1 -0
- package/dist/revision.js +69 -0
- package/dist/revision.js.map +1 -0
- package/dist/rpc/error.d.ts +47 -0
- package/dist/rpc/error.d.ts.map +1 -0
- package/dist/rpc/error.js +77 -0
- package/dist/rpc/error.js.map +1 -0
- package/dist/rpc/lines.d.ts +30 -0
- package/dist/rpc/lines.d.ts.map +1 -0
- package/dist/rpc/lines.js +63 -0
- package/dist/rpc/lines.js.map +1 -0
- package/dist/rpc/messages.d.ts +92 -0
- package/dist/rpc/messages.d.ts.map +1 -0
- package/dist/rpc/messages.js +133 -0
- package/dist/rpc/messages.js.map +1 -0
- package/dist/rpc/peer.d.ts +81 -0
- package/dist/rpc/peer.d.ts.map +1 -0
- package/dist/rpc/peer.js +208 -0
- package/dist/rpc/peer.js.map +1 -0
- package/dist/serializer.d.ts +178 -0
- package/dist/serializer.d.ts.map +1 -0
- package/dist/serializer.js +929 -0
- package/dist/serializer.js.map +1 -0
- package/dist/verify.d.ts +254 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +243 -0
- package/dist/verify.js.map +1 -0
- package/dist/view.d.ts +103 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +110 -0
- package/dist/view.js.map +1 -0
- package/dist/wire-registry.js +11 -0
- package/dist/wire-registry.js.map +1 -0
- package/dist/worker.d.ts +249 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +158 -0
- package/dist/worker.js.map +1 -0
- package/package.json +114 -3
- package/schemas/protocol.draft-07.json +5120 -0
- package/schemas/protocol.schema.json +4964 -0
- package/src/actions.ts +418 -0
- package/src/artifact.ts +187 -0
- package/src/bridge.ts +618 -0
- package/src/browser.ts +374 -0
- package/src/bundle.ts +264 -0
- package/src/canonical.ts +49 -0
- package/src/capability.ts +92 -0
- package/src/diagnostics/codes/a11y.ts +41 -0
- package/src/diagnostics/codes/action.ts +125 -0
- package/src/diagnostics/codes/artifact.ts +137 -0
- package/src/diagnostics/codes/build.ts +65 -0
- package/src/diagnostics/codes/cli.ts +53 -0
- package/src/diagnostics/codes/console.ts +41 -0
- package/src/diagnostics/codes/dep.ts +101 -0
- package/src/diagnostics/codes/env.ts +149 -0
- package/src/diagnostics/codes/field.ts +113 -0
- package/src/diagnostics/codes/home.ts +150 -0
- package/src/diagnostics/codes/host.ts +197 -0
- package/src/diagnostics/codes/hygiene.ts +175 -0
- package/src/diagnostics/codes/index.ts +142 -0
- package/src/diagnostics/codes/live.ts +41 -0
- package/src/diagnostics/codes/manifest.ts +53 -0
- package/src/diagnostics/codes/network.ts +41 -0
- package/src/diagnostics/codes/platform.ts +30 -0
- package/src/diagnostics/codes/publish.ts +53 -0
- package/src/diagnostics/codes/regression.ts +89 -0
- package/src/diagnostics/codes/runtime.ts +77 -0
- package/src/diagnostics/codes/secret.ts +29 -0
- package/src/diagnostics/codes/smoke.ts +41 -0
- package/src/diagnostics/codes/submit.ts +113 -0
- package/src/diagnostics/codes/target.ts +29 -0
- package/src/diagnostics/codes/type.ts +41 -0
- package/src/diagnostics/codes/verify.ts +113 -0
- package/src/diagnostics/diagnostic.ts +240 -0
- package/src/diagnostics/spec.ts +90 -0
- package/src/hygiene.ts +224 -0
- package/src/ids.ts +279 -0
- package/src/index.ts +576 -0
- package/src/interaction.ts +728 -0
- package/src/manifest.ts +206 -0
- package/src/method.ts +42 -0
- package/src/methods/artifact/create.ts +56 -0
- package/src/methods/artifact/get.ts +30 -0
- package/src/methods/artifact/list.ts +42 -0
- package/src/methods/artifact/publish.ts +46 -0
- package/src/methods/artifact/verify.ts +46 -0
- package/src/methods/deps/add.ts +72 -0
- package/src/methods/dev/start.ts +84 -0
- package/src/methods/dev/stop.ts +32 -0
- package/src/methods/events/ack.ts +41 -0
- package/src/methods/events/read.ts +67 -0
- package/src/methods/events/subscribe.ts +91 -0
- package/src/methods/events/unsubscribe.ts +35 -0
- package/src/methods/gc/run.ts +125 -0
- package/src/methods/index.ts +81 -0
- package/src/methods/instance/check.ts +61 -0
- package/src/methods/instance/status.ts +172 -0
- package/src/methods/live/push.ts +54 -0
- package/src/methods/mostra/initialize.ts +249 -0
- package/src/methods/mostra/shutdown.ts +31 -0
- package/src/methods/port/drafts-mirror.ts +52 -0
- package/src/methods/port/secrets-get.ts +40 -0
- package/src/methods/port/submissions-deliver.ts +70 -0
- package/src/methods/port/trusted-controls-activated.ts +51 -0
- package/src/methods/port/trusted-controls-policy.ts +38 -0
- package/src/methods/results/get.ts +59 -0
- package/src/methods/secret/delete.ts +43 -0
- package/src/methods/secret/list.ts +40 -0
- package/src/methods/secret/set.ts +69 -0
- package/src/methods/state/get.ts +44 -0
- package/src/methods/state/patch.ts +51 -0
- package/src/methods/view/default.ts +32 -0
- package/src/methods/view/launch.ts +47 -0
- package/src/methods/view/revoke.ts +39 -0
- package/src/methods/view/rotate.ts +37 -0
- package/src/methods/view/url.ts +84 -0
- package/src/methods/wait/wait.ts +58 -0
- package/src/revision.ts +101 -0
- package/src/rpc/error.ts +107 -0
- package/src/rpc/lines.ts +70 -0
- package/src/rpc/messages.ts +188 -0
- package/src/rpc/peer.ts +341 -0
- package/src/serializer.ts +1217 -0
- package/src/timers.d.ts +8 -0
- package/src/verify.ts +458 -0
- package/src/view.ts +200 -0
- package/src/web-crypto.d.ts +9 -0
- package/src/web-platform.d.ts +35 -0
- package/src/wire-registry.ts +14 -0
- package/src/worker.ts +374 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Diagnostic } from "./diagnostics/diagnostic.js";
|
|
2
|
+
import { CreateDiagnosticOptions } from "./diagnostics/codes/index.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/revision.d.ts
|
|
5
|
+
/** A protocol revision: a calendar date in `YYYY-MM-DD` form. */
|
|
6
|
+
export type Revision = string & {
|
|
7
|
+
readonly __mostraRevision: true;
|
|
8
|
+
};
|
|
9
|
+
/** Protocol revisions. */
|
|
10
|
+
export declare const Revision: {
|
|
11
|
+
/** The textual form. `is` and `parse` also reject impossible dates such as `2026-02-30`. */
|
|
12
|
+
readonly pattern: RegExp;
|
|
13
|
+
readonly schema: z.ZodType<Revision, string>;
|
|
14
|
+
is(value: unknown): value is Revision;
|
|
15
|
+
/** @throws TypeError when `value` is not a real calendar date in `YYYY-MM-DD` form. */
|
|
16
|
+
parse(value: string): Revision;
|
|
17
|
+
/** Orders revisions by date: negative when `a` is older than `b`. */
|
|
18
|
+
compare(a: Revision, b: Revision): number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The host protocol revisions this package's schemas describe, newest first. A runtime built on
|
|
22
|
+
* this package supports exactly these.
|
|
23
|
+
*/
|
|
24
|
+
export declare const HOST_PROTOCOL_REVISIONS: readonly Revision[];
|
|
25
|
+
/** The outcome of {@link negotiateRevision}. */
|
|
26
|
+
export type RevisionNegotiation = {
|
|
27
|
+
readonly ok: true;
|
|
28
|
+
readonly revision: Revision;
|
|
29
|
+
} | {
|
|
30
|
+
readonly ok: false;
|
|
31
|
+
readonly diagnostic: Diagnostic;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Picks the newest host protocol revision that both sides support. When there is none, returns
|
|
35
|
+
* the refusal diagnostic `MOSTRA_HOST_REVISION_UNSUPPORTED`, which the instance sends back as the
|
|
36
|
+
* error of `mostra/initialize`.
|
|
37
|
+
*
|
|
38
|
+
* Offered entries that are not revisions never match, and the message lists only well-formed
|
|
39
|
+
* ones, so a malformed offer can't inject text into the diagnostic.
|
|
40
|
+
*/
|
|
41
|
+
export declare function negotiateRevision(offered: readonly string[], supported?: readonly Revision[], options?: CreateDiagnosticOptions): RevisionNegotiation;
|
|
42
|
+
//#endregion
|
|
43
|
+
//# sourceMappingURL=revision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revision.d.ts","names":[],"sources":["../src/revision.ts"],"mappings":";;;;;YAaY;WAA+B;;;qBAW9B;;WAEF,SAAS;WACT,QAAQ,EAAE,QAAQ;EAC3B,GAAG,iBAAiB,SAAS;;EAE7B,MAAM,gBAAgB;;EAEtB,QAAQ,GAAG,UAAU,GAAG;;;;;;qBAuBb,kCAAkC;;YAGnC;WACG;WAAmB,UAAU;;WAC7B;WAAoB,YAAY;;;;;;;;;;wBAiB/B,kBACd,4BACA,qBAAoB,YACpB,UAAS,0BACR"}
|
package/dist/revision.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { wireRegistry } from "./wire-registry.js";
|
|
2
|
+
import { createDiagnostic } from "./diagnostics/codes/index.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/revision.ts
|
|
5
|
+
/**
|
|
6
|
+
* Dated protocol revisions and their negotiation (INTERFACES §1, STANDARDS versioning, D59).
|
|
7
|
+
*
|
|
8
|
+
* The host protocol and the browser protocol each carry a revision named by a date
|
|
9
|
+
* (`2026-10-10`). A revision only changes additively. A breaking change needs a new revision, and
|
|
10
|
+
* the old one stays supported for at least 12 months.
|
|
11
|
+
*/
|
|
12
|
+
const PATTERN = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
13
|
+
function isRevision(value) {
|
|
14
|
+
if (typeof value !== "string" || !PATTERN.test(value)) return false;
|
|
15
|
+
const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
16
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(value);
|
|
17
|
+
}
|
|
18
|
+
/** Protocol revisions. */
|
|
19
|
+
const Revision = {
|
|
20
|
+
pattern: PATTERN,
|
|
21
|
+
schema: z.iso.date().register(wireRegistry, {
|
|
22
|
+
id: "Revision",
|
|
23
|
+
description: "Protocol revision: a calendar date in YYYY-MM-DD form."
|
|
24
|
+
}),
|
|
25
|
+
is: isRevision,
|
|
26
|
+
parse(value) {
|
|
27
|
+
if (isRevision(value)) return value;
|
|
28
|
+
throw new TypeError("Expected a protocol revision: a calendar date in YYYY-MM-DD form.");
|
|
29
|
+
},
|
|
30
|
+
compare(a, b) {
|
|
31
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The host protocol revisions this package's schemas describe, newest first. A runtime built on
|
|
36
|
+
* this package supports exactly these.
|
|
37
|
+
*/
|
|
38
|
+
const HOST_PROTOCOL_REVISIONS = [Revision.parse("2026-10-10")];
|
|
39
|
+
const LISTED = 8;
|
|
40
|
+
function list(revisions) {
|
|
41
|
+
const shown = revisions.slice(0, LISTED).join(", ");
|
|
42
|
+
return revisions.length > LISTED ? `${shown} and ${revisions.length - LISTED} more` : shown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Picks the newest host protocol revision that both sides support. When there is none, returns
|
|
46
|
+
* the refusal diagnostic `MOSTRA_HOST_REVISION_UNSUPPORTED`, which the instance sends back as the
|
|
47
|
+
* error of `mostra/initialize`.
|
|
48
|
+
*
|
|
49
|
+
* Offered entries that are not revisions never match, and the message lists only well-formed
|
|
50
|
+
* ones, so a malformed offer can't inject text into the diagnostic.
|
|
51
|
+
*/
|
|
52
|
+
function negotiateRevision(offered, supported = HOST_PROTOCOL_REVISIONS, options = {}) {
|
|
53
|
+
const offeredRevisions = [...new Set(offered.filter(isRevision))].sort(Revision.compare);
|
|
54
|
+
const newest = offeredRevisions.filter((revision) => supported.includes(revision)).at(-1);
|
|
55
|
+
if (newest !== void 0) return {
|
|
56
|
+
ok: true,
|
|
57
|
+
revision: newest
|
|
58
|
+
};
|
|
59
|
+
const supportedList = [...supported].sort(Revision.compare).reverse();
|
|
60
|
+
const offeredText = offeredRevisions.length > 0 ? `The client offered host protocol revisions ${list(offeredRevisions.reverse())}` : "The client offered no valid host protocol revision";
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
diagnostic: createDiagnostic("MOSTRA_HOST_REVISION_UNSUPPORTED", { message: `${offeredText}; this instance supports ${list(supportedList)}.` }, options)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { HOST_PROTOCOL_REVISIONS, Revision, negotiateRevision };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=revision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revision.js","names":[],"sources":["../src/revision.ts"],"sourcesContent":["/**\n * Dated protocol revisions and their negotiation (INTERFACES §1, STANDARDS versioning, D59).\n *\n * The host protocol and the browser protocol each carry a revision named by a date\n * (`2026-10-10`). A revision only changes additively. A breaking change needs a new revision, and\n * the old one stays supported for at least 12 months.\n */\nimport * as z from \"zod\";\nimport { type CreateDiagnosticOptions, createDiagnostic } from \"./diagnostics/codes/index.ts\";\nimport type { Diagnostic } from \"./diagnostics/diagnostic.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** A protocol revision: a calendar date in `YYYY-MM-DD` form. */\nexport type Revision = string & { readonly __mostraRevision: true };\n\nconst PATTERN = /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/;\n\nfunction isRevision(value: unknown): value is Revision {\n if (typeof value !== \"string\" || !PATTERN.test(value)) return false;\n const date = new Date(`${value}T00:00:00Z`);\n return !Number.isNaN(date.getTime()) && date.toISOString().startsWith(value);\n}\n\n/** Protocol revisions. */\nexport const Revision: {\n /** The textual form. `is` and `parse` also reject impossible dates such as `2026-02-30`. */\n readonly pattern: RegExp;\n readonly schema: z.ZodType<Revision, string>;\n is(value: unknown): value is Revision;\n /** @throws TypeError when `value` is not a real calendar date in `YYYY-MM-DD` form. */\n parse(value: string): Revision;\n /** Orders revisions by date: negative when `a` is older than `b`. */\n compare(a: Revision, b: Revision): number;\n} = {\n pattern: PATTERN,\n // z.iso.date() checks calendar validity in its emitted pattern, so the published JSON Schema\n // rejects 2026-02-30 just as `parse` does.\n schema: z.iso.date().register(wireRegistry, {\n id: \"Revision\",\n description: \"Protocol revision: a calendar date in YYYY-MM-DD form.\",\n }) as unknown as z.ZodType<Revision, string>,\n is: isRevision,\n parse(value: string): Revision {\n if (isRevision(value)) return value;\n throw new TypeError(\"Expected a protocol revision: a calendar date in YYYY-MM-DD form.\");\n },\n compare(a: Revision, b: Revision): number {\n return a < b ? -1 : a > b ? 1 : 0;\n },\n};\n\n/**\n * The host protocol revisions this package's schemas describe, newest first. A runtime built on\n * this package supports exactly these.\n */\nexport const HOST_PROTOCOL_REVISIONS: readonly Revision[] = [Revision.parse(\"2026-10-10\")];\n\n/** The outcome of {@link negotiateRevision}. */\nexport type RevisionNegotiation =\n | { readonly ok: true; readonly revision: Revision }\n | { readonly ok: false; readonly diagnostic: Diagnostic };\n\nconst LISTED = 8;\n\nfunction list(revisions: readonly string[]): string {\n const shown = revisions.slice(0, LISTED).join(\", \");\n return revisions.length > LISTED ? `${shown} and ${revisions.length - LISTED} more` : shown;\n}\n\n/**\n * Picks the newest host protocol revision that both sides support. When there is none, returns\n * the refusal diagnostic `MOSTRA_HOST_REVISION_UNSUPPORTED`, which the instance sends back as the\n * error of `mostra/initialize`.\n *\n * Offered entries that are not revisions never match, and the message lists only well-formed\n * ones, so a malformed offer can't inject text into the diagnostic.\n */\nexport function negotiateRevision(\n offered: readonly string[],\n supported: readonly Revision[] = HOST_PROTOCOL_REVISIONS,\n options: CreateDiagnosticOptions = {},\n): RevisionNegotiation {\n const offeredRevisions = [...new Set(offered.filter(isRevision))].sort(Revision.compare);\n const common = offeredRevisions.filter((revision) => supported.includes(revision));\n const newest = common.at(-1);\n if (newest !== undefined) return { ok: true, revision: newest };\n\n const supportedList = [...supported].sort(Revision.compare).reverse();\n const offeredText =\n offeredRevisions.length > 0\n ? `The client offered host protocol revisions ${list(offeredRevisions.reverse())}`\n : \"The client offered no valid host protocol revision\";\n return {\n ok: false,\n diagnostic: createDiagnostic(\n \"MOSTRA_HOST_REVISION_UNSUPPORTED\",\n { message: `${offeredText}; this instance supports ${list(supportedList)}.` },\n options,\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,UAAU;AAEhB,SAAS,WAAW,OAAmC;CACrD,IAAI,OAAO,UAAU,YAAY,CAAC,QAAQ,KAAK,KAAK,GAAG,OAAO;CAC9D,MAAM,uBAAO,IAAI,KAAK,GAAG,MAAM,WAAW;CAC1C,OAAO,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,WAAW,KAAK;AAC7E;;AAGA,MAAa,WAST;CACF,SAAS;CAGT,QAAQ,EAAE,IAAI,KAAK,CAAC,CAAC,SAAS,cAAc;EAC1C,IAAI;EACJ,aAAa;CACf,CAAC;CACD,IAAI;CACJ,MAAM,OAAyB;EAC7B,IAAI,WAAW,KAAK,GAAG,OAAO;EAC9B,MAAM,IAAI,UAAU,mEAAmE;CACzF;CACA,QAAQ,GAAa,GAAqB;EACxC,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;CAClC;AACF;;;;;AAMA,MAAa,0BAA+C,CAAC,SAAS,MAAM,YAAY,CAAC;AAOzF,MAAM,SAAS;AAEf,SAAS,KAAK,WAAsC;CAClD,MAAM,QAAQ,UAAU,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,IAAI;CAClD,OAAO,UAAU,SAAS,SAAS,GAAG,MAAM,OAAO,UAAU,SAAS,OAAO,SAAS;AACxF;;;;;;;;;AAUA,SAAgB,kBACd,SACA,YAAiC,yBACjC,UAAmC,CAAC,GACf;CACrB,MAAM,mBAAmB,CAAC,GAAG,IAAI,IAAI,QAAQ,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,OAAO;CAEvF,MAAM,SADS,iBAAiB,QAAQ,aAAa,UAAU,SAAS,QAAQ,CAC5D,CAAC,CAAC,GAAG,EAAE;CAC3B,IAAI,WAAW,KAAA,GAAW,OAAO;EAAE,IAAI;EAAM,UAAU;CAAO;CAE9D,MAAM,gBAAgB,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,SAAS,OAAO,CAAC,CAAC,QAAQ;CACpE,MAAM,cACJ,iBAAiB,SAAS,IACtB,8CAA8C,KAAK,iBAAiB,QAAQ,CAAC,MAC7E;CACN,OAAO;EACL,IAAI;EACJ,YAAY,iBACV,oCACA,EAAE,SAAS,GAAG,YAAY,2BAA2B,KAAK,aAAa,EAAE,GAAG,GAC5E,OACF;CACF;AACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Diagnostic } from "../diagnostics/diagnostic.js";
|
|
2
|
+
import "../diagnostics/spec.js";
|
|
3
|
+
import "../diagnostics/codes/host.js";
|
|
4
|
+
import { JsonRpcErrorObject } from "./messages.js";
|
|
5
|
+
//#region src/rpc/error.d.ts
|
|
6
|
+
/** The JSON-RPC 2.0 error codes Mostra uses (INTERFACES §6). */
|
|
7
|
+
export declare const JSON_RPC_ERROR_CODES: {
|
|
8
|
+
/** The line wasn't valid JSON. */
|
|
9
|
+
readonly parseError: -32700;
|
|
10
|
+
/** The message wasn't a valid request, or was a batch. */
|
|
11
|
+
readonly invalidRequest: -32600;
|
|
12
|
+
/** The method doesn't exist on this side. */
|
|
13
|
+
readonly methodNotFound: -32601;
|
|
14
|
+
/** The params failed the method's schema. */
|
|
15
|
+
readonly invalidParams: -32602;
|
|
16
|
+
/** An unexpected failure. */
|
|
17
|
+
readonly internalError: -32603;
|
|
18
|
+
/** Every other diagnostic. */
|
|
19
|
+
readonly diagnostic: -32000;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* An error that crosses a connection as a JSON-RPC error. Throw it from a request handler to
|
|
23
|
+
* answer with this diagnostic; a request's promise rejects with it when the other side answers
|
|
24
|
+
* with an error, the connection closes or the request times out.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* throw new RpcError(
|
|
28
|
+
* createDiagnostic("MOSTRA_HOME_MISMATCH", { message: "This instance serves /a, not /b." }),
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class RpcError extends Error {
|
|
33
|
+
/** The JSON-RPC error code. */
|
|
34
|
+
readonly code: number;
|
|
35
|
+
/** The diagnostic: what happened and what to do. */
|
|
36
|
+
readonly diagnostic: Diagnostic;
|
|
37
|
+
constructor(diagnostic: Diagnostic, code?: number);
|
|
38
|
+
/** The JSON-RPC error object for a response. */
|
|
39
|
+
toErrorObject(): JsonRpcErrorObject;
|
|
40
|
+
/**
|
|
41
|
+
* Reads a received error object. When its `data` isn't a diagnostic (a peer that isn't Mostra),
|
|
42
|
+
* the result is a `MOSTRA_HOST_MALFORMED` diagnostic that keeps the peer's message.
|
|
43
|
+
*/
|
|
44
|
+
static fromErrorObject(error: JsonRpcErrorObject, docsBase?: string): RpcError;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","names":[],"sources":["../../src/rpc/error.ts"],"mappings":";;;;;;qBAUa;;WAEF;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;;;;;;;qBAoCE,iBAAiB;;WAEnB;;WAEA,YAAY;EAErB,YAAY,YAAY,YAAY;;EAQpC,iBAAiB;;;;;SAQV,gBAAgB,OAAO,oBAAoB,oBAAoB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { hostDiagnostics } from "../diagnostics/codes/host.js";
|
|
2
|
+
import { Diagnostic } from "../diagnostics/diagnostic.js";
|
|
3
|
+
import { buildDiagnostic } from "../diagnostics/spec.js";
|
|
4
|
+
//#region src/rpc/error.ts
|
|
5
|
+
/**
|
|
6
|
+
* Errors on a JSON-RPC connection. Every error carries a diagnostic (INTERFACES §1, §6): the
|
|
7
|
+
* JSON-RPC `error.code` says which kind of failure it is, and `error.data` is the diagnostic.
|
|
8
|
+
*/
|
|
9
|
+
/** The JSON-RPC 2.0 error codes Mostra uses (INTERFACES §6). */
|
|
10
|
+
const JSON_RPC_ERROR_CODES = {
|
|
11
|
+
parseError: -32700,
|
|
12
|
+
invalidRequest: -32600,
|
|
13
|
+
methodNotFound: -32601,
|
|
14
|
+
invalidParams: -32602,
|
|
15
|
+
internalError: -32603,
|
|
16
|
+
diagnostic: -32e3
|
|
17
|
+
};
|
|
18
|
+
function codeFor(diagnostic) {
|
|
19
|
+
switch (diagnostic.code) {
|
|
20
|
+
case "MOSTRA_HOST_MALFORMED": return JSON_RPC_ERROR_CODES.invalidRequest;
|
|
21
|
+
case "MOSTRA_HOST_METHOD_UNKNOWN": return JSON_RPC_ERROR_CODES.methodNotFound;
|
|
22
|
+
case "MOSTRA_HOST_INVALID_PARAMS": return JSON_RPC_ERROR_CODES.invalidParams;
|
|
23
|
+
case "MOSTRA_HOST_INTERNAL_ERROR": return JSON_RPC_ERROR_CODES.internalError;
|
|
24
|
+
default: return JSON_RPC_ERROR_CODES.diagnostic;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* An error that crosses a connection as a JSON-RPC error. Throw it from a request handler to
|
|
29
|
+
* answer with this diagnostic; a request's promise rejects with it when the other side answers
|
|
30
|
+
* with an error, the connection closes or the request times out.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* throw new RpcError(
|
|
34
|
+
* createDiagnostic("MOSTRA_HOME_MISMATCH", { message: "This instance serves /a, not /b." }),
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
var RpcError = class RpcError extends Error {
|
|
39
|
+
/** The JSON-RPC error code. */
|
|
40
|
+
code;
|
|
41
|
+
/** The diagnostic: what happened and what to do. */
|
|
42
|
+
diagnostic;
|
|
43
|
+
constructor(diagnostic, code = codeFor(diagnostic)) {
|
|
44
|
+
super(diagnostic.message);
|
|
45
|
+
this.name = "RpcError";
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.diagnostic = diagnostic;
|
|
48
|
+
}
|
|
49
|
+
/** The JSON-RPC error object for a response. */
|
|
50
|
+
toErrorObject() {
|
|
51
|
+
return {
|
|
52
|
+
code: this.code,
|
|
53
|
+
message: this.diagnostic.message,
|
|
54
|
+
data: this.diagnostic
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reads a received error object. When its `data` isn't a diagnostic (a peer that isn't Mostra),
|
|
59
|
+
* the result is a `MOSTRA_HOST_MALFORMED` diagnostic that keeps the peer's message.
|
|
60
|
+
*/
|
|
61
|
+
static fromErrorObject(error, docsBase) {
|
|
62
|
+
const parsed = Diagnostic.safeParse(error.data);
|
|
63
|
+
if (parsed.success) return new RpcError(parsed.data, error.code);
|
|
64
|
+
return new RpcError(hostDiagnostic("MOSTRA_HOST_MALFORMED", { message: `The other side answered with error ${error.code} without a diagnostic: ${error.message.slice(0, 200)}` }, docsBase), error.code);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Builds a HOST-area diagnostic from that area's catalog alone, so the JSON-RPC core doesn't pull
|
|
69
|
+
* every area's text into browser bundles (D83).
|
|
70
|
+
*/
|
|
71
|
+
function hostDiagnostic(code, details, docsBase) {
|
|
72
|
+
return buildDiagnostic(code, hostDiagnostics[code], details, docsBase);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { JSON_RPC_ERROR_CODES, RpcError, hostDiagnostic };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../src/rpc/error.ts"],"sourcesContent":["/**\n * Errors on a JSON-RPC connection. Every error carries a diagnostic (INTERFACES §1, §6): the\n * JSON-RPC `error.code` says which kind of failure it is, and `error.data` is the diagnostic.\n */\nimport { type HostDiagnosticCode, hostDiagnostics } from \"../diagnostics/codes/host.ts\";\nimport { Diagnostic } from \"../diagnostics/diagnostic.ts\";\nimport { buildDiagnostic, type DiagnosticDetails } from \"../diagnostics/spec.ts\";\nimport type { JsonRpcErrorObject } from \"./messages.ts\";\n\n/** The JSON-RPC 2.0 error codes Mostra uses (INTERFACES §6). */\nexport const JSON_RPC_ERROR_CODES: {\n /** The line wasn't valid JSON. */\n readonly parseError: -32700;\n /** The message wasn't a valid request, or was a batch. */\n readonly invalidRequest: -32600;\n /** The method doesn't exist on this side. */\n readonly methodNotFound: -32601;\n /** The params failed the method's schema. */\n readonly invalidParams: -32602;\n /** An unexpected failure. */\n readonly internalError: -32603;\n /** Every other diagnostic. */\n readonly diagnostic: -32000;\n} = {\n parseError: -32700,\n invalidRequest: -32600,\n methodNotFound: -32601,\n invalidParams: -32602,\n internalError: -32603,\n diagnostic: -32000,\n};\n\nfunction codeFor(diagnostic: Diagnostic): number {\n switch (diagnostic.code) {\n case \"MOSTRA_HOST_MALFORMED\":\n return JSON_RPC_ERROR_CODES.invalidRequest;\n case \"MOSTRA_HOST_METHOD_UNKNOWN\":\n return JSON_RPC_ERROR_CODES.methodNotFound;\n case \"MOSTRA_HOST_INVALID_PARAMS\":\n return JSON_RPC_ERROR_CODES.invalidParams;\n case \"MOSTRA_HOST_INTERNAL_ERROR\":\n return JSON_RPC_ERROR_CODES.internalError;\n default:\n return JSON_RPC_ERROR_CODES.diagnostic;\n }\n}\n\n/**\n * An error that crosses a connection as a JSON-RPC error. Throw it from a request handler to\n * answer with this diagnostic; a request's promise rejects with it when the other side answers\n * with an error, the connection closes or the request times out.\n *\n * ```ts\n * throw new RpcError(\n * createDiagnostic(\"MOSTRA_HOME_MISMATCH\", { message: \"This instance serves /a, not /b.\" }),\n * );\n * ```\n */\nexport class RpcError extends Error {\n /** The JSON-RPC error code. */\n readonly code: number;\n /** The diagnostic: what happened and what to do. */\n readonly diagnostic: Diagnostic;\n\n constructor(diagnostic: Diagnostic, code: number = codeFor(diagnostic)) {\n super(diagnostic.message);\n this.name = \"RpcError\";\n this.code = code;\n this.diagnostic = diagnostic;\n }\n\n /** The JSON-RPC error object for a response. */\n toErrorObject(): JsonRpcErrorObject {\n return { code: this.code, message: this.diagnostic.message, data: this.diagnostic };\n }\n\n /**\n * Reads a received error object. When its `data` isn't a diagnostic (a peer that isn't Mostra),\n * the result is a `MOSTRA_HOST_MALFORMED` diagnostic that keeps the peer's message.\n */\n static fromErrorObject(error: JsonRpcErrorObject, docsBase?: string): RpcError {\n const parsed = Diagnostic.safeParse(error.data);\n if (parsed.success) return new RpcError(parsed.data, error.code);\n return new RpcError(\n hostDiagnostic(\n \"MOSTRA_HOST_MALFORMED\",\n {\n message: `The other side answered with error ${error.code} without a diagnostic: ${error.message.slice(0, 200)}`,\n },\n docsBase,\n ),\n error.code,\n );\n }\n}\n\n/**\n * Builds a HOST-area diagnostic from that area's catalog alone, so the JSON-RPC core doesn't pull\n * every area's text into browser bundles (D83).\n */\nexport function hostDiagnostic(\n code: HostDiagnosticCode,\n details: DiagnosticDetails,\n docsBase?: string,\n): Diagnostic {\n return buildDiagnostic(code, hostDiagnostics[code], details, docsBase);\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,uBAaT;CACF,YAAY;CACZ,gBAAgB;CAChB,gBAAgB;CAChB,eAAe;CACf,eAAe;CACf,YAAY;AACd;AAEA,SAAS,QAAQ,YAAgC;CAC/C,QAAQ,WAAW,MAAnB;EACE,KAAK,yBACH,OAAO,qBAAqB;EAC9B,KAAK,8BACH,OAAO,qBAAqB;EAC9B,KAAK,8BACH,OAAO,qBAAqB;EAC9B,KAAK,8BACH,OAAO,qBAAqB;EAC9B,SACE,OAAO,qBAAqB;CAChC;AACF;;;;;;;;;;;;AAaA,IAAa,WAAb,MAAa,iBAAiB,MAAM;;CAElC;;CAEA;CAEA,YAAY,YAAwB,OAAe,QAAQ,UAAU,GAAG;EACtE,MAAM,WAAW,OAAO;EACxB,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;;CAGA,gBAAoC;EAClC,OAAO;GAAE,MAAM,KAAK;GAAM,SAAS,KAAK,WAAW;GAAS,MAAM,KAAK;EAAW;CACpF;;;;;CAMA,OAAO,gBAAgB,OAA2B,UAA6B;EAC7E,MAAM,SAAS,WAAW,UAAU,MAAM,IAAI;EAC9C,IAAI,OAAO,SAAS,OAAO,IAAI,SAAS,OAAO,MAAM,MAAM,IAAI;EAC/D,OAAO,IAAI,SACT,eACE,yBACA,EACE,SAAS,sCAAsC,MAAM,KAAK,yBAAyB,MAAM,QAAQ,MAAM,GAAG,GAAG,IAC/G,GACA,QACF,GACA,MAAM,IACR;CACF;AACF;;;;;AAMA,SAAgB,eACd,MACA,SACA,UACY;CACZ,OAAO,gBAAgB,MAAM,gBAAgB,OAAO,SAAS,QAAQ;AACvE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { JsonRpcMessage } from "./messages.js";
|
|
2
|
+
//#region src/rpc/lines.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The longest line, in UTF-16 code units, either side of a newline-delimited connection accepts:
|
|
5
|
+
* 64 Mi. Writers check it too, so a message that couldn't be read is never sent.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_LINE_LENGTH: number;
|
|
8
|
+
/** Serializes one message as a line, newline included. */
|
|
9
|
+
export declare function encodeLine(message: JsonRpcMessage): string;
|
|
10
|
+
/**
|
|
11
|
+
* Splits decoded text into lines. Feed it chunks as they arrive; it returns the complete lines
|
|
12
|
+
* and keeps the unfinished rest. A line longer than `maxLineLength` characters throws a
|
|
13
|
+
* `RangeError`, so a peer can't make the other side buffer without bound: the transport then
|
|
14
|
+
* answers with `MOSTRA_HOST_MALFORMED` and closes the connection.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LineSplitter {
|
|
17
|
+
#private;
|
|
18
|
+
/** @param maxLineLength - The longest line accepted, in UTF-16 code units. Default 64 Mi. */
|
|
19
|
+
constructor(maxLineLength?: number);
|
|
20
|
+
/**
|
|
21
|
+
* Returns the lines completed by `chunk`, without their newlines (and without a trailing `\r`).
|
|
22
|
+
* Only `chunk` is searched for newlines, so a long line costs time in proportion to its length,
|
|
23
|
+
* however many chunks bring it.
|
|
24
|
+
*/
|
|
25
|
+
push(chunk: string): string[];
|
|
26
|
+
/** The unfinished text after the last newline. A stream that ends with it holds a cut-off message. */
|
|
27
|
+
get rest(): string;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//# sourceMappingURL=lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.d.ts","names":[],"sources":["../../src/rpc/lines.ts"],"mappings":";;;;;;qBAUa;;wBAGG,WAAW,SAAS;;;;;;;qBAUvB;;;EAOX,YAAY;;;;;;EASZ,KAAK;;MAqBD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/rpc/lines.ts
|
|
2
|
+
/**
|
|
3
|
+
* The longest line, in UTF-16 code units, either side of a newline-delimited connection accepts:
|
|
4
|
+
* 64 Mi. Writers check it too, so a message that couldn't be read is never sent.
|
|
5
|
+
*/
|
|
6
|
+
const MAX_LINE_LENGTH = 67108864;
|
|
7
|
+
/** Serializes one message as a line, newline included. */
|
|
8
|
+
function encodeLine(message) {
|
|
9
|
+
return `${JSON.stringify(message)}\n`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Splits decoded text into lines. Feed it chunks as they arrive; it returns the complete lines
|
|
13
|
+
* and keeps the unfinished rest. A line longer than `maxLineLength` characters throws a
|
|
14
|
+
* `RangeError`, so a peer can't make the other side buffer without bound: the transport then
|
|
15
|
+
* answers with `MOSTRA_HOST_MALFORMED` and closes the connection.
|
|
16
|
+
*/
|
|
17
|
+
var LineSplitter = class {
|
|
18
|
+
#maxLineLength;
|
|
19
|
+
/** The unfinished line, in the pieces it arrived in: joined only once its newline comes. */
|
|
20
|
+
#pending = [];
|
|
21
|
+
#pendingLength = 0;
|
|
22
|
+
/** @param maxLineLength - The longest line accepted, in UTF-16 code units. Default 64 Mi. */
|
|
23
|
+
constructor(maxLineLength = MAX_LINE_LENGTH) {
|
|
24
|
+
this.#maxLineLength = maxLineLength;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the lines completed by `chunk`, without their newlines (and without a trailing `\r`).
|
|
28
|
+
* Only `chunk` is searched for newlines, so a long line costs time in proportion to its length,
|
|
29
|
+
* however many chunks bring it.
|
|
30
|
+
*/
|
|
31
|
+
push(chunk) {
|
|
32
|
+
const lines = [];
|
|
33
|
+
let start = 0;
|
|
34
|
+
for (let index = chunk.indexOf("\n"); index >= 0; index = chunk.indexOf("\n", start)) {
|
|
35
|
+
if (this.#pendingLength + index - start > this.#maxLineLength) this.#overflow();
|
|
36
|
+
this.#pending.push(chunk.slice(start, index));
|
|
37
|
+
const line = this.#pending.join("");
|
|
38
|
+
this.#pending = [];
|
|
39
|
+
this.#pendingLength = 0;
|
|
40
|
+
lines.push(line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
41
|
+
start = index + 1;
|
|
42
|
+
}
|
|
43
|
+
if (start < chunk.length) {
|
|
44
|
+
this.#pendingLength += chunk.length - start;
|
|
45
|
+
if (this.#pendingLength > this.#maxLineLength) this.#overflow();
|
|
46
|
+
this.#pending.push(chunk.slice(start));
|
|
47
|
+
}
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
/** The unfinished text after the last newline. A stream that ends with it holds a cut-off message. */
|
|
51
|
+
get rest() {
|
|
52
|
+
return this.#pending.join("");
|
|
53
|
+
}
|
|
54
|
+
#overflow() {
|
|
55
|
+
this.#pending = [];
|
|
56
|
+
this.#pendingLength = 0;
|
|
57
|
+
throw new RangeError(`A message is longer than ${this.#maxLineLength} characters.`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { LineSplitter, MAX_LINE_LENGTH, encodeLine };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.js","names":[],"sources":["../../src/rpc/lines.ts"],"sourcesContent":["/**\n * Newline-delimited JSON framing for byte streams (stdio, Unix sockets): one message per line.\n * JSON text never contains a raw newline, so a newline always ends a message.\n */\nimport type { JsonRpcMessage } from \"./messages.ts\";\n\n/**\n * The longest line, in UTF-16 code units, either side of a newline-delimited connection accepts:\n * 64 Mi. Writers check it too, so a message that couldn't be read is never sent.\n */\nexport const MAX_LINE_LENGTH: number = 64 * 1024 * 1024;\n\n/** Serializes one message as a line, newline included. */\nexport function encodeLine(message: JsonRpcMessage): string {\n return `${JSON.stringify(message)}\\n`;\n}\n\n/**\n * Splits decoded text into lines. Feed it chunks as they arrive; it returns the complete lines\n * and keeps the unfinished rest. A line longer than `maxLineLength` characters throws a\n * `RangeError`, so a peer can't make the other side buffer without bound: the transport then\n * answers with `MOSTRA_HOST_MALFORMED` and closes the connection.\n */\nexport class LineSplitter {\n readonly #maxLineLength: number;\n /** The unfinished line, in the pieces it arrived in: joined only once its newline comes. */\n #pending: string[] = [];\n #pendingLength = 0;\n\n /** @param maxLineLength - The longest line accepted, in UTF-16 code units. Default 64 Mi. */\n constructor(maxLineLength: number = MAX_LINE_LENGTH) {\n this.#maxLineLength = maxLineLength;\n }\n\n /**\n * Returns the lines completed by `chunk`, without their newlines (and without a trailing `\\r`).\n * Only `chunk` is searched for newlines, so a long line costs time in proportion to its length,\n * however many chunks bring it.\n */\n push(chunk: string): string[] {\n const lines: string[] = [];\n let start = 0;\n for (let index = chunk.indexOf(\"\\n\"); index >= 0; index = chunk.indexOf(\"\\n\", start)) {\n if (this.#pendingLength + index - start > this.#maxLineLength) this.#overflow();\n this.#pending.push(chunk.slice(start, index));\n const line = this.#pending.join(\"\");\n this.#pending = [];\n this.#pendingLength = 0;\n lines.push(line.endsWith(\"\\r\") ? line.slice(0, -1) : line);\n start = index + 1;\n }\n if (start < chunk.length) {\n this.#pendingLength += chunk.length - start;\n if (this.#pendingLength > this.#maxLineLength) this.#overflow();\n this.#pending.push(chunk.slice(start));\n }\n return lines;\n }\n\n /** The unfinished text after the last newline. A stream that ends with it holds a cut-off message. */\n get rest(): string {\n return this.#pending.join(\"\");\n }\n\n #overflow(): never {\n this.#pending = [];\n this.#pendingLength = 0;\n throw new RangeError(`A message is longer than ${this.#maxLineLength} characters.`);\n }\n}\n"],"mappings":";;;;;AAUA,MAAa,kBAA0B;;AAGvC,SAAgB,WAAW,SAAiC;CAC1D,OAAO,GAAG,KAAK,UAAU,OAAO,EAAE;AACpC;;;;;;;AAQA,IAAa,eAAb,MAA0B;CACxB;;CAEA,WAAqB,CAAC;CACtB,iBAAiB;;CAGjB,YAAY,gBAAwB,iBAAiB;EACnD,KAAK,iBAAiB;CACxB;;;;;;CAOA,KAAK,OAAyB;EAC5B,MAAM,QAAkB,CAAC;EACzB,IAAI,QAAQ;EACZ,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI,GAAG,SAAS,GAAG,QAAQ,MAAM,QAAQ,MAAM,KAAK,GAAG;GACpF,IAAI,KAAK,iBAAiB,QAAQ,QAAQ,KAAK,gBAAgB,KAAK,UAAU;GAC9E,KAAK,SAAS,KAAK,MAAM,MAAM,OAAO,KAAK,CAAC;GAC5C,MAAM,OAAO,KAAK,SAAS,KAAK,EAAE;GAClC,KAAK,WAAW,CAAC;GACjB,KAAK,iBAAiB;GACtB,MAAM,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,IAAI;GACzD,QAAQ,QAAQ;EAClB;EACA,IAAI,QAAQ,MAAM,QAAQ;GACxB,KAAK,kBAAkB,MAAM,SAAS;GACtC,IAAI,KAAK,iBAAiB,KAAK,gBAAgB,KAAK,UAAU;GAC9D,KAAK,SAAS,KAAK,MAAM,MAAM,KAAK,CAAC;EACvC;EACA,OAAO;CACT;;CAGA,IAAI,OAAe;EACjB,OAAO,KAAK,SAAS,KAAK,EAAE;CAC9B;CAEA,YAAmB;EACjB,KAAK,WAAW,CAAC;EACjB,KAAK,iBAAiB;EACtB,MAAM,IAAI,WAAW,4BAA4B,KAAK,eAAe,aAAa;CACpF;AACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
//#region src/rpc/messages.d.ts
|
|
3
|
+
/** A request ID: a string or a number, chosen by the sender and echoed in the response. */
|
|
4
|
+
export type JsonRpcId = string | number;
|
|
5
|
+
/** Request params: a JSON object (Mostra always uses objects) or an array. */
|
|
6
|
+
export type JsonRpcParams = Readonly<Record<string, unknown>> | readonly unknown[];
|
|
7
|
+
/** A request: the receiver answers with a response carrying the same `id`. */
|
|
8
|
+
export interface JsonRpcRequest {
|
|
9
|
+
/** Always `"2.0"`. */
|
|
10
|
+
readonly jsonrpc: "2.0";
|
|
11
|
+
/** Chosen by the sender; the response carries the same ID. */
|
|
12
|
+
readonly id: JsonRpcId;
|
|
13
|
+
/** The method name, `group/name` or a bare name. */
|
|
14
|
+
readonly method: string;
|
|
15
|
+
/** The method's params. */
|
|
16
|
+
readonly params?: JsonRpcParams;
|
|
17
|
+
}
|
|
18
|
+
/** A notification: a request without an `id`, which is never answered. */
|
|
19
|
+
export interface JsonRpcNotification {
|
|
20
|
+
/** Always `"2.0"`. */
|
|
21
|
+
readonly jsonrpc: "2.0";
|
|
22
|
+
/** The notification's method name. */
|
|
23
|
+
readonly method: string;
|
|
24
|
+
/** The notification's params. */
|
|
25
|
+
readonly params?: JsonRpcParams;
|
|
26
|
+
}
|
|
27
|
+
/** The error member of a failed response. Mostra puts the diagnostic in `data`. */
|
|
28
|
+
export interface JsonRpcErrorObject {
|
|
29
|
+
/** The JSON-RPC error code (INTERFACES §6). */
|
|
30
|
+
readonly code: number;
|
|
31
|
+
/** A short description; clients switch on `data.code`, never on this text. */
|
|
32
|
+
readonly message: string;
|
|
33
|
+
/** The diagnostic (INTERFACES §13). */
|
|
34
|
+
readonly data?: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** A successful response. */
|
|
37
|
+
export interface JsonRpcSuccess {
|
|
38
|
+
/** Always `"2.0"`. */
|
|
39
|
+
readonly jsonrpc: "2.0";
|
|
40
|
+
/** The ID of the request this answers. */
|
|
41
|
+
readonly id: JsonRpcId;
|
|
42
|
+
/** The method's result. */
|
|
43
|
+
readonly result: unknown;
|
|
44
|
+
}
|
|
45
|
+
/** A failed response. `id` is `null` when the request's ID couldn't be read. */
|
|
46
|
+
export interface JsonRpcFailure {
|
|
47
|
+
/** Always `"2.0"`. */
|
|
48
|
+
readonly jsonrpc: "2.0";
|
|
49
|
+
/** The ID of the request this answers, or `null` when it couldn't be read. */
|
|
50
|
+
readonly id: JsonRpcId | null;
|
|
51
|
+
/** What went wrong. */
|
|
52
|
+
readonly error: JsonRpcErrorObject;
|
|
53
|
+
}
|
|
54
|
+
/** A response to a request. */
|
|
55
|
+
export type JsonRpcResponse = JsonRpcSuccess | JsonRpcFailure;
|
|
56
|
+
/** Any message on a Mostra connection. */
|
|
57
|
+
export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
58
|
+
/** The Zod schema of the `JsonRpcRequest` type. */
|
|
59
|
+
export declare const JsonRpcRequest: z.ZodType<JsonRpcRequest>;
|
|
60
|
+
/** The Zod schema of the `JsonRpcNotification` type. */
|
|
61
|
+
export declare const JsonRpcNotification: z.ZodType<JsonRpcNotification>;
|
|
62
|
+
/** The Zod schema of the `JsonRpcErrorObject` type. */
|
|
63
|
+
export declare const JsonRpcErrorObject: z.ZodType<JsonRpcErrorObject>;
|
|
64
|
+
/** The Zod schema of the `JsonRpcSuccess` type. */
|
|
65
|
+
export declare const JsonRpcSuccess: z.ZodType<JsonRpcSuccess>;
|
|
66
|
+
/** The Zod schema of the `JsonRpcFailure` type. */
|
|
67
|
+
export declare const JsonRpcFailure: z.ZodType<JsonRpcFailure>;
|
|
68
|
+
/** A message sorted by kind, or the reason it isn't a valid message. */
|
|
69
|
+
export type ClassifiedMessage = {
|
|
70
|
+
readonly kind: "request";
|
|
71
|
+
readonly message: JsonRpcRequest;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: "notification";
|
|
74
|
+
readonly message: JsonRpcNotification;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: "success";
|
|
77
|
+
readonly message: JsonRpcSuccess;
|
|
78
|
+
} | {
|
|
79
|
+
readonly kind: "failure";
|
|
80
|
+
readonly message: JsonRpcFailure;
|
|
81
|
+
} | {
|
|
82
|
+
readonly kind: "invalid";
|
|
83
|
+
readonly reason: string;
|
|
84
|
+
readonly id: JsonRpcId | null;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Sorts a parsed JSON value into a request, notification, success or failure, or explains why it
|
|
88
|
+
* is none of them. A JSON array (a batch) is invalid in revision `2026-10-10` (D83).
|
|
89
|
+
*/
|
|
90
|
+
export declare function classifyMessage(value: unknown): ClassifiedMessage;
|
|
91
|
+
//#endregion
|
|
92
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","names":[],"sources":["../../src/rpc/messages.ts"],"mappings":";;;YASY;;YAGA,gBAAgB,SAAS;;iBAGpB;;WAEN;;WAEA,IAAI;;WAEJ;;WAEA,SAAS;;;iBAIH;;WAEN;;WAEA;;WAEA,SAAS;;;iBAIH;;WAEN;;WAEA;;WAEA;;;iBAIM;;WAEN;;WAEA,IAAI;;WAEJ;;;iBAIM;;WAEN;;WAEA,IAAI;;WAEJ,OAAO;;;YAIN,kBAAkB,iBAAiB;;YAGnC,iBAAiB,iBAAiB,sBAAsB;;qBAUvD,gBAAgB,EAAE,QAAQ;;qBAQ1B,qBAAqB,EAAE,QAAQ;;qBAQ/B,oBAAoB,EAAE,QAAQ;;qBAQ9B,gBAAgB,EAAE,QAAQ;;qBAQ1B,gBAAgB,EAAE,QAAQ;;YAQ3B;WACG;WAA0B,SAAS;;WACnC;WAA+B,SAAS;;WACxC;WAA0B,SAAS;;WACnC;WAA0B,SAAS;;WACnC;WAA0B;WAAyB,IAAI;;;;;;wBAStD,gBAAgB,iBAAiB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { wireRegistry } from "../wire-registry.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/rpc/messages.ts
|
|
4
|
+
/**
|
|
5
|
+
* JSON-RPC 2.0 message shapes (D59, D83). Every Mostra connection carries these: the host protocol
|
|
6
|
+
* over stdio or the home socket, child-process messaging and the shell bridge. Revision
|
|
7
|
+
* `2026-10-10` has no batches.
|
|
8
|
+
*/
|
|
9
|
+
const version = z.literal("2.0");
|
|
10
|
+
const id = z.union([z.string(), z.number()]);
|
|
11
|
+
const params = z.union([z.record(z.string(), z.unknown()), z.array(z.unknown()).readonly()]);
|
|
12
|
+
/** The Zod schema of the `JsonRpcRequest` type. */
|
|
13
|
+
const JsonRpcRequest = z.object({
|
|
14
|
+
jsonrpc: version,
|
|
15
|
+
id,
|
|
16
|
+
method: z.string(),
|
|
17
|
+
params: params.exactOptional()
|
|
18
|
+
}).register(wireRegistry, {
|
|
19
|
+
id: "JsonRpcRequest",
|
|
20
|
+
description: "A JSON-RPC 2.0 request: answered by a response with the same id."
|
|
21
|
+
});
|
|
22
|
+
/** The Zod schema of the `JsonRpcNotification` type. */
|
|
23
|
+
const JsonRpcNotification = z.object({
|
|
24
|
+
jsonrpc: version,
|
|
25
|
+
method: z.string(),
|
|
26
|
+
params: params.exactOptional()
|
|
27
|
+
}).register(wireRegistry, {
|
|
28
|
+
id: "JsonRpcNotification",
|
|
29
|
+
description: "A JSON-RPC 2.0 notification: a request without an id, never answered."
|
|
30
|
+
});
|
|
31
|
+
/** The Zod schema of the `JsonRpcErrorObject` type. */
|
|
32
|
+
const JsonRpcErrorObject = z.object({
|
|
33
|
+
code: z.int(),
|
|
34
|
+
message: z.string(),
|
|
35
|
+
data: z.unknown().exactOptional()
|
|
36
|
+
}).register(wireRegistry, {
|
|
37
|
+
id: "JsonRpcErrorObject",
|
|
38
|
+
description: "The error of a failed JSON-RPC 2.0 response; Mostra puts the diagnostic in data."
|
|
39
|
+
});
|
|
40
|
+
/** The Zod schema of the `JsonRpcSuccess` type. */
|
|
41
|
+
const JsonRpcSuccess = z.object({
|
|
42
|
+
jsonrpc: version,
|
|
43
|
+
id,
|
|
44
|
+
result: z.unknown()
|
|
45
|
+
}).register(wireRegistry, {
|
|
46
|
+
id: "JsonRpcSuccess",
|
|
47
|
+
description: "A successful JSON-RPC 2.0 response."
|
|
48
|
+
});
|
|
49
|
+
/** The Zod schema of the `JsonRpcFailure` type. */
|
|
50
|
+
const JsonRpcFailure = z.object({
|
|
51
|
+
jsonrpc: version,
|
|
52
|
+
id: id.nullable(),
|
|
53
|
+
error: JsonRpcErrorObject
|
|
54
|
+
}).register(wireRegistry, {
|
|
55
|
+
id: "JsonRpcFailure",
|
|
56
|
+
description: "A failed JSON-RPC 2.0 response; id is null when the request's id was unreadable."
|
|
57
|
+
});
|
|
58
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59
|
+
/**
|
|
60
|
+
* Sorts a parsed JSON value into a request, notification, success or failure, or explains why it
|
|
61
|
+
* is none of them. A JSON array (a batch) is invalid in revision `2026-10-10` (D83).
|
|
62
|
+
*/
|
|
63
|
+
function classifyMessage(value) {
|
|
64
|
+
if (Array.isArray(value)) return {
|
|
65
|
+
kind: "invalid",
|
|
66
|
+
reason: "Batches (JSON arrays) aren't supported in host protocol revision 2026-10-10.",
|
|
67
|
+
id: null
|
|
68
|
+
};
|
|
69
|
+
if (!isObject(value)) return {
|
|
70
|
+
kind: "invalid",
|
|
71
|
+
reason: "A message must be a JSON object.",
|
|
72
|
+
id: null
|
|
73
|
+
};
|
|
74
|
+
const rawId = value["id"];
|
|
75
|
+
const readableId = typeof rawId === "string" || typeof rawId === "number" ? rawId : null;
|
|
76
|
+
if (value["jsonrpc"] !== "2.0") return {
|
|
77
|
+
kind: "invalid",
|
|
78
|
+
reason: "A message must have \"jsonrpc\": \"2.0\".",
|
|
79
|
+
id: readableId
|
|
80
|
+
};
|
|
81
|
+
if ("method" in value) {
|
|
82
|
+
if ("id" in value) {
|
|
83
|
+
const parsed = JsonRpcRequest.safeParse(value);
|
|
84
|
+
return parsed.success ? {
|
|
85
|
+
kind: "request",
|
|
86
|
+
message: parsed.data
|
|
87
|
+
} : {
|
|
88
|
+
kind: "invalid",
|
|
89
|
+
reason: describeRequestProblem(value),
|
|
90
|
+
id: readableId
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const parsed = JsonRpcNotification.safeParse(value);
|
|
94
|
+
return parsed.success ? {
|
|
95
|
+
kind: "notification",
|
|
96
|
+
message: parsed.data
|
|
97
|
+
} : {
|
|
98
|
+
kind: "invalid",
|
|
99
|
+
reason: describeRequestProblem(value),
|
|
100
|
+
id: null
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const hasResult = "result" in value;
|
|
104
|
+
if (hasResult !== "error" in value && "id" in value) {
|
|
105
|
+
if (hasResult) {
|
|
106
|
+
const parsed = JsonRpcSuccess.safeParse(value);
|
|
107
|
+
if (parsed.success) return {
|
|
108
|
+
kind: "success",
|
|
109
|
+
message: parsed.data
|
|
110
|
+
};
|
|
111
|
+
} else {
|
|
112
|
+
const parsed = JsonRpcFailure.safeParse(value);
|
|
113
|
+
if (parsed.success) return {
|
|
114
|
+
kind: "failure",
|
|
115
|
+
message: parsed.data
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
kind: "invalid",
|
|
121
|
+
reason: "A message must be a request (with \"method\") or a response (with \"id\" and exactly one of \"result\" and \"error\").",
|
|
122
|
+
id: readableId
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function describeRequestProblem(value) {
|
|
126
|
+
if (typeof value["method"] !== "string") return "A request's \"method\" must be a string.";
|
|
127
|
+
if ("id" in value && typeof value["id"] !== "string" && typeof value["id"] !== "number") return "A request's \"id\" must be a string or a number.";
|
|
128
|
+
return "A request's \"params\" must be an object or an array.";
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { JsonRpcErrorObject, JsonRpcFailure, JsonRpcNotification, JsonRpcRequest, JsonRpcSuccess, classifyMessage };
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","names":[],"sources":["../../src/rpc/messages.ts"],"sourcesContent":["/**\n * JSON-RPC 2.0 message shapes (D59, D83). Every Mostra connection carries these: the host protocol\n * over stdio or the home socket, child-process messaging and the shell bridge. Revision\n * `2026-10-10` has no batches.\n */\nimport * as z from \"zod\";\nimport { wireRegistry } from \"../wire-registry.ts\";\n\n/** A request ID: a string or a number, chosen by the sender and echoed in the response. */\nexport type JsonRpcId = string | number;\n\n/** Request params: a JSON object (Mostra always uses objects) or an array. */\nexport type JsonRpcParams = Readonly<Record<string, unknown>> | readonly unknown[];\n\n/** A request: the receiver answers with a response carrying the same `id`. */\nexport interface JsonRpcRequest {\n /** Always `\"2.0\"`. */\n readonly jsonrpc: \"2.0\";\n /** Chosen by the sender; the response carries the same ID. */\n readonly id: JsonRpcId;\n /** The method name, `group/name` or a bare name. */\n readonly method: string;\n /** The method's params. */\n readonly params?: JsonRpcParams;\n}\n\n/** A notification: a request without an `id`, which is never answered. */\nexport interface JsonRpcNotification {\n /** Always `\"2.0\"`. */\n readonly jsonrpc: \"2.0\";\n /** The notification's method name. */\n readonly method: string;\n /** The notification's params. */\n readonly params?: JsonRpcParams;\n}\n\n/** The error member of a failed response. Mostra puts the diagnostic in `data`. */\nexport interface JsonRpcErrorObject {\n /** The JSON-RPC error code (INTERFACES §6). */\n readonly code: number;\n /** A short description; clients switch on `data.code`, never on this text. */\n readonly message: string;\n /** The diagnostic (INTERFACES §13). */\n readonly data?: unknown;\n}\n\n/** A successful response. */\nexport interface JsonRpcSuccess {\n /** Always `\"2.0\"`. */\n readonly jsonrpc: \"2.0\";\n /** The ID of the request this answers. */\n readonly id: JsonRpcId;\n /** The method's result. */\n readonly result: unknown;\n}\n\n/** A failed response. `id` is `null` when the request's ID couldn't be read. */\nexport interface JsonRpcFailure {\n /** Always `\"2.0\"`. */\n readonly jsonrpc: \"2.0\";\n /** The ID of the request this answers, or `null` when it couldn't be read. */\n readonly id: JsonRpcId | null;\n /** What went wrong. */\n readonly error: JsonRpcErrorObject;\n}\n\n/** A response to a request. */\nexport type JsonRpcResponse = JsonRpcSuccess | JsonRpcFailure;\n\n/** Any message on a Mostra connection. */\nexport type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;\n\nconst version = z.literal(\"2.0\");\nconst id: z.ZodType<JsonRpcId> = z.union([z.string(), z.number()]);\nconst params: z.ZodType<JsonRpcParams> = z.union([\n z.record(z.string(), z.unknown()),\n z.array(z.unknown()).readonly(),\n]);\n\n/** The Zod schema of the `JsonRpcRequest` type. */\nexport const JsonRpcRequest: z.ZodType<JsonRpcRequest> = z\n .object({ jsonrpc: version, id, method: z.string(), params: params.exactOptional() })\n .register(wireRegistry, {\n id: \"JsonRpcRequest\",\n description: \"A JSON-RPC 2.0 request: answered by a response with the same id.\",\n });\n\n/** The Zod schema of the `JsonRpcNotification` type. */\nexport const JsonRpcNotification: z.ZodType<JsonRpcNotification> = z\n .object({ jsonrpc: version, method: z.string(), params: params.exactOptional() })\n .register(wireRegistry, {\n id: \"JsonRpcNotification\",\n description: \"A JSON-RPC 2.0 notification: a request without an id, never answered.\",\n });\n\n/** The Zod schema of the `JsonRpcErrorObject` type. */\nexport const JsonRpcErrorObject: z.ZodType<JsonRpcErrorObject> = z\n .object({ code: z.int(), message: z.string(), data: z.unknown().exactOptional() })\n .register(wireRegistry, {\n id: \"JsonRpcErrorObject\",\n description: \"The error of a failed JSON-RPC 2.0 response; Mostra puts the diagnostic in data.\",\n });\n\n/** The Zod schema of the `JsonRpcSuccess` type. */\nexport const JsonRpcSuccess: z.ZodType<JsonRpcSuccess> = z\n .object({ jsonrpc: version, id, result: z.unknown() })\n .register(wireRegistry, {\n id: \"JsonRpcSuccess\",\n description: \"A successful JSON-RPC 2.0 response.\",\n });\n\n/** The Zod schema of the `JsonRpcFailure` type. */\nexport const JsonRpcFailure: z.ZodType<JsonRpcFailure> = z\n .object({ jsonrpc: version, id: id.nullable(), error: JsonRpcErrorObject })\n .register(wireRegistry, {\n id: \"JsonRpcFailure\",\n description: \"A failed JSON-RPC 2.0 response; id is null when the request's id was unreadable.\",\n });\n\n/** A message sorted by kind, or the reason it isn't a valid message. */\nexport type ClassifiedMessage =\n | { readonly kind: \"request\"; readonly message: JsonRpcRequest }\n | { readonly kind: \"notification\"; readonly message: JsonRpcNotification }\n | { readonly kind: \"success\"; readonly message: JsonRpcSuccess }\n | { readonly kind: \"failure\"; readonly message: JsonRpcFailure }\n | { readonly kind: \"invalid\"; readonly reason: string; readonly id: JsonRpcId | null };\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/**\n * Sorts a parsed JSON value into a request, notification, success or failure, or explains why it\n * is none of them. A JSON array (a batch) is invalid in revision `2026-10-10` (D83).\n */\nexport function classifyMessage(value: unknown): ClassifiedMessage {\n if (Array.isArray(value)) {\n return {\n kind: \"invalid\",\n reason: \"Batches (JSON arrays) aren't supported in host protocol revision 2026-10-10.\",\n id: null,\n };\n }\n if (!isObject(value)) {\n return { kind: \"invalid\", reason: \"A message must be a JSON object.\", id: null };\n }\n const rawId = value[\"id\"];\n const readableId = typeof rawId === \"string\" || typeof rawId === \"number\" ? rawId : null;\n if (value[\"jsonrpc\"] !== \"2.0\") {\n return { kind: \"invalid\", reason: 'A message must have \"jsonrpc\": \"2.0\".', id: readableId };\n }\n if (\"method\" in value) {\n if (\"id\" in value) {\n const parsed = JsonRpcRequest.safeParse(value);\n return parsed.success\n ? { kind: \"request\", message: parsed.data }\n : { kind: \"invalid\", reason: describeRequestProblem(value), id: readableId };\n }\n const parsed = JsonRpcNotification.safeParse(value);\n return parsed.success\n ? { kind: \"notification\", message: parsed.data }\n : { kind: \"invalid\", reason: describeRequestProblem(value), id: null };\n }\n const hasResult = \"result\" in value;\n const hasError = \"error\" in value;\n if (hasResult !== hasError && \"id\" in value) {\n if (hasResult) {\n const parsed = JsonRpcSuccess.safeParse(value);\n if (parsed.success) return { kind: \"success\", message: parsed.data };\n } else {\n const parsed = JsonRpcFailure.safeParse(value);\n if (parsed.success) return { kind: \"failure\", message: parsed.data };\n }\n }\n return {\n kind: \"invalid\",\n reason:\n 'A message must be a request (with \"method\") or a response (with \"id\" and exactly one of \"result\" and \"error\").',\n id: readableId,\n };\n}\n\nfunction describeRequestProblem(value: Record<string, unknown>): string {\n if (typeof value[\"method\"] !== \"string\") return 'A request\\'s \"method\" must be a string.';\n if (\"id\" in value && typeof value[\"id\"] !== \"string\" && typeof value[\"id\"] !== \"number\") {\n return 'A request\\'s \"id\" must be a string or a number.';\n }\n return 'A request\\'s \"params\" must be an object or an array.';\n}\n"],"mappings":";;;;;;;;AAwEA,MAAM,UAAU,EAAE,QAAQ,KAAK;AAC/B,MAAM,KAA2B,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AACjE,MAAM,SAAmC,EAAE,MAAM,CAC/C,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,GAChC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAChC,CAAC;;AAGD,MAAa,iBAA4C,EACtD,OAAO;CAAE,SAAS;CAAS;CAAI,QAAQ,EAAE,OAAO;CAAG,QAAQ,OAAO,cAAc;AAAE,CAAC,CAAC,CACpF,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,sBAAsD,EAChE,OAAO;CAAE,SAAS;CAAS,QAAQ,EAAE,OAAO;CAAG,QAAQ,OAAO,cAAc;AAAE,CAAC,CAAC,CAChF,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,qBAAoD,EAC9D,OAAO;CAAE,MAAM,EAAE,IAAI;CAAG,SAAS,EAAE,OAAO;CAAG,MAAM,EAAE,QAAQ,CAAC,CAAC,cAAc;AAAE,CAAC,CAAC,CACjF,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,iBAA4C,EACtD,OAAO;CAAE,SAAS;CAAS;CAAI,QAAQ,EAAE,QAAQ;AAAE,CAAC,CAAC,CACrD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,iBAA4C,EACtD,OAAO;CAAE,SAAS;CAAS,IAAI,GAAG,SAAS;CAAG,OAAO;AAAmB,CAAC,CAAC,CAC1E,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;AAUH,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;;;;AAMrE,SAAgB,gBAAgB,OAAmC;CACjE,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO;EACL,MAAM;EACN,QAAQ;EACR,IAAI;CACN;CAEF,IAAI,CAAC,SAAS,KAAK,GACjB,OAAO;EAAE,MAAM;EAAW,QAAQ;EAAoC,IAAI;CAAK;CAEjF,MAAM,QAAQ,MAAM;CACpB,MAAM,aAAa,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,QAAQ;CACpF,IAAI,MAAM,eAAe,OACvB,OAAO;EAAE,MAAM;EAAW,QAAQ;EAAyC,IAAI;CAAW;CAE5F,IAAI,YAAY,OAAO;EACrB,IAAI,QAAQ,OAAO;GACjB,MAAM,SAAS,eAAe,UAAU,KAAK;GAC7C,OAAO,OAAO,UACV;IAAE,MAAM;IAAW,SAAS,OAAO;GAAK,IACxC;IAAE,MAAM;IAAW,QAAQ,uBAAuB,KAAK;IAAG,IAAI;GAAW;EAC/E;EACA,MAAM,SAAS,oBAAoB,UAAU,KAAK;EAClD,OAAO,OAAO,UACV;GAAE,MAAM;GAAgB,SAAS,OAAO;EAAK,IAC7C;GAAE,MAAM;GAAW,QAAQ,uBAAuB,KAAK;GAAG,IAAI;EAAK;CACzE;CACA,MAAM,YAAY,YAAY;CAE9B,IAAI,cADa,WAAW,SACE,QAAQ,OAAO;EAC3C,IAAI,WAAW;GACb,MAAM,SAAS,eAAe,UAAU,KAAK;GAC7C,IAAI,OAAO,SAAS,OAAO;IAAE,MAAM;IAAW,SAAS,OAAO;GAAK;EACrE,OAAO;GACL,MAAM,SAAS,eAAe,UAAU,KAAK;GAC7C,IAAI,OAAO,SAAS,OAAO;IAAE,MAAM;IAAW,SAAS,OAAO;GAAK;EACrE;CACF;CACA,OAAO;EACL,MAAM;EACN,QACE;EACF,IAAI;CACN;AACF;AAEA,SAAS,uBAAuB,OAAwC;CACtE,IAAI,OAAO,MAAM,cAAc,UAAU,OAAO;CAChD,IAAI,QAAQ,SAAS,OAAO,MAAM,UAAU,YAAY,OAAO,MAAM,UAAU,UAC7E,OAAO;CAET,OAAO;AACT"}
|