Skip to main content

platform_module_remote/
protocol.rs

1use platform_core::{ActorContext, TraceContext};
2use platform_module::{AdminPage, ModuleManifest};
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use std::collections::BTreeMap;
6
7pub type RemoteManifestResponse = ModuleManifest;
8
9/// Standard error response shape for the remote module protocol.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct RemoteErrorEnvelope {
12    pub error: RemoteErrorBody,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct RemoteErrorBody {
17    pub code: String,
18    pub message: String,
19    #[serde(default)]
20    pub retryable: bool,
21    #[serde(default)]
22    pub details: Vec<RemoteErrorDetail>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct RemoteErrorDetail {
27    pub field: Option<String>,
28    pub reason: String,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct RemoteListResponse {
33    pub records: Vec<Value>,
34    pub next_cursor: Option<String>,
35}
36
37impl From<RemoteListResponse> for AdminPage {
38    fn from(value: RemoteListResponse) -> Self {
39        Self {
40            records: value.records,
41            next_cursor: value.next_cursor,
42        }
43    }
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct RemoteGetResponse {
48    pub record: Option<Value>,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct RemoteActionInvokeResponse {
53    pub result: Value,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct RemoteQueryResponse {
58    pub data: Value,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct RemoteAdminListRequest {
63    pub entity: String,
64    pub limit: i64,
65    pub cursor: Option<String>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct RemoteAdminGetRequest {
70    pub entity: String,
71    pub id: String,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct RemoteAdminActionInvokeRequest {
76    pub action: String,
77    pub input: Value,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct RemoteAdminQueryRequest {
82    pub query: String,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct RemoteHttpProxyInvokeRequest {
87    pub request_id: String,
88    pub correlation_id: String,
89    pub module_name: String,
90    pub method: String,
91    pub declared_path: String,
92    pub remote_path: String,
93    pub path_params: BTreeMap<String, String>,
94    pub headers: BTreeMap<String, String>,
95    pub body: Option<Value>,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct RemoteHttpProxyInvokeResponse {
100    pub status_code: u16,
101    pub body: Option<Value>,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct RemoteFunctionInvokeRequest {
106    pub request_id: String,
107    pub function_run_id: String,
108    pub function_name: String,
109    pub attempt: u32,
110    pub correlation_id: String,
111    pub causation_id: Option<String>,
112    pub actor: ActorContext,
113    pub trace: TraceContext,
114    pub input: Value,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct RemoteFunctionInvokeResponse {
119    pub output: Value,
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct RemoteEventHandleRequest {
124    pub request_id: String,
125    pub outbox_event_id: String,
126    pub handler_name: String,
127    pub event_name: String,
128    pub event_version: u16,
129    pub source_module: String,
130    pub aggregate_type: String,
131    pub aggregate_id: String,
132    pub correlation_id: String,
133    pub causation_id: Option<String>,
134    pub occurred_at: String,
135    pub actor: ActorContext,
136    pub trace: TraceContext,
137    pub payload: Value,
138    pub headers: Value,
139}
140
141#[derive(Debug, Clone, Default, Serialize, Deserialize)]
142pub struct RemoteEventHandleResponse {
143    #[serde(default)]
144    pub actions: Vec<RemoteEventResultAction>,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(tag = "type", rename_all = "snake_case")]
149pub enum RemoteEventResultAction {
150    EnqueueFunction { function_name: String, input: Value },
151}