zebflow 0.10.10

Reactive web automation platform — pipelines, templates, and real-time collaboration in a single binary.
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
//! Unified operation specifications for REST API, MCP tools, and assistant interfaces.
//!
//! Single source of truth for all project management operations.

use crate::platform::model::ProjectCapability;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Complete specification for one project management operation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperationSpec {
    /// Stable operation ID (used in MCP tool names, logs, assistant prompts, and `/docs/operation` extraction).
    pub id: &'static str,
    /// Category grouping (pipelines, templates, credentials, tables, files, settings).
    pub category: &'static str,
    /// Human-readable description (used in MCP, API docs, assistant context).
    pub description: &'static str,
    /// Required project capability.
    pub capability: ProjectCapability,
    /// HTTP method for REST API (GET, POST, PUT, DELETE).
    pub method: &'static str,
    /// REST API path pattern.
    pub path: &'static str,
    /// Input parameters schema (JSON schema string or empty).
    pub params_schema: &'static str,
}

/// All project management operations.
pub const OPERATIONS: &[OperationSpec] = &[
    // Pipelines
    OperationSpec {
        id: "list_pipelines",
        category: "pipelines",
        description: "List all pipelines in the project with metadata (name, title, trigger_kind, active status)",
        capability: ProjectCapability::PipelinesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/pipelines",
        params_schema: "",
    },
    OperationSpec {
        id: "get_pipeline",
        category: "pipelines",
        description: "Get a specific pipeline definition source code by virtual path and name",
        capability: ProjectCapability::PipelinesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/pipelines/{virtual_path}/{name}",
        params_schema: r#"{"virtual_path":"string","name":"string"}"#,
    },
    OperationSpec {
        id: "upsert_pipeline",
        category: "pipelines",
        description: "Create or update a pipeline definition (YAML source code)",
        capability: ProjectCapability::PipelinesWrite,
        method: "PUT",
        path: "/api/projects/{owner}/{project}/pipelines/{virtual_path}/{name}",
        params_schema: r#"{"virtual_path":"string","name":"string","title":"string","description":"string","trigger_kind":"string","source":"string"}"#,
    },
    OperationSpec {
        id: "activate_pipeline",
        category: "pipelines",
        description: "Activate a pipeline (make it available for execution)",
        capability: ProjectCapability::PipelinesWrite,
        method: "POST",
        path: "/api/projects/{owner}/{project}/pipelines/{virtual_path}/{name}/activate",
        params_schema: r#"{"virtual_path":"string","name":"string"}"#,
    },
    OperationSpec {
        id: "deactivate_pipeline",
        category: "pipelines",
        description: "Deactivate a pipeline (remove from active registry)",
        capability: ProjectCapability::PipelinesWrite,
        method: "POST",
        path: "/api/projects/{owner}/{project}/pipelines/{virtual_path}/{name}/deactivate",
        params_schema: r#"{"virtual_path":"string","name":"string"}"#,
    },
    OperationSpec {
        id: "execute_pipeline",
        category: "pipelines",
        description: "Execute a pipeline with explicit trigger payload (webhook, schedule, or manual)",
        capability: ProjectCapability::PipelinesExecute,
        method: "POST",
        path: "/api/projects/{owner}/{project}/pipelines/{virtual_path}/{name}/execute",
        params_schema: r#"{"virtual_path":"string","name":"string","trigger":"webhook|schedule|manual","webhook_path":"string?","webhook_method":"string?","schedule_cron":"string?","input":"object"}"#,
    },
    // Templates
    OperationSpec {
        id: "list_templates",
        category: "templates",
        description: "List all templates in the project workspace (pages, components, scripts, styles)",
        capability: ProjectCapability::TemplatesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/templates",
        params_schema: "",
    },
    OperationSpec {
        id: "get_template",
        category: "templates",
        description: "Get a specific template file contents by relative path",
        capability: ProjectCapability::TemplatesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/templates/{path}",
        params_schema: r#"{"path":"string"}"#,
    },
    OperationSpec {
        id: "save_template",
        category: "templates",
        description: "Save (create or update) a template file with new contents",
        capability: ProjectCapability::TemplatesWrite,
        method: "PUT",
        path: "/api/projects/{owner}/{project}/templates/{path}",
        params_schema: r#"{"path":"string","contents":"string"}"#,
    },
    OperationSpec {
        id: "create_template",
        category: "templates",
        description: "Create a new template file or folder",
        capability: ProjectCapability::TemplatesCreate,
        method: "POST",
        path: "/api/projects/{owner}/{project}/templates",
        params_schema: r#"{"path":"string","kind":"string","contents":"string"}"#,
    },
    OperationSpec {
        id: "delete_template",
        category: "templates",
        description: "Delete a template file or folder",
        capability: ProjectCapability::TemplatesDelete,
        method: "DELETE",
        path: "/api/projects/{owner}/{project}/templates/{path}",
        params_schema: r#"{"path":"string"}"#,
    },
    // Credentials
    OperationSpec {
        id: "list_credentials",
        category: "credentials",
        description: "List all credential keys in the project",
        capability: ProjectCapability::CredentialsRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/credentials",
        params_schema: "",
    },
    OperationSpec {
        id: "get_credential",
        category: "credentials",
        description: "Get a specific credential value by key (masked in logs)",
        capability: ProjectCapability::CredentialsRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/credentials/{key}",
        params_schema: r#"{"key":"string"}"#,
    },
    OperationSpec {
        id: "upsert_credential",
        category: "credentials",
        description: "Create or update a credential (store secrets securely)",
        capability: ProjectCapability::CredentialsWrite,
        method: "PUT",
        path: "/api/projects/{owner}/{project}/credentials/{key}",
        params_schema: r#"{"key":"string","title":"string","kind":"string","secret":"object","notes":"string"}"#,
    },
    // Assistant
    OperationSpec {
        id: "get_project_assistant_config",
        category: "settings",
        description: "Get project assistant runtime configuration (bound LLM credentials and limits)",
        capability: ProjectCapability::SettingsRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/assistant/config",
        params_schema: "",
    },
    OperationSpec {
        id: "upsert_project_assistant_config",
        category: "settings",
        description: "Create or update project assistant runtime configuration",
        capability: ProjectCapability::SettingsWrite,
        method: "PUT",
        path: "/api/projects/{owner}/{project}/assistant/config",
        params_schema: r#"{"llm_high_credential_id":"string?","llm_general_credential_id":"string?","max_steps":"number?","max_replans":"number?","enabled":"bool?","chat_history_pairs":"number?"}"#,
    },
    OperationSpec {
        id: "project_assistant_chat",
        category: "assistant",
        description: "Send one project-assistant chat message over SSE stream (internal web assistant path)",
        capability: ProjectCapability::ProjectRead,
        method: "POST",
        path: "/api/projects/{owner}/{project}/assistant/chat",
        params_schema: r#"{"message":"string","history":"[{role,content}]?","use_high_model":"bool?"}"#,
    },
    // DB connections
    OperationSpec {
        id: "list_db_connections",
        category: "db",
        description: "List all DB connections for the project",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections",
        params_schema: "",
    },
    OperationSpec {
        id: "get_db_connection",
        category: "db",
        description: "Get one DB connection by slug",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_slug}",
        params_schema: r#"{"connection_slug":"string"}"#,
    },
    OperationSpec {
        id: "upsert_db_connection",
        category: "db",
        description: "Create one DB connection",
        capability: ProjectCapability::TablesWrite,
        method: "POST",
        path: "/api/projects/{owner}/{project}/db/connections",
        params_schema: r#"{"connection_slug":"string","connection_label":"string","database_kind":"string","credential_id":"string?","config":"object?"}"#,
    },
    OperationSpec {
        id: "update_db_connection",
        category: "db",
        description: "Update one DB connection by slug",
        capability: ProjectCapability::TablesWrite,
        method: "PUT",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_slug}",
        params_schema: r#"{"connection_slug":"string","connection_label":"string","database_kind":"string","credential_id":"string?","config":"object?"}"#,
    },
    OperationSpec {
        id: "delete_db_connection",
        category: "db",
        description: "Delete one DB connection by slug",
        capability: ProjectCapability::TablesWrite,
        method: "DELETE",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_slug}",
        params_schema: r#"{"connection_slug":"string"}"#,
    },
    OperationSpec {
        id: "test_db_connection",
        category: "db",
        description: "Validate one DB connection (existing by slug or draft payload)",
        capability: ProjectCapability::TablesRead,
        method: "POST",
        path: "/api/projects/{owner}/{project}/db/connections/test",
        params_schema: r#"{"connection_slug":"string?","database_kind":"string?","credential_id":"string?","config":"object?"}"#,
    },
    OperationSpec {
        id: "describe_db_connection",
        category: "db",
        description: "Describe database objects for one DB connection by immutable id (schemas/tables/functions/tree)",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_id}/describe",
        params_schema: r#"{"connection_id":"string","scope":"tree|schemas|tables|functions?","schema":"string?","include_system":"boolean?"}"#,
    },
    OperationSpec {
        id: "query_db_connection",
        category: "db",
        description: "Execute one query against DB connection by immutable id (read-only by default)",
        capability: ProjectCapability::TablesRead,
        method: "POST",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_id}/query",
        params_schema: r#"{"connection_id":"string","sql":"string?","params":"array?","table":"string?","limit":"number?","read_only":"boolean?"}"#,
    },
    OperationSpec {
        id: "list_db_connection_schemas",
        category: "db",
        description: "List schemas for one DB connection by immutable id",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_id}/schemas",
        params_schema: r#"{"connection_id":"string","include_system":"boolean?"}"#,
    },
    OperationSpec {
        id: "list_db_connection_tables",
        category: "db",
        description: "List tables for one DB connection by immutable id (optionally filtered by schema)",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_id}/tables",
        params_schema: r#"{"connection_id":"string","schema":"string?","include_system":"boolean?"}"#,
    },
    OperationSpec {
        id: "list_db_connection_functions",
        category: "db",
        description: "List functions for one DB connection by immutable id (optionally filtered by schema)",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_id}/functions",
        params_schema: r#"{"connection_id":"string","schema":"string?","include_system":"boolean?"}"#,
    },
    OperationSpec {
        id: "preview_db_connection_table",
        category: "db",
        description: "Preview table rows for one DB connection by immutable id",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/db/connections/{connection_id}/table-preview",
        params_schema: r#"{"connection_id":"string","table":"string","limit":"number?"}"#,
    },
    // Docs (project docs: ERD, README.md, AGENTS.md, use cases)
    OperationSpec {
        id: "list_project_docs",
        category: "docs",
        description: "List project doc files (e.g. ERD, README.md, AGENTS.md, use case diagrams) under app/docs",
        capability: ProjectCapability::ProjectRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/docs",
        params_schema: "",
    },
    OperationSpec {
        id: "read_project_doc",
        category: "docs",
        description: "Read one project doc by path (e.g. README.md, AGENTS.md, erd.svg)",
        capability: ProjectCapability::ProjectRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/docs/{path}",
        params_schema: r#"{"path":"string"}"#,
    },
    OperationSpec {
        id: "create_project_doc",
        category: "docs",
        description: "Create or update one project doc file under app/docs",
        capability: ProjectCapability::FilesWrite,
        method: "POST",
        path: "/api/projects/{owner}/{project}/docs",
        params_schema: r#"{"path":"string","content":"string"}"#,
    },
    // Tables
    OperationSpec {
        id: "list_tables",
        category: "tables",
        description: "List simple table names",
        capability: ProjectCapability::TablesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/tables",
        params_schema: "",
    },
    OperationSpec {
        id: "create_table",
        category: "tables",
        description: "Create one sekejap table definition for the project",
        capability: ProjectCapability::TablesWrite,
        method: "POST",
        path: "/api/projects/{owner}/{project}/tables",
        params_schema: r#"{"table":"string","title":"string?","attributes":[{"name":"string","kind":"string","index_types":["string"]}]}"#,
    },
    // Files
    OperationSpec {
        id: "list_files",
        category: "files",
        description: "List all files in the project app directory",
        capability: ProjectCapability::FilesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/files",
        params_schema: "",
    },
    OperationSpec {
        id: "read_file",
        category: "files",
        description: "Read a specific file contents by path",
        capability: ProjectCapability::FilesRead,
        method: "GET",
        path: "/api/projects/{owner}/{project}/files/{path}",
        params_schema: r#"{"path":"string"}"#,
    },
    OperationSpec {
        id: "write_file",
        category: "files",
        description: "Write or update a file with new contents",
        capability: ProjectCapability::FilesWrite,
        method: "PUT",
        path: "/api/projects/{owner}/{project}/files/{path}",
        params_schema: r#"{"path":"string","contents":"string"}"#,
    },
    // Pipeline DSL shell
    OperationSpec {
        id: "execute_pipeline_dsl",
        category: "pipelines",
        description: "Execute Pipeline DSL commands: get, describe, register, patch, activate, deactivate, execute, run, git, and more. Returns terminal-style line output.",
        capability: ProjectCapability::PipelinesExecute,
        method: "POST",
        path: "/api/projects/{owner}/{project}/pipelines/dsl",
        params_schema: r#"{"dsl":"string"}"#,
    },
];

/// REST channel contract for one operation.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct OperationRestContract {
    /// HTTP method.
    pub method: String,
    /// HTTP path pattern.
    pub path: String,
    /// Whether route is enabled.
    pub enabled: bool,
}

/// Project assistant channel contract for one operation.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct OperationAssistantContract {
    /// Stable operation id exposed to assistant context.
    pub operation_id: String,
    /// Whether channel is enabled.
    pub enabled: bool,
}

/// MCP channel contract for one operation.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct OperationMcpContract {
    /// Tool name (currently same as operation id).
    pub tool_name: String,
    /// Capability mapping key if mapped.
    pub capability_mapped: Option<String>,
    /// Whether this operation is exposed in MCP.
    pub enabled: bool,
}

/// Extractable operation contract item for `/docs/operation`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OperationContractItem {
    /// Stable operation id.
    pub id: String,
    /// Category group.
    pub category: String,
    /// Human description.
    pub description: String,
    /// Required project capability key.
    pub capability: String,
    /// REST channel contract.
    pub rest: OperationRestContract,
    /// Project assistant channel contract.
    pub project_assistant: OperationAssistantContract,
    /// MCP channel contract.
    pub mcp: OperationMcpContract,
    /// Parsed params schema.
    pub params_schema: Value,
}

/// Root operation contract document served at `/docs/operation`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct OperationContractDocument {
    /// Marker for successful extraction.
    pub ok: bool,
    /// Stable contract schema version.
    pub schema_version: &'static str,
    /// Source anchor for traceability.
    pub source: &'static str,
    /// Operation contract entries.
    pub items: Vec<OperationContractItem>,
}

/// Builds operation contract items as a single source for docs extraction.
pub fn operation_contract_items() -> Vec<OperationContractItem> {
    OPERATIONS
        .iter()
        .map(|op| {
            let params_schema = if op.params_schema.trim().is_empty() {
                Value::Null
            } else {
                serde_json::from_str::<Value>(op.params_schema)
                    .unwrap_or_else(|_| Value::String(op.params_schema.to_string()))
            };
            let capability_mapped = crate::platform::model::mcp_tool_capability(op.id)
                .map(|capability| capability.key().to_string());
            OperationContractItem {
                id: op.id.to_string(),
                category: op.category.to_string(),
                description: op.description.to_string(),
                capability: op.capability.key().to_string(),
                rest: OperationRestContract {
                    method: op.method.to_string(),
                    path: op.path.to_string(),
                    enabled: true,
                },
                project_assistant: OperationAssistantContract {
                    operation_id: op.id.to_string(),
                    enabled: true,
                },
                mcp: OperationMcpContract {
                    tool_name: op.id.to_string(),
                    capability_mapped: capability_mapped.clone(),
                    enabled: capability_mapped.is_some(),
                },
                params_schema,
            }
        })
        .collect()
}

/// Get operation spec by ID.
pub fn get_operation(id: &str) -> Option<&'static OperationSpec> {
    OPERATIONS.iter().find(|op| op.id == id)
}

/// Get all operations by category.
pub fn operations_by_category(category: &str) -> Vec<&'static OperationSpec> {
    OPERATIONS
        .iter()
        .filter(|op| op.category == category)
        .collect()
}