component_dwbase/
lib.rs

1//! component-dwbase: Greentic component shim for DWBase.
2//!
3//! Implements `greentic:component@0.5.0` using greentic-interfaces-guest. DWBase
4//! logic stays internal; this adapter currently echoes inputs and can be
5//! extended to call into DWBase APIs.
6
7use greentic_interfaces_guest::component::node::{self, Guest, InvokeResult, StreamEvent};
8use serde_json::json;
9
10pub struct DwbaseComponent;
11
12impl Guest for DwbaseComponent {
13    fn get_manifest() -> String {
14        json!({
15            "name": "dwbase",
16            "version": env!("CARGO_PKG_VERSION"),
17            "description": "DWBase component shim (greentic:component@0.5.0)",
18            "capabilities": ["invoke", "invoke-stream"],
19            "tags": ["dwbase", "memory", "agent"],
20        })
21        .to_string()
22    }
23
24    fn on_start(_ctx: node::ExecCtx) -> Result<node::LifecycleStatus, String> {
25        Ok(node::LifecycleStatus::Ok)
26    }
27
28    fn on_stop(_ctx: node::ExecCtx, _reason: String) -> Result<node::LifecycleStatus, String> {
29        Ok(node::LifecycleStatus::Ok)
30    }
31
32    fn invoke(_ctx: node::ExecCtx, op: String, input: String) -> InvokeResult {
33        // Minimal adapter: echo the request; extend to call DWBase APIs per op.
34        let payload = json!({
35            "op": op,
36            "input": input,
37            "status": "ok",
38        });
39        InvokeResult::Ok(payload.to_string())
40    }
41
42    fn invoke_stream(_ctx: node::ExecCtx, op: String, input: String) -> Vec<StreamEvent> {
43        vec![
44            StreamEvent::Data(json!({"op": op, "input": input, "chunk": 0}).to_string()),
45            StreamEvent::Done,
46        ]
47    }
48}
49
50greentic_interfaces_guest::export_component_node!(DwbaseComponent);