Skip to main content

zeroclaw_plugins/
wasm_channel.rs

1//! Bridge between WASM plugins and the Channel trait.
2//!
3//! **Status:** Placeholder — `send` and `listen` are not yet wired to the
4//! Extism runtime.  Channel plugin support is a Phase 3 (v0.9.0) deliverable
5//! per the [Intentional Architecture RFC](https://github.com/zeroclaw-labs/zeroclaw/wiki/14.1-Intentional-Architecture).
6//! See `wasm_tool.rs` and `runtime.rs` for the working tool plugin bridge.
7
8use async_trait::async_trait;
9use zeroclaw_api::channel::{Channel, ChannelMessage, SendMessage};
10
11/// A channel backed by a WASM plugin.
12pub struct WasmChannel {
13    name: String,
14    plugin_name: String,
15}
16
17impl WasmChannel {
18    pub fn new(name: String, plugin_name: String) -> Self {
19        Self { name, plugin_name }
20    }
21}
22
23impl ::zeroclaw_api::attribution::Attributable for WasmChannel {
24    fn role(&self) -> ::zeroclaw_api::attribution::Role {
25        ::zeroclaw_api::attribution::Role::Channel(
26            ::zeroclaw_api::attribution::ChannelKind::Webhook,
27        )
28    }
29    fn alias(&self) -> &str {
30        &self.name
31    }
32}
33
34#[async_trait]
35impl Channel for WasmChannel {
36    fn name(&self) -> &str {
37        &self.name
38    }
39
40    async fn send(&self, message: &SendMessage) -> anyhow::Result<()> {
41        // TODO: Wire to WASM plugin send function
42        ::zeroclaw_log::record!(
43            WARN,
44            ::zeroclaw_log::Event::new(module_path!(), ::zeroclaw_log::Action::Note)
45                .with_outcome(::zeroclaw_log::EventOutcome::Unknown),
46            &format!(
47                "WasmChannel '{}' (plugin: {}) send not yet connected: {}",
48                self.name, self.plugin_name, message.content
49            )
50        );
51        Ok(())
52    }
53
54    async fn listen(&self, _tx: tokio::sync::mpsc::Sender<ChannelMessage>) -> anyhow::Result<()> {
55        // TODO: Wire to WASM plugin receive/listen function
56        ::zeroclaw_log::record!(
57            WARN,
58            ::zeroclaw_log::Event::new(module_path!(), ::zeroclaw_log::Action::Note)
59                .with_outcome(::zeroclaw_log::EventOutcome::Unknown),
60            &format!(
61                "WasmChannel '{}' (plugin: {}) listen not yet connected",
62                self.name, self.plugin_name
63            )
64        );
65        Ok(())
66    }
67}