waldiez 0.4.7__py3-none-any.whl → 0.4.9__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.

Files changed (248) hide show
  1. waldiez/__init__.py +5 -5
  2. waldiez/_version.py +1 -1
  3. waldiez/cli.py +97 -102
  4. waldiez/exporter.py +61 -19
  5. waldiez/exporting/__init__.py +25 -6
  6. waldiez/exporting/agent/__init__.py +7 -3
  7. waldiez/exporting/agent/code_execution.py +114 -0
  8. waldiez/exporting/agent/exporter.py +354 -0
  9. waldiez/exporting/agent/extras/__init__.py +15 -0
  10. waldiez/exporting/agent/extras/captain_agent_extras.py +315 -0
  11. waldiez/exporting/agent/extras/group/target.py +178 -0
  12. waldiez/exporting/agent/extras/group_manager_agent_extas.py +500 -0
  13. waldiez/exporting/agent/extras/group_member_extras.py +181 -0
  14. waldiez/exporting/agent/extras/handoffs/__init__.py +19 -0
  15. waldiez/exporting/agent/extras/handoffs/after_work.py +78 -0
  16. waldiez/exporting/agent/extras/handoffs/available.py +74 -0
  17. waldiez/exporting/agent/extras/handoffs/condition.py +158 -0
  18. waldiez/exporting/agent/extras/handoffs/handoff.py +171 -0
  19. waldiez/exporting/agent/extras/handoffs/target.py +189 -0
  20. waldiez/exporting/agent/extras/rag/__init__.py +10 -0
  21. waldiez/exporting/agent/{utils/rag_user/chroma_utils.py → extras/rag/chroma_extras.py} +37 -24
  22. waldiez/exporting/agent/{utils/rag_user/mongo_utils.py → extras/rag/mongo_extras.py} +10 -10
  23. waldiez/exporting/agent/{utils/rag_user/pgvector_utils.py → extras/rag/pgvector_extras.py} +13 -13
  24. waldiez/exporting/agent/{utils/rag_user/qdrant_utils.py → extras/rag/qdrant_extras.py} +13 -13
  25. waldiez/exporting/agent/{utils/rag_user/vector_db.py → extras/rag/vector_db_extras.py} +59 -46
  26. waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +245 -0
  27. waldiez/exporting/agent/extras/reasoning_agent_extras.py +88 -0
  28. waldiez/exporting/agent/factory.py +95 -0
  29. waldiez/exporting/agent/processor.py +150 -0
  30. waldiez/exporting/agent/system_message.py +36 -0
  31. waldiez/exporting/agent/termination.py +50 -0
  32. waldiez/exporting/chats/__init__.py +7 -3
  33. waldiez/exporting/chats/exporter.py +97 -0
  34. waldiez/exporting/chats/factory.py +65 -0
  35. waldiez/exporting/chats/processor.py +226 -0
  36. waldiez/exporting/chats/utils/__init__.py +6 -5
  37. waldiez/exporting/chats/utils/common.py +11 -45
  38. waldiez/exporting/chats/utils/group.py +55 -0
  39. waldiez/exporting/chats/utils/nested.py +37 -52
  40. waldiez/exporting/chats/utils/sequential.py +72 -61
  41. waldiez/exporting/chats/utils/{single_chat.py → single.py} +48 -50
  42. waldiez/exporting/core/__init__.py +196 -0
  43. waldiez/exporting/core/constants.py +17 -0
  44. waldiez/exporting/core/content.py +69 -0
  45. waldiez/exporting/core/context.py +244 -0
  46. waldiez/exporting/core/enums.py +89 -0
  47. waldiez/exporting/core/errors.py +19 -0
  48. waldiez/exporting/core/exporter.py +390 -0
  49. waldiez/exporting/core/exporters.py +67 -0
  50. waldiez/exporting/core/extras/__init__.py +39 -0
  51. waldiez/exporting/core/extras/agent_extras/__init__.py +27 -0
  52. waldiez/exporting/core/extras/agent_extras/captain_extras.py +57 -0
  53. waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +102 -0
  54. waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +53 -0
  55. waldiez/exporting/core/extras/agent_extras/reasoning_extras.py +68 -0
  56. waldiez/exporting/core/extras/agent_extras/standard_extras.py +263 -0
  57. waldiez/exporting/core/extras/base.py +241 -0
  58. waldiez/exporting/core/extras/chat_extras.py +118 -0
  59. waldiez/exporting/core/extras/flow_extras.py +70 -0
  60. waldiez/exporting/core/extras/model_extras.py +73 -0
  61. waldiez/exporting/core/extras/path_resolver.py +93 -0
  62. waldiez/exporting/core/extras/serializer.py +138 -0
  63. waldiez/exporting/core/extras/tool_extras.py +82 -0
  64. waldiez/exporting/core/protocols.py +259 -0
  65. waldiez/exporting/core/result.py +705 -0
  66. waldiez/exporting/core/types.py +329 -0
  67. waldiez/exporting/core/utils/__init__.py +11 -0
  68. waldiez/exporting/core/utils/comment.py +33 -0
  69. waldiez/exporting/core/utils/llm_config.py +117 -0
  70. waldiez/exporting/core/validation.py +96 -0
  71. waldiez/exporting/flow/__init__.py +6 -2
  72. waldiez/exporting/flow/execution_generator.py +193 -0
  73. waldiez/exporting/flow/exporter.py +107 -0
  74. waldiez/exporting/flow/factory.py +94 -0
  75. waldiez/exporting/flow/file_generator.py +214 -0
  76. waldiez/exporting/flow/merger.py +387 -0
  77. waldiez/exporting/flow/orchestrator.py +411 -0
  78. waldiez/exporting/flow/utils/__init__.py +9 -36
  79. waldiez/exporting/flow/utils/common.py +206 -0
  80. waldiez/exporting/flow/utils/importing.py +373 -0
  81. waldiez/exporting/flow/utils/linting.py +200 -0
  82. waldiez/exporting/flow/utils/{logging_utils.py → logging.py} +23 -9
  83. waldiez/exporting/models/__init__.py +3 -1
  84. waldiez/exporting/models/exporter.py +233 -0
  85. waldiez/exporting/models/factory.py +66 -0
  86. waldiez/exporting/models/processor.py +139 -0
  87. waldiez/exporting/tools/__init__.py +11 -0
  88. waldiez/exporting/tools/exporter.py +207 -0
  89. waldiez/exporting/tools/factory.py +57 -0
  90. waldiez/exporting/tools/processor.py +248 -0
  91. waldiez/exporting/tools/registration.py +133 -0
  92. waldiez/io/__init__.py +128 -0
  93. waldiez/io/_ws.py +199 -0
  94. waldiez/io/models/__init__.py +60 -0
  95. waldiez/io/models/base.py +66 -0
  96. waldiez/io/models/constants.py +78 -0
  97. waldiez/io/models/content/__init__.py +23 -0
  98. waldiez/io/models/content/audio.py +43 -0
  99. waldiez/io/models/content/base.py +45 -0
  100. waldiez/io/models/content/file.py +43 -0
  101. waldiez/io/models/content/image.py +96 -0
  102. waldiez/io/models/content/text.py +37 -0
  103. waldiez/io/models/content/video.py +43 -0
  104. waldiez/io/models/user_input.py +269 -0
  105. waldiez/io/models/user_response.py +215 -0
  106. waldiez/io/mqtt.py +681 -0
  107. waldiez/io/redis.py +782 -0
  108. waldiez/io/structured.py +439 -0
  109. waldiez/io/utils.py +184 -0
  110. waldiez/io/ws.py +298 -0
  111. waldiez/logger.py +481 -0
  112. waldiez/models/__init__.py +108 -51
  113. waldiez/models/agents/__init__.py +34 -70
  114. waldiez/models/agents/agent/__init__.py +10 -4
  115. waldiez/models/agents/agent/agent.py +466 -65
  116. waldiez/models/agents/agent/agent_data.py +119 -47
  117. waldiez/models/agents/agent/agent_type.py +13 -2
  118. waldiez/models/agents/agent/code_execution.py +12 -12
  119. waldiez/models/agents/agent/human_input_mode.py +8 -0
  120. waldiez/models/agents/agent/{linked_skill.py → linked_tool.py} +7 -7
  121. waldiez/models/agents/agent/nested_chat.py +35 -7
  122. waldiez/models/agents/agent/termination_message.py +30 -22
  123. waldiez/models/agents/{swarm_agent → agent}/update_system_message.py +22 -22
  124. waldiez/models/agents/agents.py +58 -63
  125. waldiez/models/agents/assistant/assistant.py +4 -4
  126. waldiez/models/agents/assistant/assistant_data.py +13 -1
  127. waldiez/models/agents/{captain_agent → captain}/captain_agent.py +5 -5
  128. waldiez/models/agents/{captain_agent → captain}/captain_agent_data.py +5 -5
  129. waldiez/models/agents/extra_requirements.py +11 -16
  130. waldiez/models/agents/group_manager/group_manager.py +103 -13
  131. waldiez/models/agents/group_manager/group_manager_data.py +36 -14
  132. waldiez/models/agents/group_manager/speakers.py +77 -24
  133. waldiez/models/agents/{rag_user → rag_user_proxy}/__init__.py +16 -16
  134. waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +64 -0
  135. waldiez/models/agents/{rag_user/rag_user_data.py → rag_user_proxy/rag_user_proxy_data.py} +6 -5
  136. waldiez/models/agents/{rag_user → rag_user_proxy}/retrieve_config.py +182 -114
  137. waldiez/models/agents/{rag_user → rag_user_proxy}/vector_db_config.py +13 -13
  138. waldiez/models/agents/reasoning/reasoning_agent.py +6 -6
  139. waldiez/models/agents/reasoning/reasoning_agent_data.py +110 -63
  140. waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +38 -10
  141. waldiez/models/agents/user_proxy/user_proxy.py +11 -7
  142. waldiez/models/agents/user_proxy/user_proxy_data.py +2 -2
  143. waldiez/models/chat/__init__.py +2 -1
  144. waldiez/models/chat/chat.py +166 -87
  145. waldiez/models/chat/chat_data.py +99 -136
  146. waldiez/models/chat/chat_message.py +33 -23
  147. waldiez/models/chat/chat_nested.py +31 -30
  148. waldiez/models/chat/chat_summary.py +10 -8
  149. waldiez/models/common/__init__.py +52 -2
  150. waldiez/models/common/ag2_version.py +1 -1
  151. waldiez/models/common/base.py +38 -7
  152. waldiez/models/common/dict_utils.py +42 -17
  153. waldiez/models/common/handoff.py +459 -0
  154. waldiez/models/common/id_generator.py +19 -0
  155. waldiez/models/common/method_utils.py +130 -68
  156. waldiez/{exporting/base/utils → models/common}/naming.py +38 -61
  157. waldiez/models/common/waldiez_version.py +37 -0
  158. waldiez/models/flow/__init__.py +9 -2
  159. waldiez/models/flow/connection.py +18 -0
  160. waldiez/models/flow/flow.py +311 -215
  161. waldiez/models/flow/flow_data.py +207 -40
  162. waldiez/models/flow/info.py +85 -0
  163. waldiez/models/flow/naming.py +131 -0
  164. waldiez/models/model/__init__.py +7 -1
  165. waldiez/models/model/extra_requirements.py +3 -12
  166. waldiez/models/model/model.py +76 -21
  167. waldiez/models/model/model_data.py +108 -20
  168. waldiez/models/tool/__init__.py +16 -0
  169. waldiez/models/tool/extra_requirements.py +36 -0
  170. waldiez/models/{skill/skill.py → tool/tool.py} +88 -88
  171. waldiez/models/tool/tool_data.py +51 -0
  172. waldiez/models/tool/tool_type.py +8 -0
  173. waldiez/models/waldiez.py +97 -80
  174. waldiez/runner.py +115 -61
  175. waldiez/running/__init__.py +13 -7
  176. waldiez/running/environment.py +49 -68
  177. waldiez/running/gen_seq_diagram.py +16 -14
  178. waldiez/running/post_run.py +119 -0
  179. waldiez/running/pre_run.py +149 -0
  180. waldiez/running/util.py +134 -0
  181. waldiez/utils/__init__.py +2 -4
  182. waldiez/utils/cli_extras/jupyter.py +5 -3
  183. waldiez/utils/cli_extras/runner.py +6 -4
  184. waldiez/utils/cli_extras/studio.py +6 -4
  185. waldiez/utils/conflict_checker.py +15 -9
  186. waldiez/utils/flaml_warnings.py +5 -5
  187. waldiez/utils/version.py +47 -0
  188. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/METADATA +235 -91
  189. waldiez-0.4.9.dist-info/RECORD +203 -0
  190. waldiez/exporting/agent/agent_exporter.py +0 -297
  191. waldiez/exporting/agent/utils/__init__.py +0 -23
  192. waldiez/exporting/agent/utils/captain_agent.py +0 -263
  193. waldiez/exporting/agent/utils/code_execution.py +0 -65
  194. waldiez/exporting/agent/utils/group_manager.py +0 -220
  195. waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
  196. waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
  197. waldiez/exporting/agent/utils/reasoning.py +0 -36
  198. waldiez/exporting/agent/utils/swarm_agent.py +0 -469
  199. waldiez/exporting/agent/utils/teachability.py +0 -41
  200. waldiez/exporting/agent/utils/termination_message.py +0 -44
  201. waldiez/exporting/base/__init__.py +0 -25
  202. waldiez/exporting/base/agent_position.py +0 -75
  203. waldiez/exporting/base/base_exporter.py +0 -118
  204. waldiez/exporting/base/export_position.py +0 -48
  205. waldiez/exporting/base/import_position.py +0 -23
  206. waldiez/exporting/base/mixin.py +0 -137
  207. waldiez/exporting/base/utils/__init__.py +0 -18
  208. waldiez/exporting/base/utils/comments.py +0 -96
  209. waldiez/exporting/base/utils/path_check.py +0 -68
  210. waldiez/exporting/base/utils/to_string.py +0 -84
  211. waldiez/exporting/chats/chats_exporter.py +0 -240
  212. waldiez/exporting/chats/utils/swarm.py +0 -210
  213. waldiez/exporting/flow/flow_exporter.py +0 -528
  214. waldiez/exporting/flow/utils/agent_utils.py +0 -204
  215. waldiez/exporting/flow/utils/chat_utils.py +0 -71
  216. waldiez/exporting/flow/utils/def_main.py +0 -77
  217. waldiez/exporting/flow/utils/flow_content.py +0 -202
  218. waldiez/exporting/flow/utils/flow_names.py +0 -116
  219. waldiez/exporting/flow/utils/importing_utils.py +0 -227
  220. waldiez/exporting/models/models_exporter.py +0 -199
  221. waldiez/exporting/models/utils.py +0 -174
  222. waldiez/exporting/skills/__init__.py +0 -9
  223. waldiez/exporting/skills/skills_exporter.py +0 -176
  224. waldiez/exporting/skills/utils.py +0 -369
  225. waldiez/models/agents/agent/teachability.py +0 -70
  226. waldiez/models/agents/rag_user/rag_user.py +0 -60
  227. waldiez/models/agents/swarm_agent/__init__.py +0 -50
  228. waldiez/models/agents/swarm_agent/after_work.py +0 -179
  229. waldiez/models/agents/swarm_agent/on_condition.py +0 -105
  230. waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
  231. waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
  232. waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
  233. waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
  234. waldiez/models/flow/utils.py +0 -232
  235. waldiez/models/skill/__init__.py +0 -16
  236. waldiez/models/skill/extra_requirements.py +0 -36
  237. waldiez/models/skill/skill_data.py +0 -53
  238. waldiez/models/skill/skill_type.py +0 -8
  239. waldiez/running/running.py +0 -369
  240. waldiez/utils/pysqlite3_checker.py +0 -308
  241. waldiez/utils/rdps_checker.py +0 -122
  242. waldiez-0.4.7.dist-info/RECORD +0 -149
  243. /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
  244. /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
  245. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/WHEEL +0 -0
  246. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/entry_points.txt +0 -0
  247. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/LICENSE +0 -0
  248. {waldiez-0.4.7.dist-info → waldiez-0.4.9.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
@@ -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)