runner.proto 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. string dynamic_outputs = 13; // JSON, ports derived from a placed node's config
  85. }
  86. message NodeInput {
  87. string name = 1;
  88. string display_name = 2;
  89. string type = 3;
  90. bool required = 4;
  91. }
  92. message NodeOutput {
  93. string name = 1;
  94. string display_name = 2;
  95. string type = 3;
  96. string color = 4; // Optional color for visual representation
  97. }
  98. // List nodes request
  99. message ListNodesRequest {
  100. string category = 1; // Optional filter
  101. }
  102. // List nodes response
  103. message ListNodesResponse {
  104. repeated NodeDefinition nodes = 1;
  105. }
  106. // Reload node request
  107. message ReloadNodeRequest {
  108. string node_id = 1;
  109. }
  110. // Reload node response
  111. message ReloadNodeResponse {
  112. bool success = 1;
  113. NodeDefinition node = 2;
  114. Error error = 3;
  115. }
  116. // Get node code request
  117. message GetNodeCodeRequest {
  118. string node_id = 1;
  119. }
  120. // Get node code response
  121. message GetNodeCodeResponse {
  122. bool success = 1;
  123. string code = 2;
  124. string file_path = 3;
  125. Error error = 4;
  126. }
  127. // Save node code request
  128. message SaveNodeCodeRequest {
  129. string node_id = 1;
  130. string code = 2;
  131. }
  132. // Save node code response
  133. message SaveNodeCodeResponse {
  134. bool success = 1;
  135. NodeDefinition node = 2; // Updated node definition
  136. Error error = 3;
  137. }
  138. // Create node request
  139. message CreateNodeRequest {
  140. string id = 1;
  141. string name = 2;
  142. string category = 3;
  143. string code = 4;
  144. }
  145. // Create node response
  146. message CreateNodeResponse {
  147. bool success = 1;
  148. NodeDefinition node = 2;
  149. Error error = 3;
  150. }
  151. // Delete node request
  152. message DeleteNodeRequest {
  153. string node_id = 1;
  154. }
  155. // Delete node response
  156. message DeleteNodeResponse {
  157. bool success = 1;
  158. Error error = 2;
  159. }
  160. // Execute node request (for testing)
  161. message ExecuteNodeRequest {
  162. string node_type = 1;
  163. string config = 2; // JSON string
  164. string input = 3; // JSON string
  165. string context = 4; // JSON string - execution context
  166. }
  167. // Execute node response
  168. message ExecuteNodeResponse {
  169. bool success = 1;
  170. string output = 2; // JSON string
  171. string error = 3;
  172. int64 execution_time_ms = 4;
  173. }
  174. // Runner service - called by WebServer to execute workflows
  175. service RunnerService {
  176. // Execute a workflow
  177. rpc ExecuteWorkflow(ExecuteWorkflowRequest) returns (ExecuteWorkflowResponse);
  178. // Cancel an execution
  179. rpc CancelExecution(CancelExecutionRequest) returns (Empty);
  180. // Node management
  181. rpc ListNodes(ListNodesRequest) returns (ListNodesResponse);
  182. rpc ReloadNode(ReloadNodeRequest) returns (ReloadNodeResponse);
  183. rpc GetNodeCode(GetNodeCodeRequest) returns (GetNodeCodeResponse);
  184. rpc SaveNodeCode(SaveNodeCodeRequest) returns (SaveNodeCodeResponse);
  185. rpc CreateNode(CreateNodeRequest) returns (CreateNodeResponse);
  186. rpc DeleteNode(DeleteNodeRequest) returns (DeleteNodeResponse);
  187. // Execute single node (for testing)
  188. rpc ExecuteNode(ExecuteNodeRequest) returns (ExecuteNodeResponse);
  189. }
  190. // Runner registration service - runners call this on WebServer
  191. service RunnerRegistrationService {
  192. rpc Register(RegisterRunnerRequest) returns (RegisterRunnerResponse);
  193. rpc Heartbeat(HeartbeatRequest) returns (HeartbeatResponse);
  194. rpc Unregister(UnregisterRunnerRequest) returns (Empty);
  195. }
  196. // ============================================================================
  197. // Node Sync Service - WebServer exposes this for runners to fetch nodes
  198. // ============================================================================
  199. // Full node definition with code (for sync)
  200. message NodeDefinitionWithCode {
  201. string id = 1;
  202. string name = 2;
  203. string category = 3;
  204. string version = 4;
  205. string description = 5;
  206. string icon = 6;
  207. string code = 7; // Full JavaScript source
  208. string config_schema = 8; // JSON Schema
  209. string input_schema = 9; // JSON Schema
  210. string output_schema = 10; // JSON Schema
  211. repeated NodeInput inputs = 11;
  212. repeated NodeOutput outputs = 12;
  213. bool is_trigger = 13;
  214. string owner_id = 14;
  215. int64 created_at = 15;
  216. int64 updated_at = 16;
  217. string dynamic_outputs = 17; // JSON, ports derived from a placed node's config
  218. }
  219. // Get all nodes request
  220. message GetAllNodesRequest {
  221. // Empty - returns all nodes
  222. }
  223. // Get all nodes response
  224. message GetAllNodesResponse {
  225. repeated NodeDefinitionWithCode nodes = 1;
  226. }
  227. // Get single node request
  228. message GetNodeRequest {
  229. string node_id = 1;
  230. }
  231. // Subscribe to node changes request
  232. message SubscribeToNodeChangesRequest {
  233. string runner_id = 1; // For tracking subscriptions
  234. }
  235. // Node change event
  236. message NodeChangeEvent {
  237. enum ChangeType {
  238. CHANGE_TYPE_UNSPECIFIED = 0;
  239. CHANGE_TYPE_CREATED = 1;
  240. CHANGE_TYPE_UPDATED = 2;
  241. CHANGE_TYPE_DELETED = 3;
  242. }
  243. ChangeType type = 1;
  244. string node_id = 2;
  245. NodeDefinitionWithCode node = 3; // Present for CREATED/UPDATED
  246. int64 timestamp = 4;
  247. }
  248. // Node sync service - WebServer hosts this for runners to sync nodes
  249. service NodeSyncService {
  250. // Get all node definitions
  251. rpc GetAllNodes(GetAllNodesRequest) returns (GetAllNodesResponse);
  252. // Get a single node by ID
  253. rpc GetNode(GetNodeRequest) returns (NodeDefinitionWithCode);
  254. // Subscribe to node changes (server-side streaming)
  255. rpc SubscribeToNodeChanges(SubscribeToNodeChangesRequest) returns (stream NodeChangeEvent);
  256. }