flock-core 0.1.2__py3-none-any.whl → 0.2.1__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.
- flock/__init__.py +1 -4
- flock/agents/__init__.py +0 -3
- flock/agents/batch_agent.py +140 -175
- flock/agents/loop_agent.py +117 -178
- flock/agents/trigger_agent.py +113 -191
- flock/agents/user_agent.py +145 -230
- flock/core/__init__.py +1 -7
- flock/core/context/context.py +211 -0
- flock/core/context/context_manager.py +34 -0
- flock/core/{context_vars.py → context/context_vars.py} +8 -6
- flock/core/execution/local_executor.py +27 -0
- flock/core/execution/temporal_executor.py +40 -0
- flock/core/flock.py +199 -208
- flock/core/flock_agent.py +492 -0
- flock/core/logging/__init__.py +2 -18
- flock/core/logging/formatters/base_formatter.py +36 -0
- flock/core/logging/formatters/formatter_factory.py +38 -0
- flock/core/logging/formatters/pprint_formatter.py +18 -0
- flock/core/logging/formatters/rich_formatters.py +132 -0
- flock/core/logging/formatters/theme_builder.py +480 -0
- flock/core/logging/formatters/themed_formatter.py +442 -0
- flock/core/logging/logging.py +123 -0
- flock/core/mixin/dspy_integration.py +171 -0
- flock/core/mixin/prompt_parser.py +125 -0
- flock/core/registry/agent_registry.py +103 -0
- flock/core/tools/basic_tools.py +273 -98
- flock/core/tools/dev_tools/github.py +161 -0
- flock/core/util/cli_helper.py +21 -0
- flock/core/util/input_resolver.py +156 -0
- flock/core/util/serializable.py +93 -0
- flock/themes/3024-day.toml +39 -0
- flock/themes/3024-night.toml +77 -0
- flock/themes/aardvark-blue.toml +77 -0
- flock/themes/abernathy.toml +77 -0
- flock/themes/adventure.toml +77 -0
- flock/themes/adventuretime.toml +77 -0
- flock/themes/afterglow.toml +77 -0
- flock/themes/alabaster.toml +77 -0
- flock/themes/alienblood.toml +77 -0
- flock/themes/andromeda.toml +77 -0
- flock/themes/apple-classic.toml +77 -0
- flock/themes/apple-system-colors.toml +77 -0
- flock/themes/arcoiris.toml +77 -0
- flock/themes/argonaut copy.toml +77 -0
- flock/themes/argonaut.toml +39 -0
- flock/themes/arthur.toml +77 -0
- flock/themes/ateliersulphurpool.toml +77 -0
- flock/themes/atom.toml +38 -0
- flock/themes/atom_test.toml +65 -0
- flock/themes/atomonelight.toml +77 -0
- flock/themes/aurora.toml +77 -0
- flock/themes/ayu copy.toml +77 -0
- flock/themes/ayu-light.toml +77 -0
- flock/themes/ayu-mirage.toml +77 -0
- flock/themes/ayu.toml +39 -0
- flock/themes/banana-blueberry.toml +77 -0
- flock/themes/batman.toml +77 -0
- flock/themes/belafonte-day.toml +77 -0
- flock/themes/belafonte-night.toml +77 -0
- flock/themes/birdsofparadise.toml +77 -0
- flock/themes/blazer.toml +77 -0
- flock/themes/blue-matrix.toml +77 -0
- flock/themes/blueberrypie.toml +77 -0
- flock/themes/bluedolphin.toml +77 -0
- flock/themes/blulocodark.toml +77 -0
- flock/themes/blulocolight.toml +77 -0
- flock/themes/borland.toml +77 -0
- flock/themes/breeze.toml +77 -0
- flock/themes/bright-lights.toml +77 -0
- flock/themes/broadcast.toml +77 -0
- flock/themes/brogrammer.toml +77 -0
- flock/themes/builtin-dark.toml +77 -0
- flock/themes/builtin-light.toml +77 -0
- flock/themes/builtin-pastel-dark.toml +77 -0
- flock/themes/builtin-solarized-dark.toml +77 -0
- flock/themes/builtin-solarized-light.toml +77 -0
- flock/themes/builtin-tango-dark.toml +77 -0
- flock/themes/builtin-tango-light.toml +77 -0
- flock/themes/c64.toml +77 -0
- flock/themes/calamity.toml +77 -0
- flock/themes/catppuccin-frappe.toml +77 -0
- flock/themes/catppuccin-latte.toml +77 -0
- flock/themes/catppuccin-macchiato.toml +77 -0
- flock/themes/catppuccin-mocha.toml +77 -0
- flock/themes/cga.toml +77 -0
- flock/themes/chalk.toml +77 -0
- flock/themes/chalkboard.toml +77 -0
- flock/themes/challengerdeep.toml +77 -0
- flock/themes/chester.toml +77 -0
- flock/themes/ciapre.toml +77 -0
- flock/themes/clrs.toml +77 -0
- flock/themes/cobalt-neon.toml +77 -0
- flock/themes/cobalt2.toml +77 -0
- flock/themes/coffee-theme.toml +77 -0
- flock/themes/crayonponyfish.toml +77 -0
- flock/themes/cutiepro.toml +77 -0
- flock/themes/cyberdyne.toml +77 -0
- flock/themes/cyberpunk.toml +77 -0
- flock/themes/cyberpunkscarletprotocol.toml +77 -0
- flock/themes/dark+.toml +77 -0
- flock/themes/dark-pastel.toml +77 -0
- flock/themes/darkermatrix.toml +77 -0
- flock/themes/darkmatrix.toml +77 -0
- flock/themes/darkside.toml +77 -0
- flock/themes/dayfox.toml +77 -0
- flock/themes/deep.toml +77 -0
- flock/themes/desert.toml +77 -0
- flock/themes/dimidium.toml +77 -0
- flock/themes/dimmedmonokai.toml +77 -0
- flock/themes/django.toml +77 -0
- flock/themes/djangorebornagain.toml +77 -0
- flock/themes/djangosmooth.toml +77 -0
- flock/themes/doom-peacock.toml +77 -0
- flock/themes/doomone.toml +77 -0
- flock/themes/dotgov.toml +77 -0
- flock/themes/dracula+.toml +77 -0
- flock/themes/dracula.toml +77 -0
- flock/themes/duckbones.toml +77 -0
- flock/themes/duotone-dark.toml +77 -0
- flock/themes/earthsong.toml +77 -0
- flock/themes/elemental.toml +77 -0
- flock/themes/elementary.toml +77 -0
- flock/themes/encom.toml +77 -0
- flock/themes/espresso-libre.toml +77 -0
- flock/themes/espresso.toml +77 -0
- flock/themes/everblush.toml +77 -0
- flock/themes/fahrenheit.toml +77 -0
- flock/themes/fairyfloss.toml +77 -0
- flock/themes/farmhouse-dark.toml +77 -0
- flock/themes/farmhouse-light.toml +77 -0
- flock/themes/fideloper.toml +77 -0
- flock/themes/firefly-traditional.toml +77 -0
- flock/themes/firefoxdev.toml +77 -0
- flock/themes/firewatch.toml +77 -0
- flock/themes/fishtank.toml +77 -0
- flock/themes/flat.toml +77 -0
- flock/themes/flatland.toml +77 -0
- flock/themes/flexoki-dark.toml +77 -0
- flock/themes/flexoki-light.toml +77 -0
- flock/themes/floraverse.toml +77 -0
- flock/themes/forestblue.toml +77 -0
- flock/themes/framer.toml +77 -0
- flock/themes/frontenddelight.toml +77 -0
- flock/themes/funforrest.toml +77 -0
- flock/themes/galaxy.toml +77 -0
- flock/themes/galizur.toml +77 -0
- flock/themes/github-dark.toml +77 -0
- flock/themes/github.toml +77 -0
- flock/themes/glacier.toml +77 -0
- flock/themes/grape.toml +77 -0
- flock/themes/grass.toml +77 -0
- flock/themes/grey-green.toml +77 -0
- flock/themes/gruber-darker.toml +77 -0
- flock/themes/gruvboxdark.toml +77 -0
- flock/themes/gruvboxdarkhard.toml +77 -0
- flock/themes/gruvboxlight.toml +77 -0
- flock/themes/guezwhoz.toml +77 -0
- flock/themes/hacktober.toml +77 -0
- flock/themes/hardcore.toml +77 -0
- flock/themes/harper.toml +77 -0
- flock/themes/hax0r-blue.toml +77 -0
- flock/themes/hax0r-gr33n.toml +77 -0
- flock/themes/hax0r-r3d.toml +77 -0
- flock/themes/highway.toml +77 -0
- flock/themes/hipster-green.toml +77 -0
- flock/themes/hivacruz.toml +77 -0
- flock/themes/homebrew.toml +77 -0
- flock/themes/hopscotch.256.toml +77 -0
- flock/themes/hopscotch.toml +77 -0
- flock/themes/hurtado.toml +77 -0
- flock/themes/hybrid.toml +77 -0
- flock/themes/ic-green-ppl.toml +77 -0
- flock/themes/ic-orange-ppl.toml +77 -0
- flock/themes/iceberg-dark.toml +77 -0
- flock/themes/iceberg-light.toml +77 -0
- flock/themes/idea.toml +77 -0
- flock/themes/idletoes.toml +77 -0
- flock/themes/ir-black.toml +77 -0
- flock/themes/iterm2-dark-background.toml +77 -0
- flock/themes/iterm2-default.toml +77 -0
- flock/themes/iterm2-light-background.toml +77 -0
- flock/themes/iterm2-pastel-dark-background.toml +77 -0
- flock/themes/iterm2-smoooooth.toml +77 -0
- flock/themes/iterm2-solarized-dark.toml +77 -0
- flock/themes/iterm2-solarized-light.toml +77 -0
- flock/themes/iterm2-tango-dark.toml +77 -0
- flock/themes/iterm2-tango-light.toml +77 -0
- flock/themes/jackie-brown.toml +77 -0
- flock/themes/japanesque.toml +77 -0
- flock/themes/jellybeans.toml +77 -0
- flock/themes/jetbrains-darcula.toml +77 -0
- flock/themes/jubi.toml +77 -0
- flock/themes/kanagawabones.toml +77 -0
- flock/themes/kibble.toml +77 -0
- flock/themes/kolorit.toml +77 -0
- flock/themes/konsolas.toml +77 -0
- flock/themes/kurokula.toml +77 -0
- flock/themes/lab-fox.toml +77 -0
- flock/themes/laser.toml +77 -0
- flock/themes/later-this-evening.toml +77 -0
- flock/themes/lavandula.toml +77 -0
- flock/themes/liquidcarbon.toml +77 -0
- flock/themes/liquidcarbontransparent.toml +77 -0
- flock/themes/liquidcarbontransparentinverse.toml +77 -0
- flock/themes/lovelace.toml +77 -0
- flock/themes/man-page.toml +77 -0
- flock/themes/mariana.toml +77 -0
- flock/themes/material.toml +77 -0
- flock/themes/materialdark.toml +77 -0
- flock/themes/materialdarker.toml +77 -0
- flock/themes/materialdesigncolors.toml +77 -0
- flock/themes/materialocean.toml +77 -0
- flock/themes/mathias.toml +77 -0
- flock/themes/matrix.toml +77 -0
- flock/themes/medallion.toml +77 -0
- flock/themes/mellifluous.toml +77 -0
- flock/themes/midnight-in-mojave.toml +77 -0
- flock/themes/mirage.toml +77 -0
- flock/themes/misterioso.toml +77 -0
- flock/themes/molokai.toml +77 -0
- flock/themes/monalisa.toml +77 -0
- flock/themes/monokai-remastered.toml +77 -0
- flock/themes/monokai-soda.toml +77 -0
- flock/themes/monokai-vivid.toml +77 -0
- flock/themes/n0tch2k.toml +77 -0
- flock/themes/neobones-dark.toml +77 -0
- flock/themes/neobones-light.toml +77 -0
- flock/themes/neon.toml +77 -0
- flock/themes/neopolitan.toml +77 -0
- flock/themes/neutron.toml +77 -0
- flock/themes/night-owlish-light.toml +77 -0
- flock/themes/nightfox.toml +77 -0
- flock/themes/nightlion-v1.toml +77 -0
- flock/themes/nightlion-v2.toml +77 -0
- flock/themes/niji.toml +77 -0
- flock/themes/nocturnal-winter.toml +77 -0
- flock/themes/nord-light.toml +77 -0
- flock/themes/nord.toml +77 -0
- flock/themes/novel.toml +77 -0
- flock/themes/nvimdark.toml +77 -0
- flock/themes/nvimlight.toml +77 -0
- flock/themes/obsidian.toml +77 -0
- flock/themes/ocean.toml +77 -0
- flock/themes/oceanic-next.toml +77 -0
- flock/themes/oceanicmaterial.toml +77 -0
- flock/themes/ollie.toml +77 -0
- flock/themes/onehalfdark.toml +77 -0
- flock/themes/onehalflight.toml +77 -0
- flock/themes/operator-mono-dark.toml +77 -0
- flock/themes/overnight-slumber.toml +77 -0
- flock/themes/oxocarbon.toml +77 -0
- flock/themes/palenighthc.toml +77 -0
- flock/themes/pandora.toml +77 -0
- flock/themes/paraiso-dark.toml +77 -0
- flock/themes/paulmillr.toml +77 -0
- flock/themes/pencildark.toml +77 -0
- flock/themes/pencillight.toml +77 -0
- flock/themes/peppermint.toml +77 -0
- flock/themes/piatto-light.toml +77 -0
- flock/themes/pnevma.toml +77 -0
- flock/themes/popping-and-locking.toml +77 -0
- flock/themes/primary.toml +77 -0
- flock/themes/pro-light.toml +77 -0
- flock/themes/pro.toml +77 -0
- flock/themes/purple-rain.toml +77 -0
- flock/themes/purplepeter.toml +77 -0
- flock/themes/rapture.toml +77 -0
- flock/themes/raycast-dark.toml +77 -0
- flock/themes/raycast-light.toml +77 -0
- flock/themes/rebecca.toml +77 -0
- flock/themes/red-alert.toml +77 -0
- flock/themes/red-planet.toml +77 -0
- flock/themes/red-sands.toml +77 -0
- flock/themes/relaxed.toml +77 -0
- flock/themes/retro.toml +77 -0
- flock/themes/rippedcasts.toml +77 -0
- flock/themes/rose-pine-dawn.toml +77 -0
- flock/themes/rose-pine-moon.toml +77 -0
- flock/themes/rose-pine.toml +77 -0
- flock/themes/rouge-2.toml +77 -0
- flock/themes/royal.toml +77 -0
- flock/themes/ryuuko.toml +77 -0
- flock/themes/sakura.toml +77 -0
- flock/themes/scarlet-protocol.toml +77 -0
- flock/themes/seafoam-pastel.toml +77 -0
- flock/themes/seashells.toml +77 -0
- flock/themes/seoulbones-dark.toml +77 -0
- flock/themes/seoulbones-light.toml +77 -0
- flock/themes/seti.toml +77 -0
- flock/themes/shades-of-purple.toml +77 -0
- flock/themes/shaman.toml +77 -0
- flock/themes/slate.toml +77 -0
- flock/themes/sleepyhollow.toml +77 -0
- flock/themes/smyck.toml +77 -0
- flock/themes/snazzy.toml +77 -0
- flock/themes/softserver.toml +77 -0
- flock/themes/solarized-darcula.toml +77 -0
- flock/themes/solarized-dark---patched.toml +77 -0
- flock/themes/solarized-dark-higher-contrast.toml +77 -0
- flock/themes/spacedust.toml +77 -0
- flock/themes/spacegray-eighties-dull.toml +77 -0
- flock/themes/spacegray-eighties.toml +77 -0
- flock/themes/spacegray.toml +77 -0
- flock/themes/spiderman.toml +77 -0
- flock/themes/spring.toml +77 -0
- flock/themes/square.toml +77 -0
- flock/themes/sublette.toml +77 -0
- flock/themes/subliminal.toml +77 -0
- flock/themes/sugarplum.toml +77 -0
- flock/themes/sundried.toml +77 -0
- flock/themes/symfonic.toml +77 -0
- flock/themes/synthwave-everything.toml +77 -0
- flock/themes/synthwave.toml +77 -0
- flock/themes/synthwavealpha.toml +77 -0
- flock/themes/tango-adapted.toml +77 -0
- flock/themes/tango-half-adapted.toml +77 -0
- flock/themes/teerb.toml +77 -0
- flock/themes/terafox.toml +77 -0
- flock/themes/terminal-basic.toml +77 -0
- flock/themes/thayer-bright.toml +77 -0
- flock/themes/the-hulk.toml +77 -0
- flock/themes/tinacious-design-(dark).toml +77 -0
- flock/themes/tinacious-design-(light).toml +77 -0
- flock/themes/tokyonight-day.toml +77 -0
- flock/themes/tokyonight-storm.toml +77 -0
- flock/themes/tokyonight.toml +77 -0
- flock/themes/tomorrow-night-blue.toml +77 -0
- flock/themes/tomorrow-night-bright.toml +77 -0
- flock/themes/tomorrow-night-burns.toml +77 -0
- flock/themes/tomorrow-night-eighties.toml +77 -0
- flock/themes/tomorrow-night.toml +77 -0
- flock/themes/tomorrow.toml +77 -0
- flock/themes/toychest.toml +77 -0
- flock/themes/treehouse.toml +77 -0
- flock/themes/twilight.toml +77 -0
- flock/themes/ubuntu.toml +77 -0
- flock/themes/ultradark.toml +77 -0
- flock/themes/ultraviolent.toml +77 -0
- flock/themes/underthesea.toml +77 -0
- flock/themes/unikitty.toml +77 -0
- flock/themes/urple.toml +77 -0
- flock/themes/vaughn.toml +77 -0
- flock/themes/vesper.toml +77 -0
- flock/themes/vibrantink.toml +77 -0
- flock/themes/vimbones.toml +77 -0
- flock/themes/violet-dark.toml +77 -0
- flock/themes/violet-light.toml +77 -0
- flock/themes/warmneon.toml +77 -0
- flock/themes/wez.toml +77 -0
- flock/themes/whimsy.toml +77 -0
- flock/themes/wildcherry.toml +77 -0
- flock/themes/wilmersdorf.toml +77 -0
- flock/themes/wombat.toml +77 -0
- flock/themes/wryan.toml +77 -0
- flock/themes/xcodedark.toml +77 -0
- flock/themes/xcodedarkhc.toml +77 -0
- flock/themes/xcodelight.toml +77 -0
- flock/themes/xcodelighthc.toml +77 -0
- flock/themes/xcodewwdc.toml +77 -0
- flock/themes/zenbones-dark.toml +77 -0
- flock/themes/zenbones-light.toml +77 -0
- flock/themes/zenbones.toml +77 -0
- flock/themes/zenburn.toml +77 -0
- flock/themes/zenburned.toml +77 -0
- flock/themes/zenwritten-dark.toml +77 -0
- flock/themes/zenwritten-light.toml +77 -0
- flock/workflow/activities.py +117 -115
- flock/workflow/agent_activities.py +24 -26
- flock/workflow/temporal_setup.py +38 -37
- flock/workflow/workflow.py +58 -53
- flock_core-0.2.1.dist-info/METADATA +287 -0
- flock_core-0.2.1.dist-info/RECORD +375 -0
- {flock_core-0.1.2.dist-info → flock_core-0.2.1.dist-info}/licenses/LICENSE +21 -21
- flock/agents/declarative_agent.py +0 -166
- flock/app/components/__init__.py +0 -14
- flock/app/components/charts/agent_workflow.py +0 -14
- flock/app/components/charts/core_architecture.py +0 -14
- flock/app/components/charts/tool_system.py +0 -14
- flock/app/components/history_grid.py +0 -168
- flock/app/components/history_grid_alt.py +0 -189
- flock/app/components/sidebar.py +0 -19
- flock/app/components/theme.py +0 -9
- flock/app/components/util.py +0 -18
- flock/app/hive_app.py +0 -118
- flock/app/html/d3.html +0 -179
- flock/app/modules/__init__.py +0 -12
- flock/app/modules/about.py +0 -17
- flock/app/modules/agent_detail.py +0 -70
- flock/app/modules/agent_list.py +0 -59
- flock/app/modules/playground.py +0 -322
- flock/app/modules/settings.py +0 -96
- flock/core/agent.py +0 -150
- flock/core/agent_registry.py +0 -162
- flock/core/context.py +0 -279
- flock/core/handoff/handoff_base.py +0 -12
- flock/core/logging/error_handler.py +0 -84
- flock/core/logging/formatters.py +0 -122
- flock/core/logging/handlers.py +0 -117
- flock/core/logging/logger.py +0 -107
- flock/core/serializable.py +0 -206
- flock_core-0.1.2.dist-info/METADATA +0 -476
- flock_core-0.1.2.dist-info/RECORD +0 -48
- flock_core-0.1.2.dist-info/entry_points.txt +0 -2
- /flock/{core/config/declarative_agent_config.py → workflow/__init__.py} +0 -0
- {flock_core-0.1.2.dist-info → flock_core-0.2.1.dist-info}/WHEEL +0 -0
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from flock.core.agent import Agent
|
|
4
|
-
from flock.core.context import FlockContext
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class HandoffBase:
|
|
8
|
-
"""Base class for handoff implementations."""
|
|
9
|
-
|
|
10
|
-
next_agent: str | Agent
|
|
11
|
-
input: dict[str, Any]
|
|
12
|
-
context: FlockContext
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
from types import TracebackType
|
|
3
|
-
|
|
4
|
-
from temporalio import workflow
|
|
5
|
-
|
|
6
|
-
with workflow.unsafe.imports_passed_through():
|
|
7
|
-
from rich.console import Console
|
|
8
|
-
from rich.panel import Panel
|
|
9
|
-
from rich.syntax import Syntax
|
|
10
|
-
from rich.traceback import Traceback
|
|
11
|
-
|
|
12
|
-
from flock.core.logging.logger import flock_logger
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ErrorHandler:
|
|
16
|
-
"""Handles error formatting and display using Rich."""
|
|
17
|
-
|
|
18
|
-
def __init__(self, console: Console | None = None):
|
|
19
|
-
self.console = console or Console()
|
|
20
|
-
|
|
21
|
-
def format_exception(
|
|
22
|
-
self,
|
|
23
|
-
exc_type: type[BaseException],
|
|
24
|
-
exc_value: BaseException,
|
|
25
|
-
exc_tb: TracebackType,
|
|
26
|
-
*,
|
|
27
|
-
show_locals: bool = True,
|
|
28
|
-
) -> Panel:
|
|
29
|
-
"""Format an exception with Rich styling."""
|
|
30
|
-
# Create a Rich traceback
|
|
31
|
-
rich_tb = Traceback.from_exception(
|
|
32
|
-
exc_type,
|
|
33
|
-
exc_value,
|
|
34
|
-
exc_tb,
|
|
35
|
-
show_locals=show_locals,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
# If there's source code available, syntax highlight it
|
|
39
|
-
if exc_tb and exc_tb.tb_frame.f_code.co_filename != "<string>":
|
|
40
|
-
try:
|
|
41
|
-
with open(exc_tb.tb_frame.f_code.co_filename) as f:
|
|
42
|
-
source = f.read()
|
|
43
|
-
syntax = Syntax(
|
|
44
|
-
source,
|
|
45
|
-
"python",
|
|
46
|
-
line_numbers=True,
|
|
47
|
-
highlight_lines={exc_tb.tb_lineno},
|
|
48
|
-
)
|
|
49
|
-
except:
|
|
50
|
-
syntax = None
|
|
51
|
-
else:
|
|
52
|
-
syntax = None
|
|
53
|
-
|
|
54
|
-
# Create a panel with the traceback
|
|
55
|
-
return Panel(
|
|
56
|
-
rich_tb,
|
|
57
|
-
title=f"[red]{exc_type.__name__}[/]: {exc_value!s}",
|
|
58
|
-
border_style="red",
|
|
59
|
-
padding=(1, 2),
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
def handle_exception(
|
|
63
|
-
self,
|
|
64
|
-
exc_type: type[BaseException],
|
|
65
|
-
exc_value: BaseException,
|
|
66
|
-
exc_tb: TracebackType,
|
|
67
|
-
) -> None:
|
|
68
|
-
"""Handle an exception by formatting and displaying it."""
|
|
69
|
-
panel = self.format_exception(exc_type, exc_value, exc_tb)
|
|
70
|
-
self.console.print(panel)
|
|
71
|
-
# Also log the error through our logger
|
|
72
|
-
flock_logger.error(
|
|
73
|
-
f"Exception occurred: {exc_type.__name__}: {exc_value!s}",
|
|
74
|
-
error_type=exc_type.__name__,
|
|
75
|
-
error_details=str(exc_value),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
def install(self) -> None:
|
|
79
|
-
"""Install this error handler as the default exception handler."""
|
|
80
|
-
sys.excepthook = self.handle_exception
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
# Global error handler instance
|
|
84
|
-
error_handler = ErrorHandler()
|
flock/core/logging/formatters.py
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from devtools import pprint
|
|
4
|
-
from temporalio import workflow
|
|
5
|
-
|
|
6
|
-
with workflow.unsafe.imports_passed_through():
|
|
7
|
-
from rich.console import Console
|
|
8
|
-
from rich.panel import Panel
|
|
9
|
-
from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn, TimeElapsedColumn
|
|
10
|
-
from rich.table import Table
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class StructuredFormatter:
|
|
14
|
-
"""Formats structured data for Rich output."""
|
|
15
|
-
|
|
16
|
-
@staticmethod
|
|
17
|
-
def create_status_table(data: dict[str, Any]) -> Table:
|
|
18
|
-
"""Create a Rich table for displaying status information."""
|
|
19
|
-
table = Table(show_header=True, header_style="bold magenta")
|
|
20
|
-
table.add_column("Key")
|
|
21
|
-
table.add_column("Value")
|
|
22
|
-
|
|
23
|
-
for key, value in data.items():
|
|
24
|
-
table.add_row(str(key), str(value))
|
|
25
|
-
|
|
26
|
-
return table
|
|
27
|
-
|
|
28
|
-
@staticmethod
|
|
29
|
-
def create_progress_bar(description: str = "Progress") -> Progress:
|
|
30
|
-
"""Create a Rich progress bar with time tracking."""
|
|
31
|
-
return Progress(
|
|
32
|
-
SpinnerColumn(),
|
|
33
|
-
TextColumn("[progress.description]{task.description}"),
|
|
34
|
-
BarColumn(),
|
|
35
|
-
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
|
|
36
|
-
TimeElapsedColumn(),
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
@staticmethod
|
|
40
|
-
def create_workflow_panel(
|
|
41
|
-
workflow_id: str, status: str, details: dict[str, Any], title: str = "Workflow Status"
|
|
42
|
-
) -> Panel:
|
|
43
|
-
"""Create a Rich panel for workflow information."""
|
|
44
|
-
table = StructuredFormatter.create_status_table({"Workflow ID": workflow_id, "Status": status, **details})
|
|
45
|
-
return Panel(table, title=title, border_style="blue")
|
|
46
|
-
|
|
47
|
-
@staticmethod
|
|
48
|
-
def create_activity_panel(
|
|
49
|
-
activity_id: str, name: str, status: str, details: dict[str, Any], title: str = "Activity Status"
|
|
50
|
-
) -> Panel:
|
|
51
|
-
"""Create a Rich panel for activity information."""
|
|
52
|
-
table = StructuredFormatter.create_status_table(
|
|
53
|
-
{"Activity ID": activity_id, "Name": name, "Status": status, **details}
|
|
54
|
-
)
|
|
55
|
-
return Panel(table, title=title, border_style="magenta")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class PerformanceFormatter:
|
|
59
|
-
"""Formats performance metrics for Rich output."""
|
|
60
|
-
|
|
61
|
-
@staticmethod
|
|
62
|
-
def create_timing_tree(timings: dict[str, float]) -> str:
|
|
63
|
-
"""Create a tree-like structure showing execution timings."""
|
|
64
|
-
if not timings:
|
|
65
|
-
return "No timings recorded"
|
|
66
|
-
|
|
67
|
-
result = "Performance Metrics:\n"
|
|
68
|
-
for operation, duration in timings.items():
|
|
69
|
-
result += f"├── {operation}: {duration:.3f}s\n"
|
|
70
|
-
return result[:-1] # Remove trailing newline
|
|
71
|
-
|
|
72
|
-
@staticmethod
|
|
73
|
-
def create_performance_panel(metrics: dict[str, Any], title: str = "Performance Metrics") -> Panel:
|
|
74
|
-
"""Create a panel showing performance metrics."""
|
|
75
|
-
table = StructuredFormatter.create_status_table(metrics)
|
|
76
|
-
return Panel(table, title=title, border_style="cyan")
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
class AgentResultFormatter:
|
|
80
|
-
"""Formats agent results in a beautiful Rich table."""
|
|
81
|
-
|
|
82
|
-
@staticmethod
|
|
83
|
-
def format_result(result: dict[str, Any], agent_name: str) -> Panel:
|
|
84
|
-
"""Format an agent's result as a Rich panel containing a table."""
|
|
85
|
-
# Create a table with a nice header
|
|
86
|
-
table = Table(
|
|
87
|
-
show_header=True,
|
|
88
|
-
header_style="bold green",
|
|
89
|
-
title=f"Agent Results: {agent_name}",
|
|
90
|
-
title_style="bold blue",
|
|
91
|
-
border_style="bright_blue",
|
|
92
|
-
)
|
|
93
|
-
table.add_column("Output", style="cyan")
|
|
94
|
-
table.add_column("Value", style="green")
|
|
95
|
-
|
|
96
|
-
# Add each result to the table
|
|
97
|
-
for key, value in result.items():
|
|
98
|
-
# Format multi-line values (like blog headers) nicely
|
|
99
|
-
if isinstance(value, (list, tuple)) or (isinstance(value, str) and "\n" in value):
|
|
100
|
-
formatted_value = "\n".join(value) if isinstance(value, (list, tuple)) else value
|
|
101
|
-
# Add some padding for multi-line values
|
|
102
|
-
table.add_row(key, f"\n{formatted_value}\n")
|
|
103
|
-
else:
|
|
104
|
-
table.add_row(key, str(value))
|
|
105
|
-
|
|
106
|
-
pprint(result)
|
|
107
|
-
|
|
108
|
-
# Wrap the table in a panel for a nice border
|
|
109
|
-
return Panel(
|
|
110
|
-
table,
|
|
111
|
-
title="🎯 Agent Output",
|
|
112
|
-
title_align="left",
|
|
113
|
-
border_style="blue",
|
|
114
|
-
padding=(1, 2),
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
@staticmethod
|
|
118
|
-
def print_result(result: dict[str, Any], agent_name: str, console: Console | None = None) -> None:
|
|
119
|
-
"""Print an agent's result using Rich formatting."""
|
|
120
|
-
console = console or Console()
|
|
121
|
-
panel = AgentResultFormatter.format_result(result, agent_name)
|
|
122
|
-
console.print(panel)
|
flock/core/logging/handlers.py
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
|
|
3
|
-
from temporalio import workflow
|
|
4
|
-
|
|
5
|
-
with workflow.unsafe.imports_passed_through():
|
|
6
|
-
from rich.console import Console
|
|
7
|
-
from rich.live import Live
|
|
8
|
-
|
|
9
|
-
from collections.abc import Callable, Generator
|
|
10
|
-
from contextlib import contextmanager
|
|
11
|
-
from functools import wraps
|
|
12
|
-
from typing import Any, TypeVar
|
|
13
|
-
|
|
14
|
-
from flock.core.logging.formatters import PerformanceFormatter, StructuredFormatter
|
|
15
|
-
|
|
16
|
-
T = TypeVar("T")
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class PerformanceHandler:
|
|
20
|
-
"""Handles performance tracking and reporting."""
|
|
21
|
-
|
|
22
|
-
def __init__(self, console: Console | None = None):
|
|
23
|
-
self.console = console or Console()
|
|
24
|
-
self.timings: dict[str, float] = {}
|
|
25
|
-
self.enabled = False
|
|
26
|
-
|
|
27
|
-
def enable(self):
|
|
28
|
-
"""Enable performance tracking."""
|
|
29
|
-
self.enabled = True
|
|
30
|
-
|
|
31
|
-
def disable(self):
|
|
32
|
-
"""Disable performance tracking."""
|
|
33
|
-
self.enabled = False
|
|
34
|
-
|
|
35
|
-
def _get_time(self) -> float:
|
|
36
|
-
"""Get current time in a workflow-safe way."""
|
|
37
|
-
try:
|
|
38
|
-
# Try to get workflow time first
|
|
39
|
-
return workflow.now().timestamp()
|
|
40
|
-
except workflow._NotInWorkflowEventLoopError:
|
|
41
|
-
# Fall back to system time if not in workflow
|
|
42
|
-
return time.time()
|
|
43
|
-
|
|
44
|
-
@contextmanager
|
|
45
|
-
def track_time(self, operation_name: str) -> Generator[None, None, None]:
|
|
46
|
-
"""Context manager for tracking operation execution time."""
|
|
47
|
-
if not self.enabled:
|
|
48
|
-
yield
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
start_time = self._get_time()
|
|
52
|
-
try:
|
|
53
|
-
yield
|
|
54
|
-
finally:
|
|
55
|
-
end_time = self._get_time()
|
|
56
|
-
duration = end_time - start_time
|
|
57
|
-
self.timings[operation_name] = duration
|
|
58
|
-
|
|
59
|
-
def track_operation(self, operation_name: str) -> Callable[[Callable[..., T]], Callable[..., T]]:
|
|
60
|
-
"""Decorator for tracking function execution time."""
|
|
61
|
-
|
|
62
|
-
def decorator(func: Callable[..., T]) -> Callable[..., T]:
|
|
63
|
-
@wraps(func)
|
|
64
|
-
def wrapper(*args: Any, **kwargs: Any) -> T:
|
|
65
|
-
with self.track_time(operation_name):
|
|
66
|
-
return func(*args, **kwargs)
|
|
67
|
-
|
|
68
|
-
return wrapper
|
|
69
|
-
|
|
70
|
-
return decorator
|
|
71
|
-
|
|
72
|
-
def display_timings(self) -> None:
|
|
73
|
-
"""Display all tracked timings in a tree format."""
|
|
74
|
-
if self.timings:
|
|
75
|
-
tree = PerformanceFormatter.create_timing_tree(self.timings)
|
|
76
|
-
self.console.print(tree)
|
|
77
|
-
|
|
78
|
-
def clear_timings(self) -> None:
|
|
79
|
-
"""Clear all tracked timings."""
|
|
80
|
-
self.timings.clear()
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
class LiveUpdateHandler:
|
|
84
|
-
"""Handles live updates for long-running operations."""
|
|
85
|
-
|
|
86
|
-
def __init__(self, console: Console | None = None):
|
|
87
|
-
self.console = console or Console()
|
|
88
|
-
|
|
89
|
-
@contextmanager
|
|
90
|
-
def progress_tracker(self, description: str = "Progress") -> Generator[Any, None, None]:
|
|
91
|
-
"""Context manager for tracking progress with a live display."""
|
|
92
|
-
progress = StructuredFormatter.create_progress_bar(description)
|
|
93
|
-
with Live(progress, console=self.console, refresh_per_second=4) as live:
|
|
94
|
-
task = progress.add_task(description, total=100)
|
|
95
|
-
try:
|
|
96
|
-
yield lambda p: progress.update(task, completed=p)
|
|
97
|
-
finally:
|
|
98
|
-
progress.update(task, completed=100)
|
|
99
|
-
|
|
100
|
-
def update_workflow_status(
|
|
101
|
-
self, workflow_id: str, status: str, details: dict[str, Any], refresh_per_second: int = 1
|
|
102
|
-
) -> Live:
|
|
103
|
-
"""Create a live updating workflow status panel."""
|
|
104
|
-
panel = StructuredFormatter.create_workflow_panel(workflow_id, status, details)
|
|
105
|
-
return Live(panel, console=self.console, refresh_per_second=refresh_per_second)
|
|
106
|
-
|
|
107
|
-
def update_activity_status(
|
|
108
|
-
self, activity_id: str, name: str, status: str, details: dict[str, Any], refresh_per_second: int = 1
|
|
109
|
-
) -> Live:
|
|
110
|
-
"""Create a live updating activity status panel."""
|
|
111
|
-
panel = StructuredFormatter.create_activity_panel(activity_id, name, status, details)
|
|
112
|
-
return Live(panel, console=self.console, refresh_per_second=refresh_per_second)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
# Global instances for convenience
|
|
116
|
-
performance_handler = PerformanceHandler()
|
|
117
|
-
live_update_handler = LiveUpdateHandler()
|
flock/core/logging/logger.py
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from temporalio import workflow
|
|
4
|
-
|
|
5
|
-
from flock.core.logging.formatters import AgentResultFormatter
|
|
6
|
-
|
|
7
|
-
with workflow.unsafe.imports_passed_through():
|
|
8
|
-
from rich.console import Console
|
|
9
|
-
from rich.theme import Theme
|
|
10
|
-
|
|
11
|
-
# Custom theme for different log levels
|
|
12
|
-
THEME = Theme({
|
|
13
|
-
"info": "cyan",
|
|
14
|
-
"warning": "yellow",
|
|
15
|
-
"error": "red",
|
|
16
|
-
"debug": "grey50",
|
|
17
|
-
"success": "green",
|
|
18
|
-
"workflow": "blue",
|
|
19
|
-
"activity": "magenta",
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class LogLevel:
|
|
24
|
-
NONE = 0 # No logging except errors
|
|
25
|
-
MINIMAL = 1 # Only agent outputs
|
|
26
|
-
BASIC = 2 # Agent outputs + basic workflow info
|
|
27
|
-
VERBOSE = 3 # Everything including debug info
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class FlockLogger:
|
|
31
|
-
"""Custom logger for Flock that integrates with Rich and respects Temporal constraints."""
|
|
32
|
-
|
|
33
|
-
def __init__(self, name: str = "flock", console: Console | None = None, level: int = LogLevel.MINIMAL):
|
|
34
|
-
self.name = name
|
|
35
|
-
self.console = console or Console(theme=THEME)
|
|
36
|
-
self._workflow_id: str | None = None
|
|
37
|
-
self._activity_id: str | None = None
|
|
38
|
-
self.level = level
|
|
39
|
-
|
|
40
|
-
def set_level(self, level: int) -> None:
|
|
41
|
-
"""Set the logging level."""
|
|
42
|
-
self.level = level
|
|
43
|
-
|
|
44
|
-
def set_context(self, workflow_id: str | None = None, activity_id: str | None = None) -> None:
|
|
45
|
-
"""Set the current workflow and activity context."""
|
|
46
|
-
self._workflow_id = workflow_id
|
|
47
|
-
self._activity_id = activity_id
|
|
48
|
-
|
|
49
|
-
def _format_message(self, level: str, message: str, **kwargs: Any) -> str:
|
|
50
|
-
"""Format log message with context but without timestamps (for Temporal compatibility)."""
|
|
51
|
-
context_parts = []
|
|
52
|
-
if self._workflow_id:
|
|
53
|
-
context_parts.append(f"[workflow]workflow={self._workflow_id}[/]")
|
|
54
|
-
if self._activity_id:
|
|
55
|
-
context_parts.append(f"[activity]activity={self._activity_id}[/]")
|
|
56
|
-
|
|
57
|
-
# Add any additional context from kwargs
|
|
58
|
-
for key, value in kwargs.items():
|
|
59
|
-
if key not in ("workflow_id", "activity_id"):
|
|
60
|
-
context_parts.append(f"{key}={value}")
|
|
61
|
-
|
|
62
|
-
context_str = " ".join(context_parts)
|
|
63
|
-
return f"[{level}]{level.upper()}[/] {message} {context_str if context_str else ''}"
|
|
64
|
-
|
|
65
|
-
def info(self, message: str, **kwargs: Any) -> None:
|
|
66
|
-
"""Log an info message."""
|
|
67
|
-
if self.level >= LogLevel.BASIC:
|
|
68
|
-
self.console.print(self._format_message("info", message, **kwargs))
|
|
69
|
-
|
|
70
|
-
def warning(self, message: str, **kwargs: Any) -> None:
|
|
71
|
-
"""Log a warning message."""
|
|
72
|
-
if self.level >= LogLevel.BASIC:
|
|
73
|
-
self.console.print(self._format_message("warning", message, **kwargs))
|
|
74
|
-
|
|
75
|
-
def error(self, message: str, **kwargs: Any) -> None:
|
|
76
|
-
"""Log an error message."""
|
|
77
|
-
# Errors are always logged regardless of level
|
|
78
|
-
self.console.print(self._format_message("error", message, **kwargs))
|
|
79
|
-
|
|
80
|
-
def debug(self, message: str, **kwargs: Any) -> None:
|
|
81
|
-
"""Log a debug message."""
|
|
82
|
-
if self.level >= LogLevel.VERBOSE:
|
|
83
|
-
self.console.print(self._format_message("debug", message, **kwargs))
|
|
84
|
-
|
|
85
|
-
def success(self, message: str, **kwargs: Any) -> None:
|
|
86
|
-
"""Log a success message."""
|
|
87
|
-
if self.level >= LogLevel.BASIC:
|
|
88
|
-
self.console.print(self._format_message("success", message, **kwargs))
|
|
89
|
-
|
|
90
|
-
def workflow_event(self, message: str, **kwargs: Any) -> None:
|
|
91
|
-
"""Log a workflow-specific event."""
|
|
92
|
-
if self.level >= LogLevel.BASIC:
|
|
93
|
-
self.console.print(self._format_message("workflow", message, **kwargs))
|
|
94
|
-
|
|
95
|
-
def activity_event(self, message: str, **kwargs: Any) -> None:
|
|
96
|
-
"""Log an activity-specific event."""
|
|
97
|
-
if self.level >= LogLevel.BASIC:
|
|
98
|
-
self.console.print(self._format_message("activity", message, **kwargs))
|
|
99
|
-
|
|
100
|
-
def result(self, message: dict, agent_name, **kwargs: Any) -> None:
|
|
101
|
-
"""Log a result message."""
|
|
102
|
-
if self.level >= LogLevel.MINIMAL:
|
|
103
|
-
AgentResultFormatter.print_result(message, agent_name, self.console)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
# Global logger instance with minimal logging by default
|
|
107
|
-
flock_logger = FlockLogger(level=LogLevel.MINIMAL)
|
flock/core/serializable.py
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"""Module for serializable objects in the system."""
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from abc import ABC, abstractmethod
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from typing import Any, TypeVar
|
|
7
|
-
|
|
8
|
-
import cloudpickle
|
|
9
|
-
import msgpack
|
|
10
|
-
|
|
11
|
-
from flock.core.logging import flock_logger, performance_handler
|
|
12
|
-
|
|
13
|
-
T = TypeVar("T", bound="Serializable")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Serializable(ABC):
|
|
17
|
-
"""Base class for all serializable objects in the system.
|
|
18
|
-
|
|
19
|
-
Provides methods for serializing/deserializing objects to various formats
|
|
20
|
-
with comprehensive logging and performance tracking.
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
@abstractmethod
|
|
24
|
-
def to_dict(self) -> dict[str, Any]:
|
|
25
|
-
"""Convert instance to dictionary representation."""
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
@classmethod
|
|
29
|
-
@abstractmethod
|
|
30
|
-
def from_dict(cls: type[T], data: dict[str, Any]) -> T:
|
|
31
|
-
"""Create instance from dictionary representation."""
|
|
32
|
-
pass
|
|
33
|
-
|
|
34
|
-
def to_json(self) -> str:
|
|
35
|
-
"""Serialize to JSON string."""
|
|
36
|
-
try:
|
|
37
|
-
with performance_handler.track_time("json_serialization"):
|
|
38
|
-
flock_logger.debug(
|
|
39
|
-
"Serializing to JSON",
|
|
40
|
-
class_name=self.__class__.__name__,
|
|
41
|
-
)
|
|
42
|
-
json_str = json.dumps(self.to_dict())
|
|
43
|
-
flock_logger.debug(
|
|
44
|
-
"JSON serialization complete",
|
|
45
|
-
size_bytes=len(json_str),
|
|
46
|
-
)
|
|
47
|
-
return json_str
|
|
48
|
-
except Exception as e:
|
|
49
|
-
flock_logger.error(
|
|
50
|
-
"JSON serialization failed",
|
|
51
|
-
class_name=self.__class__.__name__,
|
|
52
|
-
error=str(e),
|
|
53
|
-
)
|
|
54
|
-
raise
|
|
55
|
-
|
|
56
|
-
@classmethod
|
|
57
|
-
def from_json(cls: type[T], json_str: str) -> T:
|
|
58
|
-
"""Create instance from JSON string."""
|
|
59
|
-
try:
|
|
60
|
-
with performance_handler.track_time("json_deserialization"):
|
|
61
|
-
flock_logger.debug(
|
|
62
|
-
"Deserializing from JSON",
|
|
63
|
-
class_name=cls.__name__,
|
|
64
|
-
size_bytes=len(json_str),
|
|
65
|
-
)
|
|
66
|
-
instance = cls.from_dict(json.loads(json_str))
|
|
67
|
-
flock_logger.debug("JSON deserialization complete")
|
|
68
|
-
return instance
|
|
69
|
-
except Exception as e:
|
|
70
|
-
flock_logger.error(
|
|
71
|
-
"JSON deserialization failed",
|
|
72
|
-
class_name=cls.__name__,
|
|
73
|
-
error=str(e),
|
|
74
|
-
)
|
|
75
|
-
raise
|
|
76
|
-
|
|
77
|
-
def to_msgpack(self, path: Path | None = None) -> bytes:
|
|
78
|
-
"""Serialize to msgpack bytes."""
|
|
79
|
-
try:
|
|
80
|
-
with performance_handler.track_time("msgpack_serialization"):
|
|
81
|
-
flock_logger.debug(
|
|
82
|
-
"Serializing to msgpack",
|
|
83
|
-
class_name=self.__class__.__name__,
|
|
84
|
-
)
|
|
85
|
-
msgpack_bytes = msgpack.packb(self.to_dict())
|
|
86
|
-
|
|
87
|
-
if path:
|
|
88
|
-
flock_logger.debug(f"Writing msgpack to file: {path}")
|
|
89
|
-
path.write_bytes(msgpack_bytes)
|
|
90
|
-
|
|
91
|
-
flock_logger.debug(
|
|
92
|
-
"Msgpack serialization complete",
|
|
93
|
-
size_bytes=len(msgpack_bytes),
|
|
94
|
-
file_path=str(path) if path else None,
|
|
95
|
-
)
|
|
96
|
-
return msgpack_bytes
|
|
97
|
-
except Exception as e:
|
|
98
|
-
flock_logger.error(
|
|
99
|
-
"Msgpack serialization failed",
|
|
100
|
-
class_name=self.__class__.__name__,
|
|
101
|
-
file_path=str(path) if path else None,
|
|
102
|
-
error=str(e),
|
|
103
|
-
)
|
|
104
|
-
raise
|
|
105
|
-
|
|
106
|
-
@classmethod
|
|
107
|
-
def from_msgpack(cls: type[T], msgpack_bytes: bytes) -> T:
|
|
108
|
-
"""Create instance from msgpack bytes."""
|
|
109
|
-
try:
|
|
110
|
-
with performance_handler.track_time("msgpack_deserialization"):
|
|
111
|
-
flock_logger.debug(
|
|
112
|
-
"Deserializing from msgpack",
|
|
113
|
-
class_name=cls.__name__,
|
|
114
|
-
size_bytes=len(msgpack_bytes),
|
|
115
|
-
)
|
|
116
|
-
instance = cls.from_dict(msgpack.unpackb(msgpack_bytes))
|
|
117
|
-
flock_logger.debug("Msgpack deserialization complete")
|
|
118
|
-
return instance
|
|
119
|
-
except Exception as e:
|
|
120
|
-
flock_logger.error(
|
|
121
|
-
"Msgpack deserialization failed",
|
|
122
|
-
class_name=cls.__name__,
|
|
123
|
-
error=str(e),
|
|
124
|
-
)
|
|
125
|
-
raise
|
|
126
|
-
|
|
127
|
-
@classmethod
|
|
128
|
-
def from_msgpack_file(cls: type[T], path: Path) -> T:
|
|
129
|
-
"""Create instance from msgpack file."""
|
|
130
|
-
try:
|
|
131
|
-
with performance_handler.track_time("msgpack_file_read"):
|
|
132
|
-
flock_logger.debug(
|
|
133
|
-
f"Reading msgpack from file: {path}",
|
|
134
|
-
class_name=cls.__name__,
|
|
135
|
-
)
|
|
136
|
-
return cls.from_msgpack(path.read_bytes())
|
|
137
|
-
except Exception as e:
|
|
138
|
-
flock_logger.error(
|
|
139
|
-
"Msgpack file read failed",
|
|
140
|
-
class_name=cls.__name__,
|
|
141
|
-
file_path=str(path),
|
|
142
|
-
error=str(e),
|
|
143
|
-
)
|
|
144
|
-
raise
|
|
145
|
-
|
|
146
|
-
def to_pickle(self) -> bytes:
|
|
147
|
-
"""Serialize to pickle bytes."""
|
|
148
|
-
try:
|
|
149
|
-
with performance_handler.track_time("pickle_serialization"):
|
|
150
|
-
flock_logger.debug(
|
|
151
|
-
"Serializing to pickle",
|
|
152
|
-
class_name=self.__class__.__name__,
|
|
153
|
-
)
|
|
154
|
-
pickle_bytes = cloudpickle.dumps(self)
|
|
155
|
-
flock_logger.debug(
|
|
156
|
-
"Pickle serialization complete",
|
|
157
|
-
size_bytes=len(pickle_bytes),
|
|
158
|
-
)
|
|
159
|
-
return pickle_bytes
|
|
160
|
-
except Exception as e:
|
|
161
|
-
flock_logger.error(
|
|
162
|
-
"Pickle serialization failed",
|
|
163
|
-
class_name=self.__class__.__name__,
|
|
164
|
-
error=str(e),
|
|
165
|
-
)
|
|
166
|
-
raise
|
|
167
|
-
|
|
168
|
-
@classmethod
|
|
169
|
-
def from_pickle(cls, pickle_bytes: bytes) -> T:
|
|
170
|
-
"""Create instance from pickle bytes."""
|
|
171
|
-
try:
|
|
172
|
-
with performance_handler.track_time("pickle_deserialization"):
|
|
173
|
-
flock_logger.debug(
|
|
174
|
-
"Deserializing from pickle",
|
|
175
|
-
class_name=cls.__name__,
|
|
176
|
-
size_bytes=len(pickle_bytes),
|
|
177
|
-
)
|
|
178
|
-
instance = cloudpickle.loads(pickle_bytes)
|
|
179
|
-
flock_logger.debug("Pickle deserialization complete")
|
|
180
|
-
return instance
|
|
181
|
-
except Exception as e:
|
|
182
|
-
flock_logger.error(
|
|
183
|
-
"Pickle deserialization failed",
|
|
184
|
-
class_name=cls.__name__,
|
|
185
|
-
error=str(e),
|
|
186
|
-
)
|
|
187
|
-
raise
|
|
188
|
-
|
|
189
|
-
@classmethod
|
|
190
|
-
def from_pickle_file(cls: type[T], path: Path) -> T:
|
|
191
|
-
"""Create instance from pickle file."""
|
|
192
|
-
try:
|
|
193
|
-
with performance_handler.track_time("pickle_file_read"):
|
|
194
|
-
flock_logger.debug(
|
|
195
|
-
f"Reading pickle from file: {path}",
|
|
196
|
-
class_name=cls.__name__,
|
|
197
|
-
)
|
|
198
|
-
return cls.from_pickle(path.read_bytes())
|
|
199
|
-
except Exception as e:
|
|
200
|
-
flock_logger.error(
|
|
201
|
-
"Pickle file read failed",
|
|
202
|
-
class_name=cls.__name__,
|
|
203
|
-
file_path=str(path),
|
|
204
|
-
error=str(e),
|
|
205
|
-
)
|
|
206
|
-
raise
|