flock-core 0.1.2__py3-none-any.whl → 0.2.2__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.

Potentially problematic release.


This version of flock-core might be problematic. Click here for more details.

Files changed (407) hide show
  1. flock/__init__.py +1 -4
  2. flock/core/__init__.py +1 -7
  3. flock/core/context/context.py +182 -0
  4. flock/core/context/context_manager.py +34 -0
  5. flock/core/{context_vars.py → context/context_vars.py} +8 -6
  6. flock/core/execution/local_executor.py +27 -0
  7. flock/core/execution/temporal_executor.py +56 -0
  8. flock/core/flock.py +232 -208
  9. flock/core/flock_agent.py +574 -0
  10. flock/core/logging/__init__.py +2 -18
  11. flock/core/logging/formatters/base_formatter.py +36 -0
  12. flock/core/logging/formatters/formatter_factory.py +38 -0
  13. flock/core/logging/formatters/pprint_formatter.py +18 -0
  14. flock/core/logging/formatters/rich_formatters.py +132 -0
  15. flock/core/logging/formatters/theme_builder.py +480 -0
  16. flock/core/logging/formatters/themed_formatter.py +442 -0
  17. flock/core/logging/logging.py +141 -0
  18. flock/core/logging/telemetry.py +21 -0
  19. flock/core/logging/trace_and_logged.py +55 -0
  20. flock/core/mixin/dspy_integration.py +197 -0
  21. flock/core/mixin/prompt_parser.py +125 -0
  22. flock/core/registry/agent_registry.py +118 -0
  23. flock/core/tools/basic_tools.py +296 -98
  24. flock/core/tools/dev_tools/github.py +190 -0
  25. flock/core/util/cli_helper.py +25 -0
  26. flock/core/util/input_resolver.py +156 -0
  27. flock/core/util/serializable.py +93 -0
  28. flock/themes/3024-day.toml +39 -0
  29. flock/themes/3024-night.toml +77 -0
  30. flock/themes/aardvark-blue.toml +77 -0
  31. flock/themes/abernathy.toml +77 -0
  32. flock/themes/adventure.toml +77 -0
  33. flock/themes/adventuretime.toml +77 -0
  34. flock/themes/afterglow.toml +77 -0
  35. flock/themes/alabaster.toml +77 -0
  36. flock/themes/alienblood.toml +77 -0
  37. flock/themes/andromeda.toml +77 -0
  38. flock/themes/apple-classic.toml +77 -0
  39. flock/themes/apple-system-colors.toml +77 -0
  40. flock/themes/arcoiris.toml +77 -0
  41. flock/themes/argonaut copy.toml +77 -0
  42. flock/themes/argonaut.toml +39 -0
  43. flock/themes/arthur.toml +77 -0
  44. flock/themes/ateliersulphurpool.toml +77 -0
  45. flock/themes/atom.toml +38 -0
  46. flock/themes/atom_test.toml +65 -0
  47. flock/themes/atomonelight.toml +77 -0
  48. flock/themes/aurora.toml +77 -0
  49. flock/themes/ayu copy.toml +77 -0
  50. flock/themes/ayu-light.toml +77 -0
  51. flock/themes/ayu-mirage.toml +77 -0
  52. flock/themes/ayu.toml +39 -0
  53. flock/themes/banana-blueberry.toml +77 -0
  54. flock/themes/batman.toml +77 -0
  55. flock/themes/belafonte-day.toml +77 -0
  56. flock/themes/belafonte-night.toml +77 -0
  57. flock/themes/birdsofparadise.toml +77 -0
  58. flock/themes/blazer.toml +77 -0
  59. flock/themes/blue-matrix.toml +77 -0
  60. flock/themes/blueberrypie.toml +77 -0
  61. flock/themes/bluedolphin.toml +77 -0
  62. flock/themes/blulocodark.toml +77 -0
  63. flock/themes/blulocolight.toml +77 -0
  64. flock/themes/borland.toml +77 -0
  65. flock/themes/breeze.toml +77 -0
  66. flock/themes/bright-lights.toml +77 -0
  67. flock/themes/broadcast.toml +77 -0
  68. flock/themes/brogrammer.toml +77 -0
  69. flock/themes/builtin-dark.toml +77 -0
  70. flock/themes/builtin-light.toml +77 -0
  71. flock/themes/builtin-pastel-dark.toml +77 -0
  72. flock/themes/builtin-solarized-dark.toml +77 -0
  73. flock/themes/builtin-solarized-light.toml +77 -0
  74. flock/themes/builtin-tango-dark.toml +77 -0
  75. flock/themes/builtin-tango-light.toml +77 -0
  76. flock/themes/c64.toml +77 -0
  77. flock/themes/calamity.toml +77 -0
  78. flock/themes/catppuccin-frappe.toml +77 -0
  79. flock/themes/catppuccin-latte.toml +77 -0
  80. flock/themes/catppuccin-macchiato.toml +77 -0
  81. flock/themes/catppuccin-mocha.toml +77 -0
  82. flock/themes/cga.toml +77 -0
  83. flock/themes/chalk.toml +77 -0
  84. flock/themes/chalkboard.toml +77 -0
  85. flock/themes/challengerdeep.toml +77 -0
  86. flock/themes/chester.toml +77 -0
  87. flock/themes/ciapre.toml +77 -0
  88. flock/themes/clrs.toml +77 -0
  89. flock/themes/cobalt-neon.toml +77 -0
  90. flock/themes/cobalt2.toml +77 -0
  91. flock/themes/coffee-theme.toml +77 -0
  92. flock/themes/crayonponyfish.toml +77 -0
  93. flock/themes/cutiepro.toml +77 -0
  94. flock/themes/cyberdyne.toml +77 -0
  95. flock/themes/cyberpunk.toml +77 -0
  96. flock/themes/cyberpunkscarletprotocol.toml +77 -0
  97. flock/themes/dark+.toml +77 -0
  98. flock/themes/dark-pastel.toml +77 -0
  99. flock/themes/darkermatrix.toml +77 -0
  100. flock/themes/darkmatrix.toml +77 -0
  101. flock/themes/darkside.toml +77 -0
  102. flock/themes/dayfox.toml +77 -0
  103. flock/themes/deep.toml +77 -0
  104. flock/themes/desert.toml +77 -0
  105. flock/themes/dimidium.toml +77 -0
  106. flock/themes/dimmedmonokai.toml +77 -0
  107. flock/themes/django.toml +77 -0
  108. flock/themes/djangorebornagain.toml +77 -0
  109. flock/themes/djangosmooth.toml +77 -0
  110. flock/themes/doom-peacock.toml +77 -0
  111. flock/themes/doomone.toml +77 -0
  112. flock/themes/dotgov.toml +77 -0
  113. flock/themes/dracula+.toml +77 -0
  114. flock/themes/dracula.toml +77 -0
  115. flock/themes/duckbones.toml +77 -0
  116. flock/themes/duotone-dark.toml +77 -0
  117. flock/themes/earthsong.toml +77 -0
  118. flock/themes/elemental.toml +77 -0
  119. flock/themes/elementary.toml +77 -0
  120. flock/themes/encom.toml +77 -0
  121. flock/themes/espresso-libre.toml +77 -0
  122. flock/themes/espresso.toml +77 -0
  123. flock/themes/everblush.toml +77 -0
  124. flock/themes/fahrenheit.toml +77 -0
  125. flock/themes/fairyfloss.toml +77 -0
  126. flock/themes/farmhouse-dark.toml +77 -0
  127. flock/themes/farmhouse-light.toml +77 -0
  128. flock/themes/fideloper.toml +77 -0
  129. flock/themes/firefly-traditional.toml +77 -0
  130. flock/themes/firefoxdev.toml +77 -0
  131. flock/themes/firewatch.toml +77 -0
  132. flock/themes/fishtank.toml +77 -0
  133. flock/themes/flat.toml +77 -0
  134. flock/themes/flatland.toml +77 -0
  135. flock/themes/flexoki-dark.toml +77 -0
  136. flock/themes/flexoki-light.toml +77 -0
  137. flock/themes/floraverse.toml +77 -0
  138. flock/themes/forestblue.toml +77 -0
  139. flock/themes/framer.toml +77 -0
  140. flock/themes/frontenddelight.toml +77 -0
  141. flock/themes/funforrest.toml +77 -0
  142. flock/themes/galaxy.toml +77 -0
  143. flock/themes/galizur.toml +77 -0
  144. flock/themes/github-dark.toml +77 -0
  145. flock/themes/github.toml +77 -0
  146. flock/themes/glacier.toml +77 -0
  147. flock/themes/grape.toml +77 -0
  148. flock/themes/grass.toml +77 -0
  149. flock/themes/grey-green.toml +77 -0
  150. flock/themes/gruber-darker.toml +77 -0
  151. flock/themes/gruvboxdark.toml +77 -0
  152. flock/themes/gruvboxdarkhard.toml +77 -0
  153. flock/themes/gruvboxlight.toml +77 -0
  154. flock/themes/guezwhoz.toml +77 -0
  155. flock/themes/hacktober.toml +77 -0
  156. flock/themes/hardcore.toml +77 -0
  157. flock/themes/harper.toml +77 -0
  158. flock/themes/hax0r-blue.toml +77 -0
  159. flock/themes/hax0r-gr33n.toml +77 -0
  160. flock/themes/hax0r-r3d.toml +77 -0
  161. flock/themes/highway.toml +77 -0
  162. flock/themes/hipster-green.toml +77 -0
  163. flock/themes/hivacruz.toml +77 -0
  164. flock/themes/homebrew.toml +77 -0
  165. flock/themes/hopscotch.256.toml +77 -0
  166. flock/themes/hopscotch.toml +77 -0
  167. flock/themes/hurtado.toml +77 -0
  168. flock/themes/hybrid.toml +77 -0
  169. flock/themes/ic-green-ppl.toml +77 -0
  170. flock/themes/ic-orange-ppl.toml +77 -0
  171. flock/themes/iceberg-dark.toml +77 -0
  172. flock/themes/iceberg-light.toml +77 -0
  173. flock/themes/idea.toml +77 -0
  174. flock/themes/idletoes.toml +77 -0
  175. flock/themes/ir-black.toml +77 -0
  176. flock/themes/iterm2-dark-background.toml +77 -0
  177. flock/themes/iterm2-default.toml +77 -0
  178. flock/themes/iterm2-light-background.toml +77 -0
  179. flock/themes/iterm2-pastel-dark-background.toml +77 -0
  180. flock/themes/iterm2-smoooooth.toml +77 -0
  181. flock/themes/iterm2-solarized-dark.toml +77 -0
  182. flock/themes/iterm2-solarized-light.toml +77 -0
  183. flock/themes/iterm2-tango-dark.toml +77 -0
  184. flock/themes/iterm2-tango-light.toml +77 -0
  185. flock/themes/jackie-brown.toml +77 -0
  186. flock/themes/japanesque.toml +77 -0
  187. flock/themes/jellybeans.toml +77 -0
  188. flock/themes/jetbrains-darcula.toml +77 -0
  189. flock/themes/jubi.toml +77 -0
  190. flock/themes/kanagawabones.toml +77 -0
  191. flock/themes/kibble.toml +77 -0
  192. flock/themes/kolorit.toml +77 -0
  193. flock/themes/konsolas.toml +77 -0
  194. flock/themes/kurokula.toml +77 -0
  195. flock/themes/lab-fox.toml +77 -0
  196. flock/themes/laser.toml +77 -0
  197. flock/themes/later-this-evening.toml +77 -0
  198. flock/themes/lavandula.toml +77 -0
  199. flock/themes/liquidcarbon.toml +77 -0
  200. flock/themes/liquidcarbontransparent.toml +77 -0
  201. flock/themes/liquidcarbontransparentinverse.toml +77 -0
  202. flock/themes/lovelace.toml +77 -0
  203. flock/themes/man-page.toml +77 -0
  204. flock/themes/mariana.toml +77 -0
  205. flock/themes/material.toml +77 -0
  206. flock/themes/materialdark.toml +77 -0
  207. flock/themes/materialdarker.toml +77 -0
  208. flock/themes/materialdesigncolors.toml +77 -0
  209. flock/themes/materialocean.toml +77 -0
  210. flock/themes/mathias.toml +77 -0
  211. flock/themes/matrix.toml +77 -0
  212. flock/themes/medallion.toml +77 -0
  213. flock/themes/mellifluous.toml +77 -0
  214. flock/themes/midnight-in-mojave.toml +77 -0
  215. flock/themes/mirage.toml +77 -0
  216. flock/themes/misterioso.toml +77 -0
  217. flock/themes/molokai.toml +77 -0
  218. flock/themes/monalisa.toml +77 -0
  219. flock/themes/monokai-remastered.toml +77 -0
  220. flock/themes/monokai-soda.toml +77 -0
  221. flock/themes/monokai-vivid.toml +77 -0
  222. flock/themes/n0tch2k.toml +77 -0
  223. flock/themes/neobones-dark.toml +77 -0
  224. flock/themes/neobones-light.toml +77 -0
  225. flock/themes/neon.toml +77 -0
  226. flock/themes/neopolitan.toml +77 -0
  227. flock/themes/neutron.toml +77 -0
  228. flock/themes/night-owlish-light.toml +77 -0
  229. flock/themes/nightfox.toml +77 -0
  230. flock/themes/nightlion-v1.toml +77 -0
  231. flock/themes/nightlion-v2.toml +77 -0
  232. flock/themes/niji.toml +77 -0
  233. flock/themes/nocturnal-winter.toml +77 -0
  234. flock/themes/nord-light.toml +77 -0
  235. flock/themes/nord.toml +77 -0
  236. flock/themes/novel.toml +77 -0
  237. flock/themes/nvimdark.toml +77 -0
  238. flock/themes/nvimlight.toml +77 -0
  239. flock/themes/obsidian.toml +77 -0
  240. flock/themes/ocean.toml +77 -0
  241. flock/themes/oceanic-next.toml +77 -0
  242. flock/themes/oceanicmaterial.toml +77 -0
  243. flock/themes/ollie.toml +77 -0
  244. flock/themes/onehalfdark.toml +77 -0
  245. flock/themes/onehalflight.toml +77 -0
  246. flock/themes/operator-mono-dark.toml +77 -0
  247. flock/themes/overnight-slumber.toml +77 -0
  248. flock/themes/oxocarbon.toml +77 -0
  249. flock/themes/palenighthc.toml +77 -0
  250. flock/themes/pandora.toml +77 -0
  251. flock/themes/paraiso-dark.toml +77 -0
  252. flock/themes/paulmillr.toml +77 -0
  253. flock/themes/pencildark.toml +77 -0
  254. flock/themes/pencillight.toml +77 -0
  255. flock/themes/peppermint.toml +77 -0
  256. flock/themes/piatto-light.toml +77 -0
  257. flock/themes/pnevma.toml +77 -0
  258. flock/themes/popping-and-locking.toml +77 -0
  259. flock/themes/primary.toml +77 -0
  260. flock/themes/pro-light.toml +77 -0
  261. flock/themes/pro.toml +77 -0
  262. flock/themes/purple-rain.toml +77 -0
  263. flock/themes/purplepeter.toml +77 -0
  264. flock/themes/rapture.toml +77 -0
  265. flock/themes/raycast-dark.toml +77 -0
  266. flock/themes/raycast-light.toml +77 -0
  267. flock/themes/rebecca.toml +77 -0
  268. flock/themes/red-alert.toml +77 -0
  269. flock/themes/red-planet.toml +77 -0
  270. flock/themes/red-sands.toml +77 -0
  271. flock/themes/relaxed.toml +77 -0
  272. flock/themes/retro.toml +77 -0
  273. flock/themes/rippedcasts.toml +77 -0
  274. flock/themes/rose-pine-dawn.toml +77 -0
  275. flock/themes/rose-pine-moon.toml +77 -0
  276. flock/themes/rose-pine.toml +77 -0
  277. flock/themes/rouge-2.toml +77 -0
  278. flock/themes/royal.toml +77 -0
  279. flock/themes/ryuuko.toml +77 -0
  280. flock/themes/sakura.toml +77 -0
  281. flock/themes/scarlet-protocol.toml +77 -0
  282. flock/themes/seafoam-pastel.toml +77 -0
  283. flock/themes/seashells.toml +77 -0
  284. flock/themes/seoulbones-dark.toml +77 -0
  285. flock/themes/seoulbones-light.toml +77 -0
  286. flock/themes/seti.toml +77 -0
  287. flock/themes/shades-of-purple.toml +77 -0
  288. flock/themes/shaman.toml +77 -0
  289. flock/themes/slate.toml +77 -0
  290. flock/themes/sleepyhollow.toml +77 -0
  291. flock/themes/smyck.toml +77 -0
  292. flock/themes/snazzy.toml +77 -0
  293. flock/themes/softserver.toml +77 -0
  294. flock/themes/solarized-darcula.toml +77 -0
  295. flock/themes/solarized-dark---patched.toml +77 -0
  296. flock/themes/solarized-dark-higher-contrast.toml +77 -0
  297. flock/themes/spacedust.toml +77 -0
  298. flock/themes/spacegray-eighties-dull.toml +77 -0
  299. flock/themes/spacegray-eighties.toml +77 -0
  300. flock/themes/spacegray.toml +77 -0
  301. flock/themes/spiderman.toml +77 -0
  302. flock/themes/spring.toml +77 -0
  303. flock/themes/square.toml +77 -0
  304. flock/themes/sublette.toml +77 -0
  305. flock/themes/subliminal.toml +77 -0
  306. flock/themes/sugarplum.toml +77 -0
  307. flock/themes/sundried.toml +77 -0
  308. flock/themes/symfonic.toml +77 -0
  309. flock/themes/synthwave-everything.toml +77 -0
  310. flock/themes/synthwave.toml +77 -0
  311. flock/themes/synthwavealpha.toml +77 -0
  312. flock/themes/tango-adapted.toml +77 -0
  313. flock/themes/tango-half-adapted.toml +77 -0
  314. flock/themes/teerb.toml +77 -0
  315. flock/themes/terafox.toml +77 -0
  316. flock/themes/terminal-basic.toml +77 -0
  317. flock/themes/thayer-bright.toml +77 -0
  318. flock/themes/the-hulk.toml +77 -0
  319. flock/themes/tinacious-design-(dark).toml +77 -0
  320. flock/themes/tinacious-design-(light).toml +77 -0
  321. flock/themes/tokyonight-day.toml +77 -0
  322. flock/themes/tokyonight-storm.toml +77 -0
  323. flock/themes/tokyonight.toml +77 -0
  324. flock/themes/tomorrow-night-blue.toml +77 -0
  325. flock/themes/tomorrow-night-bright.toml +77 -0
  326. flock/themes/tomorrow-night-burns.toml +77 -0
  327. flock/themes/tomorrow-night-eighties.toml +77 -0
  328. flock/themes/tomorrow-night.toml +77 -0
  329. flock/themes/tomorrow.toml +77 -0
  330. flock/themes/toychest.toml +77 -0
  331. flock/themes/treehouse.toml +77 -0
  332. flock/themes/twilight.toml +77 -0
  333. flock/themes/ubuntu.toml +77 -0
  334. flock/themes/ultradark.toml +77 -0
  335. flock/themes/ultraviolent.toml +77 -0
  336. flock/themes/underthesea.toml +77 -0
  337. flock/themes/unikitty.toml +77 -0
  338. flock/themes/urple.toml +77 -0
  339. flock/themes/vaughn.toml +77 -0
  340. flock/themes/vesper.toml +77 -0
  341. flock/themes/vibrantink.toml +77 -0
  342. flock/themes/vimbones.toml +77 -0
  343. flock/themes/violet-dark.toml +77 -0
  344. flock/themes/violet-light.toml +77 -0
  345. flock/themes/warmneon.toml +77 -0
  346. flock/themes/wez.toml +77 -0
  347. flock/themes/whimsy.toml +77 -0
  348. flock/themes/wildcherry.toml +77 -0
  349. flock/themes/wilmersdorf.toml +77 -0
  350. flock/themes/wombat.toml +77 -0
  351. flock/themes/wryan.toml +77 -0
  352. flock/themes/xcodedark.toml +77 -0
  353. flock/themes/xcodedarkhc.toml +77 -0
  354. flock/themes/xcodelight.toml +77 -0
  355. flock/themes/xcodelighthc.toml +77 -0
  356. flock/themes/xcodewwdc.toml +77 -0
  357. flock/themes/zenbones-dark.toml +77 -0
  358. flock/themes/zenbones-light.toml +77 -0
  359. flock/themes/zenbones.toml +77 -0
  360. flock/themes/zenburn.toml +77 -0
  361. flock/themes/zenburned.toml +77 -0
  362. flock/themes/zenwritten-dark.toml +77 -0
  363. flock/themes/zenwritten-light.toml +77 -0
  364. flock/workflow/activities.py +175 -115
  365. flock/workflow/agent_activities.py +24 -26
  366. flock/workflow/temporal_setup.py +38 -37
  367. flock/workflow/workflow.py +58 -53
  368. flock_core-0.2.2.dist-info/METADATA +320 -0
  369. flock_core-0.2.2.dist-info/RECORD +372 -0
  370. {flock_core-0.1.2.dist-info → flock_core-0.2.2.dist-info}/licenses/LICENSE +21 -21
  371. flock/agents/__init__.py +0 -3
  372. flock/agents/batch_agent.py +0 -175
  373. flock/agents/declarative_agent.py +0 -166
  374. flock/agents/loop_agent.py +0 -178
  375. flock/agents/trigger_agent.py +0 -191
  376. flock/agents/user_agent.py +0 -230
  377. flock/app/components/__init__.py +0 -14
  378. flock/app/components/charts/agent_workflow.py +0 -14
  379. flock/app/components/charts/core_architecture.py +0 -14
  380. flock/app/components/charts/tool_system.py +0 -14
  381. flock/app/components/history_grid.py +0 -168
  382. flock/app/components/history_grid_alt.py +0 -189
  383. flock/app/components/sidebar.py +0 -19
  384. flock/app/components/theme.py +0 -9
  385. flock/app/components/util.py +0 -18
  386. flock/app/hive_app.py +0 -118
  387. flock/app/html/d3.html +0 -179
  388. flock/app/modules/__init__.py +0 -12
  389. flock/app/modules/about.py +0 -17
  390. flock/app/modules/agent_detail.py +0 -70
  391. flock/app/modules/agent_list.py +0 -59
  392. flock/app/modules/playground.py +0 -322
  393. flock/app/modules/settings.py +0 -96
  394. flock/core/agent.py +0 -150
  395. flock/core/agent_registry.py +0 -162
  396. flock/core/context.py +0 -279
  397. flock/core/handoff/handoff_base.py +0 -12
  398. flock/core/logging/error_handler.py +0 -84
  399. flock/core/logging/formatters.py +0 -122
  400. flock/core/logging/handlers.py +0 -117
  401. flock/core/logging/logger.py +0 -107
  402. flock/core/serializable.py +0 -206
  403. flock_core-0.1.2.dist-info/METADATA +0 -476
  404. flock_core-0.1.2.dist-info/RECORD +0 -48
  405. flock_core-0.1.2.dist-info/entry_points.txt +0 -2
  406. /flock/{core/config/declarative_agent_config.py → workflow/__init__.py} +0 -0
  407. {flock_core-0.1.2.dist-info → flock_core-0.2.2.dist-info}/WHEEL +0 -0
@@ -1,98 +1,296 @@
1
- import os
2
-
3
- import httpx
4
- from markdownify import markdownify as md
5
- from tavily import TavilyClient
6
-
7
-
8
- def web_search_tavily(query: str):
9
- client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
10
- try:
11
- response = client.search(query, include_answer=True) # type: ignore
12
- return response
13
- except Exception:
14
- raise
15
-
16
-
17
- def get_web_content_as_markdown(url: str):
18
- try:
19
- response = httpx.get(url)
20
- response.raise_for_status()
21
- markdown = md(response.text)
22
- return markdown
23
- except Exception:
24
- raise
25
-
26
-
27
- def evaluate_math(expression: str) -> float:
28
- import dspy
29
-
30
- try:
31
- result = dspy.PythonInterpreter({}).execute(expression)
32
- return result
33
- except Exception:
34
- raise
35
-
36
-
37
- def code_eval(python_code: str) -> float:
38
- import dspy
39
-
40
- try:
41
- result = dspy.PythonInterpreter({}).execute(python_code)
42
- return result
43
- except Exception:
44
- raise
45
-
46
-
47
- def get_current_time() -> str:
48
- import datetime
49
-
50
- time = datetime.datetime.now().isoformat()
51
- return time
52
-
53
-
54
- def count_words(text: str) -> int:
55
- count = len(text.split())
56
- return count
57
-
58
-
59
- def extract_urls(text: str) -> list[str]:
60
- import re
61
-
62
- url_pattern = r"https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+"
63
- urls = re.findall(url_pattern, text)
64
- return urls
65
-
66
-
67
- def extract_numbers(text: str) -> list[float]:
68
- import re
69
-
70
- numbers = [float(x) for x in re.findall(r"-?\d*\.?\d+", text)]
71
- return numbers
72
-
73
-
74
- def json_parse_safe(text: str) -> dict:
75
- import json
76
-
77
- try:
78
- result = json.loads(text)
79
- return result
80
- except Exception:
81
- return {}
82
-
83
-
84
- def save_to_file(content: str, filename: str):
85
- try:
86
- with open(filename, "w") as f:
87
- f.write(content)
88
- except Exception:
89
- raise
90
-
91
-
92
- def read_from_file(filename: str) -> str:
93
- try:
94
- with open(filename) as f:
95
- content = f.read()
96
- return content
97
- except Exception:
98
- raise
1
+ """This module contains basic agentic tools for performing various tasks."""
2
+
3
+ import importlib
4
+ import os
5
+
6
+ from flock.core.logging.trace_and_logged import traced_and_logged
7
+
8
+
9
+ @traced_and_logged
10
+ def web_search_tavily(query: str):
11
+ """Performs a web search using the Tavily client.
12
+
13
+ This function checks if the optional 'tavily' dependency is installed. If so,
14
+ it creates a TavilyClient using the API key from the environment variable
15
+ 'TAVILY_API_KEY' and performs a search with the provided query. The search response
16
+ is returned if successful.
17
+
18
+ Parameters:
19
+ query (str): The search query string.
20
+
21
+ Returns:
22
+ Any: The search response obtained from the Tavily client.
23
+
24
+ Raises:
25
+ ImportError: If the 'tavily' dependency is not installed.
26
+ Exception: Re-raises any exceptions encountered during the search.
27
+ """
28
+ if importlib.util.find_spec("tavily") is not None:
29
+ from tavily import TavilyClient
30
+
31
+ client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
32
+ try:
33
+ response = client.search(query, include_answer=True) # type: ignore
34
+ return response
35
+ except Exception:
36
+ raise
37
+ else:
38
+ raise ImportError(
39
+ "Optional tool dependencies not installed. Install with 'pip install flock-core[tools]'."
40
+ )
41
+
42
+
43
+ @traced_and_logged
44
+ def get_web_content_as_markdown(url: str):
45
+ """Fetches web content from a URL and converts it to Markdown.
46
+
47
+ This function uses the 'httpx' library to retrieve the content of the provided URL.
48
+ It then converts the HTML content into Markdown using the 'markdownify' library.
49
+
50
+ Parameters:
51
+ url (str): The URL of the web page to fetch.
52
+
53
+ Returns:
54
+ str: The web page content converted into Markdown format.
55
+
56
+ Raises:
57
+ ImportError: If either 'httpx' or 'markdownify' dependencies are not installed.
58
+ Exception: Re-raises any exceptions encountered during the HTTP request or conversion.
59
+ """
60
+ if (
61
+ importlib.util.find_spec("httpx") is not None
62
+ and importlib.util.find_spec("markdownify") is not None
63
+ ):
64
+ import httpx
65
+ from markdownify import markdownify as md
66
+
67
+ try:
68
+ response = httpx.get(url)
69
+ response.raise_for_status()
70
+ markdown = md(response.text)
71
+ return markdown
72
+ except Exception:
73
+ raise
74
+ else:
75
+ raise ImportError(
76
+ "Optional tool dependencies not installed. Install with 'pip install flock-core[tools]'."
77
+ )
78
+
79
+
80
+ @traced_and_logged
81
+ def get_anything_as_markdown(url_or_file_path: str):
82
+ """Converts the content of a URL or file into Markdown format.
83
+
84
+ This function leverages the 'docling' library to convert various document types
85
+ (retrieved from a URL or a local file) into Markdown. It uses the DocumentConverter
86
+ from the 'docling.document_converter' module.
87
+
88
+ Parameters:
89
+ url_or_file_path (str): The URL or local file path of the document to convert.
90
+
91
+ Returns:
92
+ str: The converted document in Markdown format.
93
+
94
+ Raises:
95
+ ImportError: If the 'docling' dependency is not installed.
96
+ Exception: Re-raises any exceptions encountered during the document conversion.
97
+ """
98
+ if importlib.util.find_spec("docling") is not None:
99
+ from docling.document_converter import DocumentConverter
100
+
101
+ try:
102
+ converter = DocumentConverter()
103
+ result = converter.convert(url_or_file_path)
104
+ markdown = result.document.export_to_markdown()
105
+ return markdown
106
+ except Exception:
107
+ raise
108
+ else:
109
+ raise ImportError(
110
+ "Optional tool dependencies not installed. Install with 'pip install flock-core[all-tools]'."
111
+ )
112
+
113
+
114
+ @traced_and_logged
115
+ def evaluate_math(expression: str) -> float:
116
+ """Evaluates a mathematical expression using the dspy interpreter.
117
+
118
+ This function uses the 'dspy' library's PythonInterpreter to evaluate the provided
119
+ mathematical expression.
120
+
121
+ Parameters:
122
+ expression (str): A string containing the mathematical expression to evaluate.
123
+
124
+ Returns:
125
+ float: The result of the evaluated expression.
126
+
127
+ Raises:
128
+ Exception: Re-raises any exceptions encountered during the evaluation.
129
+ """
130
+ import dspy
131
+
132
+ try:
133
+ result = dspy.PythonInterpreter({}).execute(expression)
134
+ return result
135
+ except Exception:
136
+ raise
137
+
138
+
139
+ @traced_and_logged
140
+ def code_eval(python_code: str) -> float:
141
+ """Executes Python code using the dspy interpreter.
142
+
143
+ This function takes a string of Python code, executes it using the 'dspy' PythonInterpreter,
144
+ and returns the result.
145
+
146
+ Parameters:
147
+ python_code (str): A string containing Python code to execute.
148
+
149
+ Returns:
150
+ float: The result of the executed code.
151
+
152
+ Raises:
153
+ Exception: Re-raises any exceptions encountered during code execution.
154
+ """
155
+ import dspy
156
+
157
+ try:
158
+ result = dspy.PythonInterpreter({}).execute(python_code)
159
+ return result
160
+ except Exception:
161
+ raise
162
+
163
+
164
+ @traced_and_logged
165
+ def get_current_time() -> str:
166
+ """Retrieves the current time in ISO 8601 format.
167
+
168
+ Returns:
169
+ str: The current date and time as an ISO 8601 formatted string.
170
+ """
171
+ import datetime
172
+
173
+ time = datetime.datetime.now().isoformat()
174
+ return time
175
+
176
+
177
+ @traced_and_logged
178
+ def count_words(text: str) -> int:
179
+ """Counts the number of words in the provided text.
180
+
181
+ This function splits the input text by whitespace and returns the count of resulting words.
182
+
183
+ Parameters:
184
+ text (str): The text in which to count words.
185
+
186
+ Returns:
187
+ int: The number of words in the text.
188
+ """
189
+ count = len(text.split())
190
+ return count
191
+
192
+
193
+ @traced_and_logged
194
+ def extract_urls(text: str) -> list[str]:
195
+ """Extracts all URLs from the given text.
196
+
197
+ This function uses a regular expression to find all substrings that match the typical
198
+ URL pattern (starting with http or https).
199
+
200
+ Parameters:
201
+ text (str): The text from which to extract URLs.
202
+
203
+ Returns:
204
+ list[str]: A list of URLs found in the text.
205
+ """
206
+ import re
207
+
208
+ url_pattern = r"https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+"
209
+ urls = re.findall(url_pattern, text)
210
+ return urls
211
+
212
+
213
+ @traced_and_logged
214
+ def extract_numbers(text: str) -> list[float]:
215
+ """Extracts all numerical values from the provided text.
216
+
217
+ This function uses a regular expression to find substrings that represent integers or decimals,
218
+ converts them to floats, and returns them as a list.
219
+
220
+ Parameters:
221
+ text (str): The text from which to extract numerical values.
222
+
223
+ Returns:
224
+ list[float]: A list of numbers (as floats) found in the text.
225
+ """
226
+ import re
227
+
228
+ numbers = [float(x) for x in re.findall(r"-?\d*\.?\d+", text)]
229
+ return numbers
230
+
231
+
232
+ @traced_and_logged
233
+ def json_parse_safe(text: str) -> dict:
234
+ """Safely parses a JSON string into a dictionary.
235
+
236
+ This function attempts to load a JSON object from the given text. If parsing fails,
237
+ it returns an empty dictionary instead of raising an exception.
238
+
239
+ Parameters:
240
+ text (str): The JSON-formatted string to parse.
241
+
242
+ Returns:
243
+ dict: The parsed JSON object as a dictionary, or an empty dictionary if parsing fails.
244
+ """
245
+ import json
246
+
247
+ try:
248
+ result = json.loads(text)
249
+ return result
250
+ except Exception:
251
+ return {}
252
+
253
+
254
+ @traced_and_logged
255
+ def save_to_file(content: str, filename: str):
256
+ """Saves the given content to a file.
257
+
258
+ This function writes the provided content to a file specified by the filename.
259
+ If the file cannot be written, an exception is raised.
260
+
261
+ Parameters:
262
+ content (str): The content to be saved.
263
+ filename (str): The path to the file where the content will be saved.
264
+
265
+ Raises:
266
+ Exception: Re-raises any exceptions encountered during the file write operation.
267
+ """
268
+ try:
269
+ with open(filename, "w") as f:
270
+ f.write(content)
271
+ except Exception:
272
+ raise
273
+
274
+
275
+ @traced_and_logged
276
+ def read_from_file(filename: str) -> str:
277
+ """Reads and returns the content of a file.
278
+
279
+ This function opens the specified file, reads its content, and returns it as a string.
280
+ If the file cannot be read, an exception is raised.
281
+
282
+ Parameters:
283
+ filename (str): The path to the file to be read.
284
+
285
+ Returns:
286
+ str: The content of the file.
287
+
288
+ Raises:
289
+ Exception: Re-raises any exceptions encountered during the file read operation.
290
+ """
291
+ try:
292
+ with open(filename) as f:
293
+ content = f.read()
294
+ return content
295
+ except Exception:
296
+ raise
@@ -0,0 +1,190 @@
1
+ """This module provides tools for interacting with GitHub repositories."""
2
+
3
+ import base64
4
+ import os
5
+
6
+ import httpx
7
+
8
+ from flock.core.logging.trace_and_logged import traced_and_logged
9
+
10
+
11
+ @traced_and_logged
12
+ def create_user_stories_as_github_issue(title: str, body: str) -> str:
13
+ """Create a new GitHub issue representing a user story.
14
+
15
+ This function creates an issue in a GitHub repository using the specified title and body.
16
+ The title is used as the issue title, and the body should contain the full user story
17
+ description along with a formatted list of acceptance criteria. The following
18
+ environment variables must be set for this function to work correctly:
19
+
20
+ - GITHUB_PAT: Personal Access Token for GitHub API authentication.
21
+ - GITHUB_REPO: Repository identifier in the format "owner/repo".
22
+
23
+ Parameters:
24
+ title (str): The title for the GitHub issue (user story).
25
+ body (str): The detailed description including acceptance criteria.
26
+
27
+ Returns:
28
+ str: A message indicating whether the issue was created successfully or not.
29
+ """
30
+ github_pat = os.getenv("GITHUB_PAT")
31
+ github_repo = os.getenv("GITHUB_REPO")
32
+
33
+ url = f"https://api.github.com/repos/{github_repo}/issues"
34
+ headers = {
35
+ "Authorization": f"Bearer {github_pat}",
36
+ "Accept": "application/vnd.github+json",
37
+ }
38
+ issue_title = title
39
+ issue_body = body
40
+
41
+ payload = {"title": issue_title, "body": issue_body}
42
+ response = httpx.post(url, json=payload, headers=headers)
43
+
44
+ if response.status_code == 201:
45
+ return "Issue created successfully."
46
+ else:
47
+ return "Failed to create issue. Please try again later."
48
+
49
+
50
+ @traced_and_logged
51
+ def upload_readme(content: str):
52
+ """Upload or update the README.md file in a GitHub repository.
53
+
54
+ This function uses the GitHub API to either create a new README.md file or update an
55
+ existing one in the specified repository. It encodes the provided content to base64 before
56
+ sending it via the API. The function requires the following environment variables to be set:
57
+
58
+ - GITHUB_USERNAME: Your GitHub username.
59
+ - GITHUB_REPO: The name of the repository.
60
+ - GITHUB_PAT: Your GitHub Personal Access Token for authentication.
61
+
62
+ Parameters:
63
+ content (str): The text content to be written into the README.md file.
64
+
65
+ Raises:
66
+ ValueError: If any of the required environment variables are missing.
67
+ """
68
+ GITHUB_USERNAME = os.getenv("GITHUB_USERNAME")
69
+ REPO_NAME = os.getenv("GITHUB_REPO")
70
+ GITHUB_TOKEN = os.getenv("GITHUB_PAT")
71
+
72
+ if not GITHUB_USERNAME or not REPO_NAME or not GITHUB_TOKEN:
73
+ raise ValueError(
74
+ "Missing environment variables: GITHUB_USERNAME, GITHUB_REPO, or GITHUB_PAT"
75
+ )
76
+
77
+ GITHUB_API_URL = f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/contents/README.md"
78
+
79
+ encoded_content = base64.b64encode(content.encode()).decode()
80
+
81
+ with httpx.Client() as client:
82
+ response = client.get(
83
+ GITHUB_API_URL,
84
+ headers={
85
+ "Authorization": f"Bearer {GITHUB_TOKEN}",
86
+ "Accept": "application/vnd.github.v3+json",
87
+ },
88
+ )
89
+
90
+ data = response.json()
91
+ sha = data.get("sha", None)
92
+
93
+ payload = {
94
+ "message": "Updating README.md",
95
+ "content": encoded_content,
96
+ "branch": "main",
97
+ }
98
+
99
+ if sha:
100
+ payload["sha"] = sha
101
+
102
+ response = client.put(
103
+ GITHUB_API_URL,
104
+ json=payload,
105
+ headers={
106
+ "Authorization": f"Bearer {GITHUB_TOKEN}",
107
+ "Accept": "application/vnd.github.v3+json",
108
+ },
109
+ )
110
+
111
+ if response.status_code in [200, 201]:
112
+ print("README.md successfully uploaded/updated!")
113
+ else:
114
+ print("Failed to upload README.md:", response.json())
115
+
116
+
117
+ @traced_and_logged
118
+ def create_files(file_paths) -> str:
119
+ """Create multiple files in a GitHub repository with a predefined content.
120
+
121
+ This function iterates over a list of file paths (relative to the repository root) and creates
122
+ each file in the specified GitHub repository with the content "#created by flock". For each file,
123
+ it checks whether the file already exists; if it does, that file is skipped. The function
124
+ uses the following environment variables for authentication and repository information:
125
+
126
+ - GITHUB_USERNAME: Your GitHub username.
127
+ - GITHUB_REPO: The name of the repository.
128
+ - GITHUB_PAT: Your GitHub Personal Access Token for authentication.
129
+
130
+ Parameters:
131
+ file_paths (list of str): A list of file paths (relative to the repository root) to be created.
132
+
133
+ Returns:
134
+ str: A message indicating whether the files were created successfully or if there was a failure.
135
+ """
136
+ try:
137
+ GITHUB_USERNAME = os.getenv("GITHUB_USERNAME")
138
+ REPO_NAME = os.getenv("GITHUB_REPO")
139
+ GITHUB_TOKEN = os.getenv("GITHUB_PAT")
140
+
141
+ if not GITHUB_USERNAME or not REPO_NAME or not GITHUB_TOKEN:
142
+ raise ValueError(
143
+ "Missing environment variables: GITHUB_USERNAME, GITHUB_REPO, or GITHUB_PAT"
144
+ )
145
+
146
+ encoded_content = base64.b64encode(b"#created by flock").decode()
147
+
148
+ with httpx.Client() as client:
149
+ for file_path in file_paths:
150
+ GITHUB_API_URL = f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/contents/{file_path}"
151
+
152
+ response = client.get(
153
+ GITHUB_API_URL,
154
+ headers={
155
+ "Authorization": f"token {GITHUB_TOKEN}",
156
+ "Accept": "application/vnd.github.v3+json",
157
+ },
158
+ )
159
+
160
+ data = response.json()
161
+ sha = data.get("sha", None)
162
+
163
+ payload = {
164
+ "message": f"Creating {file_path}",
165
+ "content": encoded_content,
166
+ "branch": "main",
167
+ }
168
+
169
+ if sha:
170
+ print(f"Skipping {file_path}, file already exists.")
171
+ continue
172
+
173
+ response = client.put(
174
+ GITHUB_API_URL,
175
+ json=payload,
176
+ headers={
177
+ "Authorization": f"token {GITHUB_TOKEN}",
178
+ "Accept": "application/vnd.github.v3+json",
179
+ },
180
+ )
181
+
182
+ if response.status_code in [200, 201]:
183
+ print(f"{file_path} successfully created!")
184
+ else:
185
+ print(f"Failed to create {file_path}:", response.json())
186
+
187
+ return "Files created successfully."
188
+
189
+ except Exception:
190
+ return "Failed to create file. Please try again later."
@@ -0,0 +1,25 @@
1
+ from rich.console import Console
2
+ from rich.syntax import Text
3
+
4
+ console = Console()
5
+
6
+
7
+ def display_banner():
8
+ """Display the Flock banner."""
9
+ banner_text = Text(
10
+ """
11
+ 🦆 🐓 🐤 🦆
12
+ ╭━━━━━━━━━━━━━━━━━━━━━━━━╮
13
+ 🐓 │ ▒█▀▀▀ █░░ █▀▀█ █▀▀ █░█ │ 🐧
14
+ │ ▒█▀▀▀ █░░ █░░█ █░░ █▀▄ │
15
+ 🐧 │ ▒█░░░ ▀▀▀ ▀▀▀▀ ▀▀▀ ▀░▀ │ 🐓
16
+ ╰━━━━━━━━━━━━━━━━━━━━━━━━╯
17
+ 🦆 🐤 🐧 🐓
18
+ """,
19
+ justify="center",
20
+ style="bold orange3",
21
+ )
22
+ console.print(banner_text)
23
+ console.print(
24
+ f"[bold]v0.2.1[/] - [bold]white duck GmbH[/] - [cyan]https://whiteduck.de[/]\n"
25
+ )