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 RemoteAdminListRequest {
58    pub entity: String,
59    pub limit: i64,
60    pub cursor: Option<String>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct RemoteAdminGetRequest {
65    pub entity: String,
66    pub id: String,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct RemoteAdminActionInvokeRequest {
71    pub action: String,
72    pub input: Value,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct RemoteHttpProxyInvokeRequest {
77    pub request_id: String,
78    pub correlation_id: String,
79    pub module_name: String,
80    pub method: String,
81    pub declared_path: String,
82    pub remote_path: String,
83    pub path_params: BTreeMap<String, String>,
84    pub headers: BTreeMap<String, String>,
85    pub body: Option<Value>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct RemoteHttpProxyInvokeResponse {
90    pub status_code: u16,
91    pub body: Option<Value>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct RemoteFunctionInvokeRequest {
96    pub request_id: String,
97    pub function_run_id: String,
98    pub function_name: String,
99    pub attempt: u32,
100    pub correlation_id: String,
101    pub causation_id: Option<String>,
102    pub actor: ActorContext,
103    pub trace: TraceContext,
104    pub input: Value,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct RemoteFunctionInvokeResponse {
109    pub output: Value,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct RemoteEventHandleRequest {
114    pub request_id: String,
115    pub outbox_event_id: String,
116    pub handler_name: String,
117    pub event_name: String,
118    pub event_version: u16,
119    pub source_module: String,
120    pub aggregate_type: String,
121    pub aggregate_id: String,
122    pub correlation_id: String,
123    pub causation_id: Option<String>,
124    pub occurred_at: String,
125    pub actor: ActorContext,
126    pub trace: TraceContext,
127    pub payload: Value,
128    pub headers: Value,
129}
130
131#[derive(Debug, Clone, Default, Serialize, Deserialize)]
132pub struct RemoteEventHandleResponse {
133    #[serde(default)]
134    pub actions: Vec<RemoteEventResultAction>,
135}
136
137#[derive(Debug, Clone, Serialize, Deserialize)]
138#[serde(tag = "type", rename_all = "snake_case")]
139pub enum RemoteEventResultAction {
140    EnqueueFunction { function_name: String, input: Value },
141}