khive_pack_template/
lib.rs1pub mod handlers;
20pub mod vocab;
21
22use async_trait::async_trait;
23use serde_json::Value;
24
25use khive_runtime::pack::PackRuntime;
26use khive_runtime::{KhiveRuntime, NamespaceToken, RuntimeError, VerbRegistry};
27use khive_types::{HandlerDef, Pack, Visibility};
28
29const PACK_NAME: &str = "template";
31
32pub struct TemplatePack {
34 runtime: KhiveRuntime,
35}
36
37impl Pack for TemplatePack {
38 const NAME: &'static str = PACK_NAME;
39 const NOTE_KINDS: &'static [&'static str] = vocab::NOTE_KINDS;
41 const ENTITY_KINDS: &'static [&'static str] = vocab::ENTITY_KINDS;
43 const HANDLERS: &'static [HandlerDef] = &TEMPLATE_HANDLERS;
45 const REQUIRES: &'static [&'static str] = &["kg"];
47}
48
49static TEMPLATE_HANDLERS: [HandlerDef; 1] = [HandlerDef {
54 name: "my_verb",
55 description: "Replace with your verb's description.",
56 visibility: Visibility::Verb,
57 category: khive_types::VerbCategory::Directive,
58}];
59
60impl TemplatePack {
61 pub fn new(runtime: KhiveRuntime) -> Self {
62 Self { runtime }
63 }
64 #[allow(dead_code)]
65 fn runtime(&self) -> &KhiveRuntime {
66 &self.runtime
67 }
68}
69
70struct TemplatePackFactory;
76
77impl khive_runtime::PackFactory for TemplatePackFactory {
78 fn name(&self) -> &'static str {
79 PACK_NAME
80 }
81 fn requires(&self) -> &'static [&'static str] {
82 &["kg"]
83 }
84 fn create(&self, runtime: KhiveRuntime) -> Box<dyn khive_runtime::PackRuntime> {
85 Box::new(TemplatePack::new(runtime))
86 }
87}
88
89inventory::submit! { khive_runtime::PackRegistration(&TemplatePackFactory) }
90
91#[async_trait]
94impl PackRuntime for TemplatePack {
95 fn name(&self) -> &str {
96 <TemplatePack as Pack>::NAME
97 }
98 fn note_kinds(&self) -> &'static [&'static str] {
99 <TemplatePack as Pack>::NOTE_KINDS
100 }
101 fn entity_kinds(&self) -> &'static [&'static str] {
102 <TemplatePack as Pack>::ENTITY_KINDS
103 }
104 fn handlers(&self) -> &'static [HandlerDef] {
105 &TEMPLATE_HANDLERS
106 }
107 fn requires(&self) -> &'static [&'static str] {
108 <TemplatePack as Pack>::REQUIRES
109 }
110
111 async fn dispatch(
113 &self,
114 verb: &str,
115 params: Value,
116 _registry: &VerbRegistry,
117 token: &NamespaceToken,
118 ) -> Result<Value, RuntimeError> {
119 match verb {
120 "my_verb" => handlers::handle_my_verb(self.runtime(), token, params).await,
121 _ => Err(RuntimeError::InvalidInput(format!(
122 "{PACK_NAME} pack does not handle verb {verb:?}"
123 ))),
124 }
125 }
126}