kiari 0.1.0__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 (451) hide show
  1. kiari/README.md +31 -0
  2. kiari/__init__.py +46 -0
  3. kiari/__main__.py +9 -0
  4. kiari/cli/__init__.py +29 -0
  5. kiari/cli/_constants/common_option_groups.py +129 -0
  6. kiari/cli/_decorators/common_options.py +188 -0
  7. kiari/cli/_helpers/build_cli_args.py +70 -0
  8. kiari/cli/_helpers/render_bootstrap_message.py +37 -0
  9. kiari/cli/_helpers/run.py +18 -0
  10. kiari/cli/_helpers/setup_profile.py +24 -0
  11. kiari/cli/_i18n.py +197 -0
  12. kiari/cli/_schemas/cli_args.py +15 -0
  13. kiari/cli/_types/extra_args.py +3 -0
  14. kiari/cli/_types/save_mode.py +3 -0
  15. kiari/cli/_utils/graceful_shutdown.py +35 -0
  16. kiari/cli/admin/clear_cache/cli.py +101 -0
  17. kiari/cli/admin/cli.py +30 -0
  18. kiari/cli/admin/init/cli.py +75 -0
  19. kiari/cli/admin/wipe_data/cli.py +102 -0
  20. kiari/cli/batch/_constants/batch_option_group.py +11 -0
  21. kiari/cli/batch/_decorators/batch_options.py +22 -0
  22. kiari/cli/batch/_i18n.py +22 -0
  23. kiari/cli/batch/_operations/run_batch.py +28 -0
  24. kiari/cli/batch/batch_handler/__init__.py +25 -0
  25. kiari/cli/batch/batch_handler/_models/base_batch_handler.py +114 -0
  26. kiari/cli/batch/batch_handler/_schemas/batch_request.py +8 -0
  27. kiari/cli/batch/batch_handler/_schemas/batch_session.py +38 -0
  28. kiari/cli/batch/batch_handler/_services/batch_handler_registry.py +27 -0
  29. kiari/cli/batch/batch_handler/_settings.py +27 -0
  30. kiari/cli/batch/batch_handler/_types/batch_handler.py +24 -0
  31. kiari/cli/batch/batch_handler/_types/batch_handler_name.py +3 -0
  32. kiari/cli/batch/batch_handler/_types/batch_handler_specifier.py +12 -0
  33. kiari/cli/batch/cli.py +103 -0
  34. kiari/cli/cli.py +95 -0
  35. kiari/cli/console/_constants/console_option_group.py +20 -0
  36. kiari/cli/console/_decorators/console_options.py +65 -0
  37. kiari/cli/console/_i18n.py +43 -0
  38. kiari/cli/console/_operations/run_console.py +269 -0
  39. kiari/cli/console/_services/console_completer.py +80 -0
  40. kiari/cli/console/cli.py +105 -0
  41. kiari/cli/console/console_handler/__init__.py +25 -0
  42. kiari/cli/console/console_handler/_models/base_console_handler.py +214 -0
  43. kiari/cli/console/console_handler/_schemas/console_request.py +8 -0
  44. kiari/cli/console/console_handler/_schemas/console_session.py +69 -0
  45. kiari/cli/console/console_handler/_services/console_handler_registry.py +27 -0
  46. kiari/cli/console/console_handler/_settings.py +27 -0
  47. kiari/cli/console/console_handler/_types/console_handler.py +34 -0
  48. kiari/cli/console/console_handler/_types/console_handler_name.py +3 -0
  49. kiari/cli/console/console_handler/_types/console_handler_specifier.py +12 -0
  50. kiari/cli/console/console_renderer/__init__.py +8 -0
  51. kiari/cli/console/console_renderer/_helpers/render_console_hint.py +11 -0
  52. kiari/cli/console/console_renderer/_helpers/render_console_status.py +492 -0
  53. kiari/cli/console/console_state/__init__.py +3 -0
  54. kiari/cli/console/console_state/_types/console_state.py +3 -0
  55. kiari/cli/console/console_text/__init__.py +7 -0
  56. kiari/cli/console/console_text/_helpers/__init__.py +3 -0
  57. kiari/cli/console/console_text/_helpers/parse_console_text.py +71 -0
  58. kiari/cli/console/console_text/_schemas/__init__.py +3 -0
  59. kiari/cli/console/console_text/_schemas/console_text.py +8 -0
  60. kiari/cli/console/slash_command/__init__.py +20 -0
  61. kiari/cli/console/slash_command/_models/base_slash_command.py +49 -0
  62. kiari/cli/console/slash_command/_services/slash_command_registry.py +27 -0
  63. kiari/cli/console/slash_command/_settings.py +58 -0
  64. kiari/cli/console/slash_command/_types/slash_command.py +23 -0
  65. kiari/cli/console/slash_command/_types/slash_command_name.py +3 -0
  66. kiari/cli/console/slash_command/_types/slash_command_specifier.py +12 -0
  67. kiari/cli/console/slash_command_impl/attach/__init__.py +3 -0
  68. kiari/cli/console/slash_command_impl/attach/_i18n.py +35 -0
  69. kiari/cli/console/slash_command_impl/attach/_models/attach_slash_command.py +183 -0
  70. kiari/cli/console/slash_command_impl/back/__init__.py +3 -0
  71. kiari/cli/console/slash_command_impl/back/_i18n.py +17 -0
  72. kiari/cli/console/slash_command_impl/back/_models/back_slash_command.py +102 -0
  73. kiari/cli/console/slash_command_impl/chat_model/__init__.py +3 -0
  74. kiari/cli/console/slash_command_impl/chat_model/_i18n.py +16 -0
  75. kiari/cli/console/slash_command_impl/chat_model/_models/chat_model_slash_command.py +106 -0
  76. kiari/cli/console/slash_command_impl/clear/__init__.py +3 -0
  77. kiari/cli/console/slash_command_impl/clear/_i18n.py +14 -0
  78. kiari/cli/console/slash_command_impl/clear/_models/clear_slash_command.py +102 -0
  79. kiari/cli/console/slash_command_impl/copy/__init__.py +3 -0
  80. kiari/cli/console/slash_command_impl/copy/_i18n.py +20 -0
  81. kiari/cli/console/slash_command_impl/copy/_models/copy_slash_command.py +117 -0
  82. kiari/cli/console/slash_command_impl/event/__init__.py +3 -0
  83. kiari/cli/console/slash_command_impl/event/_i18n.py +42 -0
  84. kiari/cli/console/slash_command_impl/event/_models/event_slash_command.py +249 -0
  85. kiari/cli/console/slash_command_impl/file_info/__init__.py +3 -0
  86. kiari/cli/console/slash_command_impl/file_info/_i18n.py +40 -0
  87. kiari/cli/console/slash_command_impl/file_info/_models/file_info_slash_command.py +290 -0
  88. kiari/cli/console/slash_command_impl/help/__init__.py +3 -0
  89. kiari/cli/console/slash_command_impl/help/_i18n.py +9 -0
  90. kiari/cli/console/slash_command_impl/help/_models/help_slash_command.py +90 -0
  91. kiari/cli/console/slash_command_impl/metadata/__init__.py +3 -0
  92. kiari/cli/console/slash_command_impl/metadata/_i18n.py +59 -0
  93. kiari/cli/console/slash_command_impl/metadata/_models/metadata_slash_command.py +267 -0
  94. kiari/cli/console/slash_command_impl/run/__init__.py +3 -0
  95. kiari/cli/console/slash_command_impl/run/_i18n.py +27 -0
  96. kiari/cli/console/slash_command_impl/run/_models/run_slash_command.py +151 -0
  97. kiari/cli/console/slash_command_impl/show/__init__.py +3 -0
  98. kiari/cli/console/slash_command_impl/show/_i18n.py +18 -0
  99. kiari/cli/console/slash_command_impl/show/_models/show_slash_command.py +105 -0
  100. kiari/cli/console/slash_command_impl/stt/__init__.py +3 -0
  101. kiari/cli/console/slash_command_impl/stt/_i18n.py +13 -0
  102. kiari/cli/console/slash_command_impl/stt/_models/stt_slash_command.py +44 -0
  103. kiari/cli/console/slash_command_impl/tool/__init__.py +3 -0
  104. kiari/cli/console/slash_command_impl/tool/_i18n.py +29 -0
  105. kiari/cli/console/slash_command_impl/tool/_models/tool_slash_command.py +250 -0
  106. kiari/cli/console/slash_command_impl/tool_choice/__init__.py +3 -0
  107. kiari/cli/console/slash_command_impl/tool_choice/_i18n.py +17 -0
  108. kiari/cli/console/slash_command_impl/tool_choice/_models/tool_choice_slash_command.py +76 -0
  109. kiari/cli/console/slash_command_impl/tool_info/__init__.py +3 -0
  110. kiari/cli/console/slash_command_impl/tool_info/_i18n.py +55 -0
  111. kiari/cli/console/slash_command_impl/tool_info/_models/tool_info_slash_command.py +360 -0
  112. kiari/cli/console/slash_command_impl/tts/__init__.py +3 -0
  113. kiari/cli/console/slash_command_impl/tts/_i18n.py +13 -0
  114. kiari/cli/console/slash_command_impl/tts/_models/tts_slash_command.py +44 -0
  115. kiari/cli/ext/_operations/run_ext.py +21 -0
  116. kiari/cli/ext/cli.py +96 -0
  117. kiari/cli/ext/extension_command/__init__.py +23 -0
  118. kiari/cli/ext/extension_command/_models/base_extension_command.py +29 -0
  119. kiari/cli/ext/extension_command/_schemas/extension_command_context.py +8 -0
  120. kiari/cli/ext/extension_command/_services/extension_command_registry.py +26 -0
  121. kiari/cli/ext/extension_command/_settings.py +20 -0
  122. kiari/cli/ext/extension_command/_types/extension_command.py +16 -0
  123. kiari/cli/ext/extension_command/_types/extension_command_name.py +3 -0
  124. kiari/cli/ext/extension_command/_types/extension_command_specifier.py +5 -0
  125. kiari/cli/fastapi/cli.py +8 -0
  126. kiari/cli/profile/cli.py +29 -0
  127. kiari/cli/profile/copy/cli.py +86 -0
  128. kiari/cli/profile/delete/cli.py +89 -0
  129. kiari/cli/profile/list/cli.py +252 -0
  130. kiari/cli/profile/new/cli.py +67 -0
  131. kiari/cli/profile/set/cli.py +68 -0
  132. kiari/cli/profile/use/cli.py +57 -0
  133. kiari/cli/schedule/_constants/schedule_option_group.py +11 -0
  134. kiari/cli/schedule/_decorators/schedule_options.py +18 -0
  135. kiari/cli/schedule/_operations/run_schedule.py +76 -0
  136. kiari/cli/schedule/cli.py +55 -0
  137. kiari/cli/schedule/schedule_handler/__init__.py +18 -0
  138. kiari/cli/schedule/schedule_handler/_models/base_schedule_handler.py +261 -0
  139. kiari/cli/schedule/schedule_handler/_schemas/schedule_session.py +72 -0
  140. kiari/cli/schedule/schedule_handler/_services/schedule_handler_registry.py +27 -0
  141. kiari/cli/schedule/schedule_handler/_settings.py +27 -0
  142. kiari/cli/schedule/schedule_handler/_types/schedule_handler.py +42 -0
  143. kiari/cli/schedule/schedule_handler/_types/schedule_handler_name.py +3 -0
  144. kiari/cli/schedule/schedule_handler/_types/schedule_handler_specifier.py +3 -0
  145. kiari/cli/schedule/scheduler/__init__.py +11 -0
  146. kiari/cli/schedule/scheduler/_helpers/create_scheduler.py +34 -0
  147. kiari/cli/schedule/scheduler/_schemas/scheduler.py +11 -0
  148. kiari/cli/schedule/scheduler/_types/schedule_type.py +3 -0
  149. kiari/cli/schedule/scheduler/_utils/parse_duration.py +13 -0
  150. kiari/cli/streamlit/cli.py +8 -0
  151. kiari/cli/watch/_constants/watch_option_group.py +11 -0
  152. kiari/cli/watch/_decorators/watch_options.py +18 -0
  153. kiari/cli/watch/_operations/run_watch.py +111 -0
  154. kiari/cli/watch/cli.py +46 -0
  155. kiari/cli/watch/watch_handler/__init__.py +18 -0
  156. kiari/cli/watch/watch_handler/_models/base_watch_handler.py +134 -0
  157. kiari/cli/watch/watch_handler/_schemas/watch_session.py +41 -0
  158. kiari/cli/watch/watch_handler/_services/watch_handler_registry.py +27 -0
  159. kiari/cli/watch/watch_handler/_settings.py +28 -0
  160. kiari/cli/watch/watch_handler/_types/watch_handler.py +25 -0
  161. kiari/cli/watch/watch_handler/_types/watch_handler_name.py +3 -0
  162. kiari/cli/watch/watch_handler/_types/watch_handler_specifier.py +5 -0
  163. kiari/core/__init__.py +0 -0
  164. kiari/core/editor/__init__.py +11 -0
  165. kiari/core/editor/_helpers/edit_text.py +64 -0
  166. kiari/core/editor/_helpers/edit_text_with_validation.py +68 -0
  167. kiari/core/editor/_i18n.py +8 -0
  168. kiari/core/editor/_schemas/validation_result.py +17 -0
  169. kiari/core/exchange_rate/__init__.py +9 -0
  170. kiari/core/exchange_rate/_exceptions/exchange_rate_not_loaded_error.py +2 -0
  171. kiari/core/exchange_rate/_services/exchange_rate_store.py +62 -0
  172. kiari/core/file_info_source/__init__.py +9 -0
  173. kiari/core/file_info_source/_helpers/resolve_file_info_specifiers.py +57 -0
  174. kiari/core/file_info_source/_types/file_info_source.py +24 -0
  175. kiari/core/file_resolver/__init__.py +7 -0
  176. kiari/core/file_resolver/_helpers/resolve_file_paths.py +73 -0
  177. kiari/core/file_resolver/_types/file_path_pattern.py +7 -0
  178. kiari/core/finalizer/__init__.py +23 -0
  179. kiari/core/finalizer/_helpers/run_finalizers.py +20 -0
  180. kiari/core/finalizer/_models/base_finalizer.py +29 -0
  181. kiari/core/finalizer/_services/finalizer_registry.py +26 -0
  182. kiari/core/finalizer/_settings.py +26 -0
  183. kiari/core/finalizer/_types/finalizer.py +10 -0
  184. kiari/core/finalizer/_types/finalizer_name.py +3 -0
  185. kiari/core/finalizer/_types/finalizer_specifier.py +13 -0
  186. kiari/core/github/__init__.py +22 -0
  187. kiari/core/github/_helpers/fetch_github_dir.py +128 -0
  188. kiari/core/github/_helpers/fetch_github_file.py +69 -0
  189. kiari/core/github/_helpers/verify_github_trust.py +123 -0
  190. kiari/core/github/_i18n.py +20 -0
  191. kiari/core/github/_models/github_path_spec.py +99 -0
  192. kiari/core/github/_services/github_trusted_source_store.py +25 -0
  193. kiari/core/github/_settings.py +17 -0
  194. kiari/core/github/_types/github_path_pattern.py +23 -0
  195. kiari/core/logging/__init__.py +12 -0
  196. kiari/core/logging/_helpers/setup_logger.py +24 -0
  197. kiari/core/logging/_models/rich_log_handler.py +60 -0
  198. kiari/core/logging/_types/log_level.py +3 -0
  199. kiari/core/paths/__init__.py +25 -0
  200. kiari/core/paths/_utils/get_config_file_path.py +7 -0
  201. kiari/core/paths/_utils/get_github_cache_dir_path.py +7 -0
  202. kiari/core/paths/_utils/get_github_trusted_sources_file_path.py +7 -0
  203. kiari/core/paths/_utils/get_profile_config_file_path.py +7 -0
  204. kiari/core/paths/_utils/get_profile_dir_path.py +7 -0
  205. kiari/core/paths/_utils/get_profile_run_spec_file_path.py +7 -0
  206. kiari/core/paths/_utils/get_profiles_dir_path.py +7 -0
  207. kiari/core/paths/_utils/get_profiles_file_path.py +7 -0
  208. kiari/core/paths/_utils/get_prompt_session_history_file_path.py +7 -0
  209. kiari/core/plugin/__init__.py +3 -0
  210. kiari/core/plugin/_helpers/load_plugin.py +61 -0
  211. kiari/core/plugin/_i18n.py +7 -0
  212. kiari/core/plugin/_settings.py +14 -0
  213. kiari/core/profile/__init__.py +16 -0
  214. kiari/core/profile/_schemas/profile.py +11 -0
  215. kiari/core/profile/_schemas/run_options.py +127 -0
  216. kiari/core/profile/_services/profile_store.py +243 -0
  217. kiari/core/profile/_types/profile_name.py +13 -0
  218. kiari/core/profile/_types/run_spec.py +3 -0
  219. kiari/core/rich/__init__.py +24 -0
  220. kiari/core/rich/_helpers/render_content.py +63 -0
  221. kiari/core/rich/_helpers/render_display_content.py +98 -0
  222. kiari/core/rich/_helpers/render_event.py +50 -0
  223. kiari/core/rich/_helpers/render_file_info.py +24 -0
  224. kiari/core/rich/_helpers/render_message.py +143 -0
  225. kiari/core/rich/_helpers/render_tool_call.py +30 -0
  226. kiari/core/rich/_services/console_registry.py +19 -0
  227. kiari/core/rich/_utils/join_renderables.py +34 -0
  228. kiari/core/rich/_utils/render_status_block.py +41 -0
  229. kiari/core/runtime/__init__.py +9 -0
  230. kiari/core/runtime/_helpers/create_agi_options.py +96 -0
  231. kiari/core/runtime/_helpers/setup_history.py +94 -0
  232. kiari/core/runtime/_helpers/setup_runtime.py +302 -0
  233. kiari/core/terminal/__init__.py +16 -0
  234. kiari/core/terminal/_helpers/has_interactive_tty.py +7 -0
  235. kiari/core/terminal/_helpers/stop_asyncio_on_enter.py +34 -0
  236. kiari/core/terminal/_helpers/stop_threading_on_enter.py +34 -0
  237. kiari/core/terminal/_services/prompt_session_registry.py +40 -0
  238. kiari/core/terminal/_utils/create_prompt_toolkit_io.py +19 -0
  239. kiari/fastapi/__init__.py +0 -0
  240. kiari/impl/batch_handler_impl/vanilla/__init__.py +3 -0
  241. kiari/impl/batch_handler_impl/vanilla/_models/vanilla_batch_handler.py +5 -0
  242. kiari/impl/chat_logger_impl/default/__init__.py +3 -0
  243. kiari/impl/chat_logger_impl/default/_models/default_chat_logger.py +205 -0
  244. kiari/impl/console_handler_impl/vanilla/__init__.py +3 -0
  245. kiari/impl/console_handler_impl/vanilla/_models/vanilla_console_handler.py +5 -0
  246. kiari/impl/cost_logger_impl/default/__init__.py +3 -0
  247. kiari/impl/cost_logger_impl/default/_models/default_cost_logger.py +63 -0
  248. kiari/impl/finalizer_impl/__init__.py +1 -0
  249. kiari/impl/finalizer_impl/chrome/__init__.py +3 -0
  250. kiari/impl/finalizer_impl/chrome/_models/chrome_finalizer.py +7 -0
  251. kiari/impl/finalizer_impl/null/__init__.py +3 -0
  252. kiari/impl/finalizer_impl/null/_models/null_finalizer.py +5 -0
  253. kiari/impl/finalizer_impl/subprocess/__init__.py +3 -0
  254. kiari/impl/finalizer_impl/subprocess/_models/subprocess_finalizer.py +7 -0
  255. kiari/impl/history_repository_impl/in_memory/__init__.py +3 -0
  256. kiari/impl/history_repository_impl/in_memory/_models/in_memory_history_repository.py +34 -0
  257. kiari/impl/history_repository_impl/local/__init__.py +13 -0
  258. kiari/impl/history_repository_impl/local/_helpers/create_local_history_repository.py +15 -0
  259. kiari/impl/history_repository_impl/local/_models/local_history_repository.py +42 -0
  260. kiari/impl/history_repository_impl/local/_settings.py +14 -0
  261. kiari/impl/history_repository_impl/null/__init__.py +3 -0
  262. kiari/impl/history_repository_impl/null/_models/null_history_repository.py +5 -0
  263. kiari/impl/schedule_handler_impl/__init__.py +1 -0
  264. kiari/impl/schedule_handler_impl/vanilla/__init__.py +3 -0
  265. kiari/impl/schedule_handler_impl/vanilla/_models/vanilla_schedule_handler.py +5 -0
  266. kiari/impl/tool_impl/__init__.py +0 -0
  267. kiari/impl/tool_impl/audio_file_view/__init__.py +3 -0
  268. kiari/impl/tool_impl/audio_file_view/_i18n.py +13 -0
  269. kiari/impl/tool_impl/audio_file_view/_models/audio_file_view.py +34 -0
  270. kiari/impl/tool_impl/audio_file_view/_schemas/audio_file_view_schema.py +33 -0
  271. kiari/impl/tool_impl/change_directory/__init__.py +3 -0
  272. kiari/impl/tool_impl/change_directory/_i18n.py +8 -0
  273. kiari/impl/tool_impl/change_directory/_models/change_directory.py +30 -0
  274. kiari/impl/tool_impl/change_directory/_schemas/change_directory_schema.py +9 -0
  275. kiari/impl/tool_impl/gui/__init__.py +3 -0
  276. kiari/impl/tool_impl/gui/_i18n.py +50 -0
  277. kiari/impl/tool_impl/gui/_models/gui.py +78 -0
  278. kiari/impl/tool_impl/gui/_operations/keyboard_hotkey.py +22 -0
  279. kiari/impl/tool_impl/gui/_operations/keyboard_press.py +22 -0
  280. kiari/impl/tool_impl/gui/_operations/keyboard_write.py +22 -0
  281. kiari/impl/tool_impl/gui/_operations/mouse_click.py +25 -0
  282. kiari/impl/tool_impl/gui/_operations/mouse_down.py +25 -0
  283. kiari/impl/tool_impl/gui/_operations/mouse_move.py +27 -0
  284. kiari/impl/tool_impl/gui/_operations/mouse_up.py +25 -0
  285. kiari/impl/tool_impl/gui/_operations/screenshot.py +15 -0
  286. kiari/impl/tool_impl/gui/_schemas/gui_schema.py +114 -0
  287. kiari/impl/tool_impl/gui/_types/action.py +12 -0
  288. kiari/impl/tool_impl/image_file_view/__init__.py +3 -0
  289. kiari/impl/tool_impl/image_file_view/_i18n.py +13 -0
  290. kiari/impl/tool_impl/image_file_view/_models/image_file_view.py +28 -0
  291. kiari/impl/tool_impl/image_file_view/_schemas/image_file_view_schema.py +14 -0
  292. kiari/impl/tool_impl/pdf_file_view/__init__.py +3 -0
  293. kiari/impl/tool_impl/pdf_file_view/_i18n.py +12 -0
  294. kiari/impl/tool_impl/pdf_file_view/_models/pdf_file_view.py +34 -0
  295. kiari/impl/tool_impl/pdf_file_view/_schemas/pdf_file_view_schema.py +33 -0
  296. kiari/impl/tool_impl/subprocess/__init__.py +3 -0
  297. kiari/impl/tool_impl/subprocess/_i18n.py +68 -0
  298. kiari/impl/tool_impl/subprocess/_models/subprocess.py +50 -0
  299. kiari/impl/tool_impl/subprocess/_operations/cancel.py +64 -0
  300. kiari/impl/tool_impl/subprocess/_operations/get_list.py +65 -0
  301. kiari/impl/tool_impl/subprocess/_operations/get_output.py +58 -0
  302. kiari/impl/tool_impl/subprocess/_operations/run.py +61 -0
  303. kiari/impl/tool_impl/subprocess/_operations/run_background.py +37 -0
  304. kiari/impl/tool_impl/subprocess/_schemas/subprocess_schema.py +145 -0
  305. kiari/impl/tool_impl/subprocess/_types/action.py +9 -0
  306. kiari/impl/tool_impl/subprocess/_utils/create_output_file.py +39 -0
  307. kiari/impl/tool_impl/text_file_edit/__init__.py +3 -0
  308. kiari/impl/tool_impl/text_file_edit/_i18n.py +49 -0
  309. kiari/impl/tool_impl/text_file_edit/_models/text_file_edit.py +42 -0
  310. kiari/impl/tool_impl/text_file_edit/_operations/create.py +33 -0
  311. kiari/impl/tool_impl/text_file_edit/_operations/line_replace.py +118 -0
  312. kiari/impl/tool_impl/text_file_edit/_operations/str_replace.py +72 -0
  313. kiari/impl/tool_impl/text_file_edit/_operations/update.py +36 -0
  314. kiari/impl/tool_impl/text_file_edit/_schemas/text_file_edit_schema.py +92 -0
  315. kiari/impl/tool_impl/text_file_edit/_types/action.py +8 -0
  316. kiari/impl/tool_impl/text_file_edit/_utils/build_result.py +46 -0
  317. kiari/impl/tool_impl/text_file_edit/_utils/replace_str.py +72 -0
  318. kiari/impl/tool_impl/text_file_edit/_utils/resolve_path.py +7 -0
  319. kiari/impl/tool_impl/text_file_edit/_utils/write_file.py +34 -0
  320. kiari/impl/tool_impl/text_file_view/__init__.py +3 -0
  321. kiari/impl/tool_impl/text_file_view/_i18n.py +14 -0
  322. kiari/impl/tool_impl/text_file_view/_models/text_file_view.py +81 -0
  323. kiari/impl/tool_impl/text_file_view/_schemas/text_file_view_schema.py +26 -0
  324. kiari/impl/tool_impl/video_file_view/__init__.py +3 -0
  325. kiari/impl/tool_impl/video_file_view/_i18n.py +13 -0
  326. kiari/impl/tool_impl/video_file_view/_models/video_file_view.py +34 -0
  327. kiari/impl/tool_impl/video_file_view/_schemas/video_file_view_schema.py +33 -0
  328. kiari/impl/tool_logger_impl/default/__init__.py +3 -0
  329. kiari/impl/tool_logger_impl/default/_models/default_tool_logger.py +104 -0
  330. kiari/impl/watch_handler_impl/__init__.py +1 -0
  331. kiari/impl/watch_handler_impl/slack/__init__.py +8 -0
  332. kiari/impl/watch_handler_impl/slack/_models/slack_watch_handler.py +259 -0
  333. kiari/impl/watch_handler_impl/slack/_settings.py +19 -0
  334. kiari/impl/watch_handler_impl/slack/_utils/convert_markdown_to_mrkdwn.py +23 -0
  335. kiari/impl/watch_handler_impl/slack/_utils/get_bot_token.py +34 -0
  336. kiari/impl/watch_handler_impl/vanilla/__init__.py +3 -0
  337. kiari/impl/watch_handler_impl/vanilla/_models/vanilla_watch_handler.py +5 -0
  338. kiari/impl/watcher_impl/__init__.py +1 -0
  339. kiari/impl/watcher_impl/file/__init__.py +18 -0
  340. kiari/impl/watcher_impl/file/_helpers/create_file_watcher.py +13 -0
  341. kiari/impl/watcher_impl/file/_models/file_watcher.py +88 -0
  342. kiari/impl/watcher_impl/file/_schemas/file_change.py +8 -0
  343. kiari/impl/watcher_impl/file/_schemas/file_watch_event.py +24 -0
  344. kiari/impl/watcher_impl/file/_schemas/file_watch_payload.py +10 -0
  345. kiari/impl/watcher_impl/file/_settings.py +37 -0
  346. kiari/impl/watcher_impl/file/_types/change_type.py +3 -0
  347. kiari/impl/watcher_impl/pubsub/__init__.py +14 -0
  348. kiari/impl/watcher_impl/pubsub/_helpers/create_pubsub_watcher.py +13 -0
  349. kiari/impl/watcher_impl/pubsub/_models/pubsub_watcher.py +99 -0
  350. kiari/impl/watcher_impl/pubsub/_schemas/pubsub_watch_event.py +48 -0
  351. kiari/impl/watcher_impl/pubsub/_schemas/pubsub_watch_payload.py +11 -0
  352. kiari/impl/watcher_impl/pubsub/_settings.py +18 -0
  353. kiari/impl/watcher_impl/rtdb/__init__.py +16 -0
  354. kiari/impl/watcher_impl/rtdb/_helpers/create_rtdb_watcher.py +13 -0
  355. kiari/impl/watcher_impl/rtdb/_models/rtdb_watcher.py +48 -0
  356. kiari/impl/watcher_impl/rtdb/_schemas/rtdb_watch_event.py +42 -0
  357. kiari/impl/watcher_impl/rtdb/_schemas/rtdb_watch_payload.py +10 -0
  358. kiari/impl/watcher_impl/rtdb/_services/file_token_cache.py +21 -0
  359. kiari/impl/watcher_impl/rtdb/_settings.py +17 -0
  360. kiari/impl/watcher_impl/slack/__init__.py +14 -0
  361. kiari/impl/watcher_impl/slack/_helpers/create_slack_watcher.py +13 -0
  362. kiari/impl/watcher_impl/slack/_models/slack_watcher.py +335 -0
  363. kiari/impl/watcher_impl/slack/_schemas/slack_watch_event.py +63 -0
  364. kiari/impl/watcher_impl/slack/_schemas/slack_watch_payload.py +13 -0
  365. kiari/impl/watcher_impl/slack/_settings.py +33 -0
  366. kiari/lib/audio_utils/__init__.py +24 -0
  367. kiari/lib/audio_utils/_utils/load_audio_samples.py +11 -0
  368. kiari/lib/audio_utils/_utils/play_audio.py +72 -0
  369. kiari/lib/chrome/__init__.py +44 -0
  370. kiari/lib/chrome/_helpers/get_chrome.py +15 -0
  371. kiari/lib/chrome/_helpers/terminate_chrome.py +15 -0
  372. kiari/lib/chrome/_models/chrome.py +201 -0
  373. kiari/lib/chrome/_settings.py +67 -0
  374. kiari/lib/chrome/_types/chrome_boot_state.py +9 -0
  375. kiari/lib/chrome/_utils/get_chrome_executable_path.py +14 -0
  376. kiari/lib/chrome/_utils/is_port_open.py +21 -0
  377. kiari/lib/chrome/_utils/kill_process.py +24 -0
  378. kiari/lib/cwd/__init__.py +7 -0
  379. kiari/lib/cwd/_helpers/create_cwd_manager.py +7 -0
  380. kiari/lib/cwd/_models/cwd_manager.py +77 -0
  381. kiari/lib/cwd/_schemas/cwd_state.py +7 -0
  382. kiari/lib/gui/__init__.py +19 -0
  383. kiari/lib/gui/_services/gui.py +34 -0
  384. kiari/lib/history_repository/__init__.py +20 -0
  385. kiari/lib/history_repository/_models/base_history_repository.py +51 -0
  386. kiari/lib/history_repository/_services/__init__.py +3 -0
  387. kiari/lib/history_repository/_services/history_repository_registry.py +27 -0
  388. kiari/lib/history_repository/_settings.py +29 -0
  389. kiari/lib/history_repository/_types/history_repository.py +15 -0
  390. kiari/lib/history_repository/_types/history_repository_name.py +3 -0
  391. kiari/lib/history_repository/_types/history_repository_specifier.py +12 -0
  392. kiari/lib/keyboard/__init__.py +31 -0
  393. kiari/lib/keyboard/_models/keyboard.py +64 -0
  394. kiari/lib/keyboard/_types/keyboard_key.py +101 -0
  395. kiari/lib/keyboard/_utils/normalize_key.py +10 -0
  396. kiari/lib/keyboard/_utils/normalize_keys.py +10 -0
  397. kiari/lib/monitor/__init__.py +51 -0
  398. kiari/lib/monitor/_constants/max_scaling_targets.py +16 -0
  399. kiari/lib/monitor/_models/monitor.py +70 -0
  400. kiari/lib/monitor/_operations/calc_physical_size.py +17 -0
  401. kiari/lib/monitor/_operations/calc_scale_factor.py +11 -0
  402. kiari/lib/monitor/_operations/calc_scale_ratio.py +30 -0
  403. kiari/lib/monitor/_operations/capture_monitor.py +37 -0
  404. kiari/lib/monitor/_operations/get_image.py +26 -0
  405. kiari/lib/monitor/_operations/get_offset_vector.py +15 -0
  406. kiari/lib/monitor/_operations/get_screenshot.py +21 -0
  407. kiari/lib/monitor/_schemas/monitor_snapshot.py +16 -0
  408. kiari/lib/monitor/_schemas/multiple_monitor_capture.py +34 -0
  409. kiari/lib/monitor/_schemas/point.py +8 -0
  410. kiari/lib/monitor/_schemas/rect.py +59 -0
  411. kiari/lib/monitor/_schemas/size.py +12 -0
  412. kiari/lib/monitor/_types/monitor_index.py +3 -0
  413. kiari/lib/monitor/_views/monitor_info.py +14 -0
  414. kiari/lib/mouse/__init__.py +29 -0
  415. kiari/lib/mouse/_models/mouse.py +50 -0
  416. kiari/lib/mouse/_types/mouse_button.py +3 -0
  417. kiari/lib/subprocess/__init__.py +32 -0
  418. kiari/lib/subprocess/_enums/subprocess_status.py +15 -0
  419. kiari/lib/subprocess/_helpers/get_subprocess_manager.py +13 -0
  420. kiari/lib/subprocess/_helpers/terminate_all_sessions.py +6 -0
  421. kiari/lib/subprocess/_models/subprocess_manager.py +179 -0
  422. kiari/lib/subprocess/_models/subprocess_session.py +162 -0
  423. kiari/lib/subprocess/_operations/cancel_subprocess.py +171 -0
  424. kiari/lib/subprocess/_operations/run_subprocess.py +158 -0
  425. kiari/lib/subprocess/_settings.py +27 -0
  426. kiari/lib/subprocess/_types/cancel_options.py +21 -0
  427. kiari/lib/subprocess/_types/run_id.py +3 -0
  428. kiari/lib/subprocess/_types/subprocess_event.py +7 -0
  429. kiari/lib/subprocess/_utils/clean_ansi.py +65 -0
  430. kiari/lib/subprocess/_views/background_event.py +10 -0
  431. kiari/lib/subprocess/_views/finish_event.py +13 -0
  432. kiari/lib/subprocess/_views/stream_event.py +11 -0
  433. kiari/lib/watcher/__init__.py +23 -0
  434. kiari/lib/watcher/_models/base_watcher.py +30 -0
  435. kiari/lib/watcher/_schemas/watch_event.py +16 -0
  436. kiari/lib/watcher/_services/watcher_registry.py +26 -0
  437. kiari/lib/watcher/_settings.py +27 -0
  438. kiari/lib/watcher/_types/watcher.py +13 -0
  439. kiari/lib/watcher/_types/watcher_name.py +3 -0
  440. kiari/lib/watcher/_types/watcher_specifier.py +12 -0
  441. kiari/py.typed +1 -0
  442. kiari/resources/__init__.py +0 -0
  443. kiari/resources/i18n/__init__.py +0 -0
  444. kiari/resources/i18n/en.yaml +0 -0
  445. kiari/resources/i18n/ja.yaml +0 -0
  446. kiari/streamlit/__init__.py +0 -0
  447. kiari-0.1.0.dist-info/METADATA +181 -0
  448. kiari-0.1.0.dist-info/RECORD +451 -0
  449. kiari-0.1.0.dist-info/WHEEL +4 -0
  450. kiari-0.1.0.dist-info/entry_points.txt +2 -0
  451. kiari-0.1.0.dist-info/licenses/LICENSE +21 -0
kiari/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## watch モード
2
+
3
+ ```sh
4
+ # ファイルの変更を監視
5
+ kiari watch "file?paths=.&include_patterns=*.md"
6
+
7
+ # PubSub を監視
8
+ kiari ext pubsub create-topic --project-id kiarina --topic-id tmp
9
+ kiari ext pubsub create-subscription --project-id kiarina --topic-id tmp --subscription-id tmp
10
+ kiari watch "pubsub?project_id=kiarina&subscription_id=tmp"
11
+ kiari ext pubsub publish-message --project-id kiarina --topic-id tmp --attribute hoge=fuga "hello"
12
+
13
+ # Realtime Database を監視
14
+ DATABASE_URL=https://kiarina-python.firebaseio.com/
15
+ kiari watch "rtdb?database_url=$DATABASE_URL&path=/posts/kiarina"
16
+ # - 複数のパスを監視
17
+ kiari watch \
18
+ "rtdb?database_url=$DATABASE_URL&path=/posts/kiarina" \
19
+ "rtdb?database_url=$DATABASE_URL&path=/status/kiarina"
20
+ kiari ext rtdb set --database-url $DATABASE_URL --path /posts/kiarina '{"message":"hello"}'
21
+ kiari ext rtdb get --database-url $DATABASE_URL --path /posts/kiarina
22
+ kiari ext rtdb watch --database-url $DATABASE_URL --path /posts/kiarina
23
+
24
+ # Slack を監視
25
+ CHANNEL_ID=C077QKNDCUR
26
+ kiari watch "slack?"
27
+ kiari watch --watch-handler slack "slack?"
28
+ kiari ext slack post-message --channel $CHANNEL_ID "hello"
29
+ kiari ext -v slack get-channel-messages --channel $CHANNEL_ID --limit 1
30
+ kiari ext slack watch-channel --channel $CHANNEL_ID
31
+ ```
kiari/__init__.py ADDED
@@ -0,0 +1,46 @@
1
+ from importlib import import_module
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ from kiarina.agi.agent import BaseAgent as Agent
6
+
7
+ __all__ = [
8
+ # --------------------------------------------------
9
+ # kiarina_agi
10
+ # --------------------------------------------------
11
+ # kiarina.agi.agent
12
+ "Agent",
13
+ ]
14
+
15
+
16
+ def __getattr__(name: str) -> object:
17
+ if name not in __all__: # pragma: no cover
18
+ raise AttributeError(f"module {__name__} has no attribute {name}")
19
+
20
+ # Map attribute names to their module paths
21
+ # Format: "name": "module_path" or "name": ("module_path", "attr_name")
22
+ # fmg: off
23
+ module_map: dict[str, str | tuple[str, str]] = {
24
+ # --------------------------------------------------
25
+ # kiarina_agi
26
+ # --------------------------------------------------
27
+ # kiarina.agi.agent
28
+ "Agent": ("kiarina.agi.agent", "BaseAgent"),
29
+ }
30
+ # fmt: on
31
+
32
+ module_info = module_map[name]
33
+
34
+ if isinstance(module_info, tuple):
35
+ # Tuple format: (module_path, attr_name)
36
+ module_path, attr_name = module_info
37
+ module = import_module(module_path)
38
+ attr = getattr(module, attr_name)
39
+ else:
40
+ # String format: module_path (attr_name is the same as name)
41
+ module_path = module_info
42
+ module = import_module(module_path)
43
+ attr = getattr(module, name)
44
+
45
+ globals()[name] = attr
46
+ return attr
kiari/__main__.py ADDED
@@ -0,0 +1,9 @@
1
+ from .cli.cli import kiari
2
+
3
+
4
+ def main() -> None:
5
+ kiari()
6
+
7
+
8
+ if __name__ == "__main__":
9
+ main()
kiari/cli/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ from ._constants.common_option_groups import COMMON_OPTION_GROUPS
2
+ from ._decorators.common_options import common_options
3
+ from ._helpers.build_cli_args import build_cli_args
4
+ from ._helpers.render_bootstrap_message import render_bootstrap_message
5
+ from ._helpers.run import run
6
+ from ._helpers.setup_profile import setup_profile
7
+ from ._schemas.cli_args import CLIArgs
8
+ from ._types.extra_args import ExtraArgs
9
+ from ._types.save_mode import SaveMode
10
+ from ._utils.graceful_shutdown import graceful_shutdown
11
+
12
+ __all__ = [
13
+ # ._constants
14
+ "COMMON_OPTION_GROUPS",
15
+ # ._decorators
16
+ "common_options",
17
+ # ._helpers
18
+ "build_cli_args",
19
+ "render_bootstrap_message",
20
+ "run",
21
+ "setup_profile",
22
+ # ._schemas
23
+ "CLIArgs",
24
+ # ._types
25
+ "ExtraArgs",
26
+ "SaveMode",
27
+ # ._utils
28
+ "graceful_shutdown",
29
+ ]
@@ -0,0 +1,129 @@
1
+ from rich_click.utils import OptionGroupDict
2
+
3
+ COMMON_OPTION_GROUPS: list[OptionGroupDict] = [
4
+ {
5
+ "name": "History Repository",
6
+ "options": [
7
+ "--history-repository",
8
+ "--stateless",
9
+ "--no-load",
10
+ "--no-save",
11
+ "--allow-active-missing-tools",
12
+ ],
13
+ },
14
+ {
15
+ "name": "History",
16
+ "options": [
17
+ "--event",
18
+ "--file-info",
19
+ "--tool-info",
20
+ "--default-tool-state",
21
+ ],
22
+ },
23
+ {
24
+ "name": "Agent",
25
+ "options": [
26
+ "--agent",
27
+ "--file-limits",
28
+ "--max-iterations",
29
+ "--until-end",
30
+ "--until-tool-call",
31
+ "--until-tool-run",
32
+ ],
33
+ },
34
+ {
35
+ "name": "Tool",
36
+ "options": [
37
+ "--tool",
38
+ "--pre-hook",
39
+ "--post-hook",
40
+ ],
41
+ },
42
+ {
43
+ "name": "Workflow",
44
+ "options": [
45
+ "--workflow",
46
+ ],
47
+ },
48
+ {
49
+ "name": "Prompt",
50
+ "options": [
51
+ "--prompt",
52
+ "--prompt-limits",
53
+ "--system-message",
54
+ ],
55
+ },
56
+ {
57
+ "name": "Chat",
58
+ "options": [
59
+ "--chat-model",
60
+ "--openai",
61
+ "--anthropic",
62
+ "--google",
63
+ "--tool-choice",
64
+ "--parallel-tool-calls",
65
+ "--streaming",
66
+ ],
67
+ },
68
+ {
69
+ "name": "Cost Recorder",
70
+ "options": [
71
+ "--cost-recorder",
72
+ ],
73
+ },
74
+ {
75
+ "name": "Observability",
76
+ "options": [
77
+ "--request-logger",
78
+ "--cost-logger",
79
+ "--chat-logger",
80
+ "--tool-logger",
81
+ ],
82
+ },
83
+ {
84
+ "name": "Run Context",
85
+ "options": [
86
+ "--organization-id",
87
+ "--user-id",
88
+ "--agent-id",
89
+ "--runner-id",
90
+ "--language",
91
+ "--time-zone",
92
+ "--currency",
93
+ ],
94
+ },
95
+ {
96
+ "name": "GitHub",
97
+ "options": [
98
+ "--github-ignore-cache",
99
+ "--github-trusted-username",
100
+ "--github-skip-trust-verification",
101
+ ],
102
+ },
103
+ {
104
+ "name": "Config",
105
+ "options": [
106
+ "--i18n-catalog",
107
+ "--config",
108
+ "--config-var",
109
+ "--plugin",
110
+ ],
111
+ },
112
+ {
113
+ "name": "Profile",
114
+ "options": [
115
+ "--profile",
116
+ "--set-profile",
117
+ "--reset-profile",
118
+ ],
119
+ },
120
+ {
121
+ "name": "Logging",
122
+ "options": [
123
+ "--logger-name",
124
+ "--log-level",
125
+ "--verbose",
126
+ "--quiet",
127
+ ],
128
+ },
129
+ ]
@@ -0,0 +1,188 @@
1
+ import functools
2
+ from collections.abc import Callable
3
+ from typing import Any
4
+
5
+ import rich_click as click
6
+ from kiarina.i18n import get_i18n, get_system_language
7
+
8
+ from .._i18n import CLII18n
9
+
10
+ t = get_i18n(CLII18n, get_system_language())
11
+
12
+
13
+ def common_options(func: Callable) -> Callable:
14
+ # fmt: off
15
+ # --------------------------------------------------
16
+ # History Repository
17
+ # --------------------------------------------------
18
+ @click.option("--history-repository", type=str, help=t.history_repository_help)
19
+ @click.option("--stateless", is_flag=True, is_eager=True, expose_value=False, callback=_set_stateless, help=t.stateless_help)
20
+ @click.option("--no-load", is_flag=True, default=None, help=t.no_load_help)
21
+ @click.option("--no-save", is_flag=True, default=None, help=t.no_save_help)
22
+ @click.option("--allow-active-missing-tools", is_flag=True, default=None, help=t.allow_active_missing_tools_help)
23
+ # --------------------------------------------------
24
+ # History
25
+ # --------------------------------------------------
26
+ @click.option("--event", "events", multiple=True, type=str, help=t.events_help)
27
+ @click.option("-f", "--file-info", "file_infos", multiple=True, type=str, help=t.file_infos_help)
28
+ @click.option("--tool-info", "tool_infos", multiple=True, type=str, help=t.tool_infos_help)
29
+ @click.option("--default-tool-state", type=click.Choice(["active", "inactive", "disabled"]), help=t.default_tool_state_help)
30
+ # --------------------------------------------------
31
+ # Agent
32
+ # --------------------------------------------------
33
+ @click.option("--agent", type=str, help=t.agent_help)
34
+ @click.option("--file-limits", type=str, help=t.file_limits_help)
35
+ @click.option("-n", "--max-iterations", type=int, help=t.max_iterations_help)
36
+ @click.option("--until-end/--no-until-end", is_flag=True, default=None, help=t.until_end_help)
37
+ @click.option("--until-tool-call", "until_tool_calls", multiple=True, type=str, help=t.until_tool_calls_help)
38
+ @click.option("--until-tool-run", "until_tool_runs", multiple=True, type=str, help=t.until_tool_runs_help)
39
+ # --------------------------------------------------
40
+ # Tool
41
+ # --------------------------------------------------
42
+ @click.option("-t", "--tool", "tools", multiple=True, type=str, help=t.tools_help)
43
+ @click.option("--pre-hook", "pre_hooks", multiple=True, type=str, help=t.pre_hooks_help)
44
+ @click.option("--post-hook", "post_hooks", multiple=True, type=str, help=t.post_hooks_help)
45
+ # --------------------------------------------------
46
+ # Workflow
47
+ # --------------------------------------------------
48
+ @click.option("--workflow", type=str, help=t.workflow_help)
49
+ # --------------------------------------------------
50
+ # Prompt
51
+ # --------------------------------------------------
52
+ @click.option("--prompt", type=str, help=t.prompt_help)
53
+ @click.option("--prompt-limits", type=str, help=t.prompt_limits_help)
54
+ @click.option("--system-message", "system_messages", multiple=True, type=str, help=t.system_messages_help)
55
+ # --------------------------------------------------
56
+ # Chat
57
+ # --------------------------------------------------
58
+ @click.option("--chat-model", type=str, help=t.chat_model_help)
59
+ @click.option("--openai", is_flag=True, default=None, is_eager=True, expose_value=False, callback=_set_openai, help=t.openai_help)
60
+ @click.option("--anthropic", is_flag=True, default=None, is_eager=True, expose_value=False, callback=_set_anthropic, help=t.anthropic_help)
61
+ @click.option("--google", is_flag=True, default=None, is_eager=True, expose_value=False, callback=_set_google, help=t.google_help)
62
+ @click.option("--tool-choice", type=str, help=t.tool_choice_help)
63
+ @click.option("--parallel-tool-calls/--no-parallel-tool-calls", default=None, help=t.parallel_tool_calls_help)
64
+ @click.option("--streaming/--no-streaming", default=None, help=t.streaming_help)
65
+ # --------------------------------------------------
66
+ # Cost Recorder
67
+ # --------------------------------------------------
68
+ @click.option("--cost-recorder", type=str, help=t.cost_recorder_help)
69
+ # --------------------------------------------------
70
+ # Observability
71
+ # --------------------------------------------------
72
+ @click.option("--request-logger", type=str, help=t.request_logger_help)
73
+ @click.option("--cost-logger", type=str, help=t.cost_logger_help)
74
+ @click.option("--chat-logger", type=str, help=t.chat_logger_help)
75
+ @click.option("--tool-logger", type=str, help=t.tool_logger_help)
76
+ # --------------------------------------------------
77
+ # Run Context
78
+ # --------------------------------------------------
79
+ @click.option("--organization-id", type=str, help=t.organization_id_help)
80
+ @click.option("--user-id", type=str, help=t.user_id_help)
81
+ @click.option("--agent-id", type=str, help=t.agent_id_help)
82
+ @click.option("--runner-id", type=str, help=t.node_id_help)
83
+ @click.option("--language", type=str, help=t.language_help)
84
+ @click.option("--time-zone", type=str, help=t.time_zone_help)
85
+ @click.option("--currency", type=str, help=t.currency_help)
86
+ # --------------------------------------------------
87
+ # GitHub
88
+ # --------------------------------------------------
89
+ @click.option("--github-ignore-cache", is_flag=True, default=None, help=t.github_ignore_cache_help)
90
+ @click.option("--github-trusted-username", "github_trusted_usernames", multiple=True, type=str, help=t.github_trusted_username_help)
91
+ @click.option("--github-skip-trust-verification", is_flag=True, default=None, help=t.github_skip_trust_verification_help)
92
+ @functools.wraps(func)
93
+ # --------------------------------------------------
94
+ # Config
95
+ # --------------------------------------------------
96
+ @click.option("--i18n-catalog", "i18n_catalogs", multiple=True, type=str, help=t.i18n_catalog_help)
97
+ @click.option("--config", "configs", multiple=True, type=str, help=t.config_file_help)
98
+ @click.option("-c", "--config-var", "config_vars", multiple=True, type=str, help=t.config_var_help)
99
+ @click.option("--plugin", "plugins", multiple=True, type=str, help=t.plugin_help)
100
+ # --------------------------------------------------
101
+ # Logging
102
+ # --------------------------------------------------
103
+ @click.option("--logger-name", "logger_names", multiple=True, type=str, help=t.logger_name_help)
104
+ @click.option("--log-level", type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]), default=None, help=t.log_level_help)
105
+ @click.option("-v", "--verbose", is_flag=True, default=None, callback=_set_verbose, help=t.verbose_help)
106
+ @click.option("-q", "--quiet", is_flag=True, default=None, callback=_set_quiet, help=t.quiet_help)
107
+ # --------------------------------------------------
108
+ # Profile
109
+ # --------------------------------------------------
110
+ @click.option("-p", "--profile", "profile_name", type=str, default=None, help=t.profile_help)
111
+ @click.option("--set", "--set-profile", is_flag=True, is_eager=True, expose_value=False, callback=_set_profile, help=t.set_profile_help)
112
+ @click.option("--reset", "--reset-profile", is_flag=True, is_eager=True, expose_value=False, callback=_reset_profile, help=t.reset_profile_help)
113
+ # --------------------------------------------------
114
+ # CLI
115
+ # --------------------------------------------------
116
+ @click.option("-x", "--exec", "exec_file", type=str, help=t.exec_file_help)
117
+ @click.option("--finalizer", "finalizers", multiple=True, type=str, help=t.finalizers_help)
118
+ @functools.wraps(func)
119
+ # fmt: on
120
+ def wrapper(*args, **kwargs):
121
+ return func(*args, **kwargs)
122
+
123
+ return wrapper
124
+
125
+
126
+ def _set_profile(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
127
+ if not value:
128
+ return value
129
+
130
+ ctx.params["save_mode"] = "set"
131
+ return value
132
+
133
+
134
+ def _reset_profile(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
135
+ if not value:
136
+ return value
137
+
138
+ ctx.params["save_mode"] = "reset"
139
+ return value
140
+
141
+
142
+ def _set_stateless(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
143
+ if not value:
144
+ return value
145
+
146
+ ctx.params["no_load"] = True
147
+ ctx.params["no_save"] = True
148
+ return value
149
+
150
+
151
+ def _set_openai(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
152
+ if not value:
153
+ return value
154
+
155
+ ctx.params["chat_model"] = "openai"
156
+ return value
157
+
158
+
159
+ def _set_anthropic(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
160
+ if not value:
161
+ return value
162
+
163
+ ctx.params["chat_model"] = "anthropic"
164
+ return value
165
+
166
+
167
+ def _set_google(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
168
+ if not value:
169
+ return value
170
+
171
+ ctx.params["chat_model"] = "google"
172
+ return value
173
+
174
+
175
+ def _set_verbose(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
176
+ if not value:
177
+ return value
178
+
179
+ ctx.params["log_level"] = "DEBUG"
180
+ return value
181
+
182
+
183
+ def _set_quiet(ctx: click.Context, _: click.Parameter, value: Any) -> Any:
184
+ if not value:
185
+ return value
186
+
187
+ ctx.params["log_level"] = "WARNING"
188
+ return value
@@ -0,0 +1,70 @@
1
+ from typing import Any
2
+
3
+ from kiari.core.profile import ProfileName
4
+
5
+ from .._schemas.cli_args import CLIArgs
6
+ from .._types.save_mode import SaveMode
7
+
8
+
9
+ def build_cli_args(
10
+ exec_file: str | None = None,
11
+ profile_name: ProfileName | None = None,
12
+ save_mode: SaveMode | None = None,
13
+ extra_args_keys: list[str] | None = None,
14
+ markdown_content_key: str | None = None,
15
+ **kwargs: Any,
16
+ ) -> CLIArgs:
17
+ run_spec = _normalize_kwargs(kwargs)
18
+
19
+ extra_args = {}
20
+
21
+ if exec_file:
22
+ file_args: dict[str, Any] | None = None
23
+
24
+ if exec_file.endswith(".json"):
25
+ from kiarina.utils.file import read_json_dict
26
+
27
+ file_args = read_json_dict(exec_file)
28
+
29
+ elif exec_file.endswith(".yaml") or exec_file.endswith(".yml"):
30
+ from kiarina.utils.file import read_yaml_dict
31
+
32
+ file_args = read_yaml_dict(exec_file)
33
+
34
+ elif exec_file.endswith(".md") or exec_file.endswith(".markdown"):
35
+ from kiarina.utils.file import read_markdown
36
+
37
+ if markdown_content := read_markdown(exec_file):
38
+ file_args = markdown_content.metadata
39
+
40
+ if markdown_content_key:
41
+ extra_args[markdown_content_key] = markdown_content.content
42
+
43
+ else: # pragma: no cover
44
+ raise ValueError(f"Unsupported file type: {exec_file}")
45
+
46
+ if file_args is None:
47
+ raise FileNotFoundError(f"File not found: {exec_file}")
48
+
49
+ run_spec = {**file_args, **run_spec}
50
+
51
+ if extra_args_keys:
52
+ for key in extra_args_keys:
53
+ if key in run_spec:
54
+ extra_args[key] = run_spec.pop(key)
55
+
56
+ return CLIArgs(
57
+ exec_file=exec_file,
58
+ profile_name=profile_name,
59
+ save_mode=save_mode,
60
+ run_spec=run_spec,
61
+ extra_args=extra_args,
62
+ )
63
+
64
+
65
+ def _normalize_kwargs(kwargs: dict[str, Any]) -> dict[str, Any]:
66
+ return {
67
+ k: v if not isinstance(v, tuple) else list(v)
68
+ for k, v in kwargs.items()
69
+ if v is not None and (not isinstance(v, tuple) or len(v) > 0)
70
+ }
@@ -0,0 +1,37 @@
1
+ from kiarina.agi.console_utils import divider, section_header
2
+ from rich.console import Group, RenderableType
3
+ from rich.text import Text
4
+
5
+ from kiari.core.profile import ProfileName, RunOptions, RunSpec
6
+
7
+
8
+ def render_bootstrap_message(
9
+ exec_file: str | None,
10
+ profile_name: ProfileName,
11
+ run_spec: RunSpec,
12
+ run_options: RunOptions,
13
+ ) -> RenderableType | None:
14
+ if run_options.log_level not in ("DEBUG", "INFO"):
15
+ return None
16
+
17
+ style = "black"
18
+
19
+ renderables: list[RenderableType] = [
20
+ Text("kiari version 1.0.0", style=style),
21
+ ]
22
+
23
+ if exec_file:
24
+ renderables.append(Text(f"+ exec: {exec_file}", style=style))
25
+
26
+ renderables.append(Text(f"+ profile: {profile_name}", style=style))
27
+ renderables.append(Text(section_header("RUN OPTIONS"), style=style))
28
+
29
+ if run_spec:
30
+ for k, v in run_spec.items():
31
+ renderables.append(Text(f"{k}: {v}", style=style))
32
+ else:
33
+ renderables.append(Text("No run options specified", style=style))
34
+
35
+ renderables.append(Text(divider(), style=style))
36
+
37
+ return Group(*renderables)
@@ -0,0 +1,18 @@
1
+ from collections.abc import Callable
2
+ from typing import Any
3
+
4
+ from kiari.core.finalizer import run_finalizers
5
+ from kiari.core.profile import ProfileName, RunOptions
6
+
7
+
8
+ async def run(
9
+ runner: Callable,
10
+ profile_name: ProfileName,
11
+ run_options: RunOptions,
12
+ *args: Any,
13
+ **kwargs: Any,
14
+ ) -> None:
15
+ try:
16
+ await runner(profile_name, run_options, *args, **kwargs)
17
+ finally:
18
+ await run_finalizers(run_options.finalizers)
@@ -0,0 +1,24 @@
1
+ from kiari.core.profile import ProfileName, RunOptions, RunSpec, profile_store
2
+
3
+ from .._types.save_mode import SaveMode
4
+
5
+
6
+ def setup_profile(
7
+ profile_name: ProfileName | None,
8
+ save_mode: SaveMode | None,
9
+ run_spec: RunSpec,
10
+ ) -> tuple[ProfileName, RunSpec, RunOptions]:
11
+ if not profile_name:
12
+ profile_name = profile_store.get_current()
13
+
14
+ if save_mode != "reset":
15
+ run_spec = {
16
+ **profile_store.load_run_spec(profile_name),
17
+ **run_spec,
18
+ }
19
+
20
+ if save_mode in ("set", "reset"):
21
+ profile_store.save_run_spec(profile_name, run_spec)
22
+
23
+ run_options = RunOptions.model_validate(run_spec)
24
+ return profile_name, run_spec, run_options