waldiez 0.6.0__py3-none-any.whl → 0.6.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 waldiez might be problematic. Click here for more details.

Files changed (188) hide show
  1. waldiez/__init__.py +1 -1
  2. waldiez/_version.py +1 -1
  3. waldiez/cli.py +18 -7
  4. waldiez/cli_extras/jupyter.py +3 -0
  5. waldiez/cli_extras/runner.py +3 -1
  6. waldiez/cli_extras/studio.py +3 -1
  7. waldiez/exporter.py +9 -3
  8. waldiez/exporting/agent/exporter.py +9 -10
  9. waldiez/exporting/agent/extras/captain_agent_extras.py +6 -6
  10. waldiez/exporting/agent/extras/doc_agent_extras.py +6 -6
  11. waldiez/exporting/agent/extras/group_manager_agent_extas.py +34 -23
  12. waldiez/exporting/agent/extras/group_member_extras.py +6 -5
  13. waldiez/exporting/agent/extras/handoffs/after_work.py +1 -1
  14. waldiez/exporting/agent/extras/handoffs/available.py +1 -1
  15. waldiez/exporting/agent/extras/handoffs/condition.py +3 -2
  16. waldiez/exporting/agent/extras/handoffs/handoff.py +1 -1
  17. waldiez/exporting/agent/extras/handoffs/target.py +6 -4
  18. waldiez/exporting/agent/extras/rag/chroma_extras.py +27 -19
  19. waldiez/exporting/agent/extras/rag/mongo_extras.py +8 -8
  20. waldiez/exporting/agent/extras/rag/pgvector_extras.py +5 -5
  21. waldiez/exporting/agent/extras/rag/qdrant_extras.py +5 -4
  22. waldiez/exporting/agent/extras/rag/vector_db_extras.py +1 -1
  23. waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +5 -7
  24. waldiez/exporting/agent/extras/reasoning_agent_extras.py +3 -5
  25. waldiez/exporting/chats/exporter.py +4 -4
  26. waldiez/exporting/chats/processor.py +1 -2
  27. waldiez/exporting/chats/utils/common.py +89 -48
  28. waldiez/exporting/chats/utils/group.py +9 -9
  29. waldiez/exporting/chats/utils/nested.py +7 -7
  30. waldiez/exporting/chats/utils/sequential.py +1 -1
  31. waldiez/exporting/chats/utils/single.py +2 -2
  32. waldiez/exporting/core/content.py +7 -7
  33. waldiez/exporting/core/context.py +5 -3
  34. waldiez/exporting/core/exporter.py +5 -3
  35. waldiez/exporting/core/exporters.py +2 -2
  36. waldiez/exporting/core/extras/agent_extras/captain_extras.py +2 -2
  37. waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +2 -2
  38. waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +2 -2
  39. waldiez/exporting/core/extras/agent_extras/standard_extras.py +3 -8
  40. waldiez/exporting/core/extras/base.py +7 -5
  41. waldiez/exporting/core/extras/flow_extras.py +4 -5
  42. waldiez/exporting/core/extras/model_extras.py +2 -2
  43. waldiez/exporting/core/extras/path_resolver.py +1 -2
  44. waldiez/exporting/core/extras/serializer.py +2 -2
  45. waldiez/exporting/core/protocols.py +6 -5
  46. waldiez/exporting/core/result.py +25 -28
  47. waldiez/exporting/core/types.py +10 -10
  48. waldiez/exporting/core/utils/llm_config.py +2 -2
  49. waldiez/exporting/core/validation.py +10 -11
  50. waldiez/exporting/flow/execution_generator.py +98 -10
  51. waldiez/exporting/flow/exporter.py +2 -2
  52. waldiez/exporting/flow/factory.py +2 -2
  53. waldiez/exporting/flow/file_generator.py +4 -2
  54. waldiez/exporting/flow/merger.py +5 -3
  55. waldiez/exporting/flow/orchestrator.py +72 -2
  56. waldiez/exporting/flow/utils/common.py +5 -5
  57. waldiez/exporting/flow/utils/importing.py +6 -7
  58. waldiez/exporting/flow/utils/linting.py +25 -9
  59. waldiez/exporting/flow/utils/logging.py +2 -2
  60. waldiez/exporting/models/exporter.py +8 -8
  61. waldiez/exporting/models/processor.py +5 -5
  62. waldiez/exporting/tools/exporter.py +2 -2
  63. waldiez/exporting/tools/processor.py +7 -4
  64. waldiez/io/__init__.py +8 -4
  65. waldiez/io/_ws.py +10 -6
  66. waldiez/io/models/constants.py +10 -10
  67. waldiez/io/models/content/audio.py +1 -0
  68. waldiez/io/models/content/base.py +20 -18
  69. waldiez/io/models/content/file.py +1 -0
  70. waldiez/io/models/content/image.py +1 -0
  71. waldiez/io/models/content/text.py +1 -0
  72. waldiez/io/models/content/video.py +1 -0
  73. waldiez/io/models/user_input.py +10 -5
  74. waldiez/io/models/user_response.py +17 -16
  75. waldiez/io/mqtt.py +18 -31
  76. waldiez/io/redis.py +18 -22
  77. waldiez/io/structured.py +52 -53
  78. waldiez/io/utils.py +3 -0
  79. waldiez/io/ws.py +5 -1
  80. waldiez/logger.py +16 -3
  81. waldiez/models/agents/__init__.py +3 -0
  82. waldiez/models/agents/agent/agent.py +23 -16
  83. waldiez/models/agents/agent/agent_data.py +25 -22
  84. waldiez/models/agents/agent/code_execution.py +9 -11
  85. waldiez/models/agents/agent/termination_message.py +10 -12
  86. waldiez/models/agents/agent/update_system_message.py +2 -4
  87. waldiez/models/agents/agents.py +8 -8
  88. waldiez/models/agents/assistant/assistant.py +6 -3
  89. waldiez/models/agents/assistant/assistant_data.py +2 -2
  90. waldiez/models/agents/captain/captain_agent.py +7 -4
  91. waldiez/models/agents/captain/captain_agent_data.py +5 -7
  92. waldiez/models/agents/doc_agent/doc_agent.py +7 -4
  93. waldiez/models/agents/doc_agent/doc_agent_data.py +9 -10
  94. waldiez/models/agents/doc_agent/rag_query_engine.py +10 -12
  95. waldiez/models/agents/extra_requirements.py +3 -3
  96. waldiez/models/agents/group_manager/group_manager.py +12 -7
  97. waldiez/models/agents/group_manager/group_manager_data.py +13 -12
  98. waldiez/models/agents/group_manager/speakers.py +17 -19
  99. waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +7 -4
  100. waldiez/models/agents/rag_user_proxy/rag_user_proxy_data.py +4 -1
  101. waldiez/models/agents/rag_user_proxy/retrieve_config.py +69 -63
  102. waldiez/models/agents/rag_user_proxy/vector_db_config.py +19 -19
  103. waldiez/models/agents/reasoning/reasoning_agent.py +7 -4
  104. waldiez/models/agents/reasoning/reasoning_agent_data.py +3 -2
  105. waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +8 -8
  106. waldiez/models/agents/user_proxy/user_proxy.py +6 -3
  107. waldiez/models/agents/user_proxy/user_proxy_data.py +1 -1
  108. waldiez/models/chat/chat.py +27 -20
  109. waldiez/models/chat/chat_data.py +22 -19
  110. waldiez/models/chat/chat_message.py +9 -9
  111. waldiez/models/chat/chat_nested.py +9 -9
  112. waldiez/models/chat/chat_summary.py +6 -6
  113. waldiez/models/common/__init__.py +2 -0
  114. waldiez/models/common/ag2_version.py +2 -0
  115. waldiez/models/common/dict_utils.py +8 -6
  116. waldiez/models/common/handoff.py +18 -17
  117. waldiez/models/common/method_utils.py +7 -7
  118. waldiez/models/common/naming.py +49 -0
  119. waldiez/models/flow/flow.py +11 -6
  120. waldiez/models/flow/flow_data.py +23 -17
  121. waldiez/models/flow/info.py +3 -3
  122. waldiez/models/flow/naming.py +2 -1
  123. waldiez/models/model/_aws.py +11 -13
  124. waldiez/models/model/_llm.py +5 -0
  125. waldiez/models/model/_price.py +2 -4
  126. waldiez/models/model/extra_requirements.py +1 -3
  127. waldiez/models/model/model.py +2 -2
  128. waldiez/models/model/model_data.py +21 -21
  129. waldiez/models/tool/extra_requirements.py +2 -4
  130. waldiez/models/tool/predefined/_duckduckgo.py +1 -0
  131. waldiez/models/tool/predefined/_email.py +1 -0
  132. waldiez/models/tool/predefined/_google.py +1 -0
  133. waldiez/models/tool/predefined/_perplexity.py +1 -0
  134. waldiez/models/tool/predefined/_searxng.py +1 -0
  135. waldiez/models/tool/predefined/_tavily.py +1 -0
  136. waldiez/models/tool/predefined/_wikipedia.py +1 -0
  137. waldiez/models/tool/predefined/_youtube.py +1 -0
  138. waldiez/models/tool/tool.py +8 -5
  139. waldiez/models/tool/tool_data.py +2 -2
  140. waldiez/models/waldiez.py +152 -4
  141. waldiez/runner.py +11 -5
  142. waldiez/running/async_utils.py +192 -0
  143. waldiez/running/base_runner.py +117 -264
  144. waldiez/running/dir_utils.py +52 -0
  145. waldiez/running/environment.py +10 -44
  146. waldiez/running/events_mixin.py +252 -0
  147. waldiez/running/exceptions.py +20 -0
  148. waldiez/running/gen_seq_diagram.py +18 -15
  149. waldiez/running/io_utils.py +216 -0
  150. waldiez/running/protocol.py +11 -5
  151. waldiez/running/requirements_mixin.py +65 -0
  152. waldiez/running/results_mixin.py +926 -0
  153. waldiez/running/standard_runner.py +22 -25
  154. waldiez/running/step_by_step/breakpoints_mixin.py +192 -60
  155. waldiez/running/step_by_step/command_handler.py +3 -0
  156. waldiez/running/step_by_step/events_processor.py +194 -14
  157. waldiez/running/step_by_step/step_by_step_models.py +110 -43
  158. waldiez/running/step_by_step/step_by_step_runner.py +107 -57
  159. waldiez/running/subprocess_runner/__base__.py +9 -1
  160. waldiez/running/subprocess_runner/_async_runner.py +5 -3
  161. waldiez/running/subprocess_runner/_sync_runner.py +6 -2
  162. waldiez/running/subprocess_runner/runner.py +39 -23
  163. waldiez/running/timeline_processor.py +1 -1
  164. waldiez/utils/__init__.py +2 -0
  165. waldiez/utils/conflict_checker.py +4 -4
  166. waldiez/utils/python_manager.py +415 -0
  167. waldiez/ws/_file_handler.py +18 -18
  168. waldiez/ws/_mock.py +2 -1
  169. waldiez/ws/cli.py +36 -12
  170. waldiez/ws/client_manager.py +35 -27
  171. waldiez/ws/errors.py +3 -0
  172. waldiez/ws/models.py +43 -52
  173. waldiez/ws/reloader.py +12 -4
  174. waldiez/ws/server.py +85 -55
  175. waldiez/ws/session_manager.py +8 -9
  176. waldiez/ws/session_stats.py +1 -1
  177. waldiez/ws/utils.py +4 -1
  178. {waldiez-0.6.0.dist-info → waldiez-0.6.1.dist-info}/METADATA +82 -93
  179. waldiez-0.6.1.dist-info/RECORD +254 -0
  180. waldiez/running/post_run.py +0 -186
  181. waldiez/running/pre_run.py +0 -281
  182. waldiez/running/run_results.py +0 -14
  183. waldiez/running/utils.py +0 -625
  184. waldiez-0.6.0.dist-info/RECORD +0 -251
  185. {waldiez-0.6.0.dist-info → waldiez-0.6.1.dist-info}/WHEEL +0 -0
  186. {waldiez-0.6.0.dist-info → waldiez-0.6.1.dist-info}/entry_points.txt +0 -0
  187. {waldiez-0.6.0.dist-info → waldiez-0.6.1.dist-info}/licenses/LICENSE +0 -0
  188. {waldiez-0.6.0.dist-info → waldiez-0.6.1.dist-info}/licenses/NOTICE.md +0 -0
@@ -1,281 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Actions to perform before running the flow."""
4
-
5
- import asyncio
6
- import io
7
- import os
8
- import subprocess
9
- import sys
10
- import tempfile
11
- from pathlib import Path
12
- from typing import Callable
13
-
14
- from waldiez.models import Waldiez
15
-
16
- from .environment import in_virtualenv, is_root
17
- from .utils import (
18
- ensure_pip,
19
- get_pip_install_location,
20
- get_python_executable,
21
- safe_filename,
22
- strip_ansi,
23
- )
24
-
25
-
26
- class RequirementsMixin:
27
- """Mixin class to handle requirements installation."""
28
-
29
- _waldiez: Waldiez
30
- _called_install_requirements: bool
31
-
32
- def gather_requirements(self) -> set[str]:
33
- """Gather extra requirements to install before running the flow.
34
-
35
- Returns
36
- -------
37
- set[str]
38
- A set of requirements that are not already installed and do not
39
- include 'waldiez' in their name.
40
- """
41
- extra_requirements = {
42
- req
43
- for req in self._waldiez.requirements
44
- if req not in sys.modules and "waldiez" not in req
45
- }
46
- if "python-dotenv" not in extra_requirements: # pragma: no branch
47
- extra_requirements.add("python-dotenv")
48
- return extra_requirements
49
-
50
- def install_requirements(self) -> None:
51
- """Install the requirements for the flow."""
52
- if not self._called_install_requirements: # pragma: no branch
53
- self._called_install_requirements = True
54
- extra_requirements = self.gather_requirements()
55
- if extra_requirements: # pragma: no branch
56
- install_requirements(extra_requirements)
57
-
58
- async def a_install_requirements(self) -> None:
59
- """Install the requirements for the flow asynchronously."""
60
- if not self._called_install_requirements: # pragma: no branch
61
- self._called_install_requirements = True
62
- extra_requirements = self.gather_requirements()
63
- if extra_requirements: # pragma: no branch
64
- await a_install_requirements(extra_requirements)
65
-
66
-
67
- # noinspection PyUnresolvedReferences
68
- def install_requirements(
69
- extra_requirements: set[str],
70
- upgrade: bool = False,
71
- printer: Callable[..., None] = print,
72
- ) -> None:
73
- """Install the requirements.
74
-
75
- Parameters
76
- ----------
77
- extra_requirements : set[str]
78
- The extra requirements.
79
- upgrade : bool, optional
80
- Whether to upgrade the requirements, by default False.
81
- printer : Callable[..., None]
82
- The printer function to use, defaults to print.
83
- """
84
- requirements_string = ", ".join(extra_requirements)
85
- printer(f"Installing requirements: {requirements_string}")
86
- ensure_pip()
87
- pip_install, break_system_packages, install_location = _before_pip(
88
- extra_requirements, upgrade
89
- )
90
-
91
- # pylint: disable=too-many-try-statements,broad-exception-caught
92
- try:
93
- with subprocess.Popen(
94
- pip_install,
95
- stdout=subprocess.PIPE,
96
- stderr=subprocess.PIPE,
97
- ) as proc:
98
- if proc.stdout: # pragma: no branch
99
- for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
100
- stripped_line = strip_ansi(line.strip())
101
- if stripped_line: # Only print non-empty lines
102
- printer(stripped_line)
103
- if proc.stderr: # pragma: no branch
104
- for line in io.TextIOWrapper(proc.stderr, encoding="utf-8"):
105
- stripped_line = strip_ansi(line.strip())
106
- if stripped_line: # Only print non-empty lines
107
- printer(stripped_line)
108
-
109
- # Wait for process to complete and check return code
110
- return_code = proc.wait()
111
- if return_code != 0:
112
- printer(
113
- f"Package installation failed with exit code {return_code}"
114
- )
115
-
116
- except Exception as e:
117
- printer(f"Failed to install requirements: {e}")
118
- finally:
119
- _after_pip(break_system_packages, install_location)
120
-
121
-
122
- async def a_install_requirements(
123
- extra_requirements: set[str],
124
- upgrade: bool = False,
125
- printer: Callable[..., None] = print,
126
- ) -> None:
127
- """Install the requirements asynchronously.
128
-
129
- Parameters
130
- ----------
131
- extra_requirements : set[str]
132
- The extra requirements.
133
- upgrade : bool, optional
134
- Whether to upgrade the requirements, by default False.
135
- printer : Callable[..., None]
136
- The printer function to use, defaults to print.
137
- """
138
- pip_install, break_system_packages, install_location = _before_pip(
139
- extra_requirements, upgrade=upgrade
140
- )
141
- requirements_string = ", ".join(extra_requirements)
142
- printer(f"Installing requirements: {requirements_string}")
143
- # pylint: disable=too-many-try-statements,broad-exception-caught
144
- try:
145
- proc = await asyncio.create_subprocess_exec(
146
- *pip_install,
147
- stdout=asyncio.subprocess.PIPE,
148
- stderr=asyncio.subprocess.PIPE,
149
- )
150
-
151
- async def _pump_stream(stream: asyncio.StreamReader | None) -> None:
152
- if not stream:
153
- return
154
- async for raw in stream:
155
- text = strip_ansi(raw.decode().rstrip())
156
- if text:
157
- printer(text)
158
-
159
- # Create tasks for concurrent execution
160
- tasks: list[asyncio.Task[int | None]] = [
161
- asyncio.create_task(_pump_stream(proc.stdout)),
162
- asyncio.create_task(_pump_stream(proc.stderr)),
163
- asyncio.create_task(proc.wait()),
164
- ]
165
- await asyncio.gather(*tasks, return_exceptions=True)
166
- if proc.returncode != 0:
167
- printer(
168
- f"Package installation failed with exit code {proc.returncode}"
169
- )
170
-
171
- except Exception as e:
172
- printer(f"Failed to install requirements: {e}")
173
- finally:
174
- _after_pip(break_system_packages, install_location)
175
-
176
-
177
- def _before_pip(
178
- packages: set[str],
179
- upgrade: bool,
180
- ) -> tuple[list[str], str, str | None]:
181
- """Gather the pip command for installing requirements.
182
-
183
- Parameters
184
- ----------
185
- packages : set[str]
186
- The packages to install.
187
- upgrade : bool
188
- Whether to upgrade the packages.
189
-
190
- Returns
191
- -------
192
- tuple[list[str], str, str | None]
193
- The pip command, break_system_packages flag, and install location.
194
- """
195
- ensure_pip()
196
- pip_install = [
197
- get_python_executable(),
198
- "-m",
199
- "pip",
200
- "install",
201
- "--disable-pip-version-check",
202
- "--no-input",
203
- ]
204
- install_location = get_pip_install_location()
205
- break_system_packages = ""
206
-
207
- if install_location:
208
- pip_install += ["--target", install_location]
209
- elif not in_virtualenv(): # it should # pragma: no cover
210
- # if not, let's try to install as user
211
- # not sure if --break-system-packages is safe,
212
- # but it might fail if we don't
213
- break_system_packages = os.environ.get("PIP_BREAK_SYSTEM_PACKAGES", "")
214
- os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = "1"
215
- if not is_root():
216
- pip_install.append("--user")
217
-
218
- if upgrade: # pragma: no cover
219
- pip_install.append("--upgrade")
220
-
221
- pip_install.extend(packages)
222
- return pip_install, break_system_packages, install_location
223
-
224
-
225
- def _after_pip(
226
- break_system_packages: str, install_location: str | None
227
- ) -> None:
228
- """Restore environment variables after pip installation.
229
-
230
- Parameters
231
- ----------
232
- break_system_packages : str
233
- The original value of PIP_BREAK_SYSTEM_PACKAGES.
234
- install_location : str | None
235
- The install location used (None if default).
236
- """
237
- if install_location is None and not in_virtualenv(): # pragma: no cover
238
- # restore the old env var
239
- if break_system_packages:
240
- os.environ["PIP_BREAK_SYSTEM_PACKAGES"] = break_system_packages
241
- else:
242
- # Use pop to avoid KeyError if the key doesn't exist
243
- os.environ.pop("PIP_BREAK_SYSTEM_PACKAGES", None)
244
-
245
-
246
- def dump_waldiez(waldiez: Waldiez, output_path: str | Path | None) -> Path:
247
- """Dump waldiez flow to a file.
248
-
249
- Parameters
250
- ----------
251
- waldiez : Waldiez
252
- The waldiez instance to dump.
253
- output_path : str | Path | None
254
- Optional output path to determine the directory to save the flow to.
255
-
256
- Returns
257
- -------
258
- Path
259
- The path to the generated file.
260
- """
261
- file_path = Path(output_path) if output_path else None
262
- if file_path:
263
- file_name = file_path.name
264
- if not file_name.endswith(".waldiez"):
265
- file_path.with_suffix(".waldiez")
266
-
267
- else:
268
- full_name = waldiez.name
269
- file_name = safe_filename(full_name, "waldiez")
270
- file_dir: Path
271
- if file_path:
272
- file_dir = file_path if file_path.is_dir() else file_path.parent
273
- else:
274
- file_dir = Path(tempfile.mkdtemp())
275
- file_dir.mkdir(parents=True, exist_ok=True)
276
- output_path = file_dir / file_name
277
- with output_path.open(
278
- "w", encoding="utf-8", errors="replace", newline="\n"
279
- ) as f_open:
280
- f_open.write(waldiez.model_dump_json())
281
- return output_path
@@ -1,14 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
-
4
- """Waldiez run results module."""
5
-
6
- from typing import Any, TypedDict
7
-
8
-
9
- class WaldiezRunResults(TypedDict):
10
- """Results of the Waldiez run."""
11
-
12
- results: list[dict[str, Any]]
13
- exception: BaseException | None
14
- completed: bool