Serve Norn plugin ABI over CultNet

This commit is contained in:
Meta Vens 2026-07-10 11:44:19 +01:00
commit ca18d54fa2
11 changed files with 1045 additions and 41 deletions

View file

@ -7,7 +7,10 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/GameCult/Norn"
[dependencies]
anyhow = "1"
base64 = "0.22"
cultnet-rs = { path = "../../../CultLib/packages/cultnet-rs" }
norn-rs = { path = "../norn-rs" }
rmp-serde = "1.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

View file

@ -213,6 +213,7 @@ fn measure(request: &PluginRequest) -> PluginResponse {
request,
json!({
"measurementKind": "graph-layout-metrics",
"measurementOutputs": ["nodeBounds", "edgeRoutes", "viewportBounds"],
"layoutSchema": "norn.graph.layout_result.v1",
"nodeBounds": node_bounds,
"edgeRoutes": edge_routes,

View file

@ -1,9 +1,71 @@
use std::io::{self, BufRead, Write};
use anyhow::{Result, anyhow};
use base64::{Engine, engine::general_purpose::STANDARD as BASE64};
use cultnet_rs::{CultNetMessage, CultNetOperationServer};
use norn_eve_plugin::{PLUGIN_ID, PluginRequest, PluginResponse, RESPONSE_SCHEMA, dispatch};
use serde_json::json;
fn main() -> io::Result<()> {
fn main() -> Result<()> {
if std::env::args().any(|argument| argument == "--stdio") {
return run_stdio().map_err(Into::into);
}
let host = std::env::var("EVE_PLUGIN_HOST").unwrap_or_else(|_| "127.0.0.1".into());
let port = std::env::var("EVE_PLUGIN_PORT")
.ok()
.and_then(|value| value.parse().ok())
.unwrap_or(0);
let mut server = CultNetOperationServer::bind("norn-graph-plugin", &host, port)?;
println!(
"{}",
json!({ "schema": "gamecult.eve.plugin_endpoint.v1", "pluginId": PLUGIN_ID, "endpoint": server.endpoint() })
);
loop {
server.serve_once(handle_operation)?;
}
}
fn handle_operation(message: CultNetMessage) -> Result<CultNetMessage> {
let CultNetMessage::OperationRequest {
message_id,
service_id,
operation,
payload_schema,
payload_encoding,
payload,
..
} = message
else {
return Err(anyhow!("expected operation request"));
};
if service_id != PLUGIN_ID
|| payload_schema != "gamecult.eve.plugin_abi.request.v1"
|| payload_encoding != "messagepack-base64"
{
return Err(anyhow!("unsupported Norn plugin operation envelope"));
}
let request: PluginRequest = rmp_serde::from_slice(&BASE64.decode(payload)?)?;
let response = dispatch(request);
let status = response.status.to_string();
let diagnostics = response
.diagnostics
.iter()
.map(|item| item.message.clone())
.collect();
Ok(CultNetMessage::OperationResponse {
message_id,
service_id,
operation,
status,
payload_schema: RESPONSE_SCHEMA.into(),
payload_encoding: "messagepack-base64".into(),
payload: BASE64.encode(rmp_serde::to_vec_named(&response)?),
diagnostics,
source_runtime_id: Some("norn-graph-plugin".into()),
})
}
fn run_stdio() -> io::Result<()> {
let stdin = io::stdin();
let mut stdout = io::stdout().lock();
for line in stdin.lock().lines() {