1use serde::{Deserialize, Serialize};
2
3use crate::model::JsonValue;
4
5pub const NATIVE_RUNTIME_PROTOCOL: &str = "a3s.flow.native_ts.v1";
7pub const NATIVE_COMPILER_PROTOCOL: &str = "a3s.flow.native_ts.compiler.v1";
9pub const NATIVE_DEPENDENCY_MANIFEST_PROTOCOL: &str = "a3s.flow.native_ts.dependencies.v1";
11
12#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14pub struct NativeTsCompilerCapabilities {
15 pub protocol: String,
17 #[serde(rename = "dependencyManifest")]
19 pub dependency_manifest: bool,
20}
21
22impl NativeTsCompilerCapabilities {
23 pub fn current() -> Self {
25 Self {
26 protocol: NATIVE_COMPILER_PROTOCOL.to_string(),
27 dependency_manifest: true,
28 }
29 }
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
34pub struct NativeTsDependencyManifest {
35 pub protocol: String,
37 #[serde(rename = "compilerIdentity")]
39 pub compiler_identity: String,
40 pub files: Vec<String>,
42}
43
44impl NativeTsDependencyManifest {
45 pub fn new(compiler_identity: impl Into<String>, files: Vec<String>) -> Self {
47 Self {
48 protocol: NATIVE_DEPENDENCY_MANIFEST_PROTOCOL.to_string(),
49 compiler_identity: compiler_identity.into(),
50 files,
51 }
52 }
53}
54
55#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
57#[serde(rename_all = "snake_case")]
58pub enum NativeRuntimeKind {
59 Workflow,
61 Step,
63}
64
65impl NativeRuntimeKind {
66 pub fn as_str(self) -> &'static str {
68 match self {
69 Self::Workflow => "workflow",
70 Self::Step => "step",
71 }
72 }
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
77pub struct NativeRuntimeRequest<T> {
78 pub protocol: String,
80 pub kind: NativeRuntimeKind,
82 #[serde(rename = "exportName")]
84 pub export_name: String,
85 #[serde(rename = "sourceHash")]
87 pub source_hash: String,
88 pub payload: T,
90}
91
92impl<T> NativeRuntimeRequest<T> {
93 pub fn new(
95 kind: NativeRuntimeKind,
96 export_name: impl Into<String>,
97 source_hash: impl Into<String>,
98 payload: T,
99 ) -> Self {
100 Self {
101 protocol: NATIVE_RUNTIME_PROTOCOL.to_string(),
102 kind,
103 export_name: export_name.into(),
104 source_hash: source_hash.into(),
105 payload,
106 }
107 }
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
112pub struct NativeRuntimeResponse {
113 pub protocol: String,
115 pub kind: NativeRuntimeKind,
117 pub ok: bool,
119 #[serde(default)]
121 pub output: Option<JsonValue>,
122 #[serde(default)]
124 pub error: Option<String>,
125}