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 params: &[],
59}];
60
61impl TemplatePack {
62 pub fn new(runtime: KhiveRuntime) -> Self {
63 Self { runtime }
64 }
65 #[allow(dead_code)]
66 fn runtime(&self) -> &KhiveRuntime {
67 &self.runtime
68 }
69}
70
71struct TemplatePackFactory;
77
78impl khive_runtime::PackFactory for TemplatePackFactory {
79 fn name(&self) -> &'static str {
80 PACK_NAME
81 }
82 fn requires(&self) -> &'static [&'static str] {
83 &["kg"]
84 }
85 fn create(&self, runtime: KhiveRuntime) -> Box<dyn khive_runtime::PackRuntime> {
86 Box::new(TemplatePack::new(runtime))
87 }
88}
89
90inventory::submit! { khive_runtime::PackRegistration(&TemplatePackFactory) }
91
92#[async_trait]
95impl PackRuntime for TemplatePack {
96 fn name(&self) -> &str {
97 <TemplatePack as Pack>::NAME
98 }
99 fn note_kinds(&self) -> &'static [&'static str] {
100 <TemplatePack as Pack>::NOTE_KINDS
101 }
102 fn entity_kinds(&self) -> &'static [&'static str] {
103 <TemplatePack as Pack>::ENTITY_KINDS
104 }
105 fn handlers(&self) -> &'static [HandlerDef] {
106 &TEMPLATE_HANDLERS
107 }
108 fn requires(&self) -> &'static [&'static str] {
109 <TemplatePack as Pack>::REQUIRES
110 }
111
112 async fn dispatch(
114 &self,
115 verb: &str,
116 params: Value,
117 _registry: &VerbRegistry,
118 token: &NamespaceToken,
119 ) -> Result<Value, RuntimeError> {
120 match verb {
121 "my_verb" => handlers::handle_my_verb(self.runtime(), token, params).await,
122 _ => Err(RuntimeError::InvalidInput(format!(
123 "{PACK_NAME} pack does not handle verb {verb:?}"
124 ))),
125 }
126 }
127}