feat(plugins): wire real db_get/db_put/dispatch_event host imports (VS-14) #22
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/wasm-host-imports-vs-14"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The wasm meshcore host imports themselves (
host_db_get,host_db_put,host_dispatch_event,host_log,host_get_version) were already fully implemented inmeshcentral-plugins. The gap:dispatch_pluginhanded each plugin aNoopBackendthat swallowed every call. Plugins could compile against the ABI but the server never saw any I/O.Changes
PluginHostBackendinuser_session.rsholds a clone ofAppState+ the plugin name.db_get/db_put: namespace toplugin/<name>/<key>so plugins can't trample each other or the server's own docs; persist viameshcentral-db.dispatch_event: writes to the event log and broadcasts anevent:{action:"plugin"}frame to every control session for cross-tab live sync.tokio::task::block_in_place+Handle::current().block_on;try_currentguard returns a clean error in non-runtime contexts.fetch_urldeferred (issue marked it optional; requires apermissions: ["net"]manifest gate which is a separate follow-up).Test plan
cargo check -p meshcentral-webclean.cargo test -p meshcentral-web --lib plugin(8/8 still passing).host_db_put/host_db_getand observe the namespaced row inmeshcentral.db.json.Closes VS-14.
The plugin sandbox already exposed full host imports (`host_db_get`, `host_db_put`, `host_dispatch_event`, `host_log`, `host_get_version`) under `crates/meshcentral-plugins/src/host_imports.rs`; the gap was that `dispatch_plugin` handed it a `NoopBackend` that returned `Ok(None)` / `Ok(())` for everything. Plugins could call into them but the server never saw the calls. Adds `PluginHostBackend` (per-plugin, holds a clone of `AppState` and the plugin name): - `db_get(key)`: namespaces to `plugin/<name>/<key>` and reads from the configured sqlite database. - `db_put(doc)`: requires `_id`, namespaces it, persists via `meshcentral-db`. - `dispatch_event(payload)`: writes to the server-wide event log and broadcasts a `{action:"event", event:{action:"plugin", plugin, payload}}` frame to every control session for cross-tab live-sync. - `server_version()`: returns `meshcentral_plugins::host_imports::HOST_IMPORT_VERSION` so guests can probe. Backend methods are sync (wasmtime calls them from a sync context); the async DB / event-log calls are bridged via `tokio::task::block_in_place` + `Handle::current().block_on`, with a `try_current()` guard that returns a clean error if a future test wraps this in `current_thread`. `fetch_url` is intentionally deferred (the issue marks it as optional + capability-gated; landing it requires the per-plugin manifest `permissions: ["net"]` check that VS-6 added). #VS-14 State Done