mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
feat(plugins): plugin hook wiring + comprehensive test suite + welcome-banner example (#3045)
Follow-up to the plugins framework (#3041): wires the plugin hooks end-to-end and adds full test coverage. - Wires `onRequest` / `onResponse` / `onError` hooks into the chat pipeline (`chatCore` now imports from the unified `hooks` registry). - Loads active plugins on server startup (`pluginManager.loadAll()` in `server-init`) so they survive restarts. - Ships a `welcome-banner` example plugin (`examples/plugins/`) + test fixture. - Adds a comprehensive plugin test suite (manifest, db, config, hooks, manager lifecycle, loader IPC, permissions, scanner, welcome-banner e2e). Integration fixes applied during review: - `manager.install` now removes an orphaned `destDir` (DB row gone but files left on disk) before the atomic rename, guarded by path containment — it previously failed with `ENOTEMPTY` (a regression surfaced by the new lifecycle test). - `plugins-db` / `plugins-manager-lifecycle` tests now initialize the DB via the real migration `076` (`getDbInstance`) rather than relying on ambient state, so a missing/renumbered migration fails loudly instead of being masked. 348/348 plugin tests pass; typecheck / cycles clean. Co-authored-by: oyi77 <14921983+oyi77@users.noreply.github.com>
This commit is contained in:
36
examples/plugins/welcome-banner/index.mjs
Normal file
36
examples/plugins/welcome-banner/index.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Welcome Banner Plugin — PoC demonstrating the OmniRoute plugin system.
|
||||
*
|
||||
* Adds a banner message to request metadata on every request.
|
||||
* Logs a delivery confirmation on every response.
|
||||
*
|
||||
* @module welcome-banner
|
||||
*/
|
||||
|
||||
/**
|
||||
* onRequest hook — injects banner text into request metadata.
|
||||
*
|
||||
* @param {object} ctx - Plugin context
|
||||
* @param {object} [ctx.config] - Plugin configuration
|
||||
* @param {object} [ctx.metadata] - Request metadata (mutable)
|
||||
*/
|
||||
export function onRequest(ctx) {
|
||||
const config = ctx?.config || {};
|
||||
const enabled = config.enabled !== false; // default true
|
||||
if (!enabled) return;
|
||||
|
||||
const bannerText = config.bannerText || "Welcome to OmniRoute!";
|
||||
if (ctx.metadata) {
|
||||
ctx.metadata.banner = bannerText;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* onResponse hook — fire-and-forget banner delivery log.
|
||||
*
|
||||
* @param {object} ctx - Plugin context
|
||||
* @param {object} response - Upstream response
|
||||
*/
|
||||
export function onResponse() {
|
||||
// No-op — banner is request-side only
|
||||
}
|
||||
29
examples/plugins/welcome-banner/plugin.json
Normal file
29
examples/plugins/welcome-banner/plugin.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "welcome-banner",
|
||||
"version": "1.0.0",
|
||||
"description": "Adds a welcome banner to API responses",
|
||||
"author": "OmniRoute",
|
||||
"license": "MIT",
|
||||
"main": "index.mjs",
|
||||
"source": "local",
|
||||
"tags": ["demo", "banner"],
|
||||
"hooks": {
|
||||
"onRequest": true,
|
||||
"onResponse": true,
|
||||
"onError": false
|
||||
},
|
||||
"permissions": [],
|
||||
"enabledByDefault": true,
|
||||
"configSchema": {
|
||||
"bannerText": {
|
||||
"type": "string",
|
||||
"default": "Welcome to OmniRoute!",
|
||||
"description": "Banner message to display"
|
||||
},
|
||||
"enabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Enable or disable the banner"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user