plugin: fix instance lifecycle blockers

This commit is contained in:
2026-06-20 23:42:44 +09:00
parent 147a600577
commit 870bcc76a5
4 changed files with 507 additions and 120 deletions
@@ -1,6 +1,14 @@
use serde_json::{json, Value};
use yoi_plugin_pdk::wit_bindgen;
use yoi_plugin_pdk::{export_plugin_instance, Plugin, PluginIngressEvent, PluginStatus, ToolOutput};
wit_bindgen::generate!({
world: "instance",
path: "../../../../resources/plugin/wit",
generate_all,
runtime_path: "yoi_plugin_pdk::wit_bindgen::rt",
});
struct ExamplePlugin {
calls: u64,
}
@@ -12,14 +20,21 @@ impl Plugin for ExamplePlugin {
fn handle_tool(&mut self, name: &str, input: Value) -> yoi_plugin_pdk::Result<ToolOutput> {
self.calls += 1;
Ok(ToolOutput::text(json!({
"tool": name,
"calls": self.calls,
"input": input
}).to_string()))
ToolOutput::json(
format!("{name} handled by shared instance"),
json!({
"tool": name,
"calls": self.calls,
"input": input
}),
)
}
fn handle_ingress(&mut self, name: &str, event: PluginIngressEvent) -> yoi_plugin_pdk::Result<Value> {
fn handle_ingress(
&mut self,
name: &str,
event: PluginIngressEvent,
) -> yoi_plugin_pdk::Result<Value> {
Ok(json!({
"ingress": name,
"kind": event.kind,
@@ -34,4 +49,4 @@ impl Plugin for ExamplePlugin {
}
}
export_plugin_instance!(ExamplePlugin);
export_plugin_instance!(ExamplePluginComponent, ExamplePlugin);