Skip to main content

gestalt/
app.rs

1// Code generated by sdkgen. DO NOT EDIT.
2
3//! Generated native types and clients for app.proto.
4
5use crate::codec::app::{
6    from_wire_get_session_catalog_response, from_wire_operation_result,
7    from_wire_provider_metadata, from_wire_resolve_http_subject_response,
8    from_wire_start_provider_response, to_wire_app_invoke_graphql_request,
9    to_wire_app_invoke_request, to_wire_execute_request, to_wire_get_session_catalog_request,
10    to_wire_resolve_http_subject_request, to_wire_start_provider_request,
11};
12use crate::codec::host_service::{HostServiceChannel, connect_host_service, plain_channel};
13use crate::generated::v1;
14use crate::invoke_support::{InvokeError, decode_app_result};
15use crate::rpc_support::GestaltError;
16
17/// Open enum for `gestalt.provider.v1.ConnectionMode`; unknown numeric values are preserved.
18pub type ConnectionMode = i32;
19
20/// ConnectionMode describes which credential sources a provider accepts.
21///
22/// Named values of `ConnectionMode`.
23pub mod connection_mode {
24    /// CONNECTION_MODE_UNSPECIFIED.
25    pub const CONNECTION_MODE_UNSPECIFIED: i32 = 0;
26    /// CONNECTION_MODE_NONE.
27    pub const CONNECTION_MODE_NONE: i32 = 1;
28    /// CONNECTION_MODE_SUBJECT.
29    pub const CONNECTION_MODE_SUBJECT: i32 = 2;
30}
31
32/// AccessContext describes the host-side access decision for an operation.
33///
34/// Native message type for `gestalt.provider.v1.AccessContext`.
35#[derive(Clone, Debug, Default, PartialEq)]
36pub struct AccessContext {
37    /// The `policy` field.
38    pub policy: String,
39    /// The `role` field.
40    pub role: String,
41}
42
43/// Native message type for `gestalt.provider.v1.AgentInvocationContext`.
44#[derive(Clone, Debug, Default, PartialEq)]
45pub struct AgentInvocationContext {
46    /// The `provider_name` field.
47    pub provider_name: String,
48    /// The `session_id` field.
49    pub session_id: String,
50    /// The `turn_id` field.
51    pub turn_id: String,
52}
53
54/// Native message type for `gestalt.provider.v1.AgentToolRef`.
55#[derive(Clone, Debug, Default, PartialEq)]
56pub struct AgentToolRef {
57    /// The `app` field.
58    pub app: String,
59    /// The `operation` field.
60    pub operation: String,
61    /// The `connection` field.
62    pub connection: String,
63    /// The `instance` field.
64    pub instance: String,
65    /// The `title` field.
66    pub title: String,
67    /// The `description` field.
68    pub description: String,
69    /// The `credential_mode` field.
70    pub credential_mode: String,
71    /// The `system` field.
72    pub system: String,
73    /// The `run_as` field; None when unset.
74    pub run_as: Option<SubjectContext>,
75}
76
77/// AppInvokeGraphQLRequest invokes the raw GraphQL surface on another plugin
78/// through Gestalt.
79///
80/// Native message type for `gestalt.provider.v1.AppInvokeGraphQLRequest`.
81#[derive(Clone, Debug, Default, PartialEq)]
82pub struct AppInvokeGraphQLRequest {
83    /// The `app` field.
84    pub app: String,
85    /// The `document` field.
86    pub document: String,
87    /// The `variables` field; None when unset.
88    pub variables: Option<serde_json::Map<String, serde_json::Value>>,
89    /// The `connection` field.
90    pub connection: String,
91    /// The `instance` field.
92    pub instance: String,
93    /// The `idempotency_key` field.
94    pub idempotency_key: String,
95    /// The `context` field; None when unset.
96    pub context: Option<RequestContext>,
97}
98
99/// AppInvokeRequest invokes a declared operation on another app through Gestalt.
100///
101/// Native message type for `gestalt.provider.v1.AppInvokeRequest`.
102#[derive(Clone, Debug, Default, PartialEq)]
103pub struct AppInvokeRequest {
104    /// The `app` field.
105    pub app: String,
106    /// The `operation` field.
107    pub operation: String,
108    /// The `params` field; None when unset.
109    pub params: Option<serde_json::Map<String, serde_json::Value>>,
110    /// The `connection` field.
111    pub connection: String,
112    /// The `instance` field.
113    pub instance: String,
114    /// The `idempotency_key` field.
115    pub idempotency_key: String,
116    /// The `credential_mode` field.
117    pub credential_mode: String,
118    /// The `context` field; None when unset.
119    pub context: Option<RequestContext>,
120}
121
122/// Catalog is the static or request-scoped executable surface exposed by a
123/// provider.
124///
125/// Native message type for `gestalt.provider.v1.Catalog`.
126#[derive(Clone, Debug, Default, PartialEq)]
127pub struct Catalog {
128    /// The `name` field.
129    pub name: String,
130    /// The `display_name` field.
131    pub display_name: String,
132    /// The `description` field.
133    pub description: String,
134    /// The `icon_svg` field.
135    pub icon_svg: String,
136    /// The `operations` field.
137    pub operations: Vec<CatalogOperation>,
138}
139
140/// CatalogOperation is one executable operation exposed by an integration
141/// provider.
142///
143/// Native message type for `gestalt.provider.v1.CatalogOperation`.
144#[derive(Clone, Debug, Default, PartialEq)]
145pub struct CatalogOperation {
146    /// The `id` field.
147    pub id: String,
148    /// The `method` field.
149    pub method: String,
150    /// The `title` field.
151    pub title: String,
152    /// The `description` field.
153    pub description: String,
154    /// The `input_schema` field.
155    pub input_schema: String,
156    /// The `output_schema` field.
157    pub output_schema: String,
158    /// The `annotations` field; None when unset.
159    pub annotations: Option<OperationAnnotations>,
160    /// The `parameters` field.
161    pub parameters: Vec<CatalogParameter>,
162    /// The `required_scopes` field.
163    pub required_scopes: Vec<String>,
164    /// The `tags` field.
165    pub tags: Vec<String>,
166    /// The `read_only` field.
167    pub read_only: bool,
168    /// The `visible` field; None when unset.
169    pub visible: Option<bool>,
170    /// The `transport` field.
171    pub transport: String,
172    /// The `allowed_roles` field.
173    pub allowed_roles: Vec<String>,
174}
175
176/// CatalogParameter describes one input parameter surfaced in the generated
177/// catalog for an operation.
178///
179/// Native message type for `gestalt.provider.v1.CatalogParameter`.
180#[derive(Clone, Debug, Default, PartialEq)]
181pub struct CatalogParameter {
182    /// The `name` field.
183    pub name: String,
184    /// The `type` field.
185    pub r#type: String,
186    /// The `description` field.
187    pub description: String,
188    /// The `required` field.
189    pub required: bool,
190    /// The `default` field; None when unset.
191    pub default: Option<serde_json::Value>,
192}
193
194/// ConnectionParamDef describes one provider-defined connection parameter.
195///
196/// Native message type for `gestalt.provider.v1.ConnectionParamDef`.
197#[derive(Clone, Debug, Default, PartialEq)]
198pub struct ConnectionParamDef {
199    /// The `required` field.
200    pub required: bool,
201    /// The `description` field.
202    pub description: String,
203    /// The `default_value` field.
204    pub default_value: String,
205    /// The `from` field.
206    pub from: String,
207    /// The `field` field.
208    pub field: String,
209}
210
211/// CredentialContext describes the resolved credential used for an operation.
212///
213/// Native message type for `gestalt.provider.v1.CredentialContext`.
214#[derive(Clone, Debug, Default, PartialEq)]
215pub struct CredentialContext {
216    /// The `mode` field.
217    pub mode: String,
218    /// The `subject_id` field.
219    pub subject_id: String,
220    /// The `connection` field.
221    pub connection: String,
222    /// The `instance` field.
223    pub instance: String,
224}
225
226/// ExecuteRequest invokes one executable operation.
227///
228/// Native message type for `gestalt.provider.v1.ExecuteRequest`.
229#[derive(Clone, Debug, Default, PartialEq)]
230pub struct ExecuteRequest {
231    /// The `operation` field.
232    pub operation: String,
233    /// The `params` field; None when unset.
234    pub params: Option<serde_json::Map<String, serde_json::Value>>,
235    /// The `token` field.
236    pub token: String,
237    /// The `connection_params` field.
238    pub connection_params: std::collections::BTreeMap<String, String>,
239    /// The `invocation_id` field.
240    pub invocation_id: String,
241    /// The `context` field; None when unset.
242    pub context: Option<RequestContext>,
243    /// The `idempotency_key` field.
244    pub idempotency_key: String,
245}
246
247/// GetSessionCatalogRequest asks a provider for request-scoped catalog
248/// extensions.
249///
250/// Native message type for `gestalt.provider.v1.GetSessionCatalogRequest`.
251#[derive(Clone, Debug, Default, PartialEq)]
252pub struct GetSessionCatalogRequest {
253    /// The `token` field.
254    pub token: String,
255    /// The `connection_params` field.
256    pub connection_params: std::collections::BTreeMap<String, String>,
257    /// The `invocation_id` field.
258    pub invocation_id: String,
259    /// The `context` field; None when unset.
260    pub context: Option<RequestContext>,
261}
262
263/// GetSessionCatalogResponse returns request-scoped catalog extensions.
264///
265/// Native message type for `gestalt.provider.v1.GetSessionCatalogResponse`.
266#[derive(Clone, Debug, Default, PartialEq)]
267pub struct GetSessionCatalogResponse {
268    /// The `catalog` field; None when unset.
269    pub catalog: Option<Catalog>,
270}
271
272/// HTTPSubjectRequest carries one verified hosted HTTP request into an optional
273/// plugin-local subject resolution hook.
274///
275/// Native message type for `gestalt.provider.v1.HTTPSubjectRequest`.
276#[derive(Clone, Debug, Default, PartialEq)]
277pub struct HTTPSubjectRequest {
278    /// The `binding` field.
279    pub binding: String,
280    /// The `method` field.
281    pub method: String,
282    /// The `path` field.
283    pub path: String,
284    /// The `content_type` field.
285    pub content_type: String,
286    /// The `headers` field.
287    pub headers: std::collections::BTreeMap<String, StringList>,
288    /// The `query` field.
289    pub query: std::collections::BTreeMap<String, StringList>,
290    /// The `params` field; None when unset.
291    pub params: Option<serde_json::Map<String, serde_json::Value>>,
292    /// The `raw_body` field.
293    pub raw_body: Vec<u8>,
294    /// The `security_scheme` field.
295    pub security_scheme: String,
296    /// The `verified_subject` field.
297    pub verified_subject: String,
298    /// The `verified_claims` field.
299    pub verified_claims: std::collections::BTreeMap<String, String>,
300}
301
302/// HostContext describes stable public host metadata available to provider code.
303///
304/// Native message type for `gestalt.provider.v1.HostContext`.
305#[derive(Clone, Debug, Default, PartialEq)]
306pub struct HostContext {
307    /// The `public_base_url` field.
308    pub public_base_url: String,
309}
310
311/// Native message type for `gestalt.provider.v1.InvocationContext`.
312#[derive(Clone, Debug, Default, PartialEq)]
313pub struct InvocationContext {
314    /// The `request_id` field.
315    pub request_id: String,
316    /// The `depth` field.
317    pub depth: i32,
318    /// The `call_chain` field.
319    pub call_chain: Vec<String>,
320    /// The `surface` field.
321    pub surface: String,
322    /// The `internal_connection_access` field.
323    pub internal_connection_access: bool,
324    /// The `connection` field.
325    pub connection: String,
326}
327
328/// OperationAnnotations carries optional host hints about how an operation
329/// behaves.
330///
331/// Native message type for `gestalt.provider.v1.OperationAnnotations`.
332#[derive(Clone, Debug, Default, PartialEq)]
333pub struct OperationAnnotations {
334    /// The `read_only_hint` field; None when unset.
335    pub read_only_hint: Option<bool>,
336    /// The `idempotent_hint` field; None when unset.
337    pub idempotent_hint: Option<bool>,
338    /// The `destructive_hint` field; None when unset.
339    pub destructive_hint: Option<bool>,
340    /// The `open_world_hint` field; None when unset.
341    pub open_world_hint: Option<bool>,
342}
343
344/// OperationResult is the serialized result returned from an Execute call.
345///
346/// Native message type for `gestalt.provider.v1.OperationResult`.
347#[derive(Clone, Debug, Default, PartialEq)]
348pub struct OperationResult {
349    /// The `status` field.
350    pub status: i32,
351    /// The `body` field.
352    pub body: Vec<u8>,
353    /// The `headers` field.
354    pub headers: std::collections::BTreeMap<String, StringList>,
355}
356
357/// ProviderContext identifies the provider process that received the request
358/// context from the host and is trusted to propagate it back to host services.
359///
360/// Native message type for `gestalt.provider.v1.ProviderContext`.
361#[derive(Clone, Debug, Default, PartialEq)]
362pub struct ProviderContext {
363    /// The `kind` field.
364    pub kind: String,
365    /// The `name` field.
366    pub name: String,
367}
368
369/// ProviderMetadata describes an integration provider's static capabilities.
370///
371/// Native message type for `gestalt.provider.v1.ProviderMetadata`.
372#[derive(Clone, Debug, Default, PartialEq)]
373pub struct ProviderMetadata {
374    /// The `name` field.
375    pub name: String,
376    /// The `display_name` field.
377    pub display_name: String,
378    /// The `description` field.
379    pub description: String,
380    /// The `connection_mode` field.
381    pub connection_mode: ConnectionMode,
382    /// The `auth_types` field.
383    pub auth_types: Vec<String>,
384    /// The `connection_params` field.
385    pub connection_params: std::collections::BTreeMap<String, ConnectionParamDef>,
386    /// The `static_catalog` field; None when unset.
387    pub static_catalog: Option<Catalog>,
388    /// The `supports_session_catalog` field.
389    pub supports_session_catalog: bool,
390    /// The `min_protocol_version` field.
391    pub min_protocol_version: i32,
392    /// The `max_protocol_version` field.
393    pub max_protocol_version: i32,
394}
395
396/// RequestContext bundles the caller, credential, access, and host metadata for
397/// one operation.
398///
399/// Native message type for `gestalt.provider.v1.RequestContext`.
400#[derive(Clone, Debug, Default, PartialEq)]
401pub struct RequestContext {
402    /// The `subject` field; None when unset.
403    pub subject: Option<SubjectContext>,
404    /// The `credential` field; None when unset.
405    pub credential: Option<CredentialContext>,
406    /// The `access` field; None when unset.
407    pub access: Option<AccessContext>,
408    /// The `workflow` field; None when unset.
409    pub workflow: Option<serde_json::Map<String, serde_json::Value>>,
410    /// The `host` field; None when unset.
411    pub host: Option<HostContext>,
412    /// Original agent caller when an agent tool executes with delegated run-as identity.
413    ///
414    /// The `agent_subject` field; None when unset.
415    pub agent_subject: Option<SubjectContext>,
416    /// The `caller` field; None when unset.
417    pub caller: Option<ProviderContext>,
418    /// The `invocation` field; None when unset.
419    pub invocation: Option<InvocationContext>,
420    /// Agent tool refs granted to the operation request, when the request is
421    /// executing as an agent tool.
422    ///
423    /// The `tool_refs` field.
424    pub tool_refs: Vec<AgentToolRef>,
425    /// Preserves the distinction between an omitted tool-ref context and an
426    /// explicitly empty inherited tool-ref context.
427    ///
428    /// The `tool_refs_set` field.
429    pub tool_refs_set: bool,
430    /// The `request_meta` field; None when unset.
431    pub request_meta: Option<RequestMetaContext>,
432    /// The `agent` field; None when unset.
433    pub agent: Option<AgentInvocationContext>,
434}
435
436/// Native message type for `gestalt.provider.v1.RequestMetaContext`.
437#[derive(Clone, Debug, Default, PartialEq)]
438pub struct RequestMetaContext {
439    /// The `client_ip` field.
440    pub client_ip: String,
441    /// The `remote_addr` field.
442    pub remote_addr: String,
443    /// The `user_agent` field.
444    pub user_agent: String,
445}
446
447/// ResolveHTTPSubjectRequest asks a provider to map a verified hosted HTTP
448/// request to a concrete Gestalt subject before normal operation authorization
449/// and dispatch.
450///
451/// Native message type for `gestalt.provider.v1.ResolveHTTPSubjectRequest`.
452#[derive(Clone, Debug, Default, PartialEq)]
453pub struct ResolveHTTPSubjectRequest {
454    /// The `request` field; None when unset.
455    pub request: Option<HTTPSubjectRequest>,
456    /// The `context` field; None when unset.
457    pub context: Option<RequestContext>,
458}
459
460/// ResolveHTTPSubjectResponse returns the concrete Gestalt subject a hosted HTTP
461/// request should execute as. An unset subject means "fall back to the binding
462/// subject". When reject_status is set, the host should reject the inbound
463/// request with the provided status and message.
464///
465/// Native message type for `gestalt.provider.v1.ResolveHTTPSubjectResponse`.
466#[derive(Clone, Debug, Default, PartialEq)]
467pub struct ResolveHTTPSubjectResponse {
468    /// The `subject` field; None when unset.
469    pub subject: Option<SubjectContext>,
470    /// The `reject_status` field.
471    pub reject_status: i32,
472    /// The `reject_message` field.
473    pub reject_message: String,
474}
475
476/// StartProviderRequest configures an integration provider for one runtime
477/// session.
478///
479/// Native message type for `gestalt.provider.v1.StartProviderRequest`.
480#[derive(Clone, Debug, Default, PartialEq)]
481pub struct StartProviderRequest {
482    /// The `name` field.
483    pub name: String,
484    /// The `config` field; None when unset.
485    pub config: Option<serde_json::Map<String, serde_json::Value>>,
486    /// The `protocol_version` field.
487    pub protocol_version: i32,
488}
489
490/// StartProviderResponse confirms the protocol version the provider is serving.
491///
492/// Native message type for `gestalt.provider.v1.StartProviderResponse`.
493#[derive(Clone, Debug, Default, PartialEq)]
494pub struct StartProviderResponse {
495    /// The `protocol_version` field.
496    pub protocol_version: i32,
497}
498
499/// StringList is a helper map value for repeated HTTP header and query values.
500///
501/// Native message type for `gestalt.provider.v1.StringList`.
502#[derive(Clone, Debug, Default, PartialEq)]
503pub struct StringList {
504    /// The `values` field.
505    pub values: Vec<String>,
506}
507
508/// SubjectContext identifies the caller that initiated an operation.
509///
510/// Native message type for `gestalt.provider.v1.SubjectContext`.
511#[derive(Clone, Debug, Default, PartialEq)]
512pub struct SubjectContext {
513    /// The `id` field.
514    pub id: String,
515    /// The `credential_subject_id` field.
516    pub credential_subject_id: String,
517    /// The `email` field.
518    pub email: String,
519    /// The `display_name` field.
520    pub display_name: String,
521    /// The `scopes` field.
522    pub scopes: Vec<String>,
523    /// The `permissions` field.
524    pub permissions: Vec<SubjectPermissionContext>,
525}
526
527/// Native message type for `gestalt.provider.v1.SubjectPermissionContext`.
528#[derive(Clone, Debug, Default, PartialEq)]
529pub struct SubjectPermissionContext {
530    /// The `app` field.
531    pub app: String,
532    /// The `operations` field.
533    pub operations: Vec<String>,
534    /// The `all_operations` field.
535    pub all_operations: bool,
536}
537
538/// Client for the `gestalt.provider.v1.App` service.
539pub struct App {
540    inner: v1::app_client::AppClient<HostServiceChannel>,
541    timeout: Option<std::time::Duration>,
542    context: Option<RequestContext>,
543}
544
545impl App {
546    /// Creates a client over an established channel.
547    pub fn new(channel: tonic::transport::Channel) -> Self {
548        Self {
549            inner: v1::app_client::AppClient::new(plain_channel(channel)),
550            timeout: None,
551            context: None,
552        }
553    }
554
555    /// Sets a deadline applied to every unary call; calls that run past it
556    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
557    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
558        self.timeout = Some(timeout);
559        self
560    }
561
562    /// Sets the default request context, injected into outgoing requests
563    /// that do not carry one.
564    pub fn with_context(mut self, context: RequestContext) -> Self {
565        self.context = Some(context);
566        self
567    }
568
569    /// Connects to the `app` host service described by the environment.
570    pub async fn connect() -> Result<Self, GestaltError> {
571        Self::connect_named("").await
572    }
573
574    /// Connects to the named `app` host-service binding.
575    pub async fn connect_named(name: &str) -> Result<Self, GestaltError> {
576        Ok(Self {
577            inner: v1::app_client::AppClient::new(connect_host_service("app", name).await?),
578            timeout: None,
579            context: None,
580        })
581    }
582
583    /// Calls `gestalt.provider.v1.App.Invoke`.
584    /// The result decodes with the standard JSON operation envelope
585    /// semantics; payload failures surface as [`InvokeError`].
586    pub async fn invoke(
587        &mut self,
588        app: String,
589        operation: String,
590        params: Option<serde_json::Map<String, serde_json::Value>>,
591        options: AppInvokeOptions,
592    ) -> Result<serde_json::Value, InvokeError> {
593        let request = AppInvokeRequest {
594            app,
595            operation,
596            params,
597            connection: options.connection,
598            instance: options.instance,
599            idempotency_key: options.idempotency_key,
600            credential_mode: options.credential_mode,
601            context: self.context.clone(),
602        };
603        let invoke_context_app = request.app.clone();
604        let invoke_context_operation = request.operation.clone();
605        let mut tonic_request = tonic::Request::new(to_wire_app_invoke_request(request));
606        if let Some(timeout) = self.timeout {
607            tonic_request.set_timeout(timeout);
608        }
609        let response = from_wire_operation_result(
610            self.inner
611                .invoke(tonic_request)
612                .await
613                .map_err(GestaltError::from)?
614                .into_inner(),
615        );
616        Ok(decode_app_result(
617            &invoke_context_app,
618            &invoke_context_operation,
619            response.status,
620            &response.body,
621        )?)
622    }
623
624    /// Calls `gestalt.provider.v1.App.Invoke` with the full request and response messages.
625    pub async fn invoke_raw(
626        &mut self,
627        request: AppInvokeRequest,
628    ) -> Result<OperationResult, GestaltError> {
629        let mut request = request;
630        if request.context.is_none() {
631            request.context = self.context.clone();
632        }
633        let mut tonic_request = tonic::Request::new(to_wire_app_invoke_request(request));
634        if let Some(timeout) = self.timeout {
635            tonic_request.set_timeout(timeout);
636        }
637        let response = self.inner.invoke(tonic_request).await?;
638        Ok(from_wire_operation_result(response.into_inner()))
639    }
640
641    /// Calls `gestalt.provider.v1.App.InvokeGraphQL`.
642    pub async fn invoke_graphql(
643        &mut self,
644        app: String,
645        document: String,
646        options: AppInvokeGraphQLOptions,
647    ) -> Result<OperationResult, GestaltError> {
648        let request = AppInvokeGraphQLRequest {
649            app,
650            document,
651            connection: options.connection,
652            instance: options.instance,
653            idempotency_key: options.idempotency_key,
654            variables: options.variables,
655            context: self.context.clone(),
656        };
657        let mut tonic_request = tonic::Request::new(to_wire_app_invoke_graphql_request(request));
658        if let Some(timeout) = self.timeout {
659            tonic_request.set_timeout(timeout);
660        }
661        let response = self.inner.invoke_graph_ql(tonic_request).await?;
662        Ok(from_wire_operation_result(response.into_inner()))
663    }
664
665    /// Calls `gestalt.provider.v1.App.InvokeGraphQL` with the full request and response messages.
666    pub async fn invoke_graphql_raw(
667        &mut self,
668        request: AppInvokeGraphQLRequest,
669    ) -> Result<OperationResult, GestaltError> {
670        let mut request = request;
671        if request.context.is_none() {
672            request.context = self.context.clone();
673        }
674        let mut tonic_request = tonic::Request::new(to_wire_app_invoke_graphql_request(request));
675        if let Some(timeout) = self.timeout {
676            tonic_request.set_timeout(timeout);
677        }
678        let response = self.inner.invoke_graph_ql(tonic_request).await?;
679        Ok(from_wire_operation_result(response.into_inner()))
680    }
681}
682
683/// Optional parameters of [`App::invoke`]; the default value leaves every
684/// option unset.
685#[derive(Clone, Debug, Default)]
686pub struct AppInvokeOptions {
687    /// The `connection` field.
688    pub connection: String,
689    /// The `instance` field.
690    pub instance: String,
691    /// The `idempotency_key` field.
692    pub idempotency_key: String,
693    /// The `credential_mode` field.
694    pub credential_mode: String,
695}
696
697/// Optional parameters of [`App::invoke_graphql`]; the default value leaves every
698/// option unset.
699#[derive(Clone, Debug, Default)]
700pub struct AppInvokeGraphQLOptions {
701    /// The `connection` field.
702    pub connection: String,
703    /// The `instance` field.
704    pub instance: String,
705    /// The `idempotency_key` field.
706    pub idempotency_key: String,
707    /// The `variables` field; None when unset.
708    pub variables: Option<serde_json::Map<String, serde_json::Value>>,
709}
710
711/// AppProvider models the shared Gestalt integration-provider protocol.
712///
713/// Client for the `gestalt.provider.v1.AppProvider` service.
714pub struct AppProvider {
715    inner: v1::app_provider_client::AppProviderClient<tonic::transport::Channel>,
716    timeout: Option<std::time::Duration>,
717    context: Option<RequestContext>,
718}
719
720impl AppProvider {
721    /// Creates a client over an established channel.
722    pub fn new(channel: tonic::transport::Channel) -> Self {
723        Self {
724            inner: v1::app_provider_client::AppProviderClient::new(channel),
725            timeout: None,
726            context: None,
727        }
728    }
729
730    /// Sets a deadline applied to every unary call; calls that run past it
731    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
732    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
733        self.timeout = Some(timeout);
734        self
735    }
736
737    /// Sets the default request context, injected into outgoing requests
738    /// that do not carry one.
739    pub fn with_context(mut self, context: RequestContext) -> Self {
740        self.context = Some(context);
741        self
742    }
743
744    /// Calls `gestalt.provider.v1.AppProvider.GetMetadata`.
745    pub async fn get_metadata(&mut self) -> Result<ProviderMetadata, GestaltError> {
746        let mut tonic_request = tonic::Request::new(());
747        if let Some(timeout) = self.timeout {
748            tonic_request.set_timeout(timeout);
749        }
750        let response = self.inner.get_metadata(tonic_request).await?;
751        Ok(from_wire_provider_metadata(response.into_inner()))
752    }
753
754    /// Calls `gestalt.provider.v1.AppProvider.StartProvider`.
755    pub async fn start_provider(
756        &mut self,
757        name: String,
758        protocol_version: i32,
759        config: Option<serde_json::Map<String, serde_json::Value>>,
760    ) -> Result<StartProviderResponse, GestaltError> {
761        let request = StartProviderRequest {
762            name,
763            protocol_version,
764            config,
765        };
766        let mut tonic_request = tonic::Request::new(to_wire_start_provider_request(request));
767        if let Some(timeout) = self.timeout {
768            tonic_request.set_timeout(timeout);
769        }
770        let response = self.inner.start_provider(tonic_request).await?;
771        Ok(from_wire_start_provider_response(response.into_inner()))
772    }
773
774    /// Calls `gestalt.provider.v1.AppProvider.StartProvider` with the full request and response messages.
775    pub async fn start_provider_raw(
776        &mut self,
777        request: StartProviderRequest,
778    ) -> Result<StartProviderResponse, GestaltError> {
779        let mut tonic_request = tonic::Request::new(to_wire_start_provider_request(request));
780        if let Some(timeout) = self.timeout {
781            tonic_request.set_timeout(timeout);
782        }
783        let response = self.inner.start_provider(tonic_request).await?;
784        Ok(from_wire_start_provider_response(response.into_inner()))
785    }
786
787    /// Calls `gestalt.provider.v1.AppProvider.Execute`.
788    pub async fn execute(
789        &mut self,
790        operation: String,
791        token: String,
792        invocation_id: String,
793        idempotency_key: String,
794        params: Option<serde_json::Map<String, serde_json::Value>>,
795    ) -> Result<OperationResult, GestaltError> {
796        let request = ExecuteRequest {
797            operation,
798            token,
799            invocation_id,
800            idempotency_key,
801            params,
802            context: self.context.clone(),
803            ..Default::default()
804        };
805        let mut tonic_request = tonic::Request::new(to_wire_execute_request(request));
806        if let Some(timeout) = self.timeout {
807            tonic_request.set_timeout(timeout);
808        }
809        let response = self.inner.execute(tonic_request).await?;
810        Ok(from_wire_operation_result(response.into_inner()))
811    }
812
813    /// Calls `gestalt.provider.v1.AppProvider.Execute` with the full request and response messages.
814    pub async fn execute_raw(
815        &mut self,
816        request: ExecuteRequest,
817    ) -> Result<OperationResult, GestaltError> {
818        let mut request = request;
819        if request.context.is_none() {
820            request.context = self.context.clone();
821        }
822        let mut tonic_request = tonic::Request::new(to_wire_execute_request(request));
823        if let Some(timeout) = self.timeout {
824            tonic_request.set_timeout(timeout);
825        }
826        let response = self.inner.execute(tonic_request).await?;
827        Ok(from_wire_operation_result(response.into_inner()))
828    }
829
830    /// Calls `gestalt.provider.v1.AppProvider.ResolveHTTPSubject`.
831    pub async fn resolve_http_subject(
832        &mut self,
833        request: ResolveHTTPSubjectRequest,
834    ) -> Result<ResolveHTTPSubjectResponse, GestaltError> {
835        let mut request = request;
836        if request.context.is_none() {
837            request.context = self.context.clone();
838        }
839        let mut tonic_request = tonic::Request::new(to_wire_resolve_http_subject_request(request));
840        if let Some(timeout) = self.timeout {
841            tonic_request.set_timeout(timeout);
842        }
843        let response = self.inner.resolve_http_subject(tonic_request).await?;
844        Ok(from_wire_resolve_http_subject_response(
845            response.into_inner(),
846        ))
847    }
848
849    /// Calls `gestalt.provider.v1.AppProvider.GetSessionCatalog`.
850    pub async fn get_session_catalog(
851        &mut self,
852        token: String,
853        invocation_id: String,
854    ) -> Result<GetSessionCatalogResponse, GestaltError> {
855        let request = GetSessionCatalogRequest {
856            token,
857            invocation_id,
858            context: self.context.clone(),
859            ..Default::default()
860        };
861        let mut tonic_request = tonic::Request::new(to_wire_get_session_catalog_request(request));
862        if let Some(timeout) = self.timeout {
863            tonic_request.set_timeout(timeout);
864        }
865        let response = self.inner.get_session_catalog(tonic_request).await?;
866        Ok(from_wire_get_session_catalog_response(
867            response.into_inner(),
868        ))
869    }
870
871    /// Calls `gestalt.provider.v1.AppProvider.GetSessionCatalog` with the full request and response messages.
872    pub async fn get_session_catalog_raw(
873        &mut self,
874        request: GetSessionCatalogRequest,
875    ) -> Result<GetSessionCatalogResponse, GestaltError> {
876        let mut request = request;
877        if request.context.is_none() {
878            request.context = self.context.clone();
879        }
880        let mut tonic_request = tonic::Request::new(to_wire_get_session_catalog_request(request));
881        if let Some(timeout) = self.timeout {
882            tonic_request.set_timeout(timeout);
883        }
884        let response = self.inner.get_session_catalog(tonic_request).await?;
885        Ok(from_wire_get_session_catalog_response(
886            response.into_inner(),
887        ))
888    }
889}