zeal-sdk 1.0.5

Rust SDK for Zeal Integration Protocol (ZIP)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
//! Type definitions for the Zeal SDK
//!
//! These types mirror the TypeScript SDK types and ZIP protocol definitions

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Node template definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeTemplate {
    pub id: String,
    #[serde(rename = "type")]
    pub type_name: String,
    pub title: String,
    pub subtitle: Option<String>,
    pub category: String,
    pub subcategory: Option<String>,
    pub description: String,
    pub icon: String,
    pub variant: Option<String>,
    pub shape: Option<NodeShape>,
    pub size: Option<NodeSize>,
    pub ports: Vec<Port>,
    pub properties: Option<HashMap<String, PropertyDefinition>>,
    #[serde(rename = "propertyRules")]
    pub property_rules: Option<PropertyRules>,
    pub runtime: Option<RuntimeRequirements>,
}

/// Node shape variants
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NodeShape {
    Rectangle,
    Circle,
    Diamond,
}

/// Node size variants
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NodeSize {
    Small,
    Medium,
    Large,
}

/// Port definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Port {
    pub id: String,
    pub label: String,
    #[serde(rename = "type")]
    pub port_type: PortType,
    pub position: PortPosition,
    #[serde(rename = "dataType")]
    pub data_type: Option<String>,
    pub required: Option<bool>,
    pub multiple: Option<bool>,
}

/// Port type
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PortType {
    Input,
    Output,
}

/// Port position
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PortPosition {
    Left,
    Right,
    Top,
    Bottom,
}

/// Property definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyDefinition {
    #[serde(rename = "type")]
    pub property_type: PropertyType,
    pub label: Option<String>,
    pub description: Option<String>,
    #[serde(rename = "defaultValue")]
    pub default_value: Option<serde_json::Value>,
    pub options: Option<Vec<serde_json::Value>>,
    pub validation: Option<PropertyValidation>,
}

/// Property type
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum PropertyType {
    String,
    Number,
    Boolean,
    Select,
    CodeEditor,
}

/// Property validation rules
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyValidation {
    pub required: Option<bool>,
    pub min: Option<f64>,
    pub max: Option<f64>,
    pub pattern: Option<String>,
}

/// Property rules for dynamic behavior
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyRules {
    pub triggers: Vec<String>,
    pub rules: Vec<PropertyRule>,
}

/// Individual property rule
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PropertyRule {
    pub when: String,
    pub updates: HashMap<String, serde_json::Value>,
}

/// Runtime requirements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RuntimeRequirements {
    pub executor: String,
    pub version: Option<String>,
    #[serde(rename = "requiredEnvVars")]
    pub required_env_vars: Option<Vec<String>>,
    pub capabilities: Option<Vec<String>>,
}

/// Register templates request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterTemplatesRequest {
    pub namespace: String,
    pub templates: Vec<NodeTemplate>,
    #[serde(rename = "webhookUrl")]
    pub webhook_url: Option<String>,
}

/// Register templates response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterTemplatesResponse {
    pub registered: usize,
    pub templates: Vec<TemplateRegistrationResult>,
}

/// Template registration result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemplateRegistrationResult {
    pub id: String,
    #[serde(rename = "globalId")]
    pub global_id: String,
    pub status: TemplateRegistrationStatus,
    pub error: Option<String>,
}

/// Template registration status
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TemplateRegistrationStatus {
    Registered,
    Updated,
    Error,
}

/// Create workflow request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateWorkflowRequest {
    pub name: String,
    pub description: Option<String>,
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Create workflow response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateWorkflowResponse {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: String,
    #[serde(rename = "embedUrl")]
    pub embed_url: String,
}

/// 2D position
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Position {
    pub x: f64,
    pub y: f64,
}

/// Add node request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddNodeRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: Option<String>,
    #[serde(rename = "templateId")]
    pub template_id: String,
    pub position: Position,
    #[serde(rename = "propertyValues")]
    pub property_values: Option<HashMap<String, serde_json::Value>>,
}

/// Add node response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddNodeResponse {
    #[serde(rename = "nodeId")]
    pub node_id: String,
    pub node: NodeInfo,
}

/// Node information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeInfo {
    pub id: String,
    #[serde(rename = "type")]
    pub node_type: String,
    pub position: Position,
    pub metadata: serde_json::Value,
}

/// Node port reference
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodePort {
    #[serde(rename = "nodeId")]
    pub node_id: String,
    #[serde(rename = "portId")]
    pub port_id: String,
}

/// Connect nodes request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectNodesRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: Option<String>,
    pub source: NodePort,
    pub target: NodePort,
}

/// Create group request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateGroupRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: Option<String>,
    pub title: String,
    #[serde(rename = "nodeIds")]
    pub node_ids: Vec<String>,
    pub color: Option<String>,
    pub description: Option<String>,
}

/// Create group response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateGroupResponse {
    pub success: bool,
    #[serde(rename = "groupId")]
    pub group_id: String,
    pub group: serde_json::Value,
}

/// Remove connection request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveConnectionRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: Option<String>,
    #[serde(rename = "connectionId")]
    pub connection_id: String,
}

/// Remove connection response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveConnectionResponse {
    pub success: bool,
    pub message: String,
}

/// Update group request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateGroupRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: Option<String>,
    #[serde(rename = "groupId")]
    pub group_id: String,
    pub title: Option<String>,
    #[serde(rename = "nodeIds")]
    pub node_ids: Option<Vec<String>>,
    pub color: Option<String>,
    pub description: Option<String>,
}

/// Update group response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateGroupResponse {
    pub success: bool,
    pub group: serde_json::Value,
}

/// Remove group request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveGroupRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "graphId")]
    pub graph_id: Option<String>,
    #[serde(rename = "groupId")]
    pub group_id: String,
}

/// Remove group response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RemoveGroupResponse {
    pub success: bool,
    pub message: String,
}

/// Create trace session request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateTraceSessionRequest {
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "workflowVersionId")]
    pub workflow_version_id: Option<String>,
    #[serde(rename = "executionId")]
    pub execution_id: String,
    pub metadata: Option<TraceMetadata>,
}

/// Trace session metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraceMetadata {
    pub trigger: Option<String>,
    pub environment: Option<String>,
    pub tags: Vec<String>,
}

/// Create trace session response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateTraceSessionResponse {
    #[serde(rename = "sessionId")]
    pub session_id: String,
    #[serde(rename = "workflowId")]
    pub workflow_id: String,
    #[serde(rename = "executionId")]
    pub execution_id: String,
    #[serde(rename = "createdAt")]
    pub created_at: DateTime<Utc>,
}

/// Trace event
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraceEvent {
    pub timestamp: i64,
    #[serde(rename = "nodeId")]
    pub node_id: String,
    #[serde(rename = "portId")]
    pub port_id: Option<String>,
    #[serde(rename = "eventType")]
    pub event_type: TraceEventType,
    pub data: TraceData,
    pub duration: Option<std::time::Duration>,
    pub metadata: Option<TraceEventMetadata>,
    pub error: Option<TraceError>,
}

impl Default for TraceEvent {
    fn default() -> Self {
        Self {
            timestamp: chrono::Utc::now().timestamp_millis(),
            node_id: String::new(),
            port_id: None,
            event_type: TraceEventType::Output,
            data: TraceData::default(),
            duration: None,
            metadata: None,
            error: None,
        }
    }
}

/// Trace event type
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TraceEventType {
    Input,
    Output,
    Error,
    Log,
}

/// Trace data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraceData {
    pub size: usize,
    #[serde(rename = "type")]
    pub data_type: String,
    pub preview: Option<serde_json::Value>,
    #[serde(rename = "fullData")]
    pub full_data: Option<serde_json::Value>,
}

impl Default for TraceData {
    fn default() -> Self {
        Self {
            size: 0,
            data_type: "application/json".to_string(),
            preview: None,
            full_data: None,
        }
    }
}

/// Trace event metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraceEventMetadata {
    #[serde(rename = "cpuUsage")]
    pub cpu_usage: Option<f64>,
    #[serde(rename = "memoryUsage")]
    pub memory_usage: Option<u64>,
    pub custom: Option<HashMap<String, serde_json::Value>>,
}

/// Trace error information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraceError {
    pub message: String,
    pub stack: Option<String>,
    pub code: Option<String>,
}

/// Trace status
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TraceStatus {
    Running,
    Completed,
    Failed,
    Cancelled,
}

/// Submit trace events request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubmitTraceEventsRequest {
    pub events: Vec<TraceEvent>,
}

/// Webhook configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebhookConfig {
    pub namespace: String,
    pub url: String,
    pub events: Option<Vec<String>>,
    pub headers: Option<HashMap<String, String>>,
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Webhook registration response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebhookRegistrationResponse {
    #[serde(rename = "webhookId")]
    pub webhook_id: String,
    pub namespace: String,
    pub url: String,
    pub events: Vec<String>,
    #[serde(rename = "isActive")]
    pub is_active: bool,
    #[serde(rename = "createdAt")]
    pub created_at: DateTime<Utc>,
}

/// Health check response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthCheckResponse {
    pub status: HealthStatus,
    pub version: String,
    pub services: HashMap<String, HealthStatus>,
}

/// Health status
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum HealthStatus {
    Healthy,
    Unhealthy,
}

/// Test webhook response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestWebhookResponse {
    pub success: bool,
    #[serde(rename = "statusCode")]
    pub status_code: u16,
    #[serde(rename = "responseTimeMs")]
    pub response_time_ms: u64,
    pub error: Option<String>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_node_template_serialization() {
        let template = NodeTemplate {
            id: "test-id".to_string(),
            type_name: "processor".to_string(),
            title: "Test Node".to_string(),
            subtitle: None,
            category: "Processing".to_string(),
            subcategory: None,
            description: "Test description".to_string(),
            icon: "processor".to_string(),
            variant: None,
            shape: Some(NodeShape::Rectangle),
            size: Some(NodeSize::Medium),
            ports: vec![],
            properties: None,
            property_rules: None,
            runtime: None,
        };

        let json = serde_json::to_string(&template).unwrap();
        assert!(json.contains("test-id"));

        let deserialized: NodeTemplate = serde_json::from_str(&json).unwrap();
        assert_eq!(deserialized.id, template.id);
    }

    #[test]
    fn test_trace_event_default() {
        let event = TraceEvent::default();
        assert!(!event.node_id.is_empty() || event.node_id.is_empty()); // Just testing compilation
        assert!(matches!(event.event_type, TraceEventType::Output));
    }

    #[test]
    fn test_position_serialization() {
        let position = Position { x: 100.0, y: 200.0 };
        let json = serde_json::to_string(&position).unwrap();
        let deserialized: Position = serde_json::from_str(&json).unwrap();
        assert_eq!(deserialized.x, 100.0);
        assert_eq!(deserialized.y, 200.0);
    }
}