Skip to main content

gestalt/
lib.rs

1#![warn(rustdoc::broken_intra_doc_links)]
2#![deny(missing_docs)]
3#![doc = include_str!("../README.md")]
4
5/// Generated Agent client and native types.
6pub mod agent;
7mod agent_provider;
8mod api;
9/// Generated App and AppProvider client and native types.
10pub mod app;
11/// Generated shared runtime for the sdkgen clients.
12mod auth;
13/// Generated Authorization client and native types.
14pub mod authorization;
15/// Generated Cache client and native types.
16pub mod cache;
17mod cache_provider;
18mod cache_server;
19mod catalog;
20mod codec;
21mod env;
22mod error;
23/// Generated ExternalCredentials client and native types.
24pub mod external_credential;
25/// Generated Identity client and native types.
26pub mod identity;
27mod identity_server;
28/// Public gestaltd transport client for external applications.
29pub mod public;
30/// Generated RemoteManagement client and native types.
31pub mod remote;
32// The prost wire module is reachable only through the doc-hidden proto
33// escape hatch; its items are not part of the documented surface.
34#[allow(missing_docs)]
35mod generated;
36/// Generated IndexedDB client and native types.
37pub mod indexeddb;
38mod indexeddb_provider;
39mod indexeddb_query_codec;
40/// Decoded app invocation results and the canonical invoke error.
41pub mod invoke_support;
42mod protocol;
43mod provider_server;
44mod router;
45mod rpc_status;
46pub mod rpc_support;
47/// Generated ProviderLifecycle client and native types.
48pub mod runtime;
49/// Runtime entrypoints for serving Gestalt provider surfaces over Unix sockets.
50pub mod runtime_impl;
51/// Generated Runtime client and native types.
52pub mod runtime_provider;
53mod runtime_provider_impl;
54mod runtime_server;
55/// Generated S3 client and native types.
56pub mod s3;
57/// S3-compatible provider contract and native provider types.
58pub mod s3_provider;
59/// Generated Secrets client and native types.
60pub mod secrets;
61mod secrets_provider;
62mod secrets_server;
63mod serde_duration;
64mod serde_time;
65/// OpenTelemetry helpers for provider-authored GenAI instrumentation.
66pub mod telemetry;
67/// Generated Test client and native types.
68pub mod test;
69mod workflow_authoring;
70#[path = "workflow.rs"]
71mod workflow_generated;
72/// Generated workflow clients and native types plus typed workflow authoring helpers.
73pub mod workflow {
74    pub use crate::workflow_authoring::*;
75    pub use crate::workflow_generated::*;
76}
77/// Workflow provider contract and native workflow types.
78pub mod workflow_provider;
79
80#[doc(hidden)]
81pub mod proto {
82    pub use crate::generated::v1;
83}
84
85pub use agent::Agent;
86pub use agent_provider::{
87    AgentCatalogToolConfig, AgentExecutionStatus, AgentInteraction, AgentInteractionState,
88    AgentInteractionType, AgentJson, AgentMessage, AgentMessagePart, AgentMessagePartImageRef,
89    AgentMessagePartToolCall, AgentMessagePartToolResult, AgentMessagePartType, AgentOutput,
90    AgentPreparedWorkspace, AgentProvider, AgentProviderCapabilities, AgentSession,
91    AgentSessionStartConfig, AgentSessionStartHook, AgentSessionStartHookOutput, AgentSessionState,
92    AgentStructuredOutput, AgentTextOutput, AgentToolAnnotations, AgentToolConfig,
93    AgentToolConfigSource, AgentToolRef, AgentToolSourceMode, AgentTurn, AgentTurnDisplay,
94    AgentTurnEvent, AgentTurnOutput, AgentTurnStructuredOutput, AgentTurnTextOutput,
95    AgentWorkspace, AgentWorkspaceGitCheckout, CancelAgentProviderTurnRequest,
96    CreateAgentProviderSessionRequest, CreateAgentProviderTurnRequest,
97    GetAgentProviderCapabilitiesRequest, GetAgentProviderInteractionRequest,
98    GetAgentProviderSessionRequest, GetAgentProviderTurnRequest,
99    ListAgentProviderInteractionsRequest, ListAgentProviderInteractionsResponse,
100    ListAgentProviderSessionsRequest, ListAgentProviderSessionsResponse,
101    ListAgentProviderTurnEventsRequest, ListAgentProviderTurnEventsResponse,
102    ListAgentProviderTurnsRequest, ListAgentProviderTurnsResponse, ListedAgentTool,
103    ResolveAgentProviderInteractionRequest, UpdateAgentProviderSessionRequest, new_agent_image_ref,
104    new_agent_message, new_agent_message_part, new_agent_tool_call, new_agent_tool_ref,
105    new_agent_tool_result,
106};
107pub use api::parse_subject_id;
108pub use api::{
109    Access, Credential, HTTPSubjectRequest, Host, Provider, Request, Response, RuntimeMetadata,
110    Subject, current_native_request_context, current_request_context, ok, with_request_context,
111};
112pub use app::App;
113pub use auth::{
114    GRANT_TYPE_AUTHORIZATION_CODE, GRANT_TYPE_TOKEN_EXCHANGE, IdentityCallContext,
115    IdentityProvider, SUBJECT_TOKEN_TYPE_ACCESS_TOKEN,
116};
117pub use cache::Cache;
118pub use cache_provider::{CacheEntry, CacheProvider, CacheSetOptions};
119pub use catalog::{
120    Catalog, CatalogOperation, CatalogParameter, OperationAnnotations, OperationResponseSpec,
121    StreamResponseSpec, UnaryResponseSpec,
122};
123pub use env::{
124    CURRENT_PROTOCOL_VERSION, ENV_HOST_SERVICE_SOCKET, ENV_HOST_SERVICE_TOKEN, ENV_PROVIDER_SOCKET,
125};
126pub use error::{Error, Result};
127pub use indexeddb_provider::{
128    Cursor, CursorApi, CursorDirection, Index, IndexApi, IndexSchema, IndexedDB, IndexedDBApi,
129    IndexedDBCursorSnapshot, IndexedDBCursorSnapshotEntry, IndexedDBError,
130    IndexedDBOpenCursorRequest, Key, KeyRange, ObjectStore, ObjectStoreApi, ObjectStoreSchema,
131    Query, Record, Transaction, TransactionApi, TransactionDurabilityHint, TransactionIndex,
132    TransactionIndexApi, TransactionMode, TransactionObjectStore, TransactionObjectStoreApi,
133    TransactionOptions, compare_indexeddb_values, compare_keys, indexeddb_range_bounds,
134    key_in_range, match_query, new_indexeddb_cursor_snapshot,
135};
136pub use invoke_support::{
137    InvokeError, InvokeResultError, decode_app_result, decode_graphql_result, error_for_status,
138    is_success,
139};
140#[doc(hidden)]
141pub use provider_server::{OperationResult, ProviderServer};
142pub use router::{Operation, Router};
143pub use runtime_provider_impl::{
144    GetRuntimeSessionRequest, HostedApp, ListRuntimeSessionsRequest, ListRuntimeSessionsResponse,
145    PrepareRuntimeWorkspaceRequest, PrepareRuntimeWorkspaceResponse, RemoveRuntimeWorkspaceRequest,
146    RuntimeEgressMode, RuntimeImagePullAuth, RuntimeProvider, RuntimeSession,
147    RuntimeSessionLifecycle, RuntimeSupport, StartHostedAppRequest, StartRuntimeSessionRequest,
148    StopRuntimeSessionRequest,
149};
150pub use s3::S3;
151pub use s3_provider::{
152    S3Provider, S3ReadObjectFrame, S3ReadObjectStream, S3WriteObjectFrame, S3WriteObjectStream,
153};
154pub use secrets_provider::SecretsProvider;
155pub use tonic::codegen::async_trait;
156pub use workflow::Workflow;
157pub use workflow_provider::{
158    ApplyWorkflowProviderDefinitionRequest, BoundWorkflowTarget, CancelWorkflowProviderRunRequest,
159    DeleteWorkflowProviderDefinitionRequest, DeliverWorkflowProviderEventRequest,
160    GetWorkflowProviderDefinitionRequest, GetWorkflowProviderRunEventsRequest,
161    GetWorkflowProviderRunEventsResponse, GetWorkflowProviderRunOutputRequest,
162    GetWorkflowProviderRunOutputResponse, GetWorkflowProviderRunRequest,
163    ListWorkflowProviderDefinitionsRequest, ListWorkflowProviderDefinitionsResponse,
164    ListWorkflowProviderRunsRequest, ListWorkflowProviderRunsResponse,
165    SetWorkflowProviderActivationPausedRequest, SetWorkflowProviderDefinitionPausedRequest,
166    SignalOrStartWorkflowProviderRunRequest, SignalWorkflowProviderRunRequest,
167    SignalWorkflowRunResponse, StartWorkflowProviderRunRequest, WorkflowActivation,
168    WorkflowAgentMessage, WorkflowArray, WorkflowDefinition, WorkflowDefinitionSpec,
169    WorkflowEvalContext, WorkflowEvalResult, WorkflowEvent, WorkflowEventActivation,
170    WorkflowEventMatch, WorkflowEventTriggerInvocation, WorkflowExecutionRequest, WorkflowJson,
171    WorkflowManualTrigger, WorkflowObject, WorkflowPathSource, WorkflowProvider, WorkflowRun,
172    WorkflowRunEvent, WorkflowRunStatus, WorkflowRunTrigger, WorkflowScheduleActivation,
173    WorkflowScheduleTrigger, WorkflowSignal, WorkflowStep, WorkflowStepAction,
174    WorkflowStepAgentTurn, WorkflowStepAppCall, WorkflowStepAttempt, WorkflowStepExecution,
175    WorkflowStepInputSource, WorkflowStepOutputSource, WorkflowStepStatus, WorkflowStepWhen,
176    WorkflowText, WorkflowValue, evaluate_workflow_value, latest_workflow_signal,
177    new_bound_workflow_target, new_bound_workflow_target_from_target, new_workflow_agent_message,
178    new_workflow_definition, new_workflow_definition_spec, new_workflow_event,
179    new_workflow_event_from_event, new_workflow_event_match, new_workflow_run,
180    new_workflow_run_from_run, new_workflow_signal, new_workflow_signal_from_signal,
181    new_workflow_step, new_workflow_step_agent_turn, new_workflow_step_app_call,
182    new_workflow_step_when, new_workflow_text, new_workflow_value, path_value,
183    render_workflow_template, workflow_event_input_from_event,
184    workflow_event_match_input_from_match, workflow_run_trigger_input_from_trigger,
185    workflow_signal_input_from_signal, workflow_step_agent_turn_input_from_turn,
186    workflow_step_app_call_input_from_call, workflow_step_input_from_step, workflow_value_array,
187    workflow_value_input, workflow_value_input_from_value, workflow_value_literal,
188    workflow_value_object, workflow_value_signal, workflow_value_step_input,
189    workflow_value_step_output, workflow_value_template,
190};
191#[doc(hidden)]
192pub trait IntoRouterResult<P> {
193    fn into_router_result(self) -> Result<Router<P>>;
194}
195
196impl<P> IntoRouterResult<P> for Router<P> {
197    fn into_router_result(self) -> Result<Router<P>> {
198        Ok(self)
199    }
200}
201
202impl<P> IntoRouterResult<P> for Result<Router<P>> {
203    fn into_router_result(self) -> Result<Router<P>> {
204        self
205    }
206}
207
208#[doc(hidden)]
209/// Converts router-like values used by the export macros into a [`Router`].
210pub fn into_router_result<P, R>(router: R) -> Result<Router<P>>
211where
212    R: IntoRouterResult<P>,
213{
214    router.into_router_result()
215}
216
217/// Exports the integration-provider entrypoints expected by `gestaltd`.
218#[macro_export]
219macro_rules! export_provider {
220    (constructor = $constructor:path, router = $router:path $(,)?) => {
221        pub fn __gestalt_serve(name: &str) -> $crate::Result<()> {
222            let provider = std::sync::Arc::new($constructor());
223            let router = $crate::into_router_result($router())?.with_name(name);
224            $crate::runtime_impl::run_provider(provider, router)
225        }
226
227        pub fn __gestalt_write_catalog(name: &str, path: &str) -> $crate::Result<()> {
228            let router = $crate::into_router_result($router())?.with_name(name);
229            $crate::runtime_impl::write_catalog_path(&router, path)
230        }
231
232        pub fn main() {
233            let name = std::env::var("GESTALT_APP_NAME").unwrap_or_else(|_| "provider".to_string());
234            let result = match std::env::var("GESTALT_APP_WRITE_CATALOG") {
235                Ok(path) => __gestalt_write_catalog(&name, &path),
236                Err(_) => __gestalt_serve(&name),
237            };
238            if let Err(error) = result {
239                eprintln!("error: {error}");
240                std::process::exit(1);
241            }
242        }
243    };
244}
245
246#[doc(hidden)]
247#[macro_export]
248macro_rules! __gestalt_kind_provider_main {
249    ($serve:ident) => {
250        pub fn main() {
251            let name = std::env::var("GESTALT_APP_NAME").unwrap_or_else(|_| "provider".to_string());
252            if let Err(error) = $serve(&name) {
253                eprintln!("error: {error}");
254                std::process::exit(1);
255            }
256        }
257    };
258}
259
260/// Exports the identity-provider entrypoint expected by `gestaltd`.
261#[macro_export]
262macro_rules! export_identity_provider {
263    (constructor = $constructor:path $(,)?) => {
264        pub fn __gestalt_serve_identity(_name: &str) -> $crate::Result<()> {
265            let provider = std::sync::Arc::new($constructor());
266            $crate::runtime_impl::run_identity_provider(provider)
267        }
268
269        $crate::__gestalt_kind_provider_main!(__gestalt_serve_identity);
270    };
271}
272
273/// Exports the cache-provider entrypoint expected by `gestaltd`.
274#[macro_export]
275macro_rules! export_cache_provider {
276    (constructor = $constructor:path $(,)?) => {
277        pub fn __gestalt_serve_cache(_name: &str) -> $crate::Result<()> {
278            let provider = std::sync::Arc::new($constructor());
279            $crate::runtime_impl::run_cache_provider(provider)
280        }
281
282        $crate::__gestalt_kind_provider_main!(__gestalt_serve_cache);
283    };
284}
285
286/// Exports the secrets-provider entrypoint expected by `gestaltd`.
287#[macro_export]
288macro_rules! export_secrets_provider {
289    (constructor = $constructor:path $(,)?) => {
290        pub fn __gestalt_serve_secrets(_name: &str) -> $crate::Result<()> {
291            let provider = std::sync::Arc::new($constructor());
292            $crate::runtime_impl::run_secrets_provider(provider)
293        }
294
295        $crate::__gestalt_kind_provider_main!(__gestalt_serve_secrets);
296    };
297}
298
299/// Exports the S3-provider entrypoint expected by `gestaltd`.
300#[macro_export]
301macro_rules! export_s3_provider {
302    (constructor = $constructor:path $(,)?) => {
303        pub fn __gestalt_serve_s3(_name: &str) -> $crate::Result<()> {
304            let provider = std::sync::Arc::new($constructor());
305            $crate::runtime_impl::run_s3_provider(provider)
306        }
307
308        $crate::__gestalt_kind_provider_main!(__gestalt_serve_s3);
309    };
310}
311
312/// Exports the runtime-provider entrypoint expected by `gestaltd`.
313#[macro_export]
314macro_rules! export_runtime_provider {
315    (constructor = $constructor:path $(,)?) => {
316        pub fn __gestalt_serve_runtime(_name: &str) -> $crate::Result<()> {
317            let provider = std::sync::Arc::new($constructor());
318            $crate::runtime_impl::run_runtime_provider(provider)
319        }
320
321        $crate::__gestalt_kind_provider_main!(__gestalt_serve_runtime);
322    };
323}
324
325/// Exports the workflow-provider entrypoint expected by `gestaltd`.
326#[macro_export]
327macro_rules! export_workflow_provider {
328    (constructor = $constructor:path $(,)?) => {
329        pub fn __gestalt_serve_workflow(_name: &str) -> $crate::Result<()> {
330            let provider = std::sync::Arc::new($constructor());
331            $crate::runtime_impl::run_workflow_provider(provider)
332        }
333
334        $crate::__gestalt_kind_provider_main!(__gestalt_serve_workflow);
335    };
336}
337
338/// Exports the agent-provider entrypoint expected by `gestaltd`.
339#[macro_export]
340macro_rules! export_agent_provider {
341    (constructor = $constructor:path $(,)?) => {
342        pub fn __gestalt_serve_agent(_name: &str) -> $crate::Result<()> {
343            let provider = std::sync::Arc::new($constructor());
344            $crate::runtime_impl::run_agent_provider(provider)
345        }
346
347        $crate::__gestalt_kind_provider_main!(__gestalt_serve_agent);
348    };
349}