waldiez 0.4.6__py3-none-any.whl → 0.4.8__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 waldiez might be problematic. Click here for more details.
- waldiez/__init__.py +5 -5
- waldiez/_version.py +1 -1
- waldiez/cli.py +112 -73
- waldiez/exporter.py +61 -19
- waldiez/exporting/__init__.py +25 -6
- waldiez/exporting/agent/__init__.py +7 -3
- waldiez/exporting/agent/code_execution.py +114 -0
- waldiez/exporting/agent/exporter.py +354 -0
- waldiez/exporting/agent/extras/__init__.py +15 -0
- waldiez/exporting/agent/extras/captain_agent_extras.py +315 -0
- waldiez/exporting/agent/extras/group/target.py +178 -0
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +500 -0
- waldiez/exporting/agent/extras/group_member_extras.py +181 -0
- waldiez/exporting/agent/extras/handoffs/__init__.py +19 -0
- waldiez/exporting/agent/extras/handoffs/after_work.py +78 -0
- waldiez/exporting/agent/extras/handoffs/available.py +74 -0
- waldiez/exporting/agent/extras/handoffs/condition.py +158 -0
- waldiez/exporting/agent/extras/handoffs/handoff.py +171 -0
- waldiez/exporting/agent/extras/handoffs/target.py +189 -0
- waldiez/exporting/agent/extras/rag/__init__.py +10 -0
- waldiez/exporting/agent/{utils/rag_user/chroma_utils.py → extras/rag/chroma_extras.py} +16 -15
- waldiez/exporting/agent/{utils/rag_user/mongo_utils.py → extras/rag/mongo_extras.py} +10 -10
- waldiez/exporting/agent/{utils/rag_user/pgvector_utils.py → extras/rag/pgvector_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/qdrant_utils.py → extras/rag/qdrant_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/vector_db.py → extras/rag/vector_db_extras.py} +59 -46
- waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +245 -0
- waldiez/exporting/agent/extras/reasoning_agent_extras.py +88 -0
- waldiez/exporting/agent/factory.py +95 -0
- waldiez/exporting/agent/processor.py +150 -0
- waldiez/exporting/agent/system_message.py +36 -0
- waldiez/exporting/agent/termination.py +50 -0
- waldiez/exporting/chats/__init__.py +7 -3
- waldiez/exporting/chats/exporter.py +97 -0
- waldiez/exporting/chats/factory.py +65 -0
- waldiez/exporting/chats/processor.py +226 -0
- waldiez/exporting/chats/utils/__init__.py +6 -5
- waldiez/exporting/chats/utils/common.py +11 -45
- waldiez/exporting/chats/utils/group.py +55 -0
- waldiez/exporting/chats/utils/nested.py +37 -52
- waldiez/exporting/chats/utils/sequential.py +72 -61
- waldiez/exporting/chats/utils/{single_chat.py → single.py} +48 -50
- waldiez/exporting/core/__init__.py +196 -0
- waldiez/exporting/core/constants.py +17 -0
- waldiez/exporting/core/content.py +69 -0
- waldiez/exporting/core/context.py +244 -0
- waldiez/exporting/core/enums.py +89 -0
- waldiez/exporting/core/errors.py +19 -0
- waldiez/exporting/core/exporter.py +390 -0
- waldiez/exporting/core/exporters.py +67 -0
- waldiez/exporting/core/extras/__init__.py +39 -0
- waldiez/exporting/core/extras/agent_extras/__init__.py +27 -0
- waldiez/exporting/core/extras/agent_extras/captain_extras.py +57 -0
- waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +102 -0
- waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +53 -0
- waldiez/exporting/core/extras/agent_extras/reasoning_extras.py +68 -0
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +263 -0
- waldiez/exporting/core/extras/base.py +241 -0
- waldiez/exporting/core/extras/chat_extras.py +118 -0
- waldiez/exporting/core/extras/flow_extras.py +70 -0
- waldiez/exporting/core/extras/model_extras.py +73 -0
- waldiez/exporting/core/extras/path_resolver.py +93 -0
- waldiez/exporting/core/extras/serializer.py +138 -0
- waldiez/exporting/core/extras/tool_extras.py +82 -0
- waldiez/exporting/core/protocols.py +259 -0
- waldiez/exporting/core/result.py +705 -0
- waldiez/exporting/core/types.py +329 -0
- waldiez/exporting/core/utils/__init__.py +11 -0
- waldiez/exporting/core/utils/comment.py +33 -0
- waldiez/exporting/core/utils/llm_config.py +117 -0
- waldiez/exporting/core/validation.py +96 -0
- waldiez/exporting/flow/__init__.py +6 -2
- waldiez/exporting/flow/execution_generator.py +193 -0
- waldiez/exporting/flow/exporter.py +107 -0
- waldiez/exporting/flow/factory.py +94 -0
- waldiez/exporting/flow/file_generator.py +214 -0
- waldiez/exporting/flow/merger.py +387 -0
- waldiez/exporting/flow/orchestrator.py +411 -0
- waldiez/exporting/flow/utils/__init__.py +9 -36
- waldiez/exporting/flow/utils/common.py +206 -0
- waldiez/exporting/flow/utils/importing.py +373 -0
- waldiez/exporting/flow/utils/linting.py +200 -0
- waldiez/exporting/flow/utils/{logging_utils.py → logging.py} +23 -9
- waldiez/exporting/models/__init__.py +3 -1
- waldiez/exporting/models/exporter.py +233 -0
- waldiez/exporting/models/factory.py +66 -0
- waldiez/exporting/models/processor.py +139 -0
- waldiez/exporting/tools/__init__.py +11 -0
- waldiez/exporting/tools/exporter.py +207 -0
- waldiez/exporting/tools/factory.py +57 -0
- waldiez/exporting/tools/processor.py +248 -0
- waldiez/exporting/tools/registration.py +133 -0
- waldiez/io/__init__.py +128 -0
- waldiez/io/_ws.py +199 -0
- waldiez/io/models/__init__.py +60 -0
- waldiez/io/models/base.py +66 -0
- waldiez/io/models/constants.py +78 -0
- waldiez/io/models/content/__init__.py +23 -0
- waldiez/io/models/content/audio.py +43 -0
- waldiez/io/models/content/base.py +45 -0
- waldiez/io/models/content/file.py +43 -0
- waldiez/io/models/content/image.py +96 -0
- waldiez/io/models/content/text.py +37 -0
- waldiez/io/models/content/video.py +43 -0
- waldiez/io/models/user_input.py +269 -0
- waldiez/io/models/user_response.py +215 -0
- waldiez/io/mqtt.py +681 -0
- waldiez/io/redis.py +782 -0
- waldiez/io/structured.py +419 -0
- waldiez/io/utils.py +184 -0
- waldiez/io/ws.py +298 -0
- waldiez/logger.py +481 -0
- waldiez/models/__init__.py +108 -51
- waldiez/models/agents/__init__.py +34 -70
- waldiez/models/agents/agent/__init__.py +10 -4
- waldiez/models/agents/agent/agent.py +466 -65
- waldiez/models/agents/agent/agent_data.py +119 -47
- waldiez/models/agents/agent/agent_type.py +13 -2
- waldiez/models/agents/agent/code_execution.py +12 -12
- waldiez/models/agents/agent/human_input_mode.py +8 -0
- waldiez/models/agents/agent/{linked_skill.py → linked_tool.py} +7 -7
- waldiez/models/agents/agent/nested_chat.py +35 -7
- waldiez/models/agents/agent/termination_message.py +30 -22
- waldiez/models/agents/{swarm_agent → agent}/update_system_message.py +22 -22
- waldiez/models/agents/agents.py +58 -63
- waldiez/models/agents/assistant/assistant.py +4 -4
- waldiez/models/agents/assistant/assistant_data.py +13 -1
- waldiez/models/agents/{captain_agent → captain}/captain_agent.py +5 -5
- waldiez/models/agents/{captain_agent → captain}/captain_agent_data.py +5 -5
- waldiez/models/agents/extra_requirements.py +11 -16
- waldiez/models/agents/group_manager/group_manager.py +103 -13
- waldiez/models/agents/group_manager/group_manager_data.py +36 -14
- waldiez/models/agents/group_manager/speakers.py +77 -24
- waldiez/models/agents/{rag_user → rag_user_proxy}/__init__.py +16 -16
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +64 -0
- waldiez/models/agents/{rag_user/rag_user_data.py → rag_user_proxy/rag_user_proxy_data.py} +6 -5
- waldiez/models/agents/{rag_user → rag_user_proxy}/retrieve_config.py +182 -114
- waldiez/models/agents/{rag_user → rag_user_proxy}/vector_db_config.py +13 -13
- waldiez/models/agents/reasoning/reasoning_agent.py +6 -6
- waldiez/models/agents/reasoning/reasoning_agent_data.py +110 -63
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +38 -10
- waldiez/models/agents/user_proxy/user_proxy.py +11 -7
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -2
- waldiez/models/chat/__init__.py +2 -1
- waldiez/models/chat/chat.py +166 -87
- waldiez/models/chat/chat_data.py +99 -136
- waldiez/models/chat/chat_message.py +33 -23
- waldiez/models/chat/chat_nested.py +31 -30
- waldiez/models/chat/chat_summary.py +10 -8
- waldiez/models/common/__init__.py +52 -2
- waldiez/models/common/ag2_version.py +1 -1
- waldiez/models/common/base.py +38 -7
- waldiez/models/common/dict_utils.py +42 -17
- waldiez/models/common/handoff.py +459 -0
- waldiez/models/common/id_generator.py +19 -0
- waldiez/models/common/method_utils.py +130 -68
- waldiez/{exporting/base/utils → models/common}/naming.py +38 -61
- waldiez/models/common/waldiez_version.py +37 -0
- waldiez/models/flow/__init__.py +9 -2
- waldiez/models/flow/connection.py +18 -0
- waldiez/models/flow/flow.py +311 -215
- waldiez/models/flow/flow_data.py +207 -40
- waldiez/models/flow/info.py +85 -0
- waldiez/models/flow/naming.py +131 -0
- waldiez/models/model/__init__.py +7 -1
- waldiez/models/model/extra_requirements.py +3 -12
- waldiez/models/model/model.py +76 -21
- waldiez/models/model/model_data.py +108 -20
- waldiez/models/tool/__init__.py +16 -0
- waldiez/models/tool/extra_requirements.py +36 -0
- waldiez/models/{skill/skill.py → tool/tool.py} +88 -88
- waldiez/models/tool/tool_data.py +51 -0
- waldiez/models/tool/tool_type.py +8 -0
- waldiez/models/waldiez.py +97 -80
- waldiez/runner.py +114 -49
- waldiez/running/__init__.py +1 -1
- waldiez/running/environment.py +49 -68
- waldiez/running/gen_seq_diagram.py +16 -14
- waldiez/running/running.py +53 -34
- waldiez/utils/__init__.py +0 -4
- waldiez/utils/cli_extras/jupyter.py +5 -3
- waldiez/utils/cli_extras/runner.py +6 -4
- waldiez/utils/cli_extras/studio.py +6 -4
- waldiez/utils/conflict_checker.py +15 -9
- waldiez/utils/flaml_warnings.py +5 -5
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/METADATA +235 -91
- waldiez-0.4.8.dist-info/RECORD +200 -0
- waldiez/exporting/agent/agent_exporter.py +0 -297
- waldiez/exporting/agent/utils/__init__.py +0 -23
- waldiez/exporting/agent/utils/captain_agent.py +0 -263
- waldiez/exporting/agent/utils/code_execution.py +0 -65
- waldiez/exporting/agent/utils/group_manager.py +0 -220
- waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
- waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
- waldiez/exporting/agent/utils/reasoning.py +0 -36
- waldiez/exporting/agent/utils/swarm_agent.py +0 -469
- waldiez/exporting/agent/utils/teachability.py +0 -41
- waldiez/exporting/agent/utils/termination_message.py +0 -44
- waldiez/exporting/base/__init__.py +0 -25
- waldiez/exporting/base/agent_position.py +0 -75
- waldiez/exporting/base/base_exporter.py +0 -118
- waldiez/exporting/base/export_position.py +0 -48
- waldiez/exporting/base/import_position.py +0 -23
- waldiez/exporting/base/mixin.py +0 -137
- waldiez/exporting/base/utils/__init__.py +0 -18
- waldiez/exporting/base/utils/comments.py +0 -96
- waldiez/exporting/base/utils/path_check.py +0 -68
- waldiez/exporting/base/utils/to_string.py +0 -84
- waldiez/exporting/chats/chats_exporter.py +0 -240
- waldiez/exporting/chats/utils/swarm.py +0 -210
- waldiez/exporting/flow/flow_exporter.py +0 -528
- waldiez/exporting/flow/utils/agent_utils.py +0 -204
- waldiez/exporting/flow/utils/chat_utils.py +0 -71
- waldiez/exporting/flow/utils/def_main.py +0 -77
- waldiez/exporting/flow/utils/flow_content.py +0 -202
- waldiez/exporting/flow/utils/flow_names.py +0 -116
- waldiez/exporting/flow/utils/importing_utils.py +0 -227
- waldiez/exporting/models/models_exporter.py +0 -199
- waldiez/exporting/models/utils.py +0 -174
- waldiez/exporting/skills/__init__.py +0 -9
- waldiez/exporting/skills/skills_exporter.py +0 -176
- waldiez/exporting/skills/utils.py +0 -369
- waldiez/models/agents/agent/teachability.py +0 -70
- waldiez/models/agents/rag_user/rag_user.py +0 -60
- waldiez/models/agents/swarm_agent/__init__.py +0 -50
- waldiez/models/agents/swarm_agent/after_work.py +0 -179
- waldiez/models/agents/swarm_agent/on_condition.py +0 -105
- waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
- waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
- waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
- waldiez/models/flow/utils.py +0 -232
- waldiez/models/skill/__init__.py +0 -16
- waldiez/models/skill/extra_requirements.py +0 -36
- waldiez/models/skill/skill_data.py +0 -53
- waldiez/models/skill/skill_type.py +0 -8
- waldiez/utils/pysqlite3_checker.py +0 -308
- waldiez/utils/rdps_checker.py +0 -122
- waldiez-0.4.6.dist-info/RECORD +0 -149
- /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
- /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/WHEEL +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Base exporter class to be inherited by all exporters."""
|
|
4
|
-
|
|
5
|
-
import abc
|
|
6
|
-
from typing import Any, List, Optional, Tuple, TypedDict, Union
|
|
7
|
-
|
|
8
|
-
from .agent_position import AgentPosition
|
|
9
|
-
from .export_position import ExportPosition
|
|
10
|
-
from .import_position import ImportPosition
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# flake8: noqa: E501,B027
|
|
14
|
-
# pylint: disable=line-too-long
|
|
15
|
-
class ExporterReturnType(TypedDict):
|
|
16
|
-
"""Exporter Return Type.
|
|
17
|
-
|
|
18
|
-
Attributes
|
|
19
|
-
----------
|
|
20
|
-
content : Optional[str]
|
|
21
|
-
The exported content.
|
|
22
|
-
imports : Optional[List[Tuple[str, ImportPosition]]]
|
|
23
|
-
The additional imports required for the exported content.
|
|
24
|
-
environment_variables : Optional[List[Tuple[str, str]]]
|
|
25
|
-
The environment variables to set.
|
|
26
|
-
before_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
27
|
-
The exported content before the main export and its position.
|
|
28
|
-
after_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
29
|
-
The exported content after the main export and its position.
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
content: Optional[str]
|
|
33
|
-
imports: Optional[List[Tuple[str, ImportPosition]]]
|
|
34
|
-
environment_variables: Optional[List[Tuple[str, str]]]
|
|
35
|
-
before_export: Optional[
|
|
36
|
-
List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
37
|
-
]
|
|
38
|
-
after_export: Optional[
|
|
39
|
-
List[Tuple[str, Union[ExportPosition, AgentPosition]]]
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class BaseExporter(abc.ABC):
|
|
44
|
-
"""Base exporter."""
|
|
45
|
-
|
|
46
|
-
@abc.abstractmethod
|
|
47
|
-
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
48
|
-
"""Initialize the exporter.
|
|
49
|
-
|
|
50
|
-
Parameters
|
|
51
|
-
----------
|
|
52
|
-
*args : Any
|
|
53
|
-
The positional arguments.
|
|
54
|
-
**kwargs : Any
|
|
55
|
-
The keyword arguments.
|
|
56
|
-
"""
|
|
57
|
-
raise NotImplementedError("Method not implemented.")
|
|
58
|
-
|
|
59
|
-
def get_environment_variables(self) -> Optional[List[Tuple[str, str]]]:
|
|
60
|
-
"""Get the environment variables to set.
|
|
61
|
-
|
|
62
|
-
Returns
|
|
63
|
-
-------
|
|
64
|
-
Optional[Set[Tuple[str, str]]]
|
|
65
|
-
The environment variables to set if any.
|
|
66
|
-
"""
|
|
67
|
-
|
|
68
|
-
def get_imports(self) -> Optional[List[Tuple[str, ImportPosition]]]:
|
|
69
|
-
"""Generate the imports string for the exporter.
|
|
70
|
-
|
|
71
|
-
Returns
|
|
72
|
-
-------
|
|
73
|
-
Optional[Tuple[str, ImportPosition]]
|
|
74
|
-
The exported imports and the position of the imports.
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
def get_before_export(
|
|
78
|
-
self,
|
|
79
|
-
) -> Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]:
|
|
80
|
-
"""Generate the content before the main export.
|
|
81
|
-
|
|
82
|
-
Returns
|
|
83
|
-
-------
|
|
84
|
-
Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
85
|
-
The exported content before the main export and its position.
|
|
86
|
-
"""
|
|
87
|
-
|
|
88
|
-
def generate(
|
|
89
|
-
self,
|
|
90
|
-
) -> Optional[str]:
|
|
91
|
-
"""Generate the main export.
|
|
92
|
-
|
|
93
|
-
Returns
|
|
94
|
-
-------
|
|
95
|
-
str
|
|
96
|
-
The exported content.
|
|
97
|
-
"""
|
|
98
|
-
|
|
99
|
-
def get_after_export(
|
|
100
|
-
self,
|
|
101
|
-
) -> Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]:
|
|
102
|
-
"""Generate the content after the main export.
|
|
103
|
-
|
|
104
|
-
Returns
|
|
105
|
-
-------
|
|
106
|
-
Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
107
|
-
The exported content after the main export and its position.
|
|
108
|
-
"""
|
|
109
|
-
|
|
110
|
-
@abc.abstractmethod
|
|
111
|
-
def export(self) -> ExporterReturnType:
|
|
112
|
-
"""Export the content.
|
|
113
|
-
|
|
114
|
-
Returns
|
|
115
|
-
-------
|
|
116
|
-
ExporterReturnType
|
|
117
|
-
The exported content.
|
|
118
|
-
"""
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Export position enum."""
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from enum import Enum
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class ExportPositions(Enum):
|
|
10
|
-
"""Export position.
|
|
11
|
-
|
|
12
|
-
Attributes
|
|
13
|
-
----------
|
|
14
|
-
TOP : int
|
|
15
|
-
The top of the export (name, comments etc.)
|
|
16
|
-
IMPORTS : int
|
|
17
|
-
The imports section.
|
|
18
|
-
MODELS : int
|
|
19
|
-
The models section (define the llm_configs).
|
|
20
|
-
SKILLS : int
|
|
21
|
-
The skills section (generate the skill files, and import them)
|
|
22
|
-
AGENTS : int
|
|
23
|
-
The agents section.
|
|
24
|
-
CHATS : int
|
|
25
|
-
The chats section (e.g. agent.initiate_chat, or initiate_chats)
|
|
26
|
-
BOTTOM : int
|
|
27
|
-
The bottom part of the export (like the main function and calling it).
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
TOP = 0
|
|
31
|
-
IMPORTS = 1
|
|
32
|
-
SKILLS = 2
|
|
33
|
-
MODELS = 3
|
|
34
|
-
AGENTS = 4
|
|
35
|
-
CHATS = 5
|
|
36
|
-
BOTTOM = 6
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@dataclass(order=True, frozen=True, slots=True)
|
|
40
|
-
class ExportPosition:
|
|
41
|
-
"""Export position.
|
|
42
|
-
|
|
43
|
-
Optionally, the order can be provided
|
|
44
|
-
to sort the exported content.
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
position: ExportPositions
|
|
48
|
-
order: int = 0
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Import position enum."""
|
|
4
|
-
|
|
5
|
-
from enum import Enum
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class ImportPosition(Enum):
|
|
9
|
-
"""Import position.
|
|
10
|
-
|
|
11
|
-
Attributes
|
|
12
|
-
----------
|
|
13
|
-
BUILTINS : int
|
|
14
|
-
The top of the import (builtins)
|
|
15
|
-
THIRD_PARTY : int
|
|
16
|
-
The third party imports.
|
|
17
|
-
LOCAL : int
|
|
18
|
-
The local imports.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
BUILTINS = 0
|
|
22
|
-
THIRD_PARTY = 1
|
|
23
|
-
LOCAL = 2
|
waldiez/exporting/base/mixin.py
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""The base exporter mixin."""
|
|
4
|
-
|
|
5
|
-
from typing import Any, Dict, Tuple
|
|
6
|
-
|
|
7
|
-
from .utils import (
|
|
8
|
-
CommentKey,
|
|
9
|
-
comment,
|
|
10
|
-
get_comment,
|
|
11
|
-
get_escaped_string,
|
|
12
|
-
get_item_string,
|
|
13
|
-
get_path_string,
|
|
14
|
-
get_valid_instance_name,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ExporterMixin:
|
|
19
|
-
"""Static methods to be used by the exporters."""
|
|
20
|
-
|
|
21
|
-
@staticmethod
|
|
22
|
-
def serializer(item: Any, tabs: int = 1) -> str:
|
|
23
|
-
"""Get the string representation of an item.
|
|
24
|
-
|
|
25
|
-
Parameters
|
|
26
|
-
----------
|
|
27
|
-
item : Any
|
|
28
|
-
The item.
|
|
29
|
-
tabs : int, optional
|
|
30
|
-
The number of tabs for indentation, by default 1.
|
|
31
|
-
|
|
32
|
-
Returns
|
|
33
|
-
-------
|
|
34
|
-
str
|
|
35
|
-
The string representation of the item.
|
|
36
|
-
"""
|
|
37
|
-
return get_item_string(item=item, tabs=tabs)
|
|
38
|
-
|
|
39
|
-
@staticmethod
|
|
40
|
-
def path_resolver(path: str) -> str:
|
|
41
|
-
"""Get the path string.
|
|
42
|
-
|
|
43
|
-
Parameters
|
|
44
|
-
----------
|
|
45
|
-
path : str
|
|
46
|
-
The path.
|
|
47
|
-
|
|
48
|
-
Returns
|
|
49
|
-
-------
|
|
50
|
-
str
|
|
51
|
-
The path string.
|
|
52
|
-
"""
|
|
53
|
-
return get_path_string(path)
|
|
54
|
-
|
|
55
|
-
@staticmethod
|
|
56
|
-
def string_escape(string: str) -> str:
|
|
57
|
-
"""Get a string with escaped quotes and newlines.
|
|
58
|
-
|
|
59
|
-
Parameters
|
|
60
|
-
----------
|
|
61
|
-
string : str
|
|
62
|
-
The original string.
|
|
63
|
-
|
|
64
|
-
Returns
|
|
65
|
-
-------
|
|
66
|
-
str
|
|
67
|
-
The escaped string.
|
|
68
|
-
"""
|
|
69
|
-
return get_escaped_string(string)
|
|
70
|
-
|
|
71
|
-
@staticmethod
|
|
72
|
-
def get_comment(key: CommentKey, for_notebook: bool) -> str:
|
|
73
|
-
"""Get the comment string.
|
|
74
|
-
|
|
75
|
-
Parameters
|
|
76
|
-
----------
|
|
77
|
-
key : CommentKey
|
|
78
|
-
The comment key.
|
|
79
|
-
for_notebook : bool
|
|
80
|
-
Whether the comment is for a notebook or not.
|
|
81
|
-
|
|
82
|
-
Returns
|
|
83
|
-
-------
|
|
84
|
-
str
|
|
85
|
-
The comment string.
|
|
86
|
-
"""
|
|
87
|
-
return get_comment(key=key, for_notebook=for_notebook)
|
|
88
|
-
|
|
89
|
-
@staticmethod
|
|
90
|
-
def comment(for_notebook: bool, hashtags: int = 1) -> str:
|
|
91
|
-
"""Comment the text.
|
|
92
|
-
|
|
93
|
-
Parameters
|
|
94
|
-
----------
|
|
95
|
-
for_notebook : bool
|
|
96
|
-
Whether the comment is for a notebook or not.
|
|
97
|
-
hashtags : int, optional
|
|
98
|
-
The number of hashtags (for notebooks), by default 1.
|
|
99
|
-
|
|
100
|
-
Returns
|
|
101
|
-
-------
|
|
102
|
-
str
|
|
103
|
-
The commented text.
|
|
104
|
-
"""
|
|
105
|
-
return comment(for_notebook=for_notebook, hashtags=hashtags)
|
|
106
|
-
|
|
107
|
-
@staticmethod
|
|
108
|
-
def get_valid_instance_name(
|
|
109
|
-
instance: Tuple[str, str],
|
|
110
|
-
current_names: Dict[str, str],
|
|
111
|
-
prefix: str = "w",
|
|
112
|
-
max_length: int = 64,
|
|
113
|
-
) -> Dict[str, str]:
|
|
114
|
-
"""Get a valid instance name.
|
|
115
|
-
|
|
116
|
-
Parameters
|
|
117
|
-
----------
|
|
118
|
-
instance : Tuple[str, str]
|
|
119
|
-
The instance id and possible name.
|
|
120
|
-
current_names : Dict[str, str]
|
|
121
|
-
The current names.
|
|
122
|
-
prefix : str, optional
|
|
123
|
-
The prefix for the instance name, by default "w".
|
|
124
|
-
max_length : int, optional
|
|
125
|
-
The maximum length of the variable name, by default 64
|
|
126
|
-
|
|
127
|
-
Returns
|
|
128
|
-
-------
|
|
129
|
-
Dict[str, str]
|
|
130
|
-
The updated dictionary of current names.
|
|
131
|
-
"""
|
|
132
|
-
return get_valid_instance_name(
|
|
133
|
-
instance=instance,
|
|
134
|
-
current_names=current_names,
|
|
135
|
-
prefix=prefix,
|
|
136
|
-
max_length=max_length,
|
|
137
|
-
)
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Generic utils to be used for exporting."""
|
|
4
|
-
|
|
5
|
-
from .comments import CommentKey, comment, get_comment
|
|
6
|
-
from .naming import get_escaped_string, get_valid_instance_name
|
|
7
|
-
from .path_check import get_path_string
|
|
8
|
-
from .to_string import get_item_string
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
"CommentKey",
|
|
12
|
-
"comment",
|
|
13
|
-
"get_comment",
|
|
14
|
-
"get_escaped_string",
|
|
15
|
-
"get_item_string",
|
|
16
|
-
"get_path_string",
|
|
17
|
-
"get_valid_instance_name",
|
|
18
|
-
]
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Utilities for comments.
|
|
4
|
-
|
|
5
|
-
Functions
|
|
6
|
-
---------
|
|
7
|
-
comment
|
|
8
|
-
Get a comment string.
|
|
9
|
-
get_comment
|
|
10
|
-
Get a comment string for some common keys (notebook headings).
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
from typing_extensions import Literal
|
|
14
|
-
|
|
15
|
-
CommentKey = Literal[
|
|
16
|
-
"agents", "imports", "skills", "models", "nested", "run", "logging"
|
|
17
|
-
]
|
|
18
|
-
"""Possible keys for comments."""
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def comment(for_notebook: bool, hashtags: int = 1) -> str:
|
|
22
|
-
"""Get the comment string.
|
|
23
|
-
|
|
24
|
-
Parameters
|
|
25
|
-
----------
|
|
26
|
-
for_notebook : bool
|
|
27
|
-
Whether the comment is for a notebook or not.
|
|
28
|
-
hashtags : int, optional
|
|
29
|
-
The number of hashtags (for notebooks), by default 1.
|
|
30
|
-
|
|
31
|
-
Returns
|
|
32
|
-
-------
|
|
33
|
-
str
|
|
34
|
-
The comment string.
|
|
35
|
-
Example
|
|
36
|
-
-------
|
|
37
|
-
```python
|
|
38
|
-
>>> comment(True, 2)
|
|
39
|
-
'## '
|
|
40
|
-
>>> comment(False)
|
|
41
|
-
'# '
|
|
42
|
-
```
|
|
43
|
-
"""
|
|
44
|
-
content = "# "
|
|
45
|
-
if for_notebook:
|
|
46
|
-
content += "#" * hashtags + " "
|
|
47
|
-
return content
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def get_comment(
|
|
51
|
-
key: CommentKey,
|
|
52
|
-
for_notebook: bool,
|
|
53
|
-
) -> str:
|
|
54
|
-
"""Get a comment string for some common keys.
|
|
55
|
-
|
|
56
|
-
The key is a heading (in a notebook) or just a comment (in a script).
|
|
57
|
-
|
|
58
|
-
Parameters
|
|
59
|
-
----------
|
|
60
|
-
key : "agents"|"imports"|"skills"|"models"|"nested"|"run"|"logging"
|
|
61
|
-
The key.
|
|
62
|
-
for_notebook : bool
|
|
63
|
-
Whether the comment is for a notebook.
|
|
64
|
-
|
|
65
|
-
Returns
|
|
66
|
-
-------
|
|
67
|
-
str
|
|
68
|
-
The comment string.
|
|
69
|
-
|
|
70
|
-
Example
|
|
71
|
-
-------
|
|
72
|
-
```python
|
|
73
|
-
>>> get_comment("agents", True)
|
|
74
|
-
|
|
75
|
-
'## Agents'
|
|
76
|
-
>>> get_comment("skills", False)
|
|
77
|
-
|
|
78
|
-
'# Skills'
|
|
79
|
-
```
|
|
80
|
-
"""
|
|
81
|
-
# pylint: disable=too-many-return-statements
|
|
82
|
-
if key == "agents":
|
|
83
|
-
return "\n" + comment(for_notebook, 2) + "Agents\n"
|
|
84
|
-
if key == "imports":
|
|
85
|
-
return "\n" + comment(for_notebook, 2) + "Imports\n"
|
|
86
|
-
if key == "skills":
|
|
87
|
-
return "\n" + comment(for_notebook, 2) + "Skills\n"
|
|
88
|
-
if key == "models":
|
|
89
|
-
return "\n" + comment(for_notebook, 2) + "Models\n"
|
|
90
|
-
if key == "nested":
|
|
91
|
-
return "\n" + comment(for_notebook, 2) + "Nested Chats\n"
|
|
92
|
-
if key == "run":
|
|
93
|
-
return "\n" + comment(for_notebook, 2) + "Run the flow\n"
|
|
94
|
-
if key == "logging":
|
|
95
|
-
return "\n" + comment(for_notebook, 2) + "Start Logging\n"
|
|
96
|
-
return comment(for_notebook)
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
# pylint: disable=broad-except
|
|
4
|
-
"""Path check utility functions."""
|
|
5
|
-
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from typing import Optional, Union
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def _check_local_path(string: str) -> Optional[Path]:
|
|
11
|
-
"""Check if a string is a local path.
|
|
12
|
-
|
|
13
|
-
Parameters
|
|
14
|
-
----------
|
|
15
|
-
string : str
|
|
16
|
-
The string to check.
|
|
17
|
-
|
|
18
|
-
Returns
|
|
19
|
-
-------
|
|
20
|
-
bool
|
|
21
|
-
True if the path is a local path.
|
|
22
|
-
"""
|
|
23
|
-
try:
|
|
24
|
-
path = Path(string).resolve()
|
|
25
|
-
except BaseException: # pragma: no cover
|
|
26
|
-
return None
|
|
27
|
-
if path.exists():
|
|
28
|
-
return path
|
|
29
|
-
return None
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def _get_raw_path_string(path: Union[str, Path]) -> str:
|
|
33
|
-
"""Get the raw path string.
|
|
34
|
-
|
|
35
|
-
Parameters
|
|
36
|
-
----------
|
|
37
|
-
path : Union[str, Path]
|
|
38
|
-
The string to check.
|
|
39
|
-
|
|
40
|
-
Returns
|
|
41
|
-
-------
|
|
42
|
-
str
|
|
43
|
-
The raw path string.
|
|
44
|
-
"""
|
|
45
|
-
if not isinstance(path, str):
|
|
46
|
-
path = str(path)
|
|
47
|
-
while path.startswith('r"') and path.endswith('"'):
|
|
48
|
-
path = path[2:-1]
|
|
49
|
-
return f'r"{path}"'
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def get_path_string(path: str) -> str:
|
|
53
|
-
"""Get the path string.
|
|
54
|
-
|
|
55
|
-
Parameters
|
|
56
|
-
----------
|
|
57
|
-
path : str
|
|
58
|
-
The string to check.
|
|
59
|
-
|
|
60
|
-
Returns
|
|
61
|
-
-------
|
|
62
|
-
str
|
|
63
|
-
The local path string.
|
|
64
|
-
"""
|
|
65
|
-
resolved = _check_local_path(path)
|
|
66
|
-
if not resolved:
|
|
67
|
-
return _get_raw_path_string(path)
|
|
68
|
-
return _get_raw_path_string(resolved)
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Utilities for converting items to strings.
|
|
4
|
-
|
|
5
|
-
To be used with dicts and/or lists.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from typing import Any
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def get_item_string(item: Any, tabs: int = 1) -> str:
|
|
12
|
-
"""Convert an item to a formatted string with given indentation.
|
|
13
|
-
|
|
14
|
-
Parameters
|
|
15
|
-
----------
|
|
16
|
-
item : Any
|
|
17
|
-
The item to convert.
|
|
18
|
-
tabs : int, optional
|
|
19
|
-
The number of tabs, by default 1.
|
|
20
|
-
|
|
21
|
-
Returns
|
|
22
|
-
-------
|
|
23
|
-
str
|
|
24
|
-
The formatted string.
|
|
25
|
-
|
|
26
|
-
Example
|
|
27
|
-
-------
|
|
28
|
-
```python
|
|
29
|
-
>>> obj = {"a": 1, "b": [1, 2, 3]}
|
|
30
|
-
>>> get_item_string(obj)
|
|
31
|
-
{
|
|
32
|
-
"a": 1,
|
|
33
|
-
"b": [
|
|
34
|
-
1,
|
|
35
|
-
2,
|
|
36
|
-
3
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
>>> obj = {"a": 1, "b": [1, 2, 3], "c": {"d": 4}}
|
|
40
|
-
>>> get_item_string(obj, 2)
|
|
41
|
-
{
|
|
42
|
-
"a": 1,
|
|
43
|
-
"b": [
|
|
44
|
-
1,
|
|
45
|
-
2,
|
|
46
|
-
3
|
|
47
|
-
],
|
|
48
|
-
"c": {
|
|
49
|
-
"d": 4
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
"""
|
|
54
|
-
indent = " " * 4 * tabs # Number of spaces corresponding to the tabs
|
|
55
|
-
next_indent = (
|
|
56
|
-
" " * 4 * (tabs + 1)
|
|
57
|
-
) # Number of spaces corresponding to the next tab level
|
|
58
|
-
if isinstance(item, dict):
|
|
59
|
-
items = []
|
|
60
|
-
for key, value in item.items():
|
|
61
|
-
items.append(
|
|
62
|
-
f'{next_indent}"{key}": {get_item_string(value, tabs + 1)}'
|
|
63
|
-
)
|
|
64
|
-
# python3.10? f-string expression part cannot include a backslash
|
|
65
|
-
items_string = ",\n".join(items)
|
|
66
|
-
to_return = "\n" + items_string + "\n" + indent
|
|
67
|
-
return f"{{{to_return}}}"
|
|
68
|
-
if isinstance(item, list):
|
|
69
|
-
items = []
|
|
70
|
-
for sub_item in item:
|
|
71
|
-
items.append(f"{next_indent}{get_item_string(sub_item, tabs + 1)}")
|
|
72
|
-
# python3.10? f-string expression part cannot include a backslash
|
|
73
|
-
items_string = ",\n".join(items)
|
|
74
|
-
to_return = "\n" + items_string + "\n" + indent
|
|
75
|
-
return f"[{to_return}]"
|
|
76
|
-
|
|
77
|
-
if isinstance(item, str):
|
|
78
|
-
if item.startswith("r'") or item.startswith('r"'):
|
|
79
|
-
return item
|
|
80
|
-
return f'"{item}"'
|
|
81
|
-
|
|
82
|
-
if item is None:
|
|
83
|
-
return "None"
|
|
84
|
-
return str(item)
|