machinaos 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/.env.template +71 -0
  2. package/LICENSE +21 -0
  3. package/README.md +87 -0
  4. package/bin/cli.js +159 -0
  5. package/client/.dockerignore +45 -0
  6. package/client/Dockerfile +68 -0
  7. package/client/eslint.config.js +29 -0
  8. package/client/index.html +13 -0
  9. package/client/nginx.conf +66 -0
  10. package/client/package.json +48 -0
  11. package/client/src/App.tsx +27 -0
  12. package/client/src/Dashboard.tsx +1173 -0
  13. package/client/src/ParameterPanel.tsx +301 -0
  14. package/client/src/components/AIAgentNode.tsx +321 -0
  15. package/client/src/components/APIKeyValidator.tsx +118 -0
  16. package/client/src/components/ClaudeChatModelNode.tsx +18 -0
  17. package/client/src/components/ConditionalEdge.tsx +189 -0
  18. package/client/src/components/CredentialsModal.tsx +306 -0
  19. package/client/src/components/EdgeConditionEditor.tsx +443 -0
  20. package/client/src/components/GeminiChatModelNode.tsx +18 -0
  21. package/client/src/components/GenericNode.tsx +357 -0
  22. package/client/src/components/LocationParameterPanel.tsx +154 -0
  23. package/client/src/components/ModelNode.tsx +286 -0
  24. package/client/src/components/OpenAIChatModelNode.tsx +18 -0
  25. package/client/src/components/OutputPanel.tsx +471 -0
  26. package/client/src/components/ParameterRenderer.tsx +1874 -0
  27. package/client/src/components/SkillEditorModal.tsx +417 -0
  28. package/client/src/components/SquareNode.tsx +797 -0
  29. package/client/src/components/StartNode.tsx +250 -0
  30. package/client/src/components/ToolkitNode.tsx +365 -0
  31. package/client/src/components/TriggerNode.tsx +463 -0
  32. package/client/src/components/auth/LoginPage.tsx +247 -0
  33. package/client/src/components/auth/ProtectedRoute.tsx +59 -0
  34. package/client/src/components/base/BaseChatModelNode.tsx +271 -0
  35. package/client/src/components/icons/AIProviderIcons.tsx +50 -0
  36. package/client/src/components/maps/GoogleMapsPicker.tsx +137 -0
  37. package/client/src/components/maps/MapsPreviewPanel.tsx +110 -0
  38. package/client/src/components/maps/index.ts +26 -0
  39. package/client/src/components/parameterPanel/InputSection.tsx +1094 -0
  40. package/client/src/components/parameterPanel/LocationPanelLayout.tsx +65 -0
  41. package/client/src/components/parameterPanel/MapsSection.tsx +92 -0
  42. package/client/src/components/parameterPanel/MiddleSection.tsx +571 -0
  43. package/client/src/components/parameterPanel/OutputSection.tsx +81 -0
  44. package/client/src/components/parameterPanel/ParameterPanelLayout.tsx +82 -0
  45. package/client/src/components/parameterPanel/ToolSchemaEditor.tsx +436 -0
  46. package/client/src/components/parameterPanel/index.ts +42 -0
  47. package/client/src/components/shared/DataPanel.tsx +142 -0
  48. package/client/src/components/shared/JSONTreeRenderer.tsx +106 -0
  49. package/client/src/components/ui/AIResultModal.tsx +204 -0
  50. package/client/src/components/ui/AndroidSettingsPanel.tsx +401 -0
  51. package/client/src/components/ui/CodeEditor.tsx +81 -0
  52. package/client/src/components/ui/CollapsibleSection.tsx +88 -0
  53. package/client/src/components/ui/ComponentItem.tsx +154 -0
  54. package/client/src/components/ui/ComponentPalette.tsx +321 -0
  55. package/client/src/components/ui/ConsolePanel.tsx +1074 -0
  56. package/client/src/components/ui/ErrorBoundary.tsx +196 -0
  57. package/client/src/components/ui/InputNodesPanel.tsx +204 -0
  58. package/client/src/components/ui/MapSelector.tsx +314 -0
  59. package/client/src/components/ui/Modal.tsx +149 -0
  60. package/client/src/components/ui/NodeContextMenu.tsx +192 -0
  61. package/client/src/components/ui/NodeOutputPanel.tsx +1150 -0
  62. package/client/src/components/ui/OutputDisplayPanel.tsx +381 -0
  63. package/client/src/components/ui/SettingsPanel.tsx +243 -0
  64. package/client/src/components/ui/TopToolbar.tsx +736 -0
  65. package/client/src/components/ui/WhatsAppSettingsPanel.tsx +345 -0
  66. package/client/src/components/ui/WorkflowSidebar.tsx +294 -0
  67. package/client/src/config/antdTheme.ts +186 -0
  68. package/client/src/config/api.ts +54 -0
  69. package/client/src/contexts/AuthContext.tsx +221 -0
  70. package/client/src/contexts/ThemeContext.tsx +42 -0
  71. package/client/src/contexts/WebSocketContext.tsx +1971 -0
  72. package/client/src/factories/baseChatModelFactory.ts +256 -0
  73. package/client/src/hooks/useAndroidOperations.ts +164 -0
  74. package/client/src/hooks/useApiKeyValidation.ts +107 -0
  75. package/client/src/hooks/useApiKeys.ts +238 -0
  76. package/client/src/hooks/useAppTheme.ts +17 -0
  77. package/client/src/hooks/useComponentPalette.ts +51 -0
  78. package/client/src/hooks/useCopyPaste.ts +155 -0
  79. package/client/src/hooks/useDragAndDrop.ts +124 -0
  80. package/client/src/hooks/useDragVariable.ts +88 -0
  81. package/client/src/hooks/useExecution.ts +313 -0
  82. package/client/src/hooks/useParameterPanel.ts +176 -0
  83. package/client/src/hooks/useReactFlowNodes.ts +189 -0
  84. package/client/src/hooks/useToolSchema.ts +209 -0
  85. package/client/src/hooks/useWhatsApp.ts +196 -0
  86. package/client/src/hooks/useWorkflowManagement.ts +46 -0
  87. package/client/src/index.css +315 -0
  88. package/client/src/main.tsx +19 -0
  89. package/client/src/nodeDefinitions/aiAgentNodes.ts +336 -0
  90. package/client/src/nodeDefinitions/aiModelNodes.ts +340 -0
  91. package/client/src/nodeDefinitions/androidDeviceNodes.ts +140 -0
  92. package/client/src/nodeDefinitions/androidServiceNodes.ts +383 -0
  93. package/client/src/nodeDefinitions/chatNodes.ts +135 -0
  94. package/client/src/nodeDefinitions/codeNodes.ts +54 -0
  95. package/client/src/nodeDefinitions/documentNodes.ts +379 -0
  96. package/client/src/nodeDefinitions/index.ts +15 -0
  97. package/client/src/nodeDefinitions/locationNodes.ts +463 -0
  98. package/client/src/nodeDefinitions/schedulerNodes.ts +220 -0
  99. package/client/src/nodeDefinitions/skillNodes.ts +211 -0
  100. package/client/src/nodeDefinitions/toolNodes.ts +198 -0
  101. package/client/src/nodeDefinitions/utilityNodes.ts +284 -0
  102. package/client/src/nodeDefinitions/whatsappNodes.ts +865 -0
  103. package/client/src/nodeDefinitions/workflowNodes.ts +41 -0
  104. package/client/src/nodeDefinitions.ts +104 -0
  105. package/client/src/schemas/workflowSchema.ts +264 -0
  106. package/client/src/services/dynamicParameterService.ts +96 -0
  107. package/client/src/services/execution/aiAgentExecutionService.ts +35 -0
  108. package/client/src/services/executionService.ts +232 -0
  109. package/client/src/services/workflowApi.ts +91 -0
  110. package/client/src/store/useAppStore.ts +582 -0
  111. package/client/src/styles/theme.ts +508 -0
  112. package/client/src/styles/zIndex.ts +17 -0
  113. package/client/src/types/ComponentTypes.ts +39 -0
  114. package/client/src/types/EdgeCondition.ts +231 -0
  115. package/client/src/types/INodeProperties.ts +288 -0
  116. package/client/src/types/NodeTypes.ts +28 -0
  117. package/client/src/utils/formatters.ts +33 -0
  118. package/client/src/utils/googleMapsLoader.ts +140 -0
  119. package/client/src/utils/locationUtils.ts +85 -0
  120. package/client/src/utils/nodeUtils.ts +31 -0
  121. package/client/src/utils/workflow.ts +30 -0
  122. package/client/src/utils/workflowExport.ts +120 -0
  123. package/client/src/vite-env.d.ts +12 -0
  124. package/client/tailwind.config.js +60 -0
  125. package/client/tsconfig.json +25 -0
  126. package/client/tsconfig.node.json +11 -0
  127. package/client/vite.config.js +35 -0
  128. package/docker-compose.prod.yml +107 -0
  129. package/docker-compose.yml +104 -0
  130. package/docs-MachinaOs/README.md +85 -0
  131. package/docs-MachinaOs/deployment/docker.mdx +228 -0
  132. package/docs-MachinaOs/deployment/production.mdx +345 -0
  133. package/docs-MachinaOs/docs.json +75 -0
  134. package/docs-MachinaOs/faq.mdx +309 -0
  135. package/docs-MachinaOs/favicon.svg +5 -0
  136. package/docs-MachinaOs/installation.mdx +160 -0
  137. package/docs-MachinaOs/introduction.mdx +114 -0
  138. package/docs-MachinaOs/logo/dark.svg +6 -0
  139. package/docs-MachinaOs/logo/light.svg +6 -0
  140. package/docs-MachinaOs/nodes/ai-agent.mdx +216 -0
  141. package/docs-MachinaOs/nodes/ai-models.mdx +240 -0
  142. package/docs-MachinaOs/nodes/android.mdx +411 -0
  143. package/docs-MachinaOs/nodes/overview.mdx +181 -0
  144. package/docs-MachinaOs/nodes/schedulers.mdx +316 -0
  145. package/docs-MachinaOs/nodes/webhooks.mdx +330 -0
  146. package/docs-MachinaOs/nodes/whatsapp.mdx +305 -0
  147. package/docs-MachinaOs/quickstart.mdx +119 -0
  148. package/docs-MachinaOs/tutorials/ai-agent-workflow.mdx +177 -0
  149. package/docs-MachinaOs/tutorials/android-automation.mdx +242 -0
  150. package/docs-MachinaOs/tutorials/first-workflow.mdx +134 -0
  151. package/docs-MachinaOs/tutorials/whatsapp-automation.mdx +185 -0
  152. package/nul +0 -0
  153. package/package.json +70 -0
  154. package/scripts/build.js +158 -0
  155. package/scripts/check-ports.ps1 +33 -0
  156. package/scripts/clean.js +40 -0
  157. package/scripts/docker.js +93 -0
  158. package/scripts/kill-port.ps1 +154 -0
  159. package/scripts/start.js +210 -0
  160. package/scripts/stop.js +325 -0
  161. package/server/.dockerignore +44 -0
  162. package/server/Dockerfile +45 -0
  163. package/server/constants.py +249 -0
  164. package/server/core/__init__.py +1 -0
  165. package/server/core/cache.py +461 -0
  166. package/server/core/config.py +128 -0
  167. package/server/core/container.py +99 -0
  168. package/server/core/database.py +1211 -0
  169. package/server/core/logging.py +314 -0
  170. package/server/main.py +289 -0
  171. package/server/middleware/__init__.py +5 -0
  172. package/server/middleware/auth.py +89 -0
  173. package/server/models/__init__.py +1 -0
  174. package/server/models/auth.py +52 -0
  175. package/server/models/cache.py +24 -0
  176. package/server/models/database.py +211 -0
  177. package/server/models/nodes.py +455 -0
  178. package/server/package.json +9 -0
  179. package/server/pyproject.toml +72 -0
  180. package/server/requirements.txt +83 -0
  181. package/server/routers/__init__.py +1 -0
  182. package/server/routers/android.py +294 -0
  183. package/server/routers/auth.py +203 -0
  184. package/server/routers/database.py +151 -0
  185. package/server/routers/maps.py +142 -0
  186. package/server/routers/nodejs_compat.py +289 -0
  187. package/server/routers/webhook.py +90 -0
  188. package/server/routers/websocket.py +2127 -0
  189. package/server/routers/whatsapp.py +761 -0
  190. package/server/routers/workflow.py +200 -0
  191. package/server/services/__init__.py +1 -0
  192. package/server/services/ai.py +2415 -0
  193. package/server/services/android/__init__.py +27 -0
  194. package/server/services/android/broadcaster.py +114 -0
  195. package/server/services/android/client.py +608 -0
  196. package/server/services/android/manager.py +78 -0
  197. package/server/services/android/protocol.py +165 -0
  198. package/server/services/android_service.py +588 -0
  199. package/server/services/auth.py +131 -0
  200. package/server/services/chat_client.py +160 -0
  201. package/server/services/deployment/__init__.py +12 -0
  202. package/server/services/deployment/manager.py +706 -0
  203. package/server/services/deployment/state.py +47 -0
  204. package/server/services/deployment/triggers.py +275 -0
  205. package/server/services/event_waiter.py +785 -0
  206. package/server/services/execution/__init__.py +77 -0
  207. package/server/services/execution/cache.py +769 -0
  208. package/server/services/execution/conditions.py +373 -0
  209. package/server/services/execution/dlq.py +132 -0
  210. package/server/services/execution/executor.py +1351 -0
  211. package/server/services/execution/models.py +531 -0
  212. package/server/services/execution/recovery.py +235 -0
  213. package/server/services/handlers/__init__.py +126 -0
  214. package/server/services/handlers/ai.py +355 -0
  215. package/server/services/handlers/android.py +260 -0
  216. package/server/services/handlers/code.py +278 -0
  217. package/server/services/handlers/document.py +598 -0
  218. package/server/services/handlers/http.py +193 -0
  219. package/server/services/handlers/polyglot.py +105 -0
  220. package/server/services/handlers/tools.py +845 -0
  221. package/server/services/handlers/triggers.py +107 -0
  222. package/server/services/handlers/utility.py +822 -0
  223. package/server/services/handlers/whatsapp.py +476 -0
  224. package/server/services/maps.py +289 -0
  225. package/server/services/memory_store.py +103 -0
  226. package/server/services/node_executor.py +375 -0
  227. package/server/services/parameter_resolver.py +218 -0
  228. package/server/services/polyglot_client.py +169 -0
  229. package/server/services/scheduler.py +155 -0
  230. package/server/services/skill_loader.py +417 -0
  231. package/server/services/status_broadcaster.py +826 -0
  232. package/server/services/temporal/__init__.py +23 -0
  233. package/server/services/temporal/activities.py +344 -0
  234. package/server/services/temporal/client.py +76 -0
  235. package/server/services/temporal/executor.py +147 -0
  236. package/server/services/temporal/worker.py +251 -0
  237. package/server/services/temporal/workflow.py +355 -0
  238. package/server/services/temporal/ws_client.py +236 -0
  239. package/server/services/text.py +111 -0
  240. package/server/services/user_auth.py +172 -0
  241. package/server/services/websocket_client.py +29 -0
  242. package/server/services/workflow.py +597 -0
  243. package/server/skills/android-skill/SKILL.md +82 -0
  244. package/server/skills/assistant-personality/SKILL.md +45 -0
  245. package/server/skills/code-skill/SKILL.md +140 -0
  246. package/server/skills/http-skill/SKILL.md +161 -0
  247. package/server/skills/maps-skill/SKILL.md +170 -0
  248. package/server/skills/memory-skill/SKILL.md +154 -0
  249. package/server/skills/scheduler-skill/SKILL.md +84 -0
  250. package/server/skills/whatsapp-skill/SKILL.md +283 -0
  251. package/server/uv.lock +2916 -0
  252. package/server/whatsapp-rpc/.dockerignore +30 -0
  253. package/server/whatsapp-rpc/Dockerfile +44 -0
  254. package/server/whatsapp-rpc/Dockerfile.web +17 -0
  255. package/server/whatsapp-rpc/README.md +139 -0
  256. package/server/whatsapp-rpc/cli.js +95 -0
  257. package/server/whatsapp-rpc/configs/config.yaml +7 -0
  258. package/server/whatsapp-rpc/docker-compose.yml +35 -0
  259. package/server/whatsapp-rpc/docs/API.md +410 -0
  260. package/server/whatsapp-rpc/go.mod +67 -0
  261. package/server/whatsapp-rpc/go.sum +203 -0
  262. package/server/whatsapp-rpc/package.json +30 -0
  263. package/server/whatsapp-rpc/schema.json +1294 -0
  264. package/server/whatsapp-rpc/scripts/clean.cjs +66 -0
  265. package/server/whatsapp-rpc/scripts/cli.js +162 -0
  266. package/server/whatsapp-rpc/src/go/cmd/server/main.go +91 -0
  267. package/server/whatsapp-rpc/src/go/config/config.go +49 -0
  268. package/server/whatsapp-rpc/src/go/rpc/rpc.go +446 -0
  269. package/server/whatsapp-rpc/src/go/rpc/server.go +112 -0
  270. package/server/whatsapp-rpc/src/go/whatsapp/history.go +166 -0
  271. package/server/whatsapp-rpc/src/go/whatsapp/messages.go +390 -0
  272. package/server/whatsapp-rpc/src/go/whatsapp/service.go +2130 -0
  273. package/server/whatsapp-rpc/src/go/whatsapp/types.go +261 -0
  274. package/server/whatsapp-rpc/src/python/pyproject.toml +15 -0
  275. package/server/whatsapp-rpc/src/python/whatsapp_rpc/__init__.py +4 -0
  276. package/server/whatsapp-rpc/src/python/whatsapp_rpc/client.py +427 -0
  277. package/server/whatsapp-rpc/web/app.py +609 -0
  278. package/server/whatsapp-rpc/web/requirements.txt +6 -0
  279. package/server/whatsapp-rpc/web/rpc_client.py +427 -0
  280. package/server/whatsapp-rpc/web/static/openapi.yaml +59 -0
  281. package/server/whatsapp-rpc/web/templates/base.html +150 -0
  282. package/server/whatsapp-rpc/web/templates/contacts.html +240 -0
  283. package/server/whatsapp-rpc/web/templates/dashboard.html +320 -0
  284. package/server/whatsapp-rpc/web/templates/groups.html +328 -0
  285. package/server/whatsapp-rpc/web/templates/messages.html +465 -0
  286. package/server/whatsapp-rpc/web/templates/messaging.html +681 -0
  287. package/server/whatsapp-rpc/web/templates/send.html +259 -0
  288. package/server/whatsapp-rpc/web/templates/settings.html +459 -0
@@ -0,0 +1,455 @@
1
+ """Pydantic models for node validation with discriminated unions.
2
+
3
+ This module provides type-safe node validation using Pydantic v2 discriminated unions.
4
+ Benefits:
5
+ - O(1) hash map lookup vs O(n) sequential validation
6
+ - Better error messages (identifies exact expected variant)
7
+ - Type safety with IDE autocompletion
8
+ - Automatic API documentation generation
9
+ """
10
+
11
+ from typing import Literal, Union, Annotated, Optional, Dict, Any, List
12
+ from pydantic import BaseModel, Field, TypeAdapter
13
+ from datetime import datetime
14
+
15
+ from constants import (
16
+ AI_CHAT_MODEL_TYPES,
17
+ AI_AGENT_TYPES,
18
+ AI_MEMORY_TYPES,
19
+ GOOGLE_MAPS_TYPES,
20
+ ANDROID_SERVICE_NODE_TYPES,
21
+ ANDROID_SETUP_TYPES,
22
+ WHATSAPP_TYPES,
23
+ CHAT_TYPES,
24
+ CODE_EXECUTOR_TYPES,
25
+ HTTP_TYPES,
26
+ TEXT_TYPES,
27
+ WORKFLOW_CONTROL_TYPES,
28
+ TRIGGER_TYPES,
29
+ )
30
+
31
+
32
+ # =============================================================================
33
+ # BASE MODELS
34
+ # =============================================================================
35
+
36
+ class BaseNodeParams(BaseModel):
37
+ """Base class for all node parameters."""
38
+ model_config = {"extra": "allow"} # Allow extra fields for flexibility
39
+
40
+
41
+ # =============================================================================
42
+ # AI NODE MODELS
43
+ # =============================================================================
44
+
45
+ class AIChatModelParams(BaseNodeParams):
46
+ """Parameters for AI chat model nodes (OpenAI, Anthropic, Gemini, OpenRouter, Groq, Cerebras)."""
47
+ type: Literal["openaiChatModel", "anthropicChatModel", "geminiChatModel", "openrouterChatModel", "groqChatModel", "cerebrasChatModel"]
48
+ prompt: str = ""
49
+ model: str = ""
50
+ temperature: float = Field(default=0.7, ge=0.0, le=2.0)
51
+ max_tokens: Optional[int] = Field(default=1000, alias="maxTokens")
52
+ system_prompt: Optional[str] = Field(default="", alias="systemMessage")
53
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
54
+
55
+
56
+ class AIAgentParams(BaseNodeParams):
57
+ """Parameters for AI agent node."""
58
+ type: Literal["aiAgent"]
59
+ prompt: str = ""
60
+ provider: Literal["openai", "anthropic", "gemini"] = "openai"
61
+ model: str = ""
62
+ temperature: float = Field(default=0.7, ge=0.0, le=2.0)
63
+ max_tokens: Optional[int] = Field(default=1000, alias="maxTokens")
64
+ system_message: Optional[str] = Field(default="You are a helpful assistant", alias="systemMessage")
65
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
66
+
67
+
68
+ class ChatAgentParams(BaseNodeParams):
69
+ """Parameters for chat agent node (skill-based)."""
70
+ type: Literal["chatAgent"]
71
+ provider: Literal["openai", "anthropic", "gemini", "groq", "openrouter", "cerebras"] = "openai"
72
+ model: str = ""
73
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
74
+
75
+
76
+ class SimpleMemoryParams(BaseNodeParams):
77
+ """Parameters for simple memory node."""
78
+ type: Literal["simpleMemory"]
79
+ session_id: str = Field(default="default", alias="sessionId")
80
+ memory_type: Literal["buffer", "window"] = Field(default="buffer", alias="memoryType")
81
+ window_size: int = Field(default=10, alias="windowSize", ge=1, le=100)
82
+ clear_on_run: bool = Field(default=False, alias="clearOnRun")
83
+
84
+
85
+ # =============================================================================
86
+ # GOOGLE MAPS NODE MODELS
87
+ # =============================================================================
88
+
89
+ class CreateMapParams(BaseNodeParams):
90
+ """Parameters for create map node."""
91
+ type: Literal["createMap"]
92
+ center_lat: float = Field(default=0.0, alias="centerLat")
93
+ center_lng: float = Field(default=0.0, alias="centerLng")
94
+ zoom: int = Field(default=10, ge=1, le=20)
95
+ map_type: Literal["roadmap", "satellite", "terrain", "hybrid"] = Field(default="roadmap", alias="mapType")
96
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
97
+
98
+
99
+ class AddLocationsParams(BaseNodeParams):
100
+ """Parameters for add locations (geocoding) node."""
101
+ type: Literal["addLocations"]
102
+ address: str = ""
103
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
104
+
105
+
106
+ class ShowNearbyPlacesParams(BaseNodeParams):
107
+ """Parameters for show nearby places node."""
108
+ type: Literal["showNearbyPlaces"]
109
+ latitude: float = 0.0
110
+ longitude: float = 0.0
111
+ radius: int = Field(default=1000, ge=1, le=50000)
112
+ place_type: str = Field(default="restaurant", alias="placeType")
113
+ api_key: Optional[str] = Field(default=None, alias="apiKey")
114
+
115
+
116
+ # =============================================================================
117
+ # ANDROID NODE MODELS
118
+ # =============================================================================
119
+
120
+ class AndroidDeviceSetupParams(BaseNodeParams):
121
+ """Parameters for Android device setup node."""
122
+ type: Literal["androidDeviceSetup"]
123
+ connection_type: Literal["local", "remote"] = Field(default="local", alias="connection_type")
124
+ device_id: str = Field(default="", alias="device_id")
125
+ websocket_url: str = Field(default="", alias="websocket_url")
126
+ port: int = Field(default=8888, ge=1, le=65535)
127
+ auto_forward: bool = Field(default=True, alias="auto_forward")
128
+ target_device_id: str = Field(default="", alias="target_device_id")
129
+
130
+
131
+ class AndroidServiceParams(BaseNodeParams):
132
+ """Parameters for Android service nodes (battery, network, wifi, etc.)."""
133
+ type: str # Validated separately against ANDROID_SERVICE_NODE_TYPES
134
+ service_id: str = Field(default="battery", alias="service_id")
135
+ action: str = Field(default="status")
136
+ parameters: Dict[str, Any] = Field(default_factory=dict)
137
+ android_host: str = Field(default="localhost", alias="android_host")
138
+ android_port: int = Field(default=8888, alias="android_port", ge=1, le=65535)
139
+
140
+
141
+ # =============================================================================
142
+ # WHATSAPP NODE MODELS
143
+ # =============================================================================
144
+
145
+ class WhatsAppSendParams(BaseNodeParams):
146
+ """Parameters for WhatsApp send message node."""
147
+ type: Literal["whatsappSend"]
148
+ phone_number: str = Field(default="", alias="phoneNumber")
149
+ message: str = ""
150
+ message_type: Literal["text", "image", "video", "audio", "document"] = Field(default="text", alias="messageType")
151
+
152
+
153
+ class WhatsAppConnectParams(BaseNodeParams):
154
+ """Parameters for WhatsApp connect node."""
155
+ type: Literal["whatsappConnect"]
156
+
157
+
158
+ class WhatsAppReceiveParams(BaseNodeParams):
159
+ """Parameters for WhatsApp receive (trigger) node."""
160
+ type: Literal["whatsappReceive"]
161
+ message_type_filter: str = Field(default="all", alias="messageTypeFilter")
162
+ sender_filter: str = Field(default="all", alias="filter")
163
+ ignore_own: bool = Field(default=True, alias="ignoreOwnMessages")
164
+ include_media: bool = Field(default=False, alias="includeMediaData")
165
+
166
+
167
+ # =============================================================================
168
+ # CODE EXECUTOR NODE MODELS
169
+ # =============================================================================
170
+
171
+ class PythonExecutorParams(BaseNodeParams):
172
+ """Parameters for Python code executor node."""
173
+ type: Literal["pythonExecutor"]
174
+ code: str = ""
175
+ timeout: int = Field(default=30, ge=1, le=300)
176
+
177
+
178
+ class JavaScriptExecutorParams(BaseNodeParams):
179
+ """Parameters for JavaScript code executor node."""
180
+ type: Literal["javascriptExecutor"]
181
+ code: str = ""
182
+ timeout: int = Field(default=30, ge=1, le=300)
183
+
184
+
185
+ # =============================================================================
186
+ # HTTP NODE MODELS
187
+ # =============================================================================
188
+
189
+ class HttpRequestParams(BaseNodeParams):
190
+ """Parameters for HTTP request node."""
191
+ type: Literal["httpRequest"]
192
+ url: str = ""
193
+ method: Literal["GET", "POST", "PUT", "DELETE", "PATCH"] = "GET"
194
+ headers: Dict[str, str] = Field(default_factory=dict)
195
+ body: str = ""
196
+ timeout: int = Field(default=30, ge=1, le=300)
197
+
198
+
199
+ class WebhookTriggerParams(BaseNodeParams):
200
+ """Parameters for webhook trigger node."""
201
+ type: Literal["webhookTrigger"]
202
+ path: str = ""
203
+ method_filter: str = Field(default="all", alias="methodFilter")
204
+ require_auth: bool = Field(default=False, alias="requireAuth")
205
+
206
+
207
+ class WebhookResponseParams(BaseNodeParams):
208
+ """Parameters for webhook response node."""
209
+ type: Literal["webhookResponse"]
210
+ status_code: int = Field(default=200, alias="statusCode", ge=100, le=599)
211
+ content_type: str = Field(default="application/json", alias="contentType")
212
+ body: str = ""
213
+
214
+
215
+ # =============================================================================
216
+ # WORKFLOW CONTROL NODE MODELS
217
+ # =============================================================================
218
+
219
+ class StartNodeParams(BaseNodeParams):
220
+ """Parameters for start node."""
221
+ type: Literal["start"]
222
+ initial_data: str = Field(default="{}", alias="initialData")
223
+
224
+
225
+ class CronSchedulerParams(BaseNodeParams):
226
+ """Parameters for cron scheduler node."""
227
+ type: Literal["cronScheduler"]
228
+ frequency: Literal["seconds", "minutes", "hours", "days", "weeks", "months", "once"] = "minutes"
229
+ interval: int = Field(default=5, ge=1)
230
+ interval_minutes: int = Field(default=5, alias="intervalMinutes", ge=1)
231
+ interval_hours: int = Field(default=1, alias="intervalHours", ge=1)
232
+ daily_time: str = Field(default="09:00", alias="dailyTime")
233
+ weekly_time: str = Field(default="09:00", alias="weeklyTime")
234
+ weekday: str = Field(default="1")
235
+ monthly_time: str = Field(default="09:00", alias="monthlyTime")
236
+ month_day: str = Field(default="1", alias="monthDay")
237
+
238
+
239
+ class WorkflowTriggerParams(BaseNodeParams):
240
+ """Parameters for workflow trigger node."""
241
+ type: Literal["workflowTrigger"]
242
+
243
+
244
+ # =============================================================================
245
+ # TEXT NODE MODELS
246
+ # =============================================================================
247
+
248
+ class TextGeneratorParams(BaseNodeParams):
249
+ """Parameters for text generator node."""
250
+ type: Literal["textGenerator"]
251
+ template: str = ""
252
+
253
+
254
+ class FileHandlerParams(BaseNodeParams):
255
+ """Parameters for file handler node."""
256
+ type: Literal["fileHandler"]
257
+ action: Literal["read", "write", "append", "delete"] = "read"
258
+ file_path: str = Field(default="", alias="filePath")
259
+ content: str = ""
260
+
261
+
262
+ # =============================================================================
263
+ # CHAT NODE MODELS
264
+ # =============================================================================
265
+
266
+ class ChatSendParams(BaseNodeParams):
267
+ """Parameters for chat send node."""
268
+ type: Literal["chatSend"]
269
+ message: str = ""
270
+
271
+
272
+ class ChatHistoryParams(BaseNodeParams):
273
+ """Parameters for chat history node."""
274
+ type: Literal["chatHistory"]
275
+ limit: int = Field(default=50, ge=1, le=1000)
276
+
277
+
278
+ # =============================================================================
279
+ # DISCRIMINATED UNION - All Node Types
280
+ # =============================================================================
281
+
282
+ # AI Nodes
283
+ AINodeParams = Annotated[
284
+ Union[AIChatModelParams, AIAgentParams, ChatAgentParams, SimpleMemoryParams],
285
+ Field(discriminator="type")
286
+ ]
287
+
288
+ # Maps Nodes
289
+ MapsNodeParams = Annotated[
290
+ Union[CreateMapParams, AddLocationsParams, ShowNearbyPlacesParams],
291
+ Field(discriminator="type")
292
+ ]
293
+
294
+ # WhatsApp Nodes
295
+ WhatsAppNodeParams = Annotated[
296
+ Union[WhatsAppSendParams, WhatsAppConnectParams, WhatsAppReceiveParams],
297
+ Field(discriminator="type")
298
+ ]
299
+
300
+ # Code Executor Nodes
301
+ CodeNodeParams = Annotated[
302
+ Union[PythonExecutorParams, JavaScriptExecutorParams],
303
+ Field(discriminator="type")
304
+ ]
305
+
306
+ # HTTP Nodes
307
+ HttpNodeParams = Annotated[
308
+ Union[HttpRequestParams, WebhookTriggerParams, WebhookResponseParams],
309
+ Field(discriminator="type")
310
+ ]
311
+
312
+ # Workflow Control Nodes
313
+ WorkflowNodeParams = Annotated[
314
+ Union[StartNodeParams, CronSchedulerParams, WorkflowTriggerParams],
315
+ Field(discriminator="type")
316
+ ]
317
+
318
+ # Text Nodes
319
+ TextNodeParams = Annotated[
320
+ Union[TextGeneratorParams, FileHandlerParams],
321
+ Field(discriminator="type")
322
+ ]
323
+
324
+ # Chat Nodes
325
+ ChatNodeParams = Annotated[
326
+ Union[ChatSendParams, ChatHistoryParams],
327
+ Field(discriminator="type")
328
+ ]
329
+
330
+ # Master union of all known node types (excluding Android service which has dynamic types)
331
+ KnownNodeParams = Annotated[
332
+ Union[
333
+ # AI
334
+ AIChatModelParams, AIAgentParams, ChatAgentParams, SimpleMemoryParams,
335
+ # Maps
336
+ CreateMapParams, AddLocationsParams, ShowNearbyPlacesParams,
337
+ # Android Setup
338
+ AndroidDeviceSetupParams,
339
+ # WhatsApp
340
+ WhatsAppSendParams, WhatsAppConnectParams, WhatsAppReceiveParams,
341
+ # Code
342
+ PythonExecutorParams, JavaScriptExecutorParams,
343
+ # HTTP
344
+ HttpRequestParams, WebhookTriggerParams, WebhookResponseParams,
345
+ # Workflow
346
+ StartNodeParams, CronSchedulerParams, WorkflowTriggerParams,
347
+ # Text
348
+ TextGeneratorParams, FileHandlerParams,
349
+ # Chat
350
+ ChatSendParams, ChatHistoryParams,
351
+ ],
352
+ Field(discriminator="type")
353
+ ]
354
+
355
+
356
+ # =============================================================================
357
+ # EXECUTION REQUEST MODELS
358
+ # =============================================================================
359
+
360
+ class NodeExecutionRequest(BaseModel):
361
+ """Request model for node execution."""
362
+ node_id: str = Field(..., alias="nodeId", min_length=1)
363
+ node_type: str = Field(..., alias="nodeType", min_length=1)
364
+ parameters: Dict[str, Any] = Field(default_factory=dict)
365
+ nodes: Optional[List[Dict[str, Any]]] = None
366
+ edges: Optional[List[Dict[str, Any]]] = None
367
+ session_id: str = Field(default="default", alias="sessionId")
368
+
369
+ model_config = {"populate_by_name": True}
370
+
371
+
372
+ class NodeExecutionResponse(BaseModel):
373
+ """Response model for node execution."""
374
+ success: bool
375
+ node_id: str
376
+ node_type: str
377
+ result: Optional[Dict[str, Any]] = None
378
+ error: Optional[str] = None
379
+ execution_time: float
380
+ timestamp: str = Field(default_factory=lambda: datetime.now().isoformat())
381
+
382
+
383
+ # =============================================================================
384
+ # VALIDATION HELPERS
385
+ # =============================================================================
386
+
387
+ # Create TypeAdapter for discriminated union (created once at module level for performance)
388
+ _known_node_adapter = TypeAdapter(KnownNodeParams)
389
+
390
+ # Set of all known node types for fallback detection
391
+ _all_known_types: set = None # Lazy initialized
392
+
393
+
394
+ def _get_all_known_types() -> set:
395
+ """Lazily get all known node types."""
396
+ global _all_known_types
397
+ if _all_known_types is None:
398
+ _all_known_types = get_all_node_types()
399
+ return _all_known_types
400
+
401
+
402
+ def validate_node_params(node_type: str, params: Dict[str, Any]) -> BaseNodeParams:
403
+ """Validate node parameters using the appropriate model.
404
+
405
+ Uses Pydantic v2 discriminated unions for O(1) type lookup instead of
406
+ sequential if/elif validation. The discriminator field 'type' routes
407
+ to the correct model automatically.
408
+
409
+ For known node types, validation errors are raised (e.g., temperature > 2.0).
410
+ For unknown node types, falls back to BaseNodeParams (allows extensibility).
411
+
412
+ Args:
413
+ node_type: The node type string
414
+ params: The parameters dictionary
415
+
416
+ Returns:
417
+ Validated parameters model (specific subclass based on node_type)
418
+
419
+ Raises:
420
+ ValidationError: If validation fails for a known node type
421
+ """
422
+ # Add type to params for discriminator
423
+ params_with_type = {"type": node_type, **params}
424
+
425
+ # Handle Android service nodes separately (dynamic types not in KnownNodeParams)
426
+ if node_type in ANDROID_SERVICE_NODE_TYPES:
427
+ return AndroidServiceParams(**params_with_type)
428
+
429
+ # Check if this is a known type
430
+ if node_type in _get_all_known_types():
431
+ # Known type - use discriminated union (O(1) lookup)
432
+ # ValidationError will be raised if params are invalid
433
+ return _known_node_adapter.validate_python(params_with_type)
434
+ else:
435
+ # Unknown type - fall back to base model (allows extensibility)
436
+ return BaseNodeParams(**params_with_type)
437
+
438
+
439
+ def get_all_node_types() -> set:
440
+ """Get set of all known node types."""
441
+ return (
442
+ AI_CHAT_MODEL_TYPES |
443
+ AI_AGENT_TYPES |
444
+ AI_MEMORY_TYPES |
445
+ GOOGLE_MAPS_TYPES |
446
+ ANDROID_SERVICE_NODE_TYPES |
447
+ ANDROID_SETUP_TYPES |
448
+ WHATSAPP_TYPES |
449
+ CHAT_TYPES |
450
+ CODE_EXECUTOR_TYPES |
451
+ HTTP_TYPES |
452
+ TEXT_TYPES |
453
+ WORKFLOW_CONTROL_TYPES |
454
+ TRIGGER_TYPES
455
+ )
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "machina-backend",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "scripts": {
6
+ "start": "python -m uvicorn main:app --host 0.0.0.0 --port ${PORT:-3010}",
7
+ "dev": "python -m uvicorn main:app --host 127.0.0.1 --port ${PORT:-3010} --reload --reload-dir . --reload-exclude \"*.pyc\" --reload-exclude \"__pycache__\" --log-level warning"
8
+ }
9
+ }
@@ -0,0 +1,72 @@
1
+ [project]
2
+ name = "machinaos-server"
3
+ version = "0.1.0"
4
+ description = "MachinaOS workflow automation backend"
5
+ requires-python = ">=3.11"
6
+ dependencies = [
7
+ # Core
8
+ "fastapi>=0.115.0",
9
+ "uvicorn[standard]>=0.32.0",
10
+ "pydantic>=2.10.0",
11
+ "pydantic-settings>=2.6.0",
12
+
13
+ # Database
14
+ "sqlmodel>=0.0.22",
15
+ "aiosqlite>=0.20.0",
16
+
17
+ # HTTP/WebSocket
18
+ "httpx>=0.28.0",
19
+ "aiohttp>=3.11.0",
20
+ "websockets>=14.0",
21
+
22
+ # Google Maps
23
+ "googlemaps>=4.10.0",
24
+
25
+ # Logging & Serialization
26
+ "structlog>=24.1.0",
27
+ "orjson>=3.9.0",
28
+
29
+ # YAML parsing (for SKILL.md files)
30
+ "pyyaml>=6.0",
31
+
32
+ # Auth
33
+ "bcrypt>=4.2.0",
34
+ "python-jose[cryptography]>=3.3.0",
35
+ "email-validator>=2.0.0",
36
+
37
+ # AI - All providers (directly imported in ai.py)
38
+ "langchain-core>=0.3.0",
39
+ "langchain-openai>=0.2.0",
40
+ "langchain-anthropic>=0.3.0",
41
+ "langchain-google-genai>=2.0.0",
42
+ "langchain-groq>=0.2.0",
43
+ "langgraph>=0.2.0",
44
+
45
+ # Dependency Injection
46
+ "dependency-injector>=4.40.0",
47
+
48
+ # Temporal (distributed execution)
49
+ "temporalio>=1.7.0",
50
+
51
+ # Utils
52
+ "python-dotenv>=1.0.0",
53
+ "apscheduler>=3.10.0",
54
+ "qrcode[pil]>=8.0",
55
+ "pytz>=2024.1",
56
+ ]
57
+
58
+ [project.optional-dependencies]
59
+ dev = [
60
+ "pytest>=8.0.0",
61
+ "ruff>=0.8.0",
62
+ ]
63
+ extra-ai = [
64
+ "langchain-cerebras>=0.1.0",
65
+ ]
66
+ docs = [
67
+ "beautifulsoup4>=4.12.0",
68
+ "pypdf>=5.0.0",
69
+ ]
70
+
71
+ [tool.uv]
72
+ index-url = "https://pypi.org/simple"
@@ -0,0 +1,83 @@
1
+ # Core Framework
2
+ fastapi>=0.110.0
3
+ uvicorn[standard]>=0.27.0
4
+
5
+ # Performance optimization
6
+ uvloop>=0.19.0;sys_platform!='win32'
7
+ orjson>=3.10.0
8
+
9
+ # Database & ORM (Python 3.13 compatible versions)
10
+ sqlmodel>=0.0.18
11
+ sqlalchemy[asyncio]>=2.0.35
12
+ aiosqlite>=0.20.0
13
+
14
+ # Settings & Configuration
15
+ pydantic>=2.6.0
16
+ pydantic-settings>=2.2.0
17
+ python-dotenv>=1.0.0
18
+
19
+ # Dependency Injection
20
+ dependency-injector>=4.41.0
21
+
22
+ # Caching (Redis) - Python 3.13 compatible
23
+ redis>=5.0.0
24
+
25
+ # HTTP Client
26
+ httpx>=0.27.0
27
+
28
+ # WebSocket Client (for WhatsApp RPC)
29
+ websockets>=12.0
30
+
31
+ # Async HTTP Client (for Android relay WebSocket)
32
+ aiohttp>=3.9.0
33
+
34
+ # QR Code Generation (for WhatsApp QR display)
35
+ qrcode[pil]>=7.4.0
36
+
37
+ # Logging
38
+ structlog>=23.2.0
39
+
40
+ # AI Providers (LangChain) - compatible versions
41
+ # langchain-anthropic 1.3+ requires langchain-core 1.2.6+ for ModelProfile class
42
+ langchain-core>=1.2.6
43
+ langchain-openai>=1.0.0
44
+ langchain-anthropic>=1.3.0
45
+ # Gemini 3+ requires >=3.1.0 for thought_signature support in tool calling
46
+ langchain-google-genai>=3.1.0
47
+ langchain-groq>=0.1.0
48
+ langchain-cerebras>=0.1.0
49
+
50
+ # LangGraph - State machine for AI agents
51
+ langgraph>=1.0.6
52
+
53
+ # Temporal - Durable workflow execution (optional, requires TEMPORAL_ENABLED=true)
54
+ temporalio>=1.21.1
55
+
56
+ # Google Services
57
+ googlemaps>=4.10.0
58
+
59
+ # Scheduling
60
+ APScheduler>=3.10.0
61
+
62
+ # Web Search
63
+ duckduckgo-search>=8.0.0
64
+
65
+ # Authentication
66
+ bcrypt>=4.1.0
67
+ python-jose[cryptography]>=3.3.0
68
+ email-validator>=2.0.0
69
+
70
+ # Timezone support
71
+ pytz>=2024.1
72
+
73
+ # Document Processing Nodes
74
+ beautifulsoup4>=4.12.0
75
+ langchain-text-splitters>=0.3.0
76
+ langchain-huggingface>=0.1.0
77
+ chromadb>=0.5.0
78
+ qdrant-client>=1.12.0
79
+ sentence-transformers>=3.0.0
80
+ pypdf>=4.0.0
81
+ # marker-pdf>=1.0.0 # Optional: GPU OCR (requires CUDA)
82
+ # unstructured>=0.16.0 # Optional: Multi-format document parsing
83
+
@@ -0,0 +1 @@
1
+ # FastAPI route modules