Skip to main content

gestalt/
lib.rs

1#![warn(rustdoc::broken_intra_doc_links)]
2#![doc = include_str!("../README.md")]
3
4mod agent;
5mod agent_manager;
6mod api;
7mod auth;
8mod auth_server;
9mod cache;
10mod cache_server;
11mod catalog;
12mod env;
13mod error;
14mod generated;
15/// IndexedDB-style datastore client and provider helpers.
16pub mod indexeddb;
17mod invoker;
18mod plugin_runtime;
19mod provider_server;
20mod router;
21mod rpc_status;
22/// Runtime entrypoints for serving Gestalt provider surfaces over Unix sockets.
23pub mod runtime;
24mod runtime_log_host;
25mod runtime_server;
26/// S3-compatible client and provider helpers.
27pub mod s3;
28mod secrets;
29mod secrets_server;
30/// OpenTelemetry helpers for provider-authored GenAI instrumentation.
31pub mod telemetry;
32mod workflow;
33mod workflow_manager;
34
35/// Generated protobuf and gRPC bindings for the Gestalt provider protocol.
36pub mod proto {
37    pub use crate::generated::v1;
38}
39
40pub use agent::{
41    AgentHost, AgentHostError, AgentProvider, ENV_AGENT_HOST_SOCKET, ENV_AGENT_HOST_SOCKET_TOKEN,
42};
43pub use agent_manager::{
44    AgentManager, AgentManagerError, ENV_AGENT_MANAGER_SOCKET, ENV_AGENT_MANAGER_SOCKET_TOKEN,
45};
46pub use api::{
47    Access, Credential, Host, Provider, Request, Response, RuntimeMetadata, Subject, ok,
48};
49pub use auth::{
50    AuthenticatedUser, AuthenticationProvider, BeginLoginRequest, BeginLoginResponse,
51    CompleteLoginRequest,
52};
53pub use cache::{
54    Cache, CacheEntry, CacheError, CacheProvider, CacheSetOptions, ENV_CACHE_SOCKET,
55    ENV_CACHE_SOCKET_TOKEN, cache_socket_env, cache_socket_token_env,
56};
57pub use catalog::{Catalog, CatalogOperation};
58pub use env::{CURRENT_PROTOCOL_VERSION, ENV_PROVIDER_SOCKET};
59pub use error::{Error, Result};
60pub use indexeddb::{
61    Cursor, CursorDirection, ENV_INDEXEDDB_SOCKET, IndexedDB, IndexedDBError, Transaction,
62    TransactionDurabilityHint, TransactionIndexClient, TransactionMode, TransactionObjectStore,
63    TransactionOptions, indexeddb_socket_env, indexeddb_socket_token_env,
64};
65pub use invoker::{
66    ENV_PLUGIN_INVOKER_SOCKET, ENV_PLUGIN_INVOKER_SOCKET_TOKEN, InvocationGrant, InvokeOptions,
67    PluginInvoker, PluginInvokerError,
68};
69pub use plugin_runtime::PluginRuntimeProvider;
70#[doc(hidden)]
71pub use provider_server::{OperationResult, ProviderServer};
72pub use router::{Operation, Router};
73pub use runtime_log_host::{
74    ENV_RUNTIME_LOG_HOST_SOCKET, ENV_RUNTIME_LOG_HOST_SOCKET_TOKEN, ENV_RUNTIME_SESSION_ID,
75    RuntimeLogHost, RuntimeLogHostError, RuntimeLogStream, runtime_session_id,
76};
77pub use s3::{
78    ENV_S3_SOCKET, ENV_S3_SOCKET_TOKEN, S3, S3Error, S3Provider, s3_socket_env, s3_socket_token_env,
79};
80pub use secrets::SecretsProvider;
81pub use tonic::codegen::async_trait;
82pub use workflow::{ENV_WORKFLOW_HOST_SOCKET, WorkflowHost, WorkflowHostError, WorkflowProvider};
83pub use workflow_manager::{
84    ENV_WORKFLOW_MANAGER_SOCKET, ENV_WORKFLOW_MANAGER_SOCKET_TOKEN, WorkflowManager,
85    WorkflowManagerError,
86};
87
88#[doc(hidden)]
89pub trait IntoRouterResult<P> {
90    fn into_router_result(self) -> Result<Router<P>>;
91}
92
93impl<P> IntoRouterResult<P> for Router<P> {
94    fn into_router_result(self) -> Result<Router<P>> {
95        Ok(self)
96    }
97}
98
99impl<P> IntoRouterResult<P> for Result<Router<P>> {
100    fn into_router_result(self) -> Result<Router<P>> {
101        self
102    }
103}
104
105#[doc(hidden)]
106/// Converts router-like values used by the export macros into a [`Router`].
107pub fn into_router_result<P, R>(router: R) -> Result<Router<P>>
108where
109    R: IntoRouterResult<P>,
110{
111    router.into_router_result()
112}
113
114/// Exports the integration-provider entrypoints expected by `gestaltd`.
115#[macro_export]
116macro_rules! export_provider {
117    (constructor = $constructor:path, router = $router:path $(,)?) => {
118        pub fn __gestalt_serve(name: &str) -> $crate::Result<()> {
119            let provider = std::sync::Arc::new($constructor());
120            let router = $crate::into_router_result($router())?.with_name(name);
121            $crate::runtime::run_provider(provider, router)
122        }
123
124        pub fn __gestalt_write_catalog(name: &str, path: &str) -> $crate::Result<()> {
125            let router = $crate::into_router_result($router())?.with_name(name);
126            $crate::runtime::write_catalog_path(&router, path)
127        }
128    };
129}
130
131/// Exports the authentication-provider entrypoint expected by `gestaltd`.
132#[macro_export]
133macro_rules! export_authentication_provider {
134    (constructor = $constructor:path $(,)?) => {
135        pub fn __gestalt_serve_authentication(_name: &str) -> $crate::Result<()> {
136            let provider = std::sync::Arc::new($constructor());
137            $crate::runtime::run_authentication_provider(provider)
138        }
139    };
140}
141
142/// Exports the cache-provider entrypoint expected by `gestaltd`.
143#[macro_export]
144macro_rules! export_cache_provider {
145    (constructor = $constructor:path $(,)?) => {
146        pub fn __gestalt_serve_cache(_name: &str) -> $crate::Result<()> {
147            let provider = std::sync::Arc::new($constructor());
148            $crate::runtime::run_cache_provider(provider)
149        }
150    };
151}
152
153/// Exports the secrets-provider entrypoint expected by `gestaltd`.
154#[macro_export]
155macro_rules! export_secrets_provider {
156    (constructor = $constructor:path $(,)?) => {
157        pub fn __gestalt_serve_secrets(_name: &str) -> $crate::Result<()> {
158            let provider = std::sync::Arc::new($constructor());
159            $crate::runtime::run_secrets_provider(provider)
160        }
161    };
162}
163
164/// Exports the S3-provider entrypoint expected by `gestaltd`.
165#[macro_export]
166macro_rules! export_s3_provider {
167    (constructor = $constructor:path $(,)?) => {
168        pub fn __gestalt_serve_s3(_name: &str) -> $crate::Result<()> {
169            let provider = std::sync::Arc::new($constructor());
170            $crate::runtime::run_s3_provider(provider)
171        }
172    };
173}
174
175/// Exports the plugin-runtime-provider entrypoint expected by `gestaltd`.
176#[macro_export]
177macro_rules! export_plugin_runtime_provider {
178    (constructor = $constructor:path $(,)?) => {
179        pub fn __gestalt_serve_runtime(_name: &str) -> $crate::Result<()> {
180            let provider = std::sync::Arc::new($constructor());
181            $crate::runtime::run_plugin_runtime_provider(provider)
182        }
183    };
184}
185
186/// Exports the workflow-provider entrypoint expected by `gestaltd`.
187#[macro_export]
188macro_rules! export_workflow_provider {
189    (constructor = $constructor:path $(,)?) => {
190        pub fn __gestalt_serve_workflow(_name: &str) -> $crate::Result<()> {
191            let provider = std::sync::Arc::new($constructor());
192            $crate::runtime::run_workflow_provider(provider)
193        }
194    };
195}
196
197/// Exports the agent-provider entrypoint expected by `gestaltd`.
198#[macro_export]
199macro_rules! export_agent_provider {
200    (constructor = $constructor:path $(,)?) => {
201        pub fn __gestalt_serve_agent(_name: &str) -> $crate::Result<()> {
202            let provider = std::sync::Arc::new($constructor());
203            $crate::runtime::run_agent_provider(provider)
204        }
205    };
206}