runner.proto 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. syntax = "proto3";
  2. package smartbotic.proto;
  3. import "common.proto";
  4. import "workflow.proto";
  5. option cc_enable_arenas = true;
  6. // Runner status
  7. enum RunnerStatus {
  8. RUNNER_STATUS_UNSPECIFIED = 0;
  9. RUNNER_STATUS_ONLINE = 1;
  10. RUNNER_STATUS_BUSY = 2;
  11. RUNNER_STATUS_OFFLINE = 3;
  12. RUNNER_STATUS_DRAINING = 4; // Not accepting new work
  13. }
  14. // Runner metrics
  15. message RunnerMetrics {
  16. int32 active_executions = 1;
  17. int32 max_executions = 2;
  18. int64 memory_used_bytes = 3;
  19. int64 memory_total_bytes = 4;
  20. double cpu_percent = 5;
  21. int64 total_executions = 6;
  22. int64 failed_executions = 7;
  23. double avg_execution_time_ms = 8;
  24. }
  25. // Runner capabilities
  26. message RunnerCapabilities {
  27. repeated string node_types = 1; // Supported node types
  28. int32 max_memory_per_script_mb = 2;
  29. int32 max_execution_timeout_sec = 3;
  30. }
  31. // Runner registration
  32. message Runner {
  33. string id = 1;
  34. string address = 2; // host:port
  35. RunnerStatus status = 3;
  36. int64 registered_at = 4;
  37. int64 last_heartbeat = 5;
  38. RunnerMetrics metrics = 6;
  39. RunnerCapabilities capabilities = 7;
  40. map<string, string> labels = 8;
  41. }
  42. // Register runner request
  43. message RegisterRunnerRequest {
  44. string runner_id = 1;
  45. string address = 2;
  46. RunnerCapabilities capabilities = 3;
  47. map<string, string> labels = 4;
  48. }
  49. // Register runner response
  50. message RegisterRunnerResponse {
  51. bool success = 1;
  52. string message = 2;
  53. }
  54. // Heartbeat request
  55. message HeartbeatRequest {
  56. string runner_id = 1;
  57. RunnerStatus status = 2;
  58. RunnerMetrics metrics = 3;
  59. }
  60. // Heartbeat response
  61. message HeartbeatResponse {
  62. bool success = 1;
  63. repeated string pending_cancellations = 2; // Execution IDs to cancel
  64. }
  65. // Unregister runner request
  66. message UnregisterRunnerRequest {
  67. string runner_id = 1;
  68. string reason = 2;
  69. }
  70. // Node definition
  71. message NodeDefinition {
  72. string id = 1;
  73. string name = 2;
  74. string category = 3;
  75. string version = 4;
  76. string description = 5;
  77. string icon = 6;
  78. string config_schema = 7; // JSON Schema
  79. string input_schema = 8; // JSON Schema
  80. string output_schema = 9; // JSON Schema
  81. repeated NodeInput inputs = 10;
  82. repeated NodeOutput outputs = 11;
  83. bool is_trigger = 12;
  84. }
  85. message NodeInput {
  86. string name = 1;
  87. string display_name = 2;
  88. string type = 3;
  89. bool required = 4;
  90. }
  91. message NodeOutput {
  92. string name = 1;
  93. string display_name = 2;
  94. string type = 3;
  95. string color = 4; // Optional color for visual representation
  96. }
  97. // List nodes request
  98. message ListNodesRequest {
  99. string category = 1; // Optional filter
  100. }
  101. // List nodes response
  102. message ListNodesResponse {
  103. repeated NodeDefinition nodes = 1;
  104. }
  105. // Reload node request
  106. message ReloadNodeRequest {
  107. string node_id = 1;
  108. }
  109. // Reload node response
  110. message ReloadNodeResponse {
  111. bool success = 1;
  112. NodeDefinition node = 2;
  113. Error error = 3;
  114. }
  115. // Get node code request
  116. message GetNodeCodeRequest {
  117. string node_id = 1;
  118. }
  119. // Get node code response
  120. message GetNodeCodeResponse {
  121. bool success = 1;
  122. string code = 2;
  123. string file_path = 3;
  124. Error error = 4;
  125. }
  126. // Save node code request
  127. message SaveNodeCodeRequest {
  128. string node_id = 1;
  129. string code = 2;
  130. }
  131. // Save node code response
  132. message SaveNodeCodeResponse {
  133. bool success = 1;
  134. NodeDefinition node = 2; // Updated node definition
  135. Error error = 3;
  136. }
  137. // Create node request
  138. message CreateNodeRequest {
  139. string id = 1;
  140. string name = 2;
  141. string category = 3;
  142. string code = 4;
  143. }
  144. // Create node response
  145. message CreateNodeResponse {
  146. bool success = 1;
  147. NodeDefinition node = 2;
  148. Error error = 3;
  149. }
  150. // Delete node request
  151. message DeleteNodeRequest {
  152. string node_id = 1;
  153. }
  154. // Delete node response
  155. message DeleteNodeResponse {
  156. bool success = 1;
  157. Error error = 2;
  158. }
  159. // Execute node request (for testing)
  160. message ExecuteNodeRequest {
  161. string node_type = 1;
  162. string config = 2; // JSON string
  163. string input = 3; // JSON string
  164. string context = 4; // JSON string - execution context
  165. }
  166. // Execute node response
  167. message ExecuteNodeResponse {
  168. bool success = 1;
  169. string output = 2; // JSON string
  170. string error = 3;
  171. int64 execution_time_ms = 4;
  172. }
  173. // Runner service - called by WebServer to execute workflows
  174. service RunnerService {
  175. // Execute a workflow
  176. rpc ExecuteWorkflow(ExecuteWorkflowRequest) returns (ExecuteWorkflowResponse);
  177. // Cancel an execution
  178. rpc CancelExecution(CancelExecutionRequest) returns (Empty);
  179. // Node management
  180. rpc ListNodes(ListNodesRequest) returns (ListNodesResponse);
  181. rpc ReloadNode(ReloadNodeRequest) returns (ReloadNodeResponse);
  182. rpc GetNodeCode(GetNodeCodeRequest) returns (GetNodeCodeResponse);
  183. rpc SaveNodeCode(SaveNodeCodeRequest) returns (SaveNodeCodeResponse);
  184. rpc CreateNode(CreateNodeRequest) returns (CreateNodeResponse);
  185. rpc DeleteNode(DeleteNodeRequest) returns (DeleteNodeResponse);
  186. // Execute single node (for testing)
  187. rpc ExecuteNode(ExecuteNodeRequest) returns (ExecuteNodeResponse);
  188. }
  189. // Runner registration service - runners call this on WebServer
  190. service RunnerRegistrationService {
  191. rpc Register(RegisterRunnerRequest) returns (RegisterRunnerResponse);
  192. rpc Heartbeat(HeartbeatRequest) returns (HeartbeatResponse);
  193. rpc Unregister(UnregisterRunnerRequest) returns (Empty);
  194. }
  195. // ============================================================================
  196. // Node Sync Service - WebServer exposes this for runners to fetch nodes
  197. // ============================================================================
  198. // Full node definition with code (for sync)
  199. message NodeDefinitionWithCode {
  200. string id = 1;
  201. string name = 2;
  202. string category = 3;
  203. string version = 4;
  204. string description = 5;
  205. string icon = 6;
  206. string code = 7; // Full JavaScript source
  207. string config_schema = 8; // JSON Schema
  208. string input_schema = 9; // JSON Schema
  209. string output_schema = 10; // JSON Schema
  210. repeated NodeInput inputs = 11;
  211. repeated NodeOutput outputs = 12;
  212. bool is_trigger = 13;
  213. string owner_id = 14;
  214. int64 created_at = 15;
  215. int64 updated_at = 16;
  216. }
  217. // Get all nodes request
  218. message GetAllNodesRequest {
  219. // Empty - returns all nodes
  220. }
  221. // Get all nodes response
  222. message GetAllNodesResponse {
  223. repeated NodeDefinitionWithCode nodes = 1;
  224. }
  225. // Get single node request
  226. message GetNodeRequest {
  227. string node_id = 1;
  228. }
  229. // Subscribe to node changes request
  230. message SubscribeToNodeChangesRequest {
  231. string runner_id = 1; // For tracking subscriptions
  232. }
  233. // Node change event
  234. message NodeChangeEvent {
  235. enum ChangeType {
  236. CHANGE_TYPE_UNSPECIFIED = 0;
  237. CHANGE_TYPE_CREATED = 1;
  238. CHANGE_TYPE_UPDATED = 2;
  239. CHANGE_TYPE_DELETED = 3;
  240. }
  241. ChangeType type = 1;
  242. string node_id = 2;
  243. NodeDefinitionWithCode node = 3; // Present for CREATED/UPDATED
  244. int64 timestamp = 4;
  245. }
  246. // Node sync service - WebServer hosts this for runners to sync nodes
  247. service NodeSyncService {
  248. // Get all node definitions
  249. rpc GetAllNodes(GetAllNodesRequest) returns (GetAllNodesResponse);
  250. // Get a single node by ID
  251. rpc GetNode(GetNodeRequest) returns (NodeDefinitionWithCode);
  252. // Subscribe to node changes (server-side streaming)
  253. rpc SubscribeToNodeChanges(SubscribeToNodeChangesRequest) returns (stream NodeChangeEvent);
  254. }