diff --git a/README.md b/README.md index c096b63..510df44 100644 --- a/README.md +++ b/README.md @@ -1,96 +1,133 @@ -# @escalated-dev/plugin-runtime +

+ Escalated +

-[![Tests](https://github.com/escalated-dev/escalated-plugin-runtime/actions/workflows/run-tests.yml/badge.svg)](https://github.com/escalated-dev/escalated-plugin-runtime/actions/workflows/run-tests.yml) -[![Node.js](https://img.shields.io/badge/node.js-20+-339933?logo=node.js&logoColor=white)](https://nodejs.org/) -[![TypeScript](https://img.shields.io/badge/typescript-5.x-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -[![Views](https://hits.sh/github.com/escalated-dev/escalated-plugin-runtime.svg?style=flat&label=views&color=007ec6)](https://hits.sh/github.com/escalated-dev/escalated-plugin-runtime/) +

Escalated Plugin Runtime

-Runtime host for [Escalated](https://escalated.dev) plugins. Loads plugins built with the [Plugin SDK](https://github.com/escalated-dev/escalated-plugin-sdk) and communicates with the host framework (Laravel, Rails, Django, AdonisJS) via JSON-RPC 2.0 over stdio. +

+ The Node.js process that runs Escalated plugins.
+ Your backend's bridge starts it and talks to it over JSON-RPC 2.0 on stdio. +

-> **[escalated.dev](https://escalated.dev)** — Learn more, view demos, and compare Cloud vs Self-Hosted options. +

+ Website · + Docs · + Cloud · + Releases +

-## Installation +
-```bash -npm install @escalated-dev/plugin-runtime +A plugin written with the [Plugin SDK](https://github.com/escalated-dev/escalated-plugin-sdk) is all the runtime needs: + +```ts +import { definePlugin } from '@escalated-dev/plugin-sdk' + +export default definePlugin({ + name: 'my-plugin', + version: '1.0.0', + + actions: { + 'ticket.created': async (event, ctx) => { + ctx.log.info('New ticket!', event) + }, + }, +}) ``` -This package is installed alongside any SDK plugins you want to use. The host framework's bridge spawns it automatically — you do not need to run it manually. +## What it does -## Usage + + + + + +
+

Runs every installed plugin in one process

+ It finds plugins in node_modules/@escalated-dev/plugin-*, routes hooks to them, and proxies their ctx.* calls back to your backend. +
+

Never takes the helpdesk down with it

+ Your backend's bridge starts it on the first hook and restarts it with backoff after a crash. While it is down, filters return values unchanged. +
-The runtime is started by the framework bridge (e.g., `escalated-laravel`, `escalated-rails`, `escalated-django`). You typically do not invoke it directly. The bridge spawns it as: +## Features -```bash -node node_modules/@escalated-dev/plugin-runtime/dist/index.js -``` + + + + + + + + + + + +
-## Architecture +**Loading** +- Discovers `@escalated-dev/plugin-*` packages +- Started by your backend's bridge +- Spawned lazily on first hook -The runtime is a long-lived Node.js process that: + -1. Discovers and loads installed plugins from `node_modules/@escalated-dev/plugin-*` -2. Responds to JSON-RPC messages from the host framework -3. Routes hooks (actions, filters) to registered plugin handlers -4. Proxies `ctx.*` calls back to the host for data operations +**Dispatch** +- Actions, filters, endpoints, webhooks +- Cron jobs and widget badges +- Activate and deactivate calls -``` -Host Framework (PHP/Ruby/Python) Plugin Runtime (Node.js) -┌──────────────────────────┐ stdio ┌──────────────────────────┐ -│ Bridge │◄──────────►│ @escalated-dev/ │ -│ - spawns subprocess │ JSON- │ plugin-runtime │ -│ - dispatches hooks │ RPC 2.0 │ ┌────────────────────┐ │ -│ - handles ctx.* calls │ │ │ plugin-slack │ │ -│ │ │ │ plugin-jira │ │ -│ │ │ │ your-custom-plugin │ │ -└──────────────────────────┘ │ └────────────────────┘ │ - └──────────────────────────┘ -``` + + +**Resilience (via the bridge)** +- Restarts with exponential backoff +- Actions degrade when it is unavailable +- Filters pass values through when down + +
+ +**Protocol** +- JSON-RPC 2.0 over stdin and stdout +- Concurrent host calls +- `host_call_id` on every `ctx.*` call -### Resilience + -- Spawned lazily on first hook dispatch -- Automatic restart with exponential backoff if the process crashes -- Action hooks degrade gracefully when the runtime is unavailable -- Filter hooks return unmodified values when the runtime is down +**Active plugins** +- Runs only plugins the host lists +- Older hosts run every loaded plugin -## Broadcasting Event Forwarding + -When the host framework has real-time broadcasting enabled, the runtime automatically forwards broadcasting events to plugins. The bridge sends these as standard action hooks (e.g., `broadcast.ticket.updated`, `broadcast.ticket.replied`) so plugins can react to real-time events without any additional configuration. See the [Plugin SDK README](https://github.com/escalated-dev/escalated-plugin-sdk#broadcastable-events) for the full list of broadcastable events. +**Real-time** +- Forwards broadcast events as action hooks +- No extra plugin configuration -## Protocol +
-Communication uses JSON-RPC 2.0 over stdin/stdout. See the [Plugin SDK docs](https://github.com/escalated-dev/escalated-plugin-sdk) for the full protocol specification. +

Every feature in detail

-### Host call ids +

+ Node.js + TypeScript + JSON-RPC 2.0 +

-The runtime serves host calls concurrently. Every `ctx.*` request a plugin makes -while handling a host call (`action`, `filter`, `endpoint`, `webhook`, `cron`, -`badge`, `activate`, `deactivate`) carries `host_call_id`: the JSON-RPC `id` of -that host call. A host serving several requests at once uses it to find the -request, and so the acting user and the plugin being served, that each `ctx.*` -call belongs to. A call made outside any host call (a timer the plugin started) -has no `host_call_id`. The handshake answers `host_call_ids: true`; hosts that -ignore the field keep working as before. +## Quick start -### Active plugins +```bash +npm install @escalated-dev/plugin-runtime +``` -The runtime loads every installed plugin, but only the host knows which ones an -admin has activated. A host passes `plugins: [names]` (the manifest names of its -active plugins) on `action`, `filter`, `endpoint`, `webhook`, `cron` and `badge`, -and the runtime then runs only those plugins' handlers: actions and filters skip -the others, an endpoint or webhook of an unlisted plugin is an error, `cron` does -nothing and `badge` answers `null`. An empty list runs nothing. A call with no -`plugins` key runs every loaded plugin, as older runtimes did. The handshake -answers `active_plugin_lists: true`. +Install it next to the plugins you want to use. Your backend's bridge spawns it, so you don't run it yourself. See [installation and usage](docs/installation.md). -## Related Packages +## Learn more -- **[Plugin SDK](https://github.com/escalated-dev/escalated-plugin-sdk)** — TypeScript SDK for building plugins -- **[Escalated](https://github.com/escalated-dev/escalated)** — Shared frontend (Vue 3 + Inertia.js) -- **[Escalated Docs](https://github.com/escalated-dev/escalated-docs)** — Full documentation +- [Installation and usage](docs/installation.md) · [Architecture and broadcasting](docs/architecture.md) · [Protocol](docs/protocol.md) +- [Releasing this package](RELEASE.md) +- [Plugin SDK](https://github.com/escalated-dev/escalated-plugin-sdk) for writing plugins +- [Escalated docs](https://escalated.dev/docs) · [Docs source](https://github.com/escalated-dev/escalated-docs) · [Shared frontend](https://github.com/escalated-dev/escalated) ## License -MIT - Copyright (c) Escalated.dev. See [LICENSE](LICENSE). +MIT. Copyright (c) Escalated.dev. See [LICENSE](LICENSE). diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..7b82435 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,34 @@ +# Architecture + +## Architecture + +The runtime is a long-lived Node.js process that: + +1. Discovers and loads installed plugins from `node_modules/@escalated-dev/plugin-*` +2. Responds to JSON-RPC messages from the host framework +3. Routes hooks (actions, filters) to registered plugin handlers +4. Proxies `ctx.*` calls back to the host for data operations + +``` +Host Framework (PHP/Ruby/Python) Plugin Runtime (Node.js) +┌──────────────────────────┐ stdio ┌──────────────────────────┐ +│ Bridge │◄──────────►│ @escalated-dev/ │ +│ - spawns subprocess │ JSON- │ plugin-runtime │ +│ - dispatches hooks │ RPC 2.0 │ ┌────────────────────┐ │ +│ - handles ctx.* calls │ │ │ plugin-slack │ │ +│ │ │ │ plugin-jira │ │ +│ │ │ │ your-custom-plugin │ │ +└──────────────────────────┘ │ └────────────────────┘ │ + └──────────────────────────┘ +``` + +### Resilience + +- Spawned lazily on first hook dispatch +- Automatic restart with exponential backoff if the process crashes +- Action hooks degrade gracefully when the runtime is unavailable +- Filter hooks return unmodified values when the runtime is down + +## Broadcasting Event Forwarding + +When the host framework has real-time broadcasting enabled, the runtime automatically forwards broadcasting events to plugins. The bridge sends these as standard action hooks (e.g., `broadcast.ticket.updated`, `broadcast.ticket.replied`) so plugins can react to real-time events without any additional configuration. See the [Plugin SDK README](https://github.com/escalated-dev/escalated-plugin-sdk/blob/master/docs/core-api.md#broadcastable-events) for the full list of broadcastable events. diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 0000000..a7539f7 --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,17 @@ +# Installation and usage + +## Installation + +```bash +npm install @escalated-dev/plugin-runtime +``` + +This package is installed alongside any SDK plugins you want to use. The host framework's bridge spawns it automatically — you do not need to run it manually. + +## Usage + +The runtime is started by the framework bridge (e.g., `escalated-laravel`, `escalated-rails`, `escalated-django`). You typically do not invoke it directly. The bridge spawns it as: + +```bash +node node_modules/@escalated-dev/plugin-runtime/dist/index.js +``` diff --git a/docs/protocol.md b/docs/protocol.md new file mode 100644 index 0000000..88f0b11 --- /dev/null +++ b/docs/protocol.md @@ -0,0 +1,27 @@ +# Protocol + +## Protocol + +Communication uses JSON-RPC 2.0 over stdin/stdout. See the [Plugin SDK docs](https://github.com/escalated-dev/escalated-plugin-sdk) for the full protocol specification. + +### Host call ids + +The runtime serves host calls concurrently. Every `ctx.*` request a plugin makes +while handling a host call (`action`, `filter`, `endpoint`, `webhook`, `cron`, +`badge`, `activate`, `deactivate`) carries `host_call_id`: the JSON-RPC `id` of +that host call. A host serving several requests at once uses it to find the +request, and so the acting user and the plugin being served, that each `ctx.*` +call belongs to. A call made outside any host call (a timer the plugin started) +has no `host_call_id`. The handshake answers `host_call_ids: true`; hosts that +ignore the field keep working as before. + +### Active plugins + +The runtime loads every installed plugin, but only the host knows which ones an +admin has activated. A host passes `plugins: [names]` (the manifest names of its +active plugins) on `action`, `filter`, `endpoint`, `webhook`, `cron` and `badge`, +and the runtime then runs only those plugins' handlers: actions and filters skip +the others, an endpoint or webhook of an unlisted plugin is an error, `cron` does +nothing and `badge` answers `null`. An empty list runs nothing. A call with no +`plugins` key runs every loaded plugin, as older runtimes did. The handshake +answers `active_plugin_lists: true`.