Skip to main content

mesh_llm_plugin/
lib.rs

1//! Shared runtime and protocol helpers for mesh-llm plugins.
2//!
3//! Plugins declare services in their manifest and implement typed service
4//! handlers. MCP and HTTP are host-side projections over those services.
5
6mod context;
7mod dsl;
8mod error;
9mod helpers;
10mod internal_rpc;
11mod io;
12mod manifest;
13mod runtime;
14mod simple_plugin;
15
16pub use async_trait::async_trait;
17pub use context::PluginContext;
18pub use dsl::DeclarativePluginBuilder;
19pub use error::{PluginError, PluginResult, PluginRpcResult, STARTUP_DISABLED_ERROR_CODE};
20pub use helpers::{
21    BulkTransferSequence, CompletionFuture, CompletionRouter, JsonOperationFuture, OperationFuture,
22    OperationRequest, OperationRouter, PromptFuture, PromptRouter, ResourceFuture, ResourceRouter,
23    SubscriptionSet, TaskCancelFuture, TaskInfoFuture, TaskListFuture, TaskRecord,
24    TaskResultFuture, TaskRouter, TaskStore, accept_bulk_transfer_message, bulk_transfer_message,
25    bulk_transfer_sequence, cancel_task_result, channel_message, complete_result,
26    empty_object_schema, get_prompt_result, get_task_payload_result, get_task_result, json_bytes,
27    json_channel_message, json_reply_channel_message, json_response, json_schema_for,
28    json_schema_operation, json_string, list_prompts, list_resource_templates, list_resources,
29    list_tasks, list_tools, operation_error, operation_with_schema, parse_get_prompt_request,
30    parse_optional_json, parse_read_resource_request, parse_rpc_params, plugin_server_info,
31    plugin_server_info_full, prompt, prompt_argument, read_resource_result, resource_template,
32    structured_tool_result, task, text_resource,
33};
34pub use io::{
35    LocalListener, LocalStream, bind_side_stream, connect_from_env, connect_side_stream,
36    read_envelope, send_bulk_transfer_message, send_channel_message, write_envelope,
37};
38pub mod http {
39    pub use crate::dsl::http::{delete, get, patch, post, put};
40}
41pub mod inference {
42    pub use crate::dsl::inference::{openai_http, provider};
43}
44pub mod mesh {
45    pub use crate::manifest::mesh_channel as channel;
46}
47pub mod events {
48    pub use crate::manifest::{
49        mesh_event_local_accepting as local_accepting, mesh_event_local_standby as local_standby,
50        mesh_event_mesh_id_updated as mesh_id_updated, mesh_event_peer_down as peer_down,
51        mesh_event_peer_up as peer_up, mesh_event_peer_updated as peer_updated,
52    };
53}
54pub use manifest::{
55    CompletionBuilder, EndpointBuilder, HttpBindingBuilder, ManifestEntry, OperationBuilder,
56    PluginConfigObjectPropertyBuilder, PluginConfigSchemaBuilder, PluginConfigSettingBuilder,
57    PluginManifestBuilder, PluginWebUiBuilder, PluginWebUiBundleBuilder,
58    PluginWebUiConfigSectionBuilder, PluginWebUiPageBuilder, PromptBuilder, ResourceBuilder,
59    ResourceTemplateBuilder, capability, completion, config_array, config_boolean, config_enum,
60    config_float, config_integer, config_object, config_object_property, config_path,
61    config_schema, config_setting, config_string, config_url, constraint_allowed_values,
62    constraint_non_empty, constraint_positive, constraint_range, constraint_requires, http_binding,
63    http_delete, http_get, http_patch, http_post, http_put, mcp_http_endpoint, mcp_stdio_endpoint,
64    mcp_tcp_endpoint, mcp_unix_socket_endpoint, mesh_channel, mesh_event_local_accepting,
65    mesh_event_local_standby, mesh_event_mesh_id_updated, mesh_event_peer_down, mesh_event_peer_up,
66    mesh_event_peer_updated, mesh_event_subscription, openai_http_inference_endpoint, operation,
67    package_manifest_json, plugin_manifest, prompt_service, resource, resource_template_service,
68    web_ui, web_ui_bundle, web_ui_config_section, web_ui_page,
69};
70pub mod mcp {
71    pub use crate::dsl::mcp::{
72        completion, external_http, external_stdio, external_tcp, external_unix_socket, prompt,
73        resource, resource_template, tool,
74    };
75}
76pub use runtime::{
77    InternalRpcPlugin, InternalRpcPluginBuilder, MeshVisibility, Plugin, PluginInitializeRequest,
78    PluginMetadata, PluginRuntime, PluginStartupPolicy, SimplePlugin,
79};
80
81#[allow(dead_code)]
82pub mod proto {
83    include!(concat!(env!("OUT_DIR"), "/meshllm.plugin.v1.rs"));
84}
85
86pub const PROTOCOL_VERSION: u32 = 2;
87
88#[macro_export]
89macro_rules! plugin_manifest {
90    ($($item:expr_2021),* $(,)?) => {{
91        let mut builder = $crate::plugin_manifest();
92        $(
93            builder = builder.item($item);
94        )*
95        builder.build()
96    }};
97}
98
99#[macro_export]
100macro_rules! plugin {
101    (
102        metadata: $metadata:expr_2021,
103        $(startup_policy: $startup_policy:expr_2021,)?
104        $(provides: [$($provide:expr_2021),* $(,)?],)?
105        $(config: [$($config:expr_2021),* $(,)?],)?
106        $(web_ui: [$($web_ui:expr_2021),* $(,)?],)?
107        $(mesh: [$($mesh:expr_2021),* $(,)?],)?
108        $(events: [$($event:expr_2021),* $(,)?],)?
109        $(mcp: [$($mcp:expr_2021),* $(,)?],)?
110        $(http: [$($http:expr_2021),* $(,)?],)?
111        $(inference: [$($inference:expr_2021),* $(,)?],)?
112        $(health: $health:expr_2021,)?
113        $(on_initialized: $on_initialized:expr_2021,)?
114        $(on_channel_message: $on_channel_message:expr_2021,)?
115        $(on_mesh_event: $on_mesh_event:expr_2021,)?
116    ) => {{
117        let mut builder = $crate::DeclarativePluginBuilder::new($metadata);
118        $(
119            builder = builder.startup_policy($startup_policy);
120        )?
121        $(
122            $(
123                builder = builder.provide($provide);
124            )*
125        )?
126        $(
127            $(
128                builder = builder.config_item($config);
129            )*
130        )?
131        $(
132            $(
133                builder = builder.web_ui_item($web_ui);
134            )*
135        )?
136        $(
137            $(
138                builder = builder.mesh_item($mesh);
139            )*
140        )?
141        $(
142            $(
143                builder = builder.event_item($event);
144            )*
145        )?
146        $(
147            $(
148                builder = builder.mcp_item($mcp);
149            )*
150        )?
151        $(
152            $(
153                builder = builder.http_item($http);
154            )*
155        )?
156        $(
157            $(
158                builder = builder.inference_item($inference);
159            )*
160        )?
161        $(
162            builder = builder.customize(move |plugin| plugin.with_health($health));
163        )?
164        $(
165            builder = builder.customize(move |plugin| plugin.on_initialized($on_initialized));
166        )?
167        $(
168            builder = builder.customize(move |plugin| plugin.on_channel_message($on_channel_message));
169        )?
170        $(
171            builder = builder.customize(move |plugin| plugin.on_mesh_event($on_mesh_event));
172        )?
173        builder.build()
174    }};
175}