waldiez 0.4.8__py3-none-any.whl → 0.4.11__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 +1 -2
- waldiez/_version.py +1 -1
- waldiez/cli.py +90 -96
- waldiez/exporter.py +64 -9
- waldiez/exporting/agent/extras/rag/chroma_extras.py +21 -9
- waldiez/exporting/core/context.py +12 -0
- waldiez/exporting/core/extras/flow_extras.py +2 -14
- waldiez/exporting/core/types.py +21 -0
- waldiez/exporting/flow/exporter.py +4 -0
- waldiez/exporting/flow/factory.py +16 -0
- waldiez/exporting/flow/orchestrator.py +12 -0
- waldiez/exporting/flow/utils/__init__.py +2 -0
- waldiez/exporting/flow/utils/common.py +96 -2
- waldiez/exporting/flow/utils/logging.py +5 -6
- waldiez/io/mqtt.py +7 -3
- waldiez/io/structured.py +26 -2
- waldiez/models/common/method_utils.py +1 -1
- waldiez/models/tool/tool.py +2 -1
- waldiez/runner.py +402 -332
- waldiez/running/__init__.py +6 -28
- waldiez/running/base_runner.py +907 -0
- waldiez/running/environment.py +74 -0
- waldiez/running/import_runner.py +424 -0
- waldiez/running/patch_io_stream.py +208 -0
- waldiez/running/post_run.py +121 -0
- waldiez/running/pre_run.py +105 -0
- waldiez/running/protocol.py +281 -0
- waldiez/running/run_results.py +22 -0
- waldiez/running/subprocess_runner.py +100 -0
- waldiez/running/utils.py +134 -0
- waldiez/utils/__init__.py +2 -2
- waldiez/utils/version.py +49 -0
- {waldiez-0.4.8.dist-info → waldiez-0.4.11.dist-info}/METADATA +11 -11
- {waldiez-0.4.8.dist-info → waldiez-0.4.11.dist-info}/RECORD +38 -30
- waldiez/running/running.py +0 -388
- waldiez/utils/flaml_warnings.py +0 -17
- {waldiez-0.4.8.dist-info → waldiez-0.4.11.dist-info}/WHEEL +0 -0
- {waldiez-0.4.8.dist-info → waldiez-0.4.11.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.8.dist-info → waldiez-0.4.11.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.8.dist-info → waldiez-0.4.11.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
|
|
4
|
+
"""Waldiez Runner protocol."""
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import TYPE_CHECKING, Protocol, Union, runtime_checkable
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from autogen import ChatResult # type: ignore[import-untyped]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@runtime_checkable
|
|
14
|
+
class WaldiezRunnerProtocol(Protocol):
|
|
15
|
+
"""Waldiez Runner protocol."""
|
|
16
|
+
|
|
17
|
+
def before_run(
|
|
18
|
+
self,
|
|
19
|
+
output_file: Path,
|
|
20
|
+
uploads_root: Path | None,
|
|
21
|
+
) -> Path: # pyright: ignore
|
|
22
|
+
"""Actions to perform before running the flow.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
output_file : Path
|
|
27
|
+
The output file.
|
|
28
|
+
uploads_root : Path | None
|
|
29
|
+
The runtime uploads root.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
Path
|
|
34
|
+
The path to the temporary directory created for the run.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
async def a_before_run(
|
|
38
|
+
self,
|
|
39
|
+
output_file: Path,
|
|
40
|
+
uploads_root: Path | None,
|
|
41
|
+
) -> Path: # pyright: ignore
|
|
42
|
+
"""Asynchronously perform actions before running the flow.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
output_file : Path
|
|
47
|
+
The output file.
|
|
48
|
+
uploads_root : Path | None
|
|
49
|
+
The runtime uploads root.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
Path
|
|
54
|
+
The path to the temporary directory created for the run.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def start(
|
|
58
|
+
self,
|
|
59
|
+
output_path: str | Path | None,
|
|
60
|
+
uploads_root: str | Path | None,
|
|
61
|
+
structured_io: bool | None = None,
|
|
62
|
+
skip_patch_io: bool | None = None,
|
|
63
|
+
skip_mmd: bool = False,
|
|
64
|
+
) -> None:
|
|
65
|
+
"""Start running the Waldiez flow in a non-blocking way.
|
|
66
|
+
|
|
67
|
+
To allow "stoping" it later.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
output_path : str | Path | None
|
|
72
|
+
The output path.
|
|
73
|
+
uploads_root : str | Path | None
|
|
74
|
+
The runtime uploads root.
|
|
75
|
+
structured_io : bool
|
|
76
|
+
Whether to use structured IO instead of the default 'input/print'.
|
|
77
|
+
skip_patch_io : bool | None
|
|
78
|
+
Whether to skip patching I/O, by default None.
|
|
79
|
+
If None, it will use the value from the context.
|
|
80
|
+
skip_mmd : bool
|
|
81
|
+
Whether to skip generating the mermaid diagram.
|
|
82
|
+
|
|
83
|
+
Raises
|
|
84
|
+
------
|
|
85
|
+
RuntimeError
|
|
86
|
+
If the runner is already running.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
async def a_start(
|
|
90
|
+
self,
|
|
91
|
+
output_path: str | Path | None,
|
|
92
|
+
uploads_root: str | Path | None,
|
|
93
|
+
structured_io: bool | None = None,
|
|
94
|
+
skip_patch_io: bool | None = None,
|
|
95
|
+
skip_mmd: bool = False,
|
|
96
|
+
) -> None:
|
|
97
|
+
"""Asynchronously start running the Waldiez flow in a non-blocking way.
|
|
98
|
+
|
|
99
|
+
To allow "stoping" it later.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
output_path : str | Path | None
|
|
104
|
+
The output path.
|
|
105
|
+
uploads_root : str | Path | None
|
|
106
|
+
The runtime uploads root.
|
|
107
|
+
structured_io : bool
|
|
108
|
+
Whether to use structured IO instead of the default 'input/print'.
|
|
109
|
+
skip_patch_io : bool | None
|
|
110
|
+
Whether to skip patching I/O, by default None.
|
|
111
|
+
If None, it will use the value from the context.
|
|
112
|
+
skip_mmd : bool
|
|
113
|
+
Whether to skip generating the mermaid diagram.
|
|
114
|
+
|
|
115
|
+
Raises
|
|
116
|
+
------
|
|
117
|
+
RuntimeError
|
|
118
|
+
If the runner is already running.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
def run(
|
|
122
|
+
self,
|
|
123
|
+
output_path: str | Path | None,
|
|
124
|
+
uploads_root: str | Path | None,
|
|
125
|
+
structured_io: bool | None = None,
|
|
126
|
+
threaded: bool | None = None,
|
|
127
|
+
skip_patch_io: bool | None = None,
|
|
128
|
+
skip_mmd: bool = False,
|
|
129
|
+
) -> Union[
|
|
130
|
+
"ChatResult",
|
|
131
|
+
list["ChatResult"],
|
|
132
|
+
dict[int, "ChatResult"],
|
|
133
|
+
]: # pyright: ignore
|
|
134
|
+
"""Run the Waldiez flow in a blocking way.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
output_path : str | Path | None
|
|
139
|
+
The output path, by default None.
|
|
140
|
+
uploads_root : str | Path | None
|
|
141
|
+
The runtime uploads root.
|
|
142
|
+
structured_io : bool
|
|
143
|
+
Whether to use structured IO instead of the default 'input/print'.
|
|
144
|
+
threaded : bool | None
|
|
145
|
+
Whether to run the flow in a separate thread.
|
|
146
|
+
skip_patch_io : bool
|
|
147
|
+
Whether to skip patching I/O, by default None.
|
|
148
|
+
If None, it will use the value from the context.
|
|
149
|
+
skip_mmd : bool
|
|
150
|
+
Whether to skip generating the mermaid diagram.
|
|
151
|
+
|
|
152
|
+
Returns
|
|
153
|
+
-------
|
|
154
|
+
Union[ChatResult, list[ChatResult], dict[int, ChatResult]]
|
|
155
|
+
The result of the run, which can be a single ChatResult,
|
|
156
|
+
a list of ChatResults,
|
|
157
|
+
or a dictionary mapping indices to ChatResults.
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
async def a_run(
|
|
161
|
+
self,
|
|
162
|
+
output_path: str | Path | None,
|
|
163
|
+
uploads_root: str | Path | None,
|
|
164
|
+
structured_io: bool | None = None,
|
|
165
|
+
skip_patch_io: bool | None = None,
|
|
166
|
+
skip_mmd: bool = False,
|
|
167
|
+
) -> Union[
|
|
168
|
+
"ChatResult",
|
|
169
|
+
list["ChatResult"],
|
|
170
|
+
dict[int, "ChatResult"],
|
|
171
|
+
]: # pyright: ignore
|
|
172
|
+
"""Run the Waldiez flow.
|
|
173
|
+
|
|
174
|
+
Parameters
|
|
175
|
+
----------
|
|
176
|
+
output_path : str | Path | None
|
|
177
|
+
The output path, by default None.
|
|
178
|
+
uploads_root : str | Path | None
|
|
179
|
+
The runtime uploads root.
|
|
180
|
+
structured_io : bool
|
|
181
|
+
Whether to use structured IO instead of the default 'input/print'.
|
|
182
|
+
skip_patch_io : bool
|
|
183
|
+
Whether to skip patching I/O, by default None.
|
|
184
|
+
If None, it will use the value from the context.
|
|
185
|
+
skip_mmd : bool
|
|
186
|
+
Whether to skip generating the mermaid diagram.
|
|
187
|
+
|
|
188
|
+
Returns
|
|
189
|
+
-------
|
|
190
|
+
Union[ChatResult, list[ChatResult], dict[int, ChatResult]]
|
|
191
|
+
The result of the run, which can be a single ChatResult,
|
|
192
|
+
a list of ChatResults,
|
|
193
|
+
or a dictionary mapping indices to ChatResults.
|
|
194
|
+
"""
|
|
195
|
+
|
|
196
|
+
def after_run(
|
|
197
|
+
self,
|
|
198
|
+
results: Union[
|
|
199
|
+
"ChatResult",
|
|
200
|
+
list["ChatResult"],
|
|
201
|
+
dict[int, "ChatResult"],
|
|
202
|
+
],
|
|
203
|
+
output_file: Path,
|
|
204
|
+
uploads_root: Path | None,
|
|
205
|
+
temp_dir: Path,
|
|
206
|
+
skip_mmd: bool,
|
|
207
|
+
) -> None:
|
|
208
|
+
"""Actions to perform after running the flow.
|
|
209
|
+
|
|
210
|
+
Parameters
|
|
211
|
+
----------
|
|
212
|
+
results : Union[ChatResult, list[ChatResult], dict[int, ChatResult]]
|
|
213
|
+
The results of the run, which can be a single ChatResult,
|
|
214
|
+
a list of ChatResults,
|
|
215
|
+
or a dictionary mapping indices to ChatResults.
|
|
216
|
+
output_file : Path
|
|
217
|
+
The path to the output file.
|
|
218
|
+
uploads_root : Path | None
|
|
219
|
+
The runtime uploads root.
|
|
220
|
+
temp_dir : Path
|
|
221
|
+
The path to the temporary directory.
|
|
222
|
+
skip_mmd : bool
|
|
223
|
+
Whether to skip generating the mermaid diagram.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
async def a_after_run(
|
|
227
|
+
self,
|
|
228
|
+
results: Union[
|
|
229
|
+
"ChatResult",
|
|
230
|
+
list["ChatResult"],
|
|
231
|
+
dict[int, "ChatResult"],
|
|
232
|
+
],
|
|
233
|
+
output_file: Path,
|
|
234
|
+
uploads_root: Path | None,
|
|
235
|
+
temp_dir: Path,
|
|
236
|
+
skip_mmd: bool,
|
|
237
|
+
) -> None:
|
|
238
|
+
"""Asynchronously perform actions after running the flow.
|
|
239
|
+
|
|
240
|
+
Parameters
|
|
241
|
+
----------
|
|
242
|
+
results : Union[ChatResult, list[ChatResult], dict[int, ChatResult]]
|
|
243
|
+
The results of the run, which can be a single ChatResult,
|
|
244
|
+
a list of ChatResults,
|
|
245
|
+
or a dictionary mapping indices to ChatResults.
|
|
246
|
+
output_file : Path
|
|
247
|
+
The path to the output file.
|
|
248
|
+
uploads_root : Path | None
|
|
249
|
+
The runtime uploads root.
|
|
250
|
+
temp_dir : Path
|
|
251
|
+
The path to the temporary directory.
|
|
252
|
+
skip_mmd : bool
|
|
253
|
+
Whether to skip generating the mermaid diagram.
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
def is_running(self) -> bool: # pyright: ignore
|
|
257
|
+
"""Check if the runner is currently running.
|
|
258
|
+
|
|
259
|
+
Returns
|
|
260
|
+
-------
|
|
261
|
+
bool
|
|
262
|
+
True if the runner is running, False otherwise.
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
def stop(self) -> None:
|
|
266
|
+
"""Stop the runner if it is running.
|
|
267
|
+
|
|
268
|
+
Raises
|
|
269
|
+
------
|
|
270
|
+
RuntimeError
|
|
271
|
+
If the runner is not running.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
async def a_stop(self) -> None:
|
|
275
|
+
"""Asynchronously stop the runner if it is running.
|
|
276
|
+
|
|
277
|
+
Raises
|
|
278
|
+
------
|
|
279
|
+
RuntimeError
|
|
280
|
+
If the runner is not running.
|
|
281
|
+
"""
|
|
@@ -0,0 +1,22 @@
|
|
|
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 TYPE_CHECKING, TypedDict, Union
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from autogen import ChatResult # type: ignore[import-untyped]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WaldiezRunResults(TypedDict):
|
|
13
|
+
"""Results of the Waldiez run."""
|
|
14
|
+
|
|
15
|
+
results: Union[
|
|
16
|
+
"ChatResult",
|
|
17
|
+
list["ChatResult"],
|
|
18
|
+
dict[int, "ChatResult"],
|
|
19
|
+
None,
|
|
20
|
+
]
|
|
21
|
+
exception: Exception | None
|
|
22
|
+
completed: bool
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Run a waldiez flow.
|
|
4
|
+
|
|
5
|
+
The flow is first converted to an autogen flow with agents, chats, and tools.
|
|
6
|
+
We then chown to temporary directory, call the flow's `main()` and
|
|
7
|
+
return the results. Before running the flow, any additional environment
|
|
8
|
+
variables specified in the waldiez file are set.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import TYPE_CHECKING, Union
|
|
13
|
+
|
|
14
|
+
from waldiez.models.waldiez import Waldiez
|
|
15
|
+
|
|
16
|
+
from .base_runner import WaldiezBaseRunner
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from autogen import ChatResult # type: ignore[import-untyped]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class WaldiezSubprocessRunner(WaldiezBaseRunner):
|
|
23
|
+
"""Waldiez runner class."""
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
waldiez: Waldiez,
|
|
28
|
+
output_path: str | Path | None = None,
|
|
29
|
+
uploads_root: str | Path | None = None,
|
|
30
|
+
structured_io: bool = True,
|
|
31
|
+
isolated: bool = True,
|
|
32
|
+
threaded: bool = False,
|
|
33
|
+
skip_patch_io: bool = True,
|
|
34
|
+
) -> None:
|
|
35
|
+
"""Initialize the Waldiez manager."""
|
|
36
|
+
super().__init__(
|
|
37
|
+
waldiez,
|
|
38
|
+
output_path=output_path,
|
|
39
|
+
uploads_root=uploads_root,
|
|
40
|
+
structured_io=structured_io,
|
|
41
|
+
isolated=isolated,
|
|
42
|
+
threaded=threaded,
|
|
43
|
+
skip_patch_io=skip_patch_io,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def _run(
|
|
47
|
+
self,
|
|
48
|
+
temp_dir: Path,
|
|
49
|
+
output_file: Path,
|
|
50
|
+
uploads_root: Path | None,
|
|
51
|
+
skip_mmd: bool,
|
|
52
|
+
) -> Union[
|
|
53
|
+
"ChatResult",
|
|
54
|
+
list["ChatResult"],
|
|
55
|
+
dict[int, "ChatResult"],
|
|
56
|
+
]:
|
|
57
|
+
"""Run the Waldiez workflow."""
|
|
58
|
+
return []
|
|
59
|
+
|
|
60
|
+
async def _a_run(
|
|
61
|
+
self,
|
|
62
|
+
temp_dir: Path,
|
|
63
|
+
output_file: Path,
|
|
64
|
+
uploads_root: Path | None,
|
|
65
|
+
skip_mmd: bool,
|
|
66
|
+
) -> Union[
|
|
67
|
+
"ChatResult",
|
|
68
|
+
list["ChatResult"],
|
|
69
|
+
dict[int, "ChatResult"],
|
|
70
|
+
]:
|
|
71
|
+
"""Run the Waldiez workflow asynchronously."""
|
|
72
|
+
return []
|
|
73
|
+
|
|
74
|
+
def _start(
|
|
75
|
+
self,
|
|
76
|
+
temp_dir: Path,
|
|
77
|
+
output_file: Path,
|
|
78
|
+
uploads_root: Path | None,
|
|
79
|
+
skip_mmd: bool,
|
|
80
|
+
) -> None:
|
|
81
|
+
"""Start the Waldiez workflow."""
|
|
82
|
+
# This method should be implemented to start the workflow
|
|
83
|
+
# For now, it is a placeholder
|
|
84
|
+
|
|
85
|
+
async def _a_start(
|
|
86
|
+
self,
|
|
87
|
+
temp_dir: Path,
|
|
88
|
+
output_file: Path,
|
|
89
|
+
uploads_root: Path | None,
|
|
90
|
+
skip_mmd: bool,
|
|
91
|
+
) -> None:
|
|
92
|
+
"""Start the Waldiez workflow asynchronously."""
|
|
93
|
+
# This method should be implemented to start the workflow asynchronously
|
|
94
|
+
# For now, it is a placeholder
|
|
95
|
+
|
|
96
|
+
def _stop(self) -> None:
|
|
97
|
+
"""Stop the Waldiez workflow."""
|
|
98
|
+
|
|
99
|
+
async def _a_stop(self) -> None:
|
|
100
|
+
"""Stop the Waldiez workflow asynchronously."""
|
waldiez/running/utils.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Common utilities for the waldiez runner."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
from asyncio.subprocess import Process
|
|
11
|
+
from contextlib import asynccontextmanager, contextmanager
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import AsyncIterator, Iterator, Union
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ProcessSetup:
|
|
19
|
+
"""Container for subprocess setup data."""
|
|
20
|
+
|
|
21
|
+
temp_dir: Path
|
|
22
|
+
file_path: Path
|
|
23
|
+
old_vars: dict[str, str]
|
|
24
|
+
skip_mmd: bool
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@contextmanager
|
|
28
|
+
def chdir(to: Union[str, Path]) -> Iterator[None]:
|
|
29
|
+
"""Change the current working directory in a context.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
to : Union[str, Path]
|
|
34
|
+
The directory to change to.
|
|
35
|
+
|
|
36
|
+
Yields
|
|
37
|
+
------
|
|
38
|
+
Iterator[None]
|
|
39
|
+
The context manager.
|
|
40
|
+
"""
|
|
41
|
+
old_cwd = str(os.getcwd())
|
|
42
|
+
os.chdir(to)
|
|
43
|
+
try:
|
|
44
|
+
yield
|
|
45
|
+
finally:
|
|
46
|
+
os.chdir(old_cwd)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@asynccontextmanager
|
|
50
|
+
async def a_chdir(to: Union[str, Path]) -> AsyncIterator[None]:
|
|
51
|
+
"""Asynchronously change the current working directory in a context.
|
|
52
|
+
|
|
53
|
+
Parameters
|
|
54
|
+
----------
|
|
55
|
+
to : Union[str, Path]
|
|
56
|
+
The directory to change to.
|
|
57
|
+
|
|
58
|
+
Yields
|
|
59
|
+
------
|
|
60
|
+
AsyncIterator[None]
|
|
61
|
+
The async context manager.
|
|
62
|
+
"""
|
|
63
|
+
old_cwd = str(os.getcwd())
|
|
64
|
+
os.chdir(to)
|
|
65
|
+
try:
|
|
66
|
+
yield
|
|
67
|
+
finally:
|
|
68
|
+
os.chdir(old_cwd)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def strip_ansi(text: str) -> str:
|
|
72
|
+
"""Remove ANSI escape sequences from text.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
text : str
|
|
77
|
+
The text to strip.
|
|
78
|
+
|
|
79
|
+
Returns
|
|
80
|
+
-------
|
|
81
|
+
str
|
|
82
|
+
The text without ANSI escape sequences.
|
|
83
|
+
"""
|
|
84
|
+
ansi_pattern = re.compile(r"\x1b\[[0-9;]*m|\x1b\[.*?[@-~]")
|
|
85
|
+
return ansi_pattern.sub("", text)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def create_sync_subprocess(setup: ProcessSetup) -> subprocess.Popen[bytes]:
|
|
89
|
+
"""Create a synchronous subprocess.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
setup : ProcessSetup
|
|
94
|
+
The setup data for the subprocess.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
subprocess.Popen[bytes]
|
|
99
|
+
The created subprocess.
|
|
100
|
+
"""
|
|
101
|
+
return subprocess.Popen(
|
|
102
|
+
[sys.executable, "-u", str(setup.file_path)],
|
|
103
|
+
stdout=subprocess.PIPE,
|
|
104
|
+
stderr=subprocess.PIPE,
|
|
105
|
+
stdin=subprocess.PIPE,
|
|
106
|
+
# text=True,
|
|
107
|
+
# bufsize=1, # Line buffered for real-time output
|
|
108
|
+
# universal_newlines=True,
|
|
109
|
+
env={**os.environ},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
async def create_async_subprocess(setup: ProcessSetup) -> Process:
|
|
114
|
+
"""Create an asynchronous subprocess.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
setup : ProcessSetup
|
|
119
|
+
The setup data for the subprocess.
|
|
120
|
+
|
|
121
|
+
Returns
|
|
122
|
+
-------
|
|
123
|
+
Process
|
|
124
|
+
The created asynchronous subprocess.
|
|
125
|
+
"""
|
|
126
|
+
return await asyncio.create_subprocess_exec(
|
|
127
|
+
sys.executable,
|
|
128
|
+
"-u",
|
|
129
|
+
str(setup.file_path),
|
|
130
|
+
# stdout=asyncio.subprocess.PIPE,
|
|
131
|
+
# stderr=asyncio.subprocess.PIPE,
|
|
132
|
+
# stdin=asyncio.subprocess.PIPE,
|
|
133
|
+
env={**os.environ},
|
|
134
|
+
)
|
waldiez/utils/__init__.py
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
from .cli_extras import add_cli_extras
|
|
6
6
|
from .conflict_checker import check_conflicts
|
|
7
|
-
from .
|
|
7
|
+
from .version import get_waldiez_version
|
|
8
8
|
|
|
9
9
|
__all__ = [
|
|
10
10
|
"check_conflicts",
|
|
11
|
-
"check_flaml_warnings",
|
|
12
11
|
"add_cli_extras",
|
|
12
|
+
"get_waldiez_version",
|
|
13
13
|
]
|
waldiez/utils/version.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Try to get the Waldiez version."""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from functools import cache
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _get_waldiez_version_from_package_json() -> str | None:
|
|
11
|
+
"""Get the Waldiez version from package.json."""
|
|
12
|
+
package_json_path = Path(__file__).parent.parent.parent / "package.json"
|
|
13
|
+
if package_json_path.exists():
|
|
14
|
+
with open(package_json_path, "r", encoding="utf-8") as f:
|
|
15
|
+
package_data = json.load(f)
|
|
16
|
+
return package_data.get("version", None)
|
|
17
|
+
return None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _get_waldiez_version_from_version_py() -> str | None:
|
|
21
|
+
"""Get the Waldiez version from _version.py."""
|
|
22
|
+
version_py_path = Path(__file__).parent.parent / "_version.py"
|
|
23
|
+
if version_py_path.exists():
|
|
24
|
+
with open(version_py_path, "r", encoding="utf-8") as f:
|
|
25
|
+
for line in f:
|
|
26
|
+
if line.startswith("__version__"):
|
|
27
|
+
return line.split('"')[1]
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@cache
|
|
32
|
+
def get_waldiez_version() -> str:
|
|
33
|
+
"""Get the Waldiez version.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
str
|
|
38
|
+
The Waldiez version, or "dev" if not found.
|
|
39
|
+
"""
|
|
40
|
+
w_version = _get_waldiez_version_from_version_py()
|
|
41
|
+
if not w_version:
|
|
42
|
+
w_version = _get_waldiez_version_from_package_json()
|
|
43
|
+
if not w_version:
|
|
44
|
+
w_version = "dev"
|
|
45
|
+
return w_version
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
print(get_waldiez_version())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: waldiez
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.11
|
|
4
4
|
Dynamic: Keywords
|
|
5
5
|
Summary: Make AG2 Agents Collaborate: Drag, Drop, and Orchestrate with Waldiez.
|
|
6
6
|
Project-URL: Homepage, https://waldiez.io
|
|
@@ -33,7 +33,7 @@ Requires-Dist: aiofiles==24.1.0
|
|
|
33
33
|
Requires-Dist: aiosqlite==0.21.0
|
|
34
34
|
Requires-Dist: asyncer==0.0.8
|
|
35
35
|
Requires-Dist: click<8.2
|
|
36
|
-
Requires-Dist: graphviz<=0.
|
|
36
|
+
Requires-Dist: graphviz<=0.21
|
|
37
37
|
Requires-Dist: httpx<1
|
|
38
38
|
Requires-Dist: jupytext
|
|
39
39
|
Requires-Dist: nest-asyncio==1.6.0
|
|
@@ -80,7 +80,7 @@ Requires-Dist: ipython; extra == 'ag2-extras'
|
|
|
80
80
|
Requires-Dist: langchain-community<1,>=0.3.12; extra == 'ag2-extras'
|
|
81
81
|
Requires-Dist: litellm; extra == 'ag2-extras'
|
|
82
82
|
Requires-Dist: markdownify; extra == 'ag2-extras'
|
|
83
|
-
Requires-Dist: mcp<
|
|
83
|
+
Requires-Dist: mcp<2,>=1.4.0; extra == 'ag2-extras'
|
|
84
84
|
Requires-Dist: mistralai>=1.8.1; extra == 'ag2-extras'
|
|
85
85
|
Requires-Dist: networkx; (python_version < '3.11') and extra == 'ag2-extras'
|
|
86
86
|
Requires-Dist: networkx>=3.5; (python_version >= '3.11') and extra == 'ag2-extras'
|
|
@@ -106,10 +106,10 @@ Provides-Extra: dev
|
|
|
106
106
|
Requires-Dist: ag2[redis]==0.9.2; extra == 'dev'
|
|
107
107
|
Requires-Dist: ag2[websockets]==0.9.2; extra == 'dev'
|
|
108
108
|
Requires-Dist: autoflake==2.3.1; extra == 'dev'
|
|
109
|
-
Requires-Dist: bandit==1.8.
|
|
109
|
+
Requires-Dist: bandit==1.8.5; extra == 'dev'
|
|
110
110
|
Requires-Dist: black[jupyter]==25.1.0; extra == 'dev'
|
|
111
111
|
Requires-Dist: build==1.2.2.post1; extra == 'dev'
|
|
112
|
-
Requires-Dist: fakeredis
|
|
112
|
+
Requires-Dist: fakeredis<=3.30.0,>=2.28.1; extra == 'dev'
|
|
113
113
|
Requires-Dist: fastjsonschema>=2.21; extra == 'dev'
|
|
114
114
|
Requires-Dist: flake8==7.2.0; extra == 'dev'
|
|
115
115
|
Requires-Dist: hatchling==1.27.0; extra == 'dev'
|
|
@@ -117,7 +117,7 @@ Requires-Dist: jsonschema==4.24.0; extra == 'dev'
|
|
|
117
117
|
Requires-Dist: jupyter-server==2.16.0; extra == 'dev'
|
|
118
118
|
Requires-Dist: jupyterlab<5.0,>=4.4.0; extra == 'dev'
|
|
119
119
|
Requires-Dist: mypy-extensions>=1.1.0; extra == 'dev'
|
|
120
|
-
Requires-Dist: mypy==1.16.
|
|
120
|
+
Requires-Dist: mypy==1.16.1; extra == 'dev'
|
|
121
121
|
Requires-Dist: nbclient>=0.10.2; extra == 'dev'
|
|
122
122
|
Requires-Dist: nbconvert>=7.16.6; extra == 'dev'
|
|
123
123
|
Requires-Dist: nbformat>=5.10.4; extra == 'dev'
|
|
@@ -134,7 +134,7 @@ Requires-Dist: toml==0.10.2; (python_version <= '3.10') and extra == 'dev'
|
|
|
134
134
|
Requires-Dist: types-jsonschema==4.24.0.20250528; extra == 'dev'
|
|
135
135
|
Requires-Dist: types-pyyaml==6.0.12.20250516; extra == 'dev'
|
|
136
136
|
Requires-Dist: types-redis==4.6.0.20241004; extra == 'dev'
|
|
137
|
-
Requires-Dist: types-requests==2.32.
|
|
137
|
+
Requires-Dist: types-requests==2.32.4.20250611; extra == 'dev'
|
|
138
138
|
Requires-Dist: types-toml==0.10.8.20240310; extra == 'dev'
|
|
139
139
|
Requires-Dist: watchdog==6.0.0; extra == 'dev'
|
|
140
140
|
Requires-Dist: yamllint==1.37.1; extra == 'dev'
|
|
@@ -157,19 +157,19 @@ Requires-Dist: natsort==8.4.0; extra == 'docs'
|
|
|
157
157
|
Provides-Extra: jupyter
|
|
158
158
|
Requires-Dist: jupyter-server==2.16.0; extra == 'jupyter'
|
|
159
159
|
Requires-Dist: jupyterlab<5.0,>=4.3.0; extra == 'jupyter'
|
|
160
|
-
Requires-Dist: waldiez-jupyter==0.4.
|
|
160
|
+
Requires-Dist: waldiez-jupyter==0.4.11; extra == 'jupyter'
|
|
161
161
|
Provides-Extra: mqtt
|
|
162
162
|
Requires-Dist: paho-mqtt<3.0,>=2.1.0; extra == 'mqtt'
|
|
163
163
|
Provides-Extra: redis
|
|
164
164
|
Requires-Dist: ag2[redis]==0.9.2; extra == 'redis'
|
|
165
165
|
Provides-Extra: runner
|
|
166
|
-
Requires-Dist: waldiez-runner==0.4.
|
|
166
|
+
Requires-Dist: waldiez-runner==0.4.11; (python_version >= '3.11') and extra == 'runner'
|
|
167
167
|
Provides-Extra: studio
|
|
168
|
-
Requires-Dist: waldiez-studio==0.4.
|
|
168
|
+
Requires-Dist: waldiez-studio==0.4.11; extra == 'studio'
|
|
169
169
|
Provides-Extra: test
|
|
170
170
|
Requires-Dist: ag2[redis]==0.9.2; extra == 'test'
|
|
171
171
|
Requires-Dist: ag2[websockets]==0.9.2; extra == 'test'
|
|
172
|
-
Requires-Dist: fakeredis
|
|
172
|
+
Requires-Dist: fakeredis<=3.30.0,>=2.28.1; extra == 'test'
|
|
173
173
|
Requires-Dist: paho-mqtt<3.0,>=2.1.0; extra == 'test'
|
|
174
174
|
Requires-Dist: pytest-asyncio==1.0.0; extra == 'test'
|
|
175
175
|
Requires-Dist: pytest-cov==6.1.1; extra == 'test'
|