@hfyjq/crannia 0.0.0-stage → 1.0.0

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 (444) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +45 -0
  3. package/README.md +3 -3
  4. package/THIRD-PARTY-FRONTEND.md +5266 -0
  5. package/THIRD-PARTY-PYTHON.md +153 -0
  6. package/THIRD-PARTY.md +316 -0
  7. package/apps/desktop/quotes.txt +56 -0
  8. package/bus/__init__.py +0 -0
  9. package/bus/core.py +671 -0
  10. package/bus/loaders/__init__.py +0 -0
  11. package/bus/loaders/channel_loader.py +64 -0
  12. package/bus/loaders/provider_loader.py +338 -0
  13. package/bus/loaders/skill_loader.py +769 -0
  14. package/bus/loaders/skill_md.py +676 -0
  15. package/bus/mcp_disabled.py +190 -0
  16. package/bus/quarantine.py +468 -0
  17. package/bus/registry.py +2284 -0
  18. package/bus/skill_state.py +124 -0
  19. package/channels/__init__.py +0 -0
  20. package/channels/base.py +275 -0
  21. package/channels/capabilities.py +77 -0
  22. package/channels/cli_channel/__init__.py +0 -0
  23. package/channels/cli_channel/handler.py +299 -0
  24. package/channels/cli_channel/manifest.yaml +5 -0
  25. package/channels/converter.py +54 -0
  26. package/channels/dingtalk_channel/handler.py +690 -0
  27. package/channels/dingtalk_channel/manifest.yaml +12 -0
  28. package/channels/dingtalk_channel/media.py +299 -0
  29. package/channels/feishu_channel/handler.py +947 -0
  30. package/channels/feishu_channel/manifest.yaml +12 -0
  31. package/channels/feishu_channel/media.py +183 -0
  32. package/channels/message.py +300 -0
  33. package/channels/qq_bot_channel/__init__.py +1 -0
  34. package/channels/qq_bot_channel/handler.py +881 -0
  35. package/channels/qq_bot_channel/manifest.yaml +4 -0
  36. package/channels/telegram_channel/__init__.py +1 -0
  37. package/channels/telegram_channel/handler.py +813 -0
  38. package/channels/telegram_channel/manifest.yaml +4 -0
  39. package/channels/telegram_channel/media.py +231 -0
  40. package/channels/textfmt.py +58 -0
  41. package/channels/wechat_channel/__init__.py +1 -0
  42. package/channels/wechat_channel/auth.py +272 -0
  43. package/channels/wechat_channel/converter.py +148 -0
  44. package/channels/wechat_channel/handler.py +971 -0
  45. package/channels/wechat_channel/manifest.yaml +5 -0
  46. package/channels/wechat_channel/media.py +178 -0
  47. package/config.yaml +172 -0
  48. package/core/__init__.py +0 -0
  49. package/core/activity.py +706 -0
  50. package/core/agent_loop.py +7188 -0
  51. package/core/allowlist.py +279 -0
  52. package/core/approval.py +989 -0
  53. package/core/approval_timeout.py +228 -0
  54. package/core/artifacts.py +559 -0
  55. package/core/ask_user.py +238 -0
  56. package/core/async_loop.py +264 -0
  57. package/core/attachment_gc.py +235 -0
  58. package/core/auto_review.py +1513 -0
  59. package/core/browser/__init__.py +10 -0
  60. package/core/browser/cdp.py +198 -0
  61. package/core/browser/discover.py +97 -0
  62. package/core/browser/session.py +595 -0
  63. package/core/browser/tools.py +191 -0
  64. package/core/cancellation.py +244 -0
  65. package/core/capabilities.py +105 -0
  66. package/core/channel_configs.py +402 -0
  67. package/core/channel_health.py +66 -0
  68. package/core/channel_turns.py +759 -0
  69. package/core/chunker.py +119 -0
  70. package/core/code_intel.py +1205 -0
  71. package/core/command_policy.py +912 -0
  72. package/core/compaction_tool.py +54 -0
  73. package/core/computer/__init__.py +21 -0
  74. package/core/computer/annotate.py +164 -0
  75. package/core/computer/capture.py +202 -0
  76. package/core/computer/guard.py +209 -0
  77. package/core/computer/input.py +500 -0
  78. package/core/computer/session.py +381 -0
  79. package/core/computer/tools.py +928 -0
  80. package/core/computer/uia.py +508 -0
  81. package/core/computer/watch.py +270 -0
  82. package/core/computer/win32.py +954 -0
  83. package/core/content_sanitizer.py +340 -0
  84. package/core/context_pressure.py +173 -0
  85. package/core/context_report.py +236 -0
  86. package/core/cron/__init__.py +8 -0
  87. package/core/cron/expr.py +411 -0
  88. package/core/cron/runner.py +786 -0
  89. package/core/cron/store.py +434 -0
  90. package/core/cron/tools.py +271 -0
  91. package/core/daily_log.py +109 -0
  92. package/core/dedup.py +310 -0
  93. package/core/delivery_outbox.py +121 -0
  94. package/core/egress_gate.py +183 -0
  95. package/core/egress_preapproved.py +338 -0
  96. package/core/events.py +885 -0
  97. package/core/extension.py +461 -0
  98. package/core/externals.py +144 -0
  99. package/core/file_history.py +960 -0
  100. package/core/file_tools.py +1656 -0
  101. package/core/framework_preset.py +133 -0
  102. package/core/github_config.py +96 -0
  103. package/core/group_digest.py +140 -0
  104. package/core/group_dispatch.py +362 -0
  105. package/core/group_minutes.py +349 -0
  106. package/core/group_reply.py +526 -0
  107. package/core/groups.py +513 -0
  108. package/core/history_tools.py +390 -0
  109. package/core/hooks.py +653 -0
  110. package/core/i18n.py +329 -0
  111. package/core/ice/__init__.py +122 -0
  112. package/core/ice/boundary.py +252 -0
  113. package/core/ice/canary.py +143 -0
  114. package/core/ice/detect.py +123 -0
  115. package/core/ice/guard.py +185 -0
  116. package/core/ice/handles.py +226 -0
  117. package/core/ice/net_heuristics.py +198 -0
  118. package/core/ice/pseudonym.py +215 -0
  119. package/core/ice/reveal.py +229 -0
  120. package/core/ice/rules/builtin.toml +68 -0
  121. package/core/ice/rules.py +268 -0
  122. package/core/ice/store.py +191 -0
  123. package/core/ice/types.py +97 -0
  124. package/core/im_routing.py +389 -0
  125. package/core/image_input.py +1815 -0
  126. package/core/inbound.py +193 -0
  127. package/core/incidents.py +291 -0
  128. package/core/jobs.py +767 -0
  129. package/core/last_good.py +150 -0
  130. package/core/leaf_md.py +312 -0
  131. package/core/llm_errors.py +227 -0
  132. package/core/llm_retry.py +230 -0
  133. package/core/loop_health.py +221 -0
  134. package/core/mail_config.py +150 -0
  135. package/core/memory/__init__.py +0 -0
  136. package/core/memory/compressor.py +1214 -0
  137. package/core/memory/manager.py +1831 -0
  138. package/core/memory/output_trim.py +98 -0
  139. package/core/memory/session_memory.py +367 -0
  140. package/core/memory/short_term.py +1423 -0
  141. package/core/memory_extract.py +491 -0
  142. package/core/memory_organize.py +667 -0
  143. package/core/memory_store.py +860 -0
  144. package/core/memory_transfer.py +410 -0
  145. package/core/message_history.py +234 -0
  146. package/core/model_capabilities.py +138 -0
  147. package/core/model_configs.py +1308 -0
  148. package/core/modes.py +361 -0
  149. package/core/net_proxy.py +614 -0
  150. package/core/outbound.py +199 -0
  151. package/core/partial_read.py +65 -0
  152. package/core/paths.py +478 -0
  153. package/core/pdf_text_repair.py +545 -0
  154. package/core/persistent_shell.py +294 -0
  155. package/core/pipeline/__init__.py +18 -0
  156. package/core/pipeline/scheduler.py +1700 -0
  157. package/core/pipeline/stage.py +233 -0
  158. package/core/pipeline/stages/__init__.py +1 -0
  159. package/core/pipeline/stages/agent_loop.py +1055 -0
  160. package/core/pipeline/stages/group_reply.py +598 -0
  161. package/core/pipeline/stages/post_process.py +141 -0
  162. package/core/pipeline/stages/pre_process.py +3420 -0
  163. package/core/plan.py +688 -0
  164. package/core/plugin_packages.py +166 -0
  165. package/core/program_discipline.py +192 -0
  166. package/core/promote.py +166 -0
  167. package/core/prompt_assembler.py +680 -0
  168. package/core/recycle.py +295 -0
  169. package/core/request_snapshot.py +215 -0
  170. package/core/response_language.py +170 -0
  171. package/core/retention.py +203 -0
  172. package/core/retriever.py +97 -0
  173. package/core/rg.py +255 -0
  174. package/core/security.py +1544 -0
  175. package/core/services.py +188 -0
  176. package/core/session_date.py +98 -0
  177. package/core/session_key.py +81 -0
  178. package/core/session_model.py +230 -0
  179. package/core/session_pool.py +441 -0
  180. package/core/session_recap.py +181 -0
  181. package/core/session_workspace.py +362 -0
  182. package/core/settings_baseline.py +134 -0
  183. package/core/settings_transfer.py +497 -0
  184. package/core/shell.py +1783 -0
  185. package/core/side_call.py +130 -0
  186. package/core/skill_doctor.py +766 -0
  187. package/core/skill_factory.py +391 -0
  188. package/core/skill_guidance.py +346 -0
  189. package/core/skill_index.py +404 -0
  190. package/core/skill_load_report.py +47 -0
  191. package/core/skill_settings.py +257 -0
  192. package/core/skill_sources.py +313 -0
  193. package/core/state_registry.py +1217 -0
  194. package/core/steer.py +97 -0
  195. package/core/subagent.py +498 -0
  196. package/core/subagent_defs.py +200 -0
  197. package/core/subagent_model.py +114 -0
  198. package/core/summarizer.py +344 -0
  199. package/core/task_events.py +95 -0
  200. package/core/task_tool.py +148 -0
  201. package/core/tasks_notify.py +339 -0
  202. package/core/tiers.py +660 -0
  203. package/core/todos.py +230 -0
  204. package/core/token_calibrator.py +173 -0
  205. package/core/tokenizer.py +77 -0
  206. package/core/tool_names.py +61 -0
  207. package/core/tool_output_kind.py +185 -0
  208. package/core/tool_permission.py +398 -0
  209. package/core/tool_program.py +317 -0
  210. package/core/tool_program_child.py +78 -0
  211. package/core/touched_files.py +141 -0
  212. package/core/trace.py +170 -0
  213. package/core/unlock.py +138 -0
  214. package/core/updater.py +1463 -0
  215. package/core/version.py +14 -0
  216. package/core/walk_scope.py +207 -0
  217. package/core/window_estimate.py +298 -0
  218. package/core/workflow.py +282 -0
  219. package/core/workspace.py +3189 -0
  220. package/core/worktree.py +115 -0
  221. package/crannia_tray.py +278 -0
  222. package/creators/models.json +394 -0
  223. package/licenses/GPL-3.0.txt +619 -0
  224. package/licenses/LGPL-2.1.txt +502 -0
  225. package/licenses/LGPL-3.0.txt +165 -0
  226. package/licenses/MIT-chat-on-wechat.txt +19 -0
  227. package/licenses/MIT-deepseek-harness.txt +21 -0
  228. package/licenses/MPL-2.0.txt +373 -0
  229. package/licenses/Molio-LICENSE.txt +44 -0
  230. package/locales/en.json +1757 -0
  231. package/main.py +154 -0
  232. package/mcpx/__init__.py +14 -0
  233. package/mcpx/bridge.py +156 -0
  234. package/mcpx/client.py +546 -0
  235. package/mcpx/manager.py +522 -0
  236. package/mcpx/servers/__init__.py +22 -0
  237. package/mcpx/servers/web_search.py +655 -0
  238. package/package.json +33 -5
  239. package/providers/__init__.py +0 -0
  240. package/providers/anthropic/__init__.py +1 -0
  241. package/providers/anthropic/client.py +772 -0
  242. package/providers/anthropic/manifest.yaml +16 -0
  243. package/providers/azure/__init__.py +1 -0
  244. package/providers/azure/client.py +2 -0
  245. package/providers/azure/manifest.yaml +16 -0
  246. package/providers/base.py +1080 -0
  247. package/providers/cost_table.json +3779 -0
  248. package/providers/deepseek/__init__.py +1 -0
  249. package/providers/deepseek/client.py +20 -0
  250. package/providers/deepseek/manifest.yaml +16 -0
  251. package/providers/factory.py +136 -0
  252. package/providers/gemini/__init__.py +1 -0
  253. package/providers/gemini/client.py +2 -0
  254. package/providers/gemini/manifest.yaml +16 -0
  255. package/providers/grok/__init__.py +1 -0
  256. package/providers/grok/client.py +2 -0
  257. package/providers/grok/manifest.yaml +16 -0
  258. package/providers/hunyuan/__init__.py +1 -0
  259. package/providers/hunyuan/client.py +2 -0
  260. package/providers/hunyuan/manifest.yaml +16 -0
  261. package/providers/key_rotation.py +114 -0
  262. package/providers/lmstudio/__init__.py +1 -0
  263. package/providers/lmstudio/client.py +2 -0
  264. package/providers/lmstudio/manifest.yaml +14 -0
  265. package/providers/metadata.py +80 -0
  266. package/providers/minimax/__init__.py +1 -0
  267. package/providers/minimax/client.py +2 -0
  268. package/providers/minimax/manifest.yaml +16 -0
  269. package/providers/model_capabilities.json +6665 -0
  270. package/providers/moonshot/__init__.py +1 -0
  271. package/providers/moonshot/client.py +12 -0
  272. package/providers/moonshot/manifest.yaml +16 -0
  273. package/providers/ollama/__init__.py +1 -0
  274. package/providers/ollama/client.py +2 -0
  275. package/providers/ollama/manifest.yaml +16 -0
  276. package/providers/openai/__init__.py +1 -0
  277. package/providers/openai/client.py +13 -0
  278. package/providers/openai/manifest.yaml +16 -0
  279. package/providers/openai_compat.py +1010 -0
  280. package/providers/openrouter/__init__.py +1 -0
  281. package/providers/openrouter/client.py +2 -0
  282. package/providers/openrouter/manifest.yaml +16 -0
  283. package/providers/qwen/__init__.py +1 -0
  284. package/providers/qwen/client.py +2 -0
  285. package/providers/qwen/manifest.yaml +16 -0
  286. package/providers/rate_limiter.py +144 -0
  287. package/providers/siliconflow/__init__.py +1 -0
  288. package/providers/siliconflow/client.py +2 -0
  289. package/providers/siliconflow/manifest.yaml +16 -0
  290. package/providers/validation.py +171 -0
  291. package/providers/volcengine/__init__.py +1 -0
  292. package/providers/volcengine/client.py +2 -0
  293. package/providers/volcengine/manifest.yaml +16 -0
  294. package/providers/window_table.json +8909 -0
  295. package/providers/zhipu/__init__.py +1 -0
  296. package/providers/zhipu/client.py +2 -0
  297. package/providers/zhipu/manifest.yaml +16 -0
  298. package/requirements.txt +51 -0
  299. package/sbom.json +4296 -0
  300. package/skills/__init__.py +0 -0
  301. package/skills/entertainment/SKILL.md +35 -0
  302. package/skills/entertainment/__init__.py +1 -0
  303. package/skills/entertainment/handler.py +91 -0
  304. package/skills/entertainment/manifest.yaml +26 -0
  305. package/skills/file_parser/GUIDANCE.md +10 -0
  306. package/skills/file_parser/SKILL.md +62 -0
  307. package/skills/file_parser/__init__.py +0 -0
  308. package/skills/file_parser/handler.py +2553 -0
  309. package/skills/file_parser/manifest.yaml +646 -0
  310. package/skills/github/SKILL.md +32 -0
  311. package/skills/github/__init__.py +1 -0
  312. package/skills/github/handler.py +338 -0
  313. package/skills/github/manifest.yaml +205 -0
  314. package/skills/mail_parser/SKILL.md +68 -0
  315. package/skills/mail_parser/__init__.py +1 -0
  316. package/skills/mail_parser/handler.py +806 -0
  317. package/skills/mail_parser/manifest.yaml +315 -0
  318. package/skills/media_gen/GUIDANCE.md +19 -0
  319. package/skills/media_gen/SKILL.md +43 -0
  320. package/skills/media_gen/__init__.py +1 -0
  321. package/skills/media_gen/handler.py +430 -0
  322. package/skills/media_gen/manifest.yaml +88 -0
  323. package/skills/office_parser/GUIDANCE.md +20 -0
  324. package/skills/office_parser/SKILL.md +82 -0
  325. package/skills/office_parser/__init__.py +0 -0
  326. package/skills/office_parser/_excel_io.py +420 -0
  327. package/skills/office_parser/cell_validation.py +127 -0
  328. package/skills/office_parser/excel_query.py +566 -0
  329. package/skills/office_parser/excel_tools.py +2267 -0
  330. package/skills/office_parser/excel_transform.py +936 -0
  331. package/skills/office_parser/handler.py +3219 -0
  332. package/skills/office_parser/layout_spec.py +243 -0
  333. package/skills/office_parser/manifest.yaml +3060 -0
  334. package/skills/office_parser/ppt_tools.py +697 -0
  335. package/skills/office_parser/pptx_export/__init__.py +20 -0
  336. package/skills/office_parser/pptx_export/console_encoding.py +27 -0
  337. package/skills/office_parser/pptx_export/resource_paths.py +88 -0
  338. package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -0
  339. package/skills/office_parser/pptx_export/svg_finalize/align_embed_images.py +575 -0
  340. package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -0
  341. package/skills/office_parser/pptx_export/svg_finalize/embed_icons.py +498 -0
  342. package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -0
  343. package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -0
  344. package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -0
  345. package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -0
  346. package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -0
  347. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -0
  348. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -0
  349. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -0
  350. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/elements.py +2490 -0
  351. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -0
  352. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/styles.py +656 -0
  353. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/utils.py +770 -0
  354. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -0
  355. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -0
  356. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -0
  357. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -0
  358. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/media.py +141 -0
  359. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -0
  360. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -0
  361. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -0
  362. package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -0
  363. package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -0
  364. package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +21 -0
  365. package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -0
  366. package/skills/office_parser/references/layout_library.md +816 -0
  367. package/skills/office_parser/references/ppt-master/LICENSE +21 -0
  368. package/skills/office_parser/references/ppt-master/SKILL.md +765 -0
  369. package/skills/office_parser/references/ppt-master/SOURCE.md +102 -0
  370. package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -0
  371. package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -0
  372. package/skills/office_parser/references/ppt-master/references/strategist.md +880 -0
  373. package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -0
  374. package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -0
  375. package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -0
  376. package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -0
  377. package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -0
  378. package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -0
  379. package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -0
  380. package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -0
  381. package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -0
  382. package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -0
  383. package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -0
  384. package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -0
  385. package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -0
  386. package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -0
  387. package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -0
  388. package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -0
  389. package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -0
  390. package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -0
  391. package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -0
  392. package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -0
  393. package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -0
  394. package/skills/office_parser/references/ppt-master/workflows/beautify-pptx.md +278 -0
  395. package/skills/office_parser/references/ppt-master/workflows/customize-animations.md +287 -0
  396. package/skills/office_parser/references/ppt-master/workflows/native-enhance-pptx.md +323 -0
  397. package/skills/office_parser/references/ppt-master/workflows/template-fill-pptx.md +364 -0
  398. package/skills/office_parser/references/ppt-master/workflows/visual-review.md +190 -0
  399. package/skills/office_parser/references/spec_lock.md +235 -0
  400. package/skills/office_parser/session.py +274 -0
  401. package/skills/office_parser/soffice.py +68 -0
  402. package/skills/office_parser/word_tools.py +2909 -0
  403. package/skills/ppt-master/SKILL.md +47 -0
  404. package/vendor/ripgrep/COPYING.txt +3 -0
  405. package/vendor/ripgrep/LICENSE-MIT.txt +21 -0
  406. package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -0
  407. package/vendor/ripgrep/README.md +51 -0
  408. package/vendor/ripgrep/UNLICENSE.txt +24 -0
  409. package/vendor/ripgrep/package-source.json +19 -0
  410. package/vendor/ripgrep/win32-x64/rg.exe +0 -0
  411. package/web/__init__.py +0 -0
  412. package/web/__main__.py +62 -0
  413. package/web/server.py +8436 -0
  414. package/web/static/audio/safety-mode.mp3 +0 -0
  415. package/web/static/img/channel-dingtalk.png +0 -0
  416. package/web/static/img/channel-feishu.png +0 -0
  417. package/web/static/img/channel-qq.svg +1 -0
  418. package/web/static/img/channel-telegram.svg +1 -0
  419. package/web/static/img/channel-wechat.svg +1 -0
  420. package/web/static/img/logo.svg +12 -0
  421. package/web/static/img/provider-anthropic.svg +1 -0
  422. package/web/static/img/provider-azure.svg +1 -0
  423. package/web/static/img/provider-deepseek.svg +1 -0
  424. package/web/static/img/provider-gemini.svg +1 -0
  425. package/web/static/img/provider-grok.svg +1 -0
  426. package/web/static/img/provider-hunyuan.svg +1 -0
  427. package/web/static/img/provider-lmstudio.svg +1 -0
  428. package/web/static/img/provider-minimax.svg +1 -0
  429. package/web/static/img/provider-moonshot.svg +1 -0
  430. package/web/static/img/provider-ollama.svg +1 -0
  431. package/web/static/img/provider-openai.svg +1 -0
  432. package/web/static/img/provider-openrouter.svg +1 -0
  433. package/web/static/img/provider-qwen.svg +1 -0
  434. package/web/static/img/provider-siliconflow.svg +1 -0
  435. package/web/static/img/provider-volcengine.svg +1 -0
  436. package/web/static/img/provider-zhipu.svg +1 -0
  437. package/web/static/style.css +2029 -0
  438. package/web/templates/base.html +985 -0
  439. package/web/templates/chat.html +2462 -0
  440. package/web/templates/dashboard.html +821 -0
  441. package/web/templates/logs.html +49 -0
  442. package/web/templates/models.html +46 -0
  443. package/web/templates/security.html +2760 -0
  444. package/web/templates/skills.html +891 -0
@@ -0,0 +1,429 @@
1
+ """SVG path parsing, normalization, and DrawingML path command generation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import re
7
+ from dataclasses import dataclass, field
8
+
9
+ from .utils import px_to_emu
10
+
11
+
12
+ @dataclass
13
+ class PathCommand:
14
+ """A single SVG path command with its arguments."""
15
+ cmd: str # M, L, C, Z, etc. (uppercase = absolute)
16
+ args: list[float] = field(default_factory=list)
17
+
18
+
19
+ # Argument counts per SVG path command
20
+ _ARG_COUNTS = {
21
+ 'M': 2, 'm': 2, 'L': 2, 'l': 2,
22
+ 'H': 1, 'h': 1, 'V': 1, 'v': 1,
23
+ 'C': 6, 'c': 6, 'S': 4, 's': 4,
24
+ 'Q': 4, 'q': 4, 'T': 2, 't': 2,
25
+ 'A': 7, 'a': 7, 'Z': 0, 'z': 0,
26
+ }
27
+
28
+
29
+ def parse_svg_path(d: str) -> list[PathCommand]:
30
+ """Parse SVG path d attribute into a list of PathCommands."""
31
+ if not d:
32
+ return []
33
+
34
+ commands: list[PathCommand] = []
35
+ tokens = re.findall(
36
+ r'[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?', d
37
+ )
38
+
39
+ current_cmd: str | None = None
40
+ current_args: list[float] = []
41
+
42
+ def flush() -> None:
43
+ nonlocal current_cmd, current_args
44
+ if current_cmd is None:
45
+ return
46
+
47
+ n = _ARG_COUNTS.get(current_cmd, 0)
48
+ if n == 0:
49
+ commands.append(PathCommand(current_cmd, []))
50
+ elif n > 0 and len(current_args) >= n:
51
+ i = 0
52
+ while i + n <= len(current_args):
53
+ commands.append(PathCommand(current_cmd, current_args[i:i + n]))
54
+ # After first M, implicit commands become L
55
+ if current_cmd == 'M':
56
+ current_cmd = 'L'
57
+ elif current_cmd == 'm':
58
+ current_cmd = 'l'
59
+ i += n
60
+ current_args = []
61
+
62
+ for token in tokens:
63
+ if token in 'MmLlHhVvCcSsQqTtAaZz':
64
+ flush()
65
+ current_cmd = token
66
+ current_args = []
67
+ else:
68
+ try:
69
+ current_args.append(float(token))
70
+ except ValueError:
71
+ pass
72
+
73
+ flush()
74
+ return commands
75
+
76
+
77
+ def svg_path_to_absolute(commands: list[PathCommand]) -> list[PathCommand]:
78
+ """Convert all relative path commands to absolute."""
79
+ result: list[PathCommand] = []
80
+ cx, cy = 0.0, 0.0 # current point
81
+ sx, sy = 0.0, 0.0 # subpath start
82
+
83
+ for cmd in commands:
84
+ a = cmd.args
85
+ if cmd.cmd == 'M':
86
+ cx, cy = a[0], a[1]
87
+ sx, sy = cx, cy
88
+ result.append(PathCommand('M', [cx, cy]))
89
+ elif cmd.cmd == 'm':
90
+ cx += a[0]; cy += a[1]
91
+ sx, sy = cx, cy
92
+ result.append(PathCommand('M', [cx, cy]))
93
+ elif cmd.cmd == 'L':
94
+ cx, cy = a[0], a[1]
95
+ result.append(PathCommand('L', [cx, cy]))
96
+ elif cmd.cmd == 'l':
97
+ cx += a[0]; cy += a[1]
98
+ result.append(PathCommand('L', [cx, cy]))
99
+ elif cmd.cmd == 'H':
100
+ cx = a[0]
101
+ result.append(PathCommand('L', [cx, cy]))
102
+ elif cmd.cmd == 'h':
103
+ cx += a[0]
104
+ result.append(PathCommand('L', [cx, cy]))
105
+ elif cmd.cmd == 'V':
106
+ cy = a[0]
107
+ result.append(PathCommand('L', [cx, cy]))
108
+ elif cmd.cmd == 'v':
109
+ cy += a[0]
110
+ result.append(PathCommand('L', [cx, cy]))
111
+ elif cmd.cmd == 'C':
112
+ result.append(PathCommand('C', list(a)))
113
+ cx, cy = a[4], a[5]
114
+ elif cmd.cmd == 'c':
115
+ abs_args = [
116
+ cx + a[0], cy + a[1],
117
+ cx + a[2], cy + a[3],
118
+ cx + a[4], cy + a[5],
119
+ ]
120
+ result.append(PathCommand('C', abs_args))
121
+ cx, cy = abs_args[4], abs_args[5]
122
+ elif cmd.cmd == 'S':
123
+ result.append(PathCommand('S', list(a)))
124
+ cx, cy = a[2], a[3]
125
+ elif cmd.cmd == 's':
126
+ abs_args = [cx + a[0], cy + a[1], cx + a[2], cy + a[3]]
127
+ result.append(PathCommand('S', abs_args))
128
+ cx, cy = abs_args[2], abs_args[3]
129
+ elif cmd.cmd == 'Q':
130
+ result.append(PathCommand('Q', list(a)))
131
+ cx, cy = a[2], a[3]
132
+ elif cmd.cmd == 'q':
133
+ abs_args = [cx + a[0], cy + a[1], cx + a[2], cy + a[3]]
134
+ result.append(PathCommand('Q', abs_args))
135
+ cx, cy = abs_args[2], abs_args[3]
136
+ elif cmd.cmd == 'T':
137
+ result.append(PathCommand('T', list(a)))
138
+ cx, cy = a[0], a[1]
139
+ elif cmd.cmd == 't':
140
+ abs_args = [cx + a[0], cy + a[1]]
141
+ result.append(PathCommand('T', abs_args))
142
+ cx, cy = abs_args[0], abs_args[1]
143
+ elif cmd.cmd == 'A':
144
+ result.append(PathCommand('A', list(a)))
145
+ cx, cy = a[5], a[6]
146
+ elif cmd.cmd == 'a':
147
+ abs_args = [a[0], a[1], a[2], a[3], a[4], cx + a[5], cy + a[6]]
148
+ result.append(PathCommand('A', abs_args))
149
+ cx, cy = abs_args[5], abs_args[6]
150
+ elif cmd.cmd in ('Z', 'z'):
151
+ result.append(PathCommand('Z', []))
152
+ cx, cy = sx, sy
153
+
154
+ return result
155
+
156
+
157
+ def _reflect_control_point(
158
+ cp_x: float, cp_y: float,
159
+ cx: float, cy: float,
160
+ ) -> tuple[float, float]:
161
+ """Reflect a control point through the current point."""
162
+ return 2 * cx - cp_x, 2 * cy - cp_y
163
+
164
+
165
+ def _quad_to_cubic(
166
+ qp_x: float, qp_y: float,
167
+ p0_x: float, p0_y: float,
168
+ p3_x: float, p3_y: float,
169
+ ) -> list[float]:
170
+ """Convert quadratic bezier control point to cubic bezier control points."""
171
+ cp1_x = p0_x + 2.0 / 3.0 * (qp_x - p0_x)
172
+ cp1_y = p0_y + 2.0 / 3.0 * (qp_y - p0_y)
173
+ cp2_x = p3_x + 2.0 / 3.0 * (qp_x - p3_x)
174
+ cp2_y = p3_y + 2.0 / 3.0 * (qp_y - p3_y)
175
+ return [cp1_x, cp1_y, cp2_x, cp2_y, p3_x, p3_y]
176
+
177
+
178
+ def _arc_to_cubic_beziers(
179
+ cx_: float, cy_: float,
180
+ rx: float, ry: float,
181
+ phi: float,
182
+ large_arc: int, sweep: int,
183
+ x2: float, y2: float,
184
+ ) -> list[PathCommand]:
185
+ """Convert SVG arc (endpoint parameterization) to cubic bezier curves.
186
+
187
+ Uses the algorithm from the SVG spec (F.6.5) to convert endpoint to center
188
+ parameterization, then approximates each arc segment with cubic beziers.
189
+ """
190
+ x1, y1 = cx_, cy_
191
+
192
+ if abs(x1 - x2) < 1e-10 and abs(y1 - y2) < 1e-10:
193
+ return []
194
+
195
+ rx = abs(rx)
196
+ ry = abs(ry)
197
+ if rx < 1e-10 or ry < 1e-10:
198
+ return [PathCommand('L', [x2, y2])]
199
+
200
+ phi_rad = math.radians(phi)
201
+ cos_phi = math.cos(phi_rad)
202
+ sin_phi = math.sin(phi_rad)
203
+
204
+ # Step 1: Compute (x1', y1')
205
+ dx = (x1 - x2) / 2.0
206
+ dy = (y1 - y2) / 2.0
207
+ x1p = cos_phi * dx + sin_phi * dy
208
+ y1p = -sin_phi * dx + cos_phi * dy
209
+
210
+ # Step 2: Compute (cx', cy')
211
+ x1p2 = x1p * x1p
212
+ y1p2 = y1p * y1p
213
+ rx2 = rx * rx
214
+ ry2 = ry * ry
215
+
216
+ # Ensure radii are large enough
217
+ lam = x1p2 / rx2 + y1p2 / ry2
218
+ if lam > 1:
219
+ lam_sqrt = math.sqrt(lam)
220
+ rx *= lam_sqrt
221
+ ry *= lam_sqrt
222
+ rx2 = rx * rx
223
+ ry2 = ry * ry
224
+
225
+ num = max(rx2 * ry2 - rx2 * y1p2 - ry2 * x1p2, 0)
226
+ den = rx2 * y1p2 + ry2 * x1p2
227
+ sq = math.sqrt(num / den) if den > 1e-10 else 0.0
228
+
229
+ if large_arc == sweep:
230
+ sq = -sq
231
+
232
+ cxp = sq * rx * y1p / ry
233
+ cyp = -sq * ry * x1p / rx
234
+
235
+ # Step 3: Compute (cx, cy)
236
+ arc_cx = cos_phi * cxp - sin_phi * cyp + (x1 + x2) / 2.0
237
+ arc_cy = sin_phi * cxp + cos_phi * cyp + (y1 + y2) / 2.0
238
+
239
+ # Step 4: Compute theta1 and dtheta
240
+ def angle_between(ux: float, uy: float, vx: float, vy: float) -> float:
241
+ n = math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy))
242
+ if n < 1e-10:
243
+ return 0
244
+ c = max(-1, min(1, (ux * vx + uy * vy) / n))
245
+ a = math.acos(c)
246
+ if ux * vy - uy * vx < 0:
247
+ a = -a
248
+ return a
249
+
250
+ theta1 = angle_between(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry)
251
+ dtheta = angle_between(
252
+ (x1p - cxp) / rx, (y1p - cyp) / ry,
253
+ (-x1p - cxp) / rx, (-y1p - cyp) / ry,
254
+ )
255
+
256
+ if sweep == 0 and dtheta > 0:
257
+ dtheta -= 2 * math.pi
258
+ elif sweep == 1 and dtheta < 0:
259
+ dtheta += 2 * math.pi
260
+
261
+ # Split arc into segments of at most 90 degrees
262
+ n_segs = max(1, int(math.ceil(abs(dtheta) / (math.pi / 2))))
263
+ d_per_seg = dtheta / n_segs
264
+
265
+ result: list[PathCommand] = []
266
+ alpha = 4.0 / 3.0 * math.tan(d_per_seg / 4.0)
267
+
268
+ for i in range(n_segs):
269
+ t1 = theta1 + i * d_per_seg
270
+ t2 = theta1 + (i + 1) * d_per_seg
271
+
272
+ cos_t1 = math.cos(t1)
273
+ sin_t1 = math.sin(t1)
274
+ cos_t2 = math.cos(t2)
275
+ sin_t2 = math.sin(t2)
276
+
277
+ ep1_x = cos_t1 - alpha * sin_t1
278
+ ep1_y = sin_t1 + alpha * cos_t1
279
+ ep2_x = cos_t2 + alpha * sin_t2
280
+ ep2_y = sin_t2 - alpha * cos_t2
281
+ ep_x = cos_t2
282
+ ep_y = sin_t2
283
+
284
+ def transform_pt(px: float, py: float) -> tuple[float, float]:
285
+ x = rx * px
286
+ y = ry * py
287
+ xr = cos_phi * x - sin_phi * y + arc_cx
288
+ yr = sin_phi * x + cos_phi * y + arc_cy
289
+ return xr, yr
290
+
291
+ cp1 = transform_pt(ep1_x, ep1_y)
292
+ cp2 = transform_pt(ep2_x, ep2_y)
293
+ ep = transform_pt(ep_x, ep_y)
294
+
295
+ result.append(PathCommand('C', [cp1[0], cp1[1], cp2[0], cp2[1], ep[0], ep[1]]))
296
+
297
+ return result
298
+
299
+
300
+ def normalize_path_commands(commands: list[PathCommand]) -> list[PathCommand]:
301
+ """Normalize path commands to M/L/C/Z only.
302
+
303
+ Converts S -> C, Q -> C, T -> C, A -> C sequences.
304
+ """
305
+ result: list[PathCommand] = []
306
+ cx, cy = 0.0, 0.0
307
+ last_cp_x, last_cp_y = 0.0, 0.0
308
+ last_cmd = ''
309
+
310
+ for cmd in commands:
311
+ a = cmd.args
312
+
313
+ if cmd.cmd == 'M':
314
+ cx, cy = a[0], a[1]
315
+ last_cp_x, last_cp_y = cx, cy
316
+ result.append(cmd)
317
+ elif cmd.cmd == 'L':
318
+ cx, cy = a[0], a[1]
319
+ last_cp_x, last_cp_y = cx, cy
320
+ result.append(cmd)
321
+ elif cmd.cmd == 'C':
322
+ last_cp_x, last_cp_y = a[2], a[3]
323
+ cx, cy = a[4], a[5]
324
+ result.append(cmd)
325
+ elif cmd.cmd == 'S':
326
+ if last_cmd in ('C', 'S'):
327
+ rcp_x, rcp_y = _reflect_control_point(last_cp_x, last_cp_y, cx, cy)
328
+ else:
329
+ rcp_x, rcp_y = cx, cy
330
+ last_cp_x, last_cp_y = a[0], a[1]
331
+ new_cx, new_cy = a[2], a[3]
332
+ result.append(PathCommand('C', [rcp_x, rcp_y, a[0], a[1], new_cx, new_cy]))
333
+ cx, cy = new_cx, new_cy
334
+ elif cmd.cmd == 'Q':
335
+ cubic = _quad_to_cubic(a[0], a[1], cx, cy, a[2], a[3])
336
+ last_cp_x, last_cp_y = a[0], a[1]
337
+ result.append(PathCommand('C', cubic))
338
+ cx, cy = a[2], a[3]
339
+ elif cmd.cmd == 'T':
340
+ if last_cmd in ('Q', 'T'):
341
+ qp_x, qp_y = _reflect_control_point(last_cp_x, last_cp_y, cx, cy)
342
+ else:
343
+ qp_x, qp_y = cx, cy
344
+ last_cp_x, last_cp_y = qp_x, qp_y
345
+ cubic = _quad_to_cubic(qp_x, qp_y, cx, cy, a[0], a[1])
346
+ result.append(PathCommand('C', cubic))
347
+ cx, cy = a[0], a[1]
348
+ elif cmd.cmd == 'A':
349
+ arc_beziers = _arc_to_cubic_beziers(
350
+ cx, cy, a[0], a[1], a[2], int(a[3]), int(a[4]), a[5], a[6],
351
+ )
352
+ for bc in arc_beziers:
353
+ result.append(bc)
354
+ cx, cy = a[5], a[6]
355
+ last_cp_x, last_cp_y = cx, cy
356
+ elif cmd.cmd == 'Z':
357
+ result.append(cmd)
358
+ else:
359
+ result.append(cmd)
360
+
361
+ last_cmd = cmd.cmd
362
+
363
+ return result
364
+
365
+
366
+ def path_commands_to_drawingml(
367
+ commands: list[PathCommand],
368
+ offset_x: float = 0,
369
+ offset_y: float = 0,
370
+ scale_x: float = 1.0,
371
+ scale_y: float = 1.0,
372
+ ) -> tuple[str, float, float, float, float]:
373
+ """Convert normalized path commands to DrawingML <a:path> inner XML.
374
+
375
+ Returns:
376
+ (path_xml, min_x, min_y, width, height) in scaled+offset coordinates.
377
+ """
378
+ if not commands:
379
+ return '', 0, 0, 0, 0
380
+
381
+ # First pass: calculate bounding box
382
+ points: list[tuple[float, float]] = []
383
+ for cmd in commands:
384
+ if cmd.cmd in ('M', 'L'):
385
+ points.append((
386
+ cmd.args[0] * scale_x + offset_x,
387
+ cmd.args[1] * scale_y + offset_y,
388
+ ))
389
+ elif cmd.cmd == 'C':
390
+ for i in range(0, 6, 2):
391
+ points.append((
392
+ cmd.args[i] * scale_x + offset_x,
393
+ cmd.args[i + 1] * scale_y + offset_y,
394
+ ))
395
+
396
+ if not points:
397
+ return '', 0, 0, 0, 0
398
+
399
+ min_x = min(p[0] for p in points)
400
+ min_y = min(p[1] for p in points)
401
+ max_x = max(p[0] for p in points)
402
+ max_y = max(p[1] for p in points)
403
+
404
+ width = max(max_x - min_x, 1)
405
+ height = max(max_y - min_y, 1)
406
+
407
+ # Second pass: generate DrawingML path commands (EMU, relative to shape)
408
+ parts: list[str] = []
409
+ for cmd in commands:
410
+ if cmd.cmd == 'M':
411
+ x_emu = px_to_emu(cmd.args[0] * scale_x + offset_x - min_x)
412
+ y_emu = px_to_emu(cmd.args[1] * scale_y + offset_y - min_y)
413
+ parts.append(f'<a:moveTo><a:pt x="{x_emu}" y="{y_emu}"/></a:moveTo>')
414
+ elif cmd.cmd == 'L':
415
+ x_emu = px_to_emu(cmd.args[0] * scale_x + offset_x - min_x)
416
+ y_emu = px_to_emu(cmd.args[1] * scale_y + offset_y - min_y)
417
+ parts.append(f'<a:lnTo><a:pt x="{x_emu}" y="{y_emu}"/></a:lnTo>')
418
+ elif cmd.cmd == 'C':
419
+ pts = []
420
+ for i in range(0, 6, 2):
421
+ x_emu = px_to_emu(cmd.args[i] * scale_x + offset_x - min_x)
422
+ y_emu = px_to_emu(cmd.args[i + 1] * scale_y + offset_y - min_y)
423
+ pts.append(f'<a:pt x="{x_emu}" y="{y_emu}"/>')
424
+ parts.append(f'<a:cubicBezTo>{"".join(pts)}</a:cubicBezTo>')
425
+ elif cmd.cmd == 'Z':
426
+ parts.append('<a:close/>')
427
+
428
+ path_inner = '\n'.join(parts)
429
+ return path_inner, min_x, min_y, width, height