HelixAgentAi 0.1.3__py3-none-any.whl

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 (375) hide show
  1. .env.example +117 -0
  2. api/__init__.py +0 -0
  3. api/deps.py +75 -0
  4. api/errors.py +58 -0
  5. api/gateway.py +624 -0
  6. api/models.py +29 -0
  7. api/prometheus.py +23 -0
  8. cli/__init__.py +3 -0
  9. cli/__main__.py +6 -0
  10. cli/commands/__init__.py +0 -0
  11. cli/commands/chat.py +511 -0
  12. cli/commands/config.py +76 -0
  13. cli/commands/cron.py +112 -0
  14. cli/commands/docs.py +69 -0
  15. cli/commands/doctor.py +62 -0
  16. cli/commands/gateway.py +87 -0
  17. cli/commands/hub.py +408 -0
  18. cli/commands/install_cmd.py +89 -0
  19. cli/commands/logs.py +185 -0
  20. cli/commands/mcp.py +506 -0
  21. cli/commands/memory.py +53 -0
  22. cli/commands/models.py +648 -0
  23. cli/commands/run.py +58 -0
  24. cli/commands/search.py +223 -0
  25. cli/commands/skills.py +323 -0
  26. cli/commands/telegram.py +108 -0
  27. cli/commands/telegram_setup.py +198 -0
  28. cli/commands/update_cmd.py +106 -0
  29. cli/config/__init__.py +0 -0
  30. cli/core.py +329 -0
  31. cli/doctor/__init__.py +5 -0
  32. cli/doctor/checks.py +733 -0
  33. cli/doctor/findings.py +35 -0
  34. cli/doctor/fixes.py +128 -0
  35. cli/doctor/llm_doctor.py +180 -0
  36. cli/doctor/report.py +74 -0
  37. cli/doctor/runner.py +77 -0
  38. cli/installer/__init__.py +29 -0
  39. cli/installer/manifest.py +95 -0
  40. cli/installer/system.py +379 -0
  41. cli/installer/update.py +426 -0
  42. cli/main.py +322 -0
  43. cli/services/__init__.py +5 -0
  44. cli/services/cron_worker.py +33 -0
  45. cli/services/docs_site.py +128 -0
  46. cli/services/docs_worker.py +30 -0
  47. cli/services/gateway_daemon.py +271 -0
  48. cli/services/gateway_state.py +137 -0
  49. cli/services/gateway_worker.py +63 -0
  50. cli/services/supervisor.py +265 -0
  51. cli/shared/__init__.py +24 -0
  52. cli/shared/agent_host.py +43 -0
  53. cli/shared/commands/__init__.py +3 -0
  54. cli/shared/commands/agent_commands.py +488 -0
  55. cli/shared/commands/context_compress.py +87 -0
  56. cli/shared/commands/cron_commands.py +224 -0
  57. cli/shared/commands/project_init.py +67 -0
  58. cli/shared/commands/registry.py +118 -0
  59. cli/shared/commands/search_commands.py +75 -0
  60. cli/shared/commands/skills_commands.py +149 -0
  61. cli/shared/commands/subagent_commands.py +92 -0
  62. cli/shared/rich_text.py +35 -0
  63. cli/shared/slash_input.py +74 -0
  64. cli/tui/__init__.py +24 -0
  65. cli/tui/app.py +5 -0
  66. cli/tui/code/__init__.py +19 -0
  67. cli/tui/code/app.py +1374 -0
  68. cli/tui/code/handlers/__init__.py +4 -0
  69. cli/tui/code/handlers/events.py +211 -0
  70. cli/tui/code/handlers/slash.py +7 -0
  71. cli/tui/code/styles.py +85 -0
  72. cli/tui/code/widgets/__init__.py +17 -0
  73. cli/tui/code/widgets/context_bar.py +34 -0
  74. cli/tui/code/widgets/copy_selection_bar.py +77 -0
  75. cli/tui/code/widgets/prompt.py +11 -0
  76. cli/tui/code/widgets/slash_suggestions.py +40 -0
  77. cli/tui/code/widgets/status_bar.py +12 -0
  78. cli/tui/code/widgets/transcript.py +25 -0
  79. cli/tui/code/widgets/transcript_panel.py +41 -0
  80. cli/tui/legacy/app.py +4005 -0
  81. cli/tui/legacy/confirmation_modal.py +5 -0
  82. cli/tui/legacy/handlers/__init__.py +6 -0
  83. cli/tui/legacy/handlers/event_handler.py +381 -0
  84. cli/tui/legacy/handlers/slash_commands.py +306 -0
  85. cli/tui/legacy/plan_review_modal.py +35 -0
  86. cli/tui/legacy/subagents_widget.py +406 -0
  87. cli/tui/legacy/widgets/__init__.py +15 -0
  88. cli/tui/legacy/widgets/chat_log.py +42 -0
  89. cli/tui/legacy/widgets/input_area.py +15 -0
  90. cli/tui/legacy/widgets/main_content.py +29 -0
  91. cli/tui/legacy/widgets/sidebar.py +52 -0
  92. cli/tui/legacy/widgets/styles.py +366 -0
  93. cli/tui/modals/__init__.py +7 -0
  94. cli/tui/modals/confirmation.py +148 -0
  95. cli/tui/modals/confirmation_presenter.py +74 -0
  96. cli/tui/modals/cron_manager.py +222 -0
  97. cli/tui/modals/hub_browser.py +1054 -0
  98. cli/tui/modals/model_picker.py +188 -0
  99. cli/tui/modals/plan_review.py +135 -0
  100. cli/tui/modals/stack.py +29 -0
  101. cli/tui/modals/transcript_viewer.py +109 -0
  102. cli/tui/shared/__init__.py +43 -0
  103. cli/tui/shared/clipboard.py +91 -0
  104. cli/tui/shared/copy_bar.py +38 -0
  105. cli/tui/shared/diff_render.py +161 -0
  106. cli/tui/shared/formatters.py +73 -0
  107. cli/tui/shared/host_protocol.py +20 -0
  108. cli/tui/shared/keyboard_layout.py +131 -0
  109. cli/tui/shared/slash_suggestions.py +65 -0
  110. cli/tui/shared/text_escape.py +18 -0
  111. cli/tui/shared/transcript_store.py +134 -0
  112. cli/tui/web_entry.py +27 -0
  113. cli/tui/web_security.py +139 -0
  114. cli/tui/web_serve.py +88 -0
  115. cli/tui/web_server.py +70 -0
  116. cli/utils/__init__.py +0 -0
  117. cli/utils/banner.py +59 -0
  118. cli/utils/ports.py +42 -0
  119. cli/utils/rich_console.py +158 -0
  120. config.py +240 -0
  121. core/__init__.py +0 -0
  122. core/agent.py +409 -0
  123. core/agent_events.py +638 -0
  124. core/agent_execution.py +529 -0
  125. core/config_utils.py +126 -0
  126. core/context/__init__.py +17 -0
  127. core/context/compressor.py +186 -0
  128. core/context/manager.py +258 -0
  129. core/context/token_counter.py +125 -0
  130. core/cron/__init__.py +12 -0
  131. core/cron/expressions.py +43 -0
  132. core/cron/models.py +43 -0
  133. core/cron/notifier.py +79 -0
  134. core/cron/runner.py +211 -0
  135. core/cron/schedule_parse.py +76 -0
  136. core/cron/scheduler.py +76 -0
  137. core/cron/session_sync.py +75 -0
  138. core/cron/store.py +130 -0
  139. core/di/__init__.py +20 -0
  140. core/di/container.py +105 -0
  141. core/di/factories.py +20 -0
  142. core/di/providers.py +53 -0
  143. core/di/runtime_config.py +225 -0
  144. core/env_loader.py +178 -0
  145. core/evolution/__init__.py +7 -0
  146. core/evolution/engine.py +258 -0
  147. core/graph/__init__.py +7 -0
  148. core/graph/builder.py +199 -0
  149. core/graph/modes/__init__.py +13 -0
  150. core/graph/modes/_compile.py +22 -0
  151. core/graph/modes/hybrid.py +55 -0
  152. core/graph/modes/plan_execute.py +77 -0
  153. core/graph/modes/react.py +45 -0
  154. core/graph/modes/router.py +157 -0
  155. core/graph/nodes/__init__.py +3 -0
  156. core/graph/nodes/collect_subagent_node.py +60 -0
  157. core/graph/nodes/delegate_subagent_node.py +69 -0
  158. core/graph/nodes/execute_step_node.py +223 -0
  159. core/graph/nodes/finalize_node.py +146 -0
  160. core/graph/nodes/memory_retrieval_node.py +128 -0
  161. core/graph/nodes/meta_agent_node.py +83 -0
  162. core/graph/nodes/plan_node.py +481 -0
  163. core/graph/nodes/plan_review_node.py +177 -0
  164. core/graph/nodes/react_node.py +425 -0
  165. core/graph/nodes/self_refinement_node.py +117 -0
  166. core/graph/nodes/step_orchestrate_node.py +202 -0
  167. core/graph/nodes/tool_execution_node.py +108 -0
  168. core/graph/routers.py +99 -0
  169. core/graph/state.py +94 -0
  170. core/graph/tools.py +180 -0
  171. core/graph/visualization.py +310 -0
  172. core/hub/__init__.py +6 -0
  173. core/hub/autoupdate.py +119 -0
  174. core/hub/catalog.py +157 -0
  175. core/hub/claude_convert.py +45 -0
  176. core/hub/claude_marketplace.py +203 -0
  177. core/hub/claude_mcp.py +67 -0
  178. core/hub/clawhub.py +140 -0
  179. core/hub/hermes_hub.py +116 -0
  180. core/hub/importer.py +495 -0
  181. core/hub/installed.py +149 -0
  182. core/hub/interactive.py +178 -0
  183. core/hub/lockfile.py +75 -0
  184. core/hub/normalize.py +120 -0
  185. core/hub/skills_sh.py +67 -0
  186. core/hub/slash_registry.py +108 -0
  187. core/hub/sources.py +95 -0
  188. core/hub/updates.py +46 -0
  189. core/i18n/__init__.py +23 -0
  190. core/i18n/locale.py +81 -0
  191. core/i18n/messages.py +271 -0
  192. core/logging/__init__.py +14 -0
  193. core/logging/events.py +62 -0
  194. core/logging/paths.py +86 -0
  195. core/logging/reader.py +230 -0
  196. core/logging/rotation.py +81 -0
  197. core/logging/setup.py +93 -0
  198. core/logging/state.py +42 -0
  199. core/loop.py +55 -0
  200. core/loop_streaming.py +79 -0
  201. core/mcp/config.py +90 -0
  202. core/mcp/installer.py +269 -0
  203. core/mcp/manager.py +263 -0
  204. core/mcp/popular.py +144 -0
  205. core/mcp/tool.py +62 -0
  206. core/mcp/validate.py +52 -0
  207. core/memory/__init__.py +14 -0
  208. core/memory/chroma_embeddings.py +48 -0
  209. core/memory/conversation.py +274 -0
  210. core/memory/episodic.py +270 -0
  211. core/memory/facade.py +173 -0
  212. core/memory/ltm.py +128 -0
  213. core/memory/manager.py +17 -0
  214. core/memory/markdown.py +99 -0
  215. core/memory/procedural.py +218 -0
  216. core/memory/semantic.py +222 -0
  217. core/memory/strategic.py +286 -0
  218. core/memory/summarizer.py +77 -0
  219. core/memory/vector.py +236 -0
  220. core/meta_agent.py +300 -0
  221. core/models/__init__.py +32 -0
  222. core/models/catalog.py +436 -0
  223. core/models/client_factory.py +67 -0
  224. core/models/discovery.py +203 -0
  225. core/models/manager.py +186 -0
  226. core/models/profile_cleanup.py +118 -0
  227. core/models/provider.py +93 -0
  228. core/models/selector.py +106 -0
  229. core/models/setup_helpers.py +362 -0
  230. core/monitoring/__init__.py +4 -0
  231. core/monitoring/event_fields.py +25 -0
  232. core/monitoring/logger.py +152 -0
  233. core/monitoring/metrics.py +203 -0
  234. core/persistence.py +51 -0
  235. core/plan_review/__init__.py +27 -0
  236. core/plan_review/markdown_builder.py +144 -0
  237. core/plan_review/parser.py +245 -0
  238. core/plan_review/plan_storage.py +263 -0
  239. core/plan_review/review_events.py +121 -0
  240. core/plan_review/review_guard.py +200 -0
  241. core/platform_compat.py +213 -0
  242. core/presenters/__init__.py +3 -0
  243. core/presenters/live_buffer.py +108 -0
  244. core/project/__init__.py +27 -0
  245. core/project/helix_md.py +89 -0
  246. core/project/init_prompt.py +103 -0
  247. core/prompt_builder.py +132 -0
  248. core/runtime/__init__.py +6 -0
  249. core/runtime/executor.py +59 -0
  250. core/runtime/session.py +52 -0
  251. core/search/__init__.py +6 -0
  252. core/search/catalog.py +70 -0
  253. core/search/config.py +80 -0
  254. core/search/content.py +166 -0
  255. core/search/engine.py +108 -0
  256. core/search/providers.py +203 -0
  257. core/security/__init__.py +24 -0
  258. core/security/auth.py +178 -0
  259. core/security/confirmation.py +635 -0
  260. core/security/confirmation_events.py +117 -0
  261. core/security/permissions.py +53 -0
  262. core/security/safety.py +142 -0
  263. core/self_refinement/__init__.py +7 -0
  264. core/self_refinement/loop.py +295 -0
  265. core/session_models.py +176 -0
  266. core/skills/__init__.py +0 -0
  267. core/skills/assignments.py +165 -0
  268. core/skills/bundled/helix-cron/SKILL.md +124 -0
  269. core/skills/bundled.py +93 -0
  270. core/skills/generator.py +158 -0
  271. core/skills/manager.py +421 -0
  272. core/subagents/__init__.py +11 -0
  273. core/subagents/async_runner.py +375 -0
  274. core/subagents/base.py +134 -0
  275. core/subagents/communication.py +355 -0
  276. core/subagents/interaction.py +258 -0
  277. core/subagents/interaction_events.py +41 -0
  278. core/subagents/manager.py +405 -0
  279. core/subagents/process.py +933 -0
  280. core/subagents/registry.py +174 -0
  281. core/subagents/spawn.py +39 -0
  282. core/tools/__init__.py +0 -0
  283. core/tools/aliases.py +31 -0
  284. core/tools/ask_user.py +53 -0
  285. core/tools/base.py +42 -0
  286. core/tools/browser/__init__.py +5 -0
  287. core/tools/browser/policy.py +76 -0
  288. core/tools/browser/session.py +124 -0
  289. core/tools/browser/snapshot.py +77 -0
  290. core/tools/browser/tools.py +247 -0
  291. core/tools/code_executor.py +219 -0
  292. core/tools/database.py +167 -0
  293. core/tools/execution_context.py +52 -0
  294. core/tools/file_diff.py +77 -0
  295. core/tools/file_ops.py +155 -0
  296. core/tools/registry.py +182 -0
  297. core/tools/subagents.py +168 -0
  298. core/tools/terminal.py +79 -0
  299. core/tools/web_search.py +87 -0
  300. helixagentai-0.1.3.dist-info/METADATA +225 -0
  301. helixagentai-0.1.3.dist-info/RECORD +375 -0
  302. helixagentai-0.1.3.dist-info/WHEEL +4 -0
  303. helixagentai-0.1.3.dist-info/entry_points.txt +2 -0
  304. helixagentai-0.1.3.dist-info/licenses/LICENSE +21 -0
  305. integrations/__init__.py +1 -0
  306. integrations/telegram/__init__.py +5 -0
  307. integrations/telegram/agent_setup.py +32 -0
  308. integrations/telegram/approvals.py +237 -0
  309. integrations/telegram/bot.py +494 -0
  310. integrations/telegram/commands.py +140 -0
  311. integrations/telegram/config.py +59 -0
  312. integrations/telegram/env_store.py +123 -0
  313. integrations/telegram/event_handler.py +201 -0
  314. integrations/telegram/file_handler.py +478 -0
  315. integrations/telegram/host.py +649 -0
  316. integrations/telegram/interactive.py +781 -0
  317. integrations/telegram/keyboards.py +318 -0
  318. integrations/telegram/live_presenter.py +120 -0
  319. integrations/telegram/main.py +25 -0
  320. integrations/telegram/markdown.py +215 -0
  321. integrations/telegram/media_group.py +84 -0
  322. integrations/telegram/model_switch.py +286 -0
  323. integrations/telegram/render.py +76 -0
  324. integrations/telegram/session.py +65 -0
  325. integrations/telegram/setup_api.py +83 -0
  326. integrations/telegram/typing_indicator.py +66 -0
  327. integrations/telegram/voice_handler.py +355 -0
  328. web-docs/assets/css/style.css +816 -0
  329. web-docs/assets/js/app.js +633 -0
  330. web-docs/assets/logo.svg +33 -0
  331. web-docs/build.py +105 -0
  332. web-docs/content/en/ARCHITECTURE.md +71 -0
  333. web-docs/content/en/BROWSER_TOOLS.md +67 -0
  334. web-docs/content/en/CLI.md +493 -0
  335. web-docs/content/en/CONFIGURATION.md +134 -0
  336. web-docs/content/en/DEPLOYMENT.md +28 -0
  337. web-docs/content/en/DOCTOR.md +40 -0
  338. web-docs/content/en/GATEWAY.md +43 -0
  339. web-docs/content/en/HUB.md +74 -0
  340. web-docs/content/en/INSTALLATION.md +154 -0
  341. web-docs/content/en/LOGS.md +144 -0
  342. web-docs/content/en/PYPI.md +231 -0
  343. web-docs/content/en/QUICKSTART.md +31 -0
  344. web-docs/content/en/README.md +40 -0
  345. web-docs/content/en/SECURITY.md +53 -0
  346. web-docs/content/en/SLASH_COMMANDS.md +188 -0
  347. web-docs/content/en/START_HERE.md +75 -0
  348. web-docs/content/en/TELEGRAM.md +91 -0
  349. web-docs/content/en/TROUBLESHOOTING.md +52 -0
  350. web-docs/content/en/TUI.md +35 -0
  351. web-docs/content/en/USER_GUIDE.md +854 -0
  352. web-docs/content/ru/ARCHITECTURE.md +19 -0
  353. web-docs/content/ru/BROWSER_TOOLS.md +41 -0
  354. web-docs/content/ru/CLI.md +260 -0
  355. web-docs/content/ru/CONFIGURATION.md +63 -0
  356. web-docs/content/ru/DEPLOYMENT.md +28 -0
  357. web-docs/content/ru/DOCTOR.md +39 -0
  358. web-docs/content/ru/GATEWAY.md +37 -0
  359. web-docs/content/ru/HUB.md +74 -0
  360. web-docs/content/ru/INSTALLATION.md +102 -0
  361. web-docs/content/ru/LOGS.md +90 -0
  362. web-docs/content/ru/PYPI.md +90 -0
  363. web-docs/content/ru/QUICKSTART.md +20 -0
  364. web-docs/content/ru/README.md +29 -0
  365. web-docs/content/ru/SECURITY.md +53 -0
  366. web-docs/content/ru/SLASH_COMMANDS.md +161 -0
  367. web-docs/content/ru/START_HERE.md +72 -0
  368. web-docs/content/ru/TELEGRAM.md +118 -0
  369. web-docs/content/ru/TROUBLESHOOTING.md +50 -0
  370. web-docs/content/ru/TUI.md +35 -0
  371. web-docs/content/ru/USER_GUIDE.md +854 -0
  372. web-docs/index.html +86 -0
  373. web-docs/nav.json +122 -0
  374. web-docs/search-index.json +402 -0
  375. web-docs/serve.py +32 -0
.env.example ADDED
@@ -0,0 +1,117 @@
1
+ # Helix environment — copy to ~/.helix/.env (primary location)
2
+ # Optional: ./.env in a project dir (lower priority than ~/.helix/.env)
3
+
4
+ # --- Environment ---
5
+ HELIX_ENV=development
6
+ # HELIX_HOME= # override data dir (default: ~/.helix, XDG_DATA_HOME/helix, or %LOCALAPPDATA%\Helix on Windows)
7
+ # production: forces auth, stricter Telegram/CORS checks
8
+
9
+ # --- LLM (legacy single-provider; prefer helix models setup + profile providers) ---
10
+ MODEL=qwen2.5-coder:32b
11
+ BASE_URL=http://localhost:11434/v1
12
+ API_KEY=ollama
13
+ TEMPERATURE=0.7
14
+
15
+ # --- Cloud provider API keys (used via ${ENV:VAR} in ~/.helix/profiles/*/config.yaml) ---
16
+ # OPENAI_API_KEY=
17
+ # OPENROUTER_API_KEY=
18
+ # OPENROUTER_HTTP_REFERER=https://github.com/your-org/helix
19
+ # DEEPSEEK_API_KEY=
20
+ # MOONSHOT_API_KEY=
21
+ # XAI_API_KEY=
22
+ # GROQ_API_KEY=
23
+ # GOOGLE_API_KEY=
24
+ # MISTRAL_API_KEY=
25
+ # TOGETHER_API_KEY=
26
+ # FIREWORKS_API_KEY=
27
+ # CEREBRAS_API_KEY=
28
+ # LITELLM_API_KEY=
29
+ # Hosts for local / remote inference (used by helix models add ollama|litellm|vllm)
30
+ # OLLAMA_HOST=http://127.0.0.1:11434
31
+ # LITELLM_API_BASE=http://127.0.0.1:4000
32
+ # VLLM_HOST=http://127.0.0.1:8000
33
+
34
+ # --- Agent ---
35
+ MAX_STEPS=15
36
+ DATA_DIR=data
37
+
38
+ # --- Logging (helix logs) ---
39
+ # HELIX_LOG_LEVEL=INFO
40
+ # HELIX_LOG_DEBUG=false
41
+ # HELIX_LOG_MAX_BYTES=10485760
42
+ # HELIX_LOG_BACKUP_COUNT=10
43
+ # HELIX_LOG_ROTATION_DAYS=14
44
+
45
+ # --- Web TUI (helix tui --web) ---
46
+ # HELIX_TUI_WEB_TOKEN= # required for --allow-lan / production; optional on 127.0.0.1
47
+
48
+ # --- Gateway ---
49
+ HELIX_GATEWAY_HOST=127.0.0.1
50
+ HELIX_GATEWAY_PORT=8000
51
+ # HELIX_GATEWAY_WITH_DOCS=1
52
+ # HELIX_DOCS_HOST=127.0.0.1
53
+ # HELIX_DOCS_PORT=8080
54
+ HELIX_REQUIRE_AUTH=false
55
+ HELIX_CORS_ORIGINS=http://127.0.0.1:8000,http://localhost:8000
56
+ HELIX_API_KEYS_DB=data/security/api_keys.db
57
+ HELIX_API_KEY_PEPPER=
58
+ HELIX_RATE_LIMIT_RPM=100
59
+ HELIX_ADMIN_RATE_LIMIT_RPM=30
60
+ HELIX_ENABLE_PROMETHEUS_METRICS=true
61
+
62
+ # --- Tools (production: disable risky tools) ---
63
+ HELIX_ENABLE_CODE_EXECUTOR=true
64
+ HELIX_ENABLE_TERMINAL_TOOL=true
65
+ HELIX_TERMINAL_COMMAND_WHITELIST=true
66
+ # Extra allowed commands/prefixes (comma-separated): helix gateway start, docker, make
67
+ # HELIX_TERMINAL_WHITELIST_EXTRA=helix,uv,docker,make
68
+
69
+ # --- Telegram (optional: uv sync --extra telegram) ---
70
+ TELEGRAM_BOT_TOKEN=
71
+ HELIX_TELEGRAM_ALLOWED_USERS=
72
+ # HELIX_TELEGRAM_ALLOW_ALL=true # dev only: allow any Telegram user (never use in production)
73
+ HELIX_TELEGRAM_PROFILE=default
74
+
75
+ # --- Voice Messages (Telegram) ---
76
+ # Вариант A — OpenAI Whisper напрямую:
77
+ # OPENAI_API_KEY=sk-...
78
+ # HELIX_WHISPER_MODEL=whisper-1
79
+ #
80
+ # Вариант B — через LiteLLM proxy (нужна модель whisper в config LiteLLM):
81
+ # HELIX_WHISPER_BASE_URL=http://192.168.88.252:4000/v1
82
+ # HELIX_WHISPER_API_KEY=sk-... # virtual key LiteLLM
83
+ # HELIX_WHISPER_MODEL=whisper # model_name из LiteLLM config, не whisper-1
84
+ #
85
+ # Вариант C — тот же litellm-провайдер из профиля (HELIX_WHISPER_USE_PROFILE_LITELLM=true):
86
+ # HELIX_WHISPER_MODEL=whisper
87
+ #
88
+ # Вариант D — локально на машине с агентом (без облака, нужен ffmpeg):
89
+ # uv sync --extra voice
90
+ # HELIX_WHISPER_BACKEND=local
91
+ # HELIX_WHISPER_LOCAL_MODEL=base # tiny | base | small | medium | large-v3
92
+ # HELIX_WHISPER_LOCAL_DEVICE=cpu # cuda для GPU
93
+ # HELIX_WHISPER_LOCAL_COMPUTE_TYPE=int8 # float16 на GPU
94
+ # HELIX_WHISPER_AUTO_DOWNLOAD=true # скачать модель при старте бота (по умолчанию)
95
+ # HELIX_WHISPER_LOCAL_DOWNLOAD_ROOT= # каталог кэша (по умолчанию ~/.helix/models/whisper)
96
+ # HELIX_TELEGRAM_VOICE_LANGUAGE=ru
97
+ #
98
+ # HELIX_WHISPER_BACKEND=auto # local если установлен faster-whisper, иначе API
99
+ # HELIX_TELEGRAM_VOICE_ENABLED=true
100
+
101
+ # --- Telegram files (photos, documents) ---
102
+ # HELIX_TELEGRAM_FILES_ENABLED=true
103
+ # HELIX_TELEGRAM_MAX_FILE_MB=20
104
+ # HELIX_TELEGRAM_MEDIA_GROUP_DELAY_MS=800 # пауза перед обработкой альбома
105
+ # HELIX_TELEGRAM_VISION_MODEL=smart # имя модели в LiteLLM с поддержкой vision
106
+ # Требуются также LITELLM_API_KEY + LITELLM_API_BASE (или helix models setup)
107
+
108
+ # --- Browser (optional: uv sync --extra browser) ---
109
+ ENABLE_BROWSER_TOOLS=true
110
+ BROWSER_HEADLESS=true
111
+ BROWSER_ALLOWED_HOSTS=
112
+
113
+ # --- Web search (helix search configure) ---
114
+ # FIRECRAWL_API_KEY=fc-...
115
+ # SEARXNG_BASE_URL=http://127.0.0.1:8080
116
+
117
+ # Profile secrets in config.yaml: use ${OPENAI_API_KEY} or ${ENV:OPENAI_API_KEY}
api/__init__.py ADDED
File without changes
api/deps.py ADDED
@@ -0,0 +1,75 @@
1
+ """FastAPI dependencies for Helix gateway."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ from fastapi import Header, HTTPException
8
+
9
+ from config import settings
10
+
11
+ # Set by gateway lifespan
12
+ api_key_manager = None
13
+ rate_limiter = None
14
+
15
+
16
+ def _extract_api_key(
17
+ authorization: Optional[str],
18
+ x_api_key: Optional[str],
19
+ ) -> Optional[str]:
20
+ if authorization and authorization.startswith("Bearer "):
21
+ return authorization[7:]
22
+ if x_api_key:
23
+ return x_api_key
24
+ return None
25
+
26
+
27
+ async def _validate_key(api_key: str, *, default_limit: int) -> dict:
28
+ if api_key_manager is None:
29
+ raise HTTPException(status_code=503, detail="API key manager not initialized")
30
+
31
+ key_info = await api_key_manager.validate_api_key(api_key)
32
+ if not key_info:
33
+ raise HTTPException(status_code=401, detail="Invalid API key")
34
+
35
+ limit = int(key_info.get("rate_limit") or default_limit)
36
+ key_hash = api_key_manager.hash_key(api_key)
37
+ if rate_limiter and not rate_limiter.check_rate_limit(key_hash, limit):
38
+ raise HTTPException(status_code=429, detail="Rate limit exceeded")
39
+
40
+ return key_info
41
+
42
+
43
+ async def verify_api_key(
44
+ authorization: Optional[str] = Header(None),
45
+ x_api_key: Optional[str] = Header(None),
46
+ ) -> Optional[dict]:
47
+ """Optional auth for public /v1 routes when require_auth is disabled."""
48
+ if not settings.effective_require_auth:
49
+ api_key = _extract_api_key(authorization, x_api_key)
50
+ if not api_key:
51
+ return None
52
+ return await _validate_key(api_key, default_limit=settings.rate_limit_rpm)
53
+
54
+ api_key = _extract_api_key(authorization, x_api_key)
55
+ if not api_key:
56
+ raise HTTPException(status_code=401, detail="API key required")
57
+ return await _validate_key(api_key, default_limit=settings.rate_limit_rpm)
58
+
59
+
60
+ async def verify_admin_key(
61
+ authorization: Optional[str] = Header(None),
62
+ x_api_key: Optional[str] = Header(None),
63
+ ) -> dict:
64
+ """Admin routes always require a valid admin API key."""
65
+ from core.security.permissions import PermissionChecker
66
+
67
+ api_key = _extract_api_key(authorization, x_api_key)
68
+ if not api_key:
69
+ raise HTTPException(status_code=401, detail="Admin API key required")
70
+
71
+ key_info = await _validate_key(api_key, default_limit=settings.admin_rate_limit_rpm)
72
+ checker = PermissionChecker(key_info["permissions"])
73
+ if not checker.is_admin():
74
+ raise HTTPException(status_code=403, detail="Admin permission required")
75
+ return key_info
api/errors.py ADDED
@@ -0,0 +1,58 @@
1
+ """OpenAI-compatible error mapping for the API gateway."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from fastapi import HTTPException
6
+
7
+
8
+ def openai_error_body(
9
+ message: str,
10
+ *,
11
+ error_type: str = "server_error",
12
+ code: str = "internal_error",
13
+ ) -> dict:
14
+ return {
15
+ "error": {
16
+ "message": message,
17
+ "type": error_type,
18
+ "code": code,
19
+ }
20
+ }
21
+
22
+
23
+ def agent_error_to_http(exc: Exception, *, default_status: int = 500) -> HTTPException:
24
+ """Map agent/runtime exceptions to OpenAI-style HTTPException detail."""
25
+ if isinstance(exc, HTTPException):
26
+ return exc
27
+
28
+ message = str(exc) or "Unknown error"
29
+ lower = message.lower()
30
+ status = default_status
31
+ error_type = "server_error"
32
+ code = "internal_error"
33
+
34
+ if "not initialized" in lower or "not ready" in lower:
35
+ status = 503
36
+ error_type = "service_unavailable"
37
+ code = "agent_unavailable"
38
+ elif "permission" in lower or "forbidden" in lower:
39
+ status = 403
40
+ error_type = "permission_denied"
41
+ code = "insufficient_permissions"
42
+ elif "confirmation" in lower or "denied" in lower:
43
+ status = 409
44
+ error_type = "confirmation_required"
45
+ code = "confirmation_denied"
46
+ elif "plan review" in lower or "review" in lower and "not found" in lower:
47
+ status = 404
48
+ error_type = "invalid_request_error"
49
+ code = "plan_review_not_found"
50
+ elif "timeout" in lower:
51
+ status = 504
52
+ error_type = "timeout"
53
+ code = "gateway_timeout"
54
+
55
+ return HTTPException(
56
+ status_code=status,
57
+ detail=openai_error_body(message, error_type=error_type, code=code),
58
+ )