runner.proto 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. // Resume execution request
  175. message ResumeExecutionRequest {
  176. string execution_id = 1;
  177. string token = 2;
  178. string payload = 3; // JSON given by whoever answered
  179. }
  180. // Runner service - called by WebServer to execute workflows
  181. service RunnerService {
  182. // Execute a workflow
  183. rpc ExecuteWorkflow(ExecuteWorkflowRequest) returns (ExecuteWorkflowResponse);
  184. // Cancel an execution
  185. rpc CancelExecution(CancelExecutionRequest) returns (CancelExecutionResponse);
  186. // Continue an execution that paused for an answer
  187. rpc ResumeExecution(ResumeExecutionRequest) returns (ExecuteWorkflowResponse);
  188. // Node management
  189. rpc ListNodes(ListNodesRequest) returns (ListNodesResponse);
  190. rpc ReloadNode(ReloadNodeRequest) returns (ReloadNodeResponse);
  191. rpc GetNodeCode(GetNodeCodeRequest) returns (GetNodeCodeResponse);
  192. rpc SaveNodeCode(SaveNodeCodeRequest) returns (SaveNodeCodeResponse);
  193. rpc CreateNode(CreateNodeRequest) returns (CreateNodeResponse);
  194. rpc DeleteNode(DeleteNodeRequest) returns (DeleteNodeResponse);
  195. // Execute single node (for testing)
  196. rpc ExecuteNode(ExecuteNodeRequest) returns (ExecuteNodeResponse);
  197. }
  198. // Runner registration service - runners call this on WebServer
  199. service RunnerRegistrationService {
  200. rpc Register(RegisterRunnerRequest) returns (RegisterRunnerResponse);
  201. rpc Heartbeat(HeartbeatRequest) returns (HeartbeatResponse);
  202. rpc Unregister(UnregisterRunnerRequest) returns (Empty);
  203. }
  204. // ============================================================================
  205. // Node Sync Service - WebServer exposes this for runners to fetch nodes
  206. // ============================================================================
  207. // Full node definition with code (for sync)
  208. message NodeDefinitionWithCode {
  209. string id = 1;
  210. string name = 2;
  211. string category = 3;
  212. string version = 4;
  213. string description = 5;
  214. string icon = 6;
  215. string code = 7; // Full JavaScript source
  216. string config_schema = 8; // JSON Schema
  217. string input_schema = 9; // JSON Schema
  218. string output_schema = 10; // JSON Schema
  219. repeated NodeInput inputs = 11;
  220. repeated NodeOutput outputs = 12;
  221. bool is_trigger = 13;
  222. string owner_id = 14;
  223. int64 created_at = 15;
  224. int64 updated_at = 16;
  225. string dynamic_outputs = 17; // JSON, ports derived from a placed node's config
  226. }
  227. // Get all nodes request
  228. message GetAllNodesRequest {
  229. // Empty - returns all nodes
  230. }
  231. // Get all nodes response
  232. message GetAllNodesResponse {
  233. repeated NodeDefinitionWithCode nodes = 1;
  234. }
  235. // Get single node request
  236. message GetNodeRequest {
  237. string node_id = 1;
  238. }
  239. // Subscribe to node changes request
  240. message SubscribeToNodeChangesRequest {
  241. string runner_id = 1; // For tracking subscriptions
  242. }
  243. // Node change event
  244. message NodeChangeEvent {
  245. enum ChangeType {
  246. CHANGE_TYPE_UNSPECIFIED = 0;
  247. CHANGE_TYPE_CREATED = 1;
  248. CHANGE_TYPE_UPDATED = 2;
  249. CHANGE_TYPE_DELETED = 3;
  250. }
  251. ChangeType type = 1;
  252. string node_id = 2;
  253. NodeDefinitionWithCode node = 3; // Present for CREATED/UPDATED
  254. int64 timestamp = 4;
  255. }
  256. // Node sync service - WebServer hosts this for runners to sync nodes
  257. service NodeSyncService {
  258. // Get all node definitions
  259. rpc GetAllNodes(GetAllNodesRequest) returns (GetAllNodesResponse);
  260. // Get a single node by ID
  261. rpc GetNode(GetNodeRequest) returns (NodeDefinitionWithCode);
  262. // Subscribe to node changes (server-side streaming)
  263. rpc SubscribeToNodeChanges(SubscribeToNodeChangesRequest) returns (stream NodeChangeEvent);
  264. }