The Dor Tool integration protocol, for Tools and for the hosts that run them. MIT-licensed, with no runtime dependencies. It is at 0.x, and its API may change before 1.0.
@dor-tools/api/osc: OSC 367. A Tool writesserveSequence({ port, path })once it listens, each one replacing the last whole, andstateSequence({ dirty })on every change. A host reads both withparseToolAnnounce/parseToolState.- Opening:
openSequence({ path, place, trusted, fragment })asks the host to show a file in its preview pane (place: 'preview'), in the Tool's own pane, interrupting the Tool ('self'), or in another pane ('new', the default).trusted: truesays the user picked this exact file in the Tool's page, so the host does not ask before opening it as a page that runs its own script; a path from content, such as a document's link, leaves it out. A host reads it withparseToolOpen. - Saving: a Tool that announces
serveSequence({ port, save: '/<token>/save' })receives aPOSTofTOOL_SAVE_REQUESTthere when the user presses Save in the host's close prompt, and answers withtoolSaveReply({ dirty }), which a host reads withparseToolSaveReply. - Reaping: a Tool that announces
serveSequence({ ..., dehydrate: true })may be stopped while idle with Ctrl+C (SIGINT). It can writedehydrateSequence(state)on the way out, ordehydrateSequence()when it kept nothing. When the host holds a state or a heading for the next run (after a reap, a document navigation's Back or Forward, or anopenthat named a heading), it appendsREHYDRATE_PARAMto the first URL it opens for that run, asrehydrateUrlwrites it: unpadded base64url of the UTF-8 JSON{"v":1}plus thestateand theopen'sfragment, at mostREHYDRATE_PARAM_LIMIT(4,096) characters, which is 3,072 bytes of JSON; past it the state is dropped and the fragment kept. The Tool reads itsstateandfragmentfrom its page's first request withreadRehydrateParam, which answers null for anything else, and a host's renderer remembers the addresswithoutRehydrateParamleaves. Its args alone must restart it correctly.
The protocol is described in PROTOCOL.md. Dormouse's side of it is in its docs/specs/dor-tool.md, and this package's own rules in docs/specs/dor-tools-api.md.