plugin: fix instance lifecycle blockers
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
[workspace]
|
||||
|
||||
[package]
|
||||
name = "example-yoi-instance-plugin"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user