waldiez 0.5.10__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.
- waldiez/__init__.py +1 -1
- waldiez/_version.py +1 -1
- waldiez/cli.py +19 -7
- waldiez/cli_extras/jupyter.py +3 -0
- waldiez/cli_extras/runner.py +3 -1
- waldiez/cli_extras/studio.py +3 -1
- waldiez/exporter.py +9 -3
- waldiez/exporting/agent/exporter.py +15 -16
- waldiez/exporting/agent/extras/captain_agent_extras.py +6 -6
- waldiez/exporting/agent/extras/doc_agent_extras.py +6 -6
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +40 -24
- waldiez/exporting/agent/extras/group_member_extras.py +6 -5
- waldiez/exporting/agent/extras/handoffs/after_work.py +2 -1
- waldiez/exporting/agent/extras/handoffs/available.py +2 -1
- waldiez/exporting/agent/extras/handoffs/condition.py +3 -2
- waldiez/exporting/agent/extras/handoffs/handoff.py +2 -1
- waldiez/exporting/agent/extras/handoffs/target.py +7 -4
- waldiez/exporting/agent/extras/rag/chroma_extras.py +27 -19
- waldiez/exporting/agent/extras/rag/mongo_extras.py +8 -8
- waldiez/exporting/agent/extras/rag/pgvector_extras.py +5 -5
- waldiez/exporting/agent/extras/rag/qdrant_extras.py +5 -4
- waldiez/exporting/agent/extras/rag/vector_db_extras.py +1 -1
- waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +5 -7
- waldiez/exporting/agent/extras/reasoning_agent_extras.py +3 -5
- waldiez/exporting/agent/termination.py +1 -0
- waldiez/exporting/chats/exporter.py +4 -4
- waldiez/exporting/chats/processor.py +1 -2
- waldiez/exporting/chats/utils/common.py +89 -48
- waldiez/exporting/chats/utils/group.py +9 -9
- waldiez/exporting/chats/utils/nested.py +7 -7
- waldiez/exporting/chats/utils/sequential.py +1 -1
- waldiez/exporting/chats/utils/single.py +2 -2
- waldiez/exporting/core/constants.py +3 -1
- waldiez/exporting/core/content.py +7 -7
- waldiez/exporting/core/context.py +5 -3
- waldiez/exporting/core/exporter.py +5 -3
- waldiez/exporting/core/exporters.py +2 -2
- waldiez/exporting/core/extras/agent_extras/captain_extras.py +2 -2
- waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +2 -2
- waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +2 -2
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +3 -8
- waldiez/exporting/core/extras/base.py +7 -5
- waldiez/exporting/core/extras/flow_extras.py +4 -5
- waldiez/exporting/core/extras/model_extras.py +2 -2
- waldiez/exporting/core/extras/path_resolver.py +1 -2
- waldiez/exporting/core/extras/serializer.py +13 -11
- waldiez/exporting/core/protocols.py +6 -5
- waldiez/exporting/core/result.py +25 -28
- waldiez/exporting/core/types.py +11 -10
- waldiez/exporting/core/utils/llm_config.py +4 -4
- waldiez/exporting/core/validation.py +10 -11
- waldiez/exporting/flow/execution_generator.py +99 -10
- waldiez/exporting/flow/exporter.py +2 -2
- waldiez/exporting/flow/factory.py +2 -2
- waldiez/exporting/flow/file_generator.py +4 -2
- waldiez/exporting/flow/merger.py +5 -3
- waldiez/exporting/flow/orchestrator.py +72 -2
- waldiez/exporting/flow/utils/common.py +6 -6
- waldiez/exporting/flow/utils/importing.py +7 -8
- waldiez/exporting/flow/utils/linting.py +25 -9
- waldiez/exporting/flow/utils/logging.py +5 -77
- waldiez/exporting/models/exporter.py +8 -8
- waldiez/exporting/models/processor.py +5 -5
- waldiez/exporting/tools/exporter.py +2 -2
- waldiez/exporting/tools/processor.py +7 -4
- waldiez/io/__init__.py +11 -5
- waldiez/io/_ws.py +12 -6
- waldiez/io/models/constants.py +10 -10
- waldiez/io/models/content/audio.py +1 -0
- waldiez/io/models/content/base.py +20 -18
- waldiez/io/models/content/file.py +1 -0
- waldiez/io/models/content/image.py +1 -0
- waldiez/io/models/content/text.py +1 -0
- waldiez/io/models/content/video.py +1 -0
- waldiez/io/models/user_input.py +10 -5
- waldiez/io/models/user_response.py +17 -16
- waldiez/io/mqtt.py +18 -31
- waldiez/io/redis.py +18 -22
- waldiez/io/structured.py +122 -70
- waldiez/io/utils.py +19 -10
- waldiez/io/ws.py +7 -3
- waldiez/logger.py +16 -3
- waldiez/models/agents/__init__.py +3 -0
- waldiez/models/agents/agent/agent.py +25 -17
- waldiez/models/agents/agent/agent_data.py +25 -22
- waldiez/models/agents/agent/code_execution.py +9 -11
- waldiez/models/agents/agent/termination_message.py +10 -12
- waldiez/models/agents/agent/update_system_message.py +2 -4
- waldiez/models/agents/agents.py +8 -8
- waldiez/models/agents/assistant/assistant.py +6 -3
- waldiez/models/agents/assistant/assistant_data.py +2 -2
- waldiez/models/agents/captain/captain_agent.py +7 -4
- waldiez/models/agents/captain/captain_agent_data.py +5 -7
- waldiez/models/agents/doc_agent/doc_agent.py +7 -4
- waldiez/models/agents/doc_agent/doc_agent_data.py +9 -10
- waldiez/models/agents/doc_agent/rag_query_engine.py +10 -12
- waldiez/models/agents/extra_requirements.py +3 -3
- waldiez/models/agents/group_manager/group_manager.py +12 -7
- waldiez/models/agents/group_manager/group_manager_data.py +13 -12
- waldiez/models/agents/group_manager/speakers.py +17 -19
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +7 -4
- waldiez/models/agents/rag_user_proxy/rag_user_proxy_data.py +4 -1
- waldiez/models/agents/rag_user_proxy/retrieve_config.py +69 -63
- waldiez/models/agents/rag_user_proxy/vector_db_config.py +19 -19
- waldiez/models/agents/reasoning/reasoning_agent.py +7 -4
- waldiez/models/agents/reasoning/reasoning_agent_data.py +3 -2
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +8 -8
- waldiez/models/agents/user_proxy/user_proxy.py +6 -3
- waldiez/models/agents/user_proxy/user_proxy_data.py +1 -1
- waldiez/models/chat/chat.py +28 -20
- waldiez/models/chat/chat_data.py +22 -21
- waldiez/models/chat/chat_message.py +9 -9
- waldiez/models/chat/chat_nested.py +9 -9
- waldiez/models/chat/chat_summary.py +6 -6
- waldiez/models/common/__init__.py +2 -0
- waldiez/models/common/ag2_version.py +2 -0
- waldiez/models/common/base.py +2 -0
- waldiez/models/common/dict_utils.py +8 -6
- waldiez/models/common/handoff.py +20 -17
- waldiez/models/common/method_utils.py +9 -7
- waldiez/models/common/naming.py +49 -0
- waldiez/models/flow/flow.py +11 -6
- waldiez/models/flow/flow_data.py +23 -17
- waldiez/models/flow/info.py +3 -3
- waldiez/models/flow/naming.py +2 -1
- waldiez/models/model/_aws.py +11 -13
- waldiez/models/model/_llm.py +8 -0
- waldiez/models/model/_price.py +2 -4
- waldiez/models/model/extra_requirements.py +1 -3
- waldiez/models/model/model.py +2 -2
- waldiez/models/model/model_data.py +21 -21
- waldiez/models/tool/extra_requirements.py +2 -4
- waldiez/models/tool/predefined/_duckduckgo.py +1 -0
- waldiez/models/tool/predefined/_email.py +4 -0
- waldiez/models/tool/predefined/_google.py +1 -0
- waldiez/models/tool/predefined/_perplexity.py +2 -1
- waldiez/models/tool/predefined/_searxng.py +2 -1
- waldiez/models/tool/predefined/_tavily.py +1 -0
- waldiez/models/tool/predefined/_wikipedia.py +2 -1
- waldiez/models/tool/predefined/_youtube.py +1 -0
- waldiez/models/tool/tool.py +8 -5
- waldiez/models/tool/tool_data.py +2 -2
- waldiez/models/waldiez.py +152 -4
- waldiez/runner.py +11 -5
- waldiez/running/async_utils.py +192 -0
- waldiez/running/base_runner.py +155 -241
- waldiez/running/dir_utils.py +52 -0
- waldiez/running/environment.py +10 -44
- waldiez/running/events_mixin.py +252 -0
- waldiez/running/exceptions.py +20 -0
- waldiez/running/gen_seq_diagram.py +18 -15
- waldiez/running/io_utils.py +216 -0
- waldiez/running/protocol.py +11 -5
- waldiez/running/requirements_mixin.py +65 -0
- waldiez/running/results_mixin.py +926 -0
- waldiez/running/standard_runner.py +24 -27
- waldiez/running/step_by_step/breakpoints_mixin.py +503 -47
- waldiez/running/step_by_step/command_handler.py +154 -0
- waldiez/running/step_by_step/events_processor.py +379 -0
- waldiez/running/step_by_step/step_by_step_models.py +425 -41
- waldiez/running/step_by_step/step_by_step_runner.py +437 -382
- waldiez/running/subprocess_runner/__base__.py +13 -8
- waldiez/running/subprocess_runner/_async_runner.py +6 -4
- waldiez/running/subprocess_runner/_sync_runner.py +11 -6
- waldiez/running/subprocess_runner/runner.py +48 -23
- waldiez/running/timeline_processor.py +1 -1
- waldiez/utils/__init__.py +2 -0
- waldiez/utils/conflict_checker.py +4 -4
- waldiez/utils/python_manager.py +415 -0
- waldiez/ws/__init__.py +8 -7
- waldiez/ws/_file_handler.py +18 -20
- waldiez/ws/_mock.py +75 -0
- waldiez/ws/cli.py +58 -10
- waldiez/ws/client_manager.py +77 -53
- waldiez/ws/errors.py +3 -0
- waldiez/ws/models.py +61 -53
- waldiez/ws/reloader.py +33 -4
- waldiez/ws/server.py +121 -52
- waldiez/ws/session_manager.py +8 -9
- waldiez/ws/session_stats.py +1 -1
- waldiez/ws/utils.py +33 -5
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/METADATA +107 -109
- waldiez-0.6.1.dist-info/RECORD +254 -0
- waldiez/running/post_run.py +0 -180
- waldiez/running/pre_run.py +0 -159
- waldiez/running/run_results.py +0 -14
- waldiez/running/utils.py +0 -511
- waldiez-0.5.10.dist-info/RECORD +0 -248
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/WHEEL +0 -0
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/entry_points.txt +0 -0
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.5.10.dist-info → waldiez-0.6.1.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Constants for Waldiez exporting core."""
|
|
4
4
|
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
5
7
|
from .enums import (
|
|
6
8
|
AgentPosition,
|
|
7
9
|
ExportPosition,
|
|
@@ -10,7 +12,7 @@ from .enums import (
|
|
|
10
12
|
|
|
11
13
|
FILE_HEADER = (
|
|
12
14
|
"# SPDX-License-Identifier: Apache-2.0.\n"
|
|
13
|
-
"# Copyright (c) 2024 -
|
|
15
|
+
f"# Copyright (c) 2024 - {datetime.now().year} Waldiez and contributors."
|
|
14
16
|
)
|
|
15
17
|
DEFAULT_IMPORT_POSITION = ImportPosition.THIRD_PARTY
|
|
16
18
|
DEFAULT_EXPORT_POSITION = ExportPosition.AGENTS
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"""Content module for Waldiez exporting core."""
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass, field
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
from .enums import (
|
|
9
9
|
AgentPosition,
|
|
@@ -20,9 +20,9 @@ class PositionedContent:
|
|
|
20
20
|
content: str
|
|
21
21
|
position: ExportPosition
|
|
22
22
|
order: int = 0
|
|
23
|
-
agent_id:
|
|
24
|
-
agent_position:
|
|
25
|
-
metadata: dict[str, Any] = field(default_factory=dict
|
|
23
|
+
agent_id: str | None = None
|
|
24
|
+
agent_position: AgentPosition | None = None
|
|
25
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
26
26
|
|
|
27
27
|
def __post_init__(self) -> None:
|
|
28
28
|
"""Validate positioned content."""
|
|
@@ -64,6 +64,6 @@ class ContentMetadata:
|
|
|
64
64
|
"""Metadata about exported content."""
|
|
65
65
|
|
|
66
66
|
content_type: ContentType
|
|
67
|
-
source_id:
|
|
68
|
-
dependencies: list[str] = field(default_factory=list
|
|
69
|
-
tags: set[str] = field(default_factory=set
|
|
67
|
+
source_id: str | None = None
|
|
68
|
+
dependencies: list[str] = field(default_factory=list)
|
|
69
|
+
tags: set[str] = field(default_factory=set)
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Singleton context for exporters."""
|
|
4
4
|
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
5
7
|
import threading
|
|
6
8
|
from dataclasses import dataclass
|
|
7
|
-
from typing import Any
|
|
9
|
+
from typing import Any
|
|
8
10
|
|
|
9
11
|
from waldiez.logger import WaldiezLogger, get_logger
|
|
10
12
|
|
|
@@ -137,10 +139,10 @@ class DefaultExporterContext(ExporterContext):
|
|
|
137
139
|
Direct instantiation may not behave as expected.
|
|
138
140
|
"""
|
|
139
141
|
|
|
140
|
-
_instance:
|
|
142
|
+
_instance: DefaultExporterContext | None = None
|
|
141
143
|
_lock = threading.Lock()
|
|
142
144
|
|
|
143
|
-
def __new__(cls, *args: Any, **kwargs: Any) ->
|
|
145
|
+
def __new__(cls, *args: Any, **kwargs: Any) -> DefaultExporterContext:
|
|
144
146
|
"""Create a new instance of DefaultExporterContext.
|
|
145
147
|
|
|
146
148
|
Parameters
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
# pylint: disable=too-few-public-methods
|
|
4
|
+
# pyright: reportUnusedParameter=false
|
|
5
|
+
|
|
4
6
|
"""Base exporter classes."""
|
|
5
7
|
|
|
6
8
|
import abc
|
|
7
|
-
from typing import Any, Generic
|
|
9
|
+
from typing import Any, Generic
|
|
8
10
|
|
|
9
11
|
from .constants import DEFAULT_IMPORT_POSITION
|
|
10
12
|
from .content import PositionedContent
|
|
@@ -30,7 +32,7 @@ class Exporter(abc.ABC, Generic[Extras]):
|
|
|
30
32
|
|
|
31
33
|
def __init__(
|
|
32
34
|
self,
|
|
33
|
-
context:
|
|
35
|
+
context: ExporterContext | None = None,
|
|
34
36
|
**kwargs: Any,
|
|
35
37
|
):
|
|
36
38
|
"""Initialize the exporter.
|
|
@@ -312,7 +314,7 @@ class Exporter(abc.ABC, Generic[Extras]):
|
|
|
312
314
|
self._ensure_initialized()
|
|
313
315
|
return self._result.get_content_by_position(position)
|
|
314
316
|
|
|
315
|
-
def get_main_content(self) ->
|
|
317
|
+
def get_main_content(self) -> str | None:
|
|
316
318
|
"""Get the main content.
|
|
317
319
|
|
|
318
320
|
Returns
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
"""Exporters for Waldiez."""
|
|
5
5
|
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
from .exporter import Exporter
|
|
9
9
|
from .types import Extras
|
|
@@ -50,7 +50,7 @@ class ConfigurableExporter(Exporter[Extras]):
|
|
|
50
50
|
"""
|
|
51
51
|
raise NotImplementedError("Subclasses must implement this method.")
|
|
52
52
|
|
|
53
|
-
def __init__(self, config:
|
|
53
|
+
def __init__(self, config: dict[str, Any] | None = None, **kwargs: Any):
|
|
54
54
|
"""Initialize with configuration.
|
|
55
55
|
|
|
56
56
|
Parameters
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"""Captain agent extras module."""
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
from waldiez.exporting.core.result import ExportResult
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ from .standard_extras import StandardExtras
|
|
|
14
14
|
class CaptainExtras(StandardExtras):
|
|
15
15
|
"""Extras for captain agents."""
|
|
16
16
|
|
|
17
|
-
nested_config:
|
|
17
|
+
nested_config: dict[str, Any] | None = None
|
|
18
18
|
|
|
19
19
|
def _contribute_specific_content(self, result: ExportResult) -> None:
|
|
20
20
|
"""Contribute captain specific content to the export result.
|
|
@@ -26,7 +26,7 @@ class GroupManagerExtras(StandardExtras):
|
|
|
26
26
|
# Pattern-based content
|
|
27
27
|
pattern_definition: str = ""
|
|
28
28
|
pattern_class_name: str = "AutoPattern"
|
|
29
|
-
pattern_imports: set[str] = field(default_factory=set
|
|
29
|
+
pattern_imports: set[str] = field(default_factory=set)
|
|
30
30
|
|
|
31
31
|
# Traditional GroupChat content
|
|
32
32
|
group_chat_definition: str = ""
|
|
@@ -88,7 +88,7 @@ class GroupManagerExtras(StandardExtras):
|
|
|
88
88
|
order=ContentOrder.LATE_CLEANUP,
|
|
89
89
|
)
|
|
90
90
|
|
|
91
|
-
# Add
|
|
91
|
+
# Add group chat argument if specified
|
|
92
92
|
if self.group_chat_argument:
|
|
93
93
|
self.add_arg(self.group_chat_argument, tabs=1)
|
|
94
94
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""RAG related
|
|
3
|
+
"""RAG related extras."""
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass, field
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ class RAGUserExtras(StandardExtras):
|
|
|
15
15
|
"""RAG configuration."""
|
|
16
16
|
|
|
17
17
|
before_content: str = ""
|
|
18
|
-
imports: set[str] = field(default_factory=set
|
|
18
|
+
imports: set[str] = field(default_factory=set)
|
|
19
19
|
|
|
20
20
|
def _contribute_specific_content(self, result: ExportResult) -> None:
|
|
21
21
|
"""Contribute RAG specific content to the export result."""
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"""Standard agent extras module."""
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
|
-
from typing import Optional
|
|
8
7
|
|
|
9
8
|
from ...enums import AgentPosition, ExportPosition
|
|
10
9
|
from ...result import ExportResult
|
|
@@ -76,9 +75,9 @@ class SystemMessageConfig:
|
|
|
76
75
|
class StandardExtras(BaseExtras):
|
|
77
76
|
"""Extras for standard agents (UserProxy, Assistant, etc.)."""
|
|
78
77
|
|
|
79
|
-
code_execution_config:
|
|
80
|
-
termination_config:
|
|
81
|
-
system_message_config:
|
|
78
|
+
code_execution_config: CodeExecutionConfig | None = None
|
|
79
|
+
termination_config: TerminationConfig | None = None
|
|
80
|
+
system_message_config: SystemMessageConfig | None = None
|
|
82
81
|
|
|
83
82
|
def set_code_execution(self, config: CodeExecutionConfig) -> None:
|
|
84
83
|
"""Set code execution configuration.
|
|
@@ -155,14 +154,10 @@ class StandardExtras(BaseExtras):
|
|
|
155
154
|
argument = self.termination_config.termination_arg
|
|
156
155
|
else:
|
|
157
156
|
argument = "None"
|
|
158
|
-
comment: str | None = None
|
|
159
|
-
if argument == "None":
|
|
160
|
-
comment = "pyright: ignore"
|
|
161
157
|
return InstanceArgument(
|
|
162
158
|
instance_id=self.instance_id,
|
|
163
159
|
name="is_termination_msg",
|
|
164
160
|
value=argument,
|
|
165
|
-
comment=comment,
|
|
166
161
|
tabs=1,
|
|
167
162
|
)
|
|
168
163
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
|
|
4
|
+
# pyright: reportUnnecessaryIsInstance=false, reportUnusedParameter=false
|
|
5
|
+
|
|
4
6
|
"""Base extras system for all exporters."""
|
|
5
7
|
|
|
6
8
|
import abc
|
|
9
|
+
from collections.abc import Sequence
|
|
7
10
|
from dataclasses import dataclass, field
|
|
8
|
-
from typing import Sequence
|
|
9
11
|
|
|
10
12
|
from ..enums import AgentPosition, ContentOrder, ExportPosition, ImportPosition
|
|
11
13
|
from ..protocols import ExportContributor
|
|
@@ -14,18 +16,18 @@ from ..types import ImportStatement, InstanceArgument
|
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
@dataclass
|
|
17
|
-
class BaseExtras(ExportContributor):
|
|
19
|
+
class BaseExtras(ExportContributor, metaclass=abc.ABCMeta):
|
|
18
20
|
"""Base class for all exporter extras with export contribution."""
|
|
19
21
|
|
|
20
22
|
instance_id: str
|
|
21
23
|
extra_imports: list[ImportStatement] = field(
|
|
22
|
-
default_factory=list
|
|
24
|
+
default_factory=list,
|
|
23
25
|
)
|
|
24
26
|
before_agent: str = ""
|
|
25
27
|
after_agent: str = ""
|
|
26
28
|
after_all_agents: str = ""
|
|
27
29
|
extra_args: list[InstanceArgument] = field(
|
|
28
|
-
default_factory=list
|
|
30
|
+
default_factory=list,
|
|
29
31
|
)
|
|
30
32
|
|
|
31
33
|
def get_extra_args_content(self) -> str:
|
|
@@ -51,7 +53,7 @@ class BaseExtras(ExportContributor):
|
|
|
51
53
|
if isinstance(arg, InstanceArgument):
|
|
52
54
|
if arg not in self.extra_args:
|
|
53
55
|
self.extra_args.append(arg)
|
|
54
|
-
elif isinstance(arg, str) and arg.strip():
|
|
56
|
+
elif isinstance(arg, str) and arg.strip():
|
|
55
57
|
# If it's a string, create an InstanceArgument
|
|
56
58
|
# split by '=' (it's an argument line)
|
|
57
59
|
parts = arg.split("=", 1)
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
"""Flow specific extras module."""
|
|
6
6
|
|
|
7
7
|
from dataclasses import dataclass, field
|
|
8
|
-
from typing import Optional
|
|
9
8
|
|
|
10
9
|
from waldiez.utils import get_waldiez_version
|
|
11
10
|
|
|
@@ -25,10 +24,10 @@ class FlowExtras(BaseExtras):
|
|
|
25
24
|
version: str = field(default_factory=get_waldiez_version)
|
|
26
25
|
|
|
27
26
|
# Sub-exporter results
|
|
28
|
-
tools_result:
|
|
29
|
-
models_result:
|
|
30
|
-
agents_result:
|
|
31
|
-
chats_result:
|
|
27
|
+
tools_result: ExportResult | None = None
|
|
28
|
+
models_result: ExportResult | None = None
|
|
29
|
+
agents_result: ExportResult | None = None
|
|
30
|
+
chats_result: ExportResult | None = None
|
|
32
31
|
|
|
33
32
|
# Generated script parts
|
|
34
33
|
header_content: str = ""
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"""Agent specific extras module."""
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any
|
|
8
8
|
|
|
9
9
|
from waldiez.exporting.core.result import ExportResult
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ from .base import BaseExtras
|
|
|
16
16
|
class ModelExtras(BaseExtras):
|
|
17
17
|
"""Extras for model exporters."""
|
|
18
18
|
|
|
19
|
-
llm_config:
|
|
19
|
+
llm_config: dict[str, Any] | None = None
|
|
20
20
|
config_file_path: str = ""
|
|
21
21
|
|
|
22
22
|
def set_llm_config(self, config: dict[str, Any]) -> None:
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
"""Default path resolver for Waldiez items."""
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Union
|
|
7
6
|
|
|
8
7
|
from ..protocols import PathResolver
|
|
9
8
|
|
|
@@ -70,7 +69,7 @@ class DefaultPathResolver(PathResolver):
|
|
|
70
69
|
return None
|
|
71
70
|
|
|
72
71
|
|
|
73
|
-
def _get_raw_path_string(path:
|
|
72
|
+
def _get_raw_path_string(path: str | Path) -> str:
|
|
74
73
|
"""Get the raw path string.
|
|
75
74
|
|
|
76
75
|
Parameters
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
"""serializer for converting items to formatted strings."""
|
|
6
6
|
|
|
7
7
|
import json
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
from ..protocols import Serializer
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
# pylint: disable=too-few-public-methods
|
|
13
|
+
# pylint: disable=too-few-public-methods,no-self-use
|
|
14
14
|
class DefaultSerializer(Serializer):
|
|
15
15
|
"""Default serializer for Waldiez items."""
|
|
16
16
|
|
|
@@ -37,7 +37,7 @@ class DefaultSerializer(Serializer):
|
|
|
37
37
|
def serialize_item(
|
|
38
38
|
item: Any,
|
|
39
39
|
tabs: int = 1,
|
|
40
|
-
|
|
40
|
+
visited: set[int] | None = None,
|
|
41
41
|
) -> str:
|
|
42
42
|
"""Convert an item to a formatted string with given indentation.
|
|
43
43
|
|
|
@@ -47,6 +47,8 @@ def serialize_item(
|
|
|
47
47
|
The item to convert.
|
|
48
48
|
tabs : int, optional
|
|
49
49
|
The number of tabs, by default 1.
|
|
50
|
+
visited : set[int], optional
|
|
51
|
+
A set of visited IDs, by default None
|
|
50
52
|
|
|
51
53
|
Returns
|
|
52
54
|
-------
|
|
@@ -81,8 +83,8 @@ def serialize_item(
|
|
|
81
83
|
}
|
|
82
84
|
```
|
|
83
85
|
"""
|
|
84
|
-
if
|
|
85
|
-
|
|
86
|
+
if visited is None:
|
|
87
|
+
visited = set()
|
|
86
88
|
|
|
87
89
|
if callable(item):
|
|
88
90
|
return item.__name__
|
|
@@ -92,37 +94,37 @@ def serialize_item(
|
|
|
92
94
|
return _format_primitive(item)
|
|
93
95
|
|
|
94
96
|
# Handle circular references in containers
|
|
95
|
-
if isinstance(item, (dict, list, tuple, set)) and id(item) in
|
|
97
|
+
if isinstance(item, (dict, list, tuple, set)) and id(item) in visited:
|
|
96
98
|
return '"<circular reference>"'
|
|
97
99
|
|
|
98
100
|
next_indent = " " * 4 * (tabs + 1)
|
|
99
|
-
|
|
101
|
+
visited.add(id(item))
|
|
100
102
|
|
|
101
103
|
if isinstance(item, dict):
|
|
102
104
|
items: list[str] = []
|
|
103
105
|
for key, value in item.items():
|
|
104
106
|
key_str = f'{next_indent}"{key}"'
|
|
105
|
-
value_str = serialize_item(value, tabs + 1,
|
|
107
|
+
value_str = serialize_item(value, tabs + 1, visited)
|
|
106
108
|
items.append(f"{key_str}: {value_str}")
|
|
107
109
|
return _format_container(items, "{", "}", tabs)
|
|
108
110
|
|
|
109
111
|
if isinstance(item, list):
|
|
110
112
|
items = [
|
|
111
|
-
f"{next_indent}{serialize_item(sub_item, tabs + 1,
|
|
113
|
+
f"{next_indent}{serialize_item(sub_item, tabs + 1, visited)}"
|
|
112
114
|
for sub_item in item
|
|
113
115
|
]
|
|
114
116
|
return _format_container(items, "[", "]", tabs)
|
|
115
117
|
|
|
116
118
|
if isinstance(item, tuple):
|
|
117
119
|
items = [
|
|
118
|
-
f"{next_indent}{serialize_item(sub_item, tabs + 1,
|
|
120
|
+
f"{next_indent}{serialize_item(sub_item, tabs + 1, visited)}"
|
|
119
121
|
for sub_item in item
|
|
120
122
|
]
|
|
121
123
|
return _format_container(items, "(", ")", tabs)
|
|
122
124
|
|
|
123
125
|
if isinstance(item, set):
|
|
124
126
|
items = [
|
|
125
|
-
f"{next_indent}{serialize_item(sub_item, tabs + 1,
|
|
127
|
+
f"{next_indent}{serialize_item(sub_item, tabs + 1, visited)}"
|
|
126
128
|
for sub_item in item
|
|
127
129
|
]
|
|
128
130
|
return _format_container(items, "{", "}", tabs)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
# pylint: disable=too-few-public-methods
|
|
4
|
+
# pyright: reportReturnType=false
|
|
4
5
|
"""Core exporting protocols."""
|
|
5
6
|
|
|
6
7
|
from typing import Any, Protocol, runtime_checkable
|
|
@@ -28,7 +29,7 @@ class ExportContributor(Protocol):
|
|
|
28
29
|
class Validator(Protocol):
|
|
29
30
|
"""Protocol for validation components."""
|
|
30
31
|
|
|
31
|
-
def validate(self, content: Any) -> ValidationResult:
|
|
32
|
+
def validate(self, content: Any) -> ValidationResult:
|
|
32
33
|
"""Validate content and return result.
|
|
33
34
|
|
|
34
35
|
Parameters
|
|
@@ -47,7 +48,7 @@ class Validator(Protocol):
|
|
|
47
48
|
class Serializer(Protocol):
|
|
48
49
|
"""Protocol for serialization components."""
|
|
49
50
|
|
|
50
|
-
def serialize(self, obj: Any, **kwargs: Any) -> str:
|
|
51
|
+
def serialize(self, obj: Any, **kwargs: Any) -> str:
|
|
51
52
|
"""Serialize an object to string representation.
|
|
52
53
|
|
|
53
54
|
Parameters
|
|
@@ -68,7 +69,7 @@ class Serializer(Protocol):
|
|
|
68
69
|
class PathResolver(Protocol):
|
|
69
70
|
"""Protocol for resolving a path."""
|
|
70
71
|
|
|
71
|
-
def resolve(self, path: str) -> str:
|
|
72
|
+
def resolve(self, path: str) -> str:
|
|
72
73
|
"""Resolve a path.
|
|
73
74
|
|
|
74
75
|
Parameters
|
|
@@ -87,7 +88,7 @@ class PathResolver(Protocol):
|
|
|
87
88
|
If the path cannot be resolved.
|
|
88
89
|
"""
|
|
89
90
|
|
|
90
|
-
def is_local(self, path: str) -> bool:
|
|
91
|
+
def is_local(self, path: str) -> bool:
|
|
91
92
|
"""Check if the given path is a local path.
|
|
92
93
|
|
|
93
94
|
Parameters
|
|
@@ -112,7 +113,7 @@ class ContentGenerator(Protocol):
|
|
|
112
113
|
after_run: str,
|
|
113
114
|
skip_logging: bool,
|
|
114
115
|
**kwargs: Any,
|
|
115
|
-
) -> str:
|
|
116
|
+
) -> str:
|
|
116
117
|
"""Generate content based on provided parameters.
|
|
117
118
|
|
|
118
119
|
Parameters
|
waldiez/exporting/core/result.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"""Export result containers and related classes."""
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass, field
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any
|
|
8
8
|
|
|
9
9
|
from .constants import (
|
|
10
10
|
DEFAULT_EXPORT_POSITION,
|
|
@@ -31,21 +31,21 @@ from .validation import ValidationResult
|
|
|
31
31
|
class ExportResult:
|
|
32
32
|
"""Complete export result with all components."""
|
|
33
33
|
|
|
34
|
-
main_content:
|
|
34
|
+
main_content: str | None = None
|
|
35
35
|
imports: set[ImportStatement] = field(
|
|
36
|
-
default_factory=set
|
|
36
|
+
default_factory=set,
|
|
37
37
|
)
|
|
38
38
|
positioned_content: list[PositionedContent] = field(
|
|
39
|
-
default_factory=list
|
|
39
|
+
default_factory=list,
|
|
40
40
|
)
|
|
41
41
|
instance_arguments: list[InstanceArgument] = field(
|
|
42
|
-
default_factory=list
|
|
42
|
+
default_factory=list,
|
|
43
43
|
)
|
|
44
44
|
environment_variables: list[EnvironmentVariable] = field(
|
|
45
|
-
default_factory=list
|
|
45
|
+
default_factory=list
|
|
46
46
|
)
|
|
47
|
-
validation_result:
|
|
48
|
-
metadata: dict[str, Any] = field(default_factory=dict
|
|
47
|
+
validation_result: ValidationResult | None = None
|
|
48
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
49
49
|
|
|
50
50
|
def add_import(
|
|
51
51
|
self, statement: str, position: ImportPosition = DEFAULT_IMPORT_POSITION
|
|
@@ -69,12 +69,9 @@ class ExportResult:
|
|
|
69
69
|
|
|
70
70
|
def add_imports(
|
|
71
71
|
self,
|
|
72
|
-
statements:
|
|
73
|
-
set[str]
|
|
74
|
-
|
|
75
|
-
set[ImportStatement],
|
|
76
|
-
list[ImportStatement],
|
|
77
|
-
],
|
|
72
|
+
statements: (
|
|
73
|
+
set[str] | list[str] | set[ImportStatement] | list[ImportStatement]
|
|
74
|
+
),
|
|
78
75
|
position: ImportPosition = DEFAULT_IMPORT_POSITION,
|
|
79
76
|
) -> None:
|
|
80
77
|
"""Add multiple import statements.
|
|
@@ -106,7 +103,7 @@ class ExportResult:
|
|
|
106
103
|
value: Any,
|
|
107
104
|
instance_id: str,
|
|
108
105
|
tabs: int = 0,
|
|
109
|
-
comment:
|
|
106
|
+
comment: str | None = None,
|
|
110
107
|
) -> None:
|
|
111
108
|
"""Add an instance argument.
|
|
112
109
|
|
|
@@ -120,7 +117,7 @@ class ExportResult:
|
|
|
120
117
|
The ID of the instance this argument belongs to.
|
|
121
118
|
tabs : int, optional
|
|
122
119
|
Number of tabs for indentation, by default 0
|
|
123
|
-
comment :
|
|
120
|
+
comment : str | None, optional
|
|
124
121
|
Optional comment for the argument, by default None
|
|
125
122
|
"""
|
|
126
123
|
if name and value is not None: # pragma: no branch
|
|
@@ -142,7 +139,7 @@ class ExportResult:
|
|
|
142
139
|
|
|
143
140
|
def add_instance_arguments(
|
|
144
141
|
self,
|
|
145
|
-
arguments:
|
|
142
|
+
arguments: list[InstanceArgument] | set[InstanceArgument],
|
|
146
143
|
) -> None:
|
|
147
144
|
"""Add multiple instance arguments.
|
|
148
145
|
|
|
@@ -217,9 +214,9 @@ class ExportResult:
|
|
|
217
214
|
position: ExportPosition = DEFAULT_EXPORT_POSITION,
|
|
218
215
|
order: ContentOrder | int = ContentOrder.MAIN_CONTENT,
|
|
219
216
|
skip_strip: bool = False,
|
|
220
|
-
agent_id:
|
|
221
|
-
agent_position:
|
|
222
|
-
metadata:
|
|
217
|
+
agent_id: str | None = None,
|
|
218
|
+
agent_position: AgentPosition | None = None,
|
|
219
|
+
metadata: dict[str, Any] | None = None,
|
|
223
220
|
) -> None:
|
|
224
221
|
"""Add positioned content.
|
|
225
222
|
|
|
@@ -257,7 +254,7 @@ class ExportResult:
|
|
|
257
254
|
self,
|
|
258
255
|
name: str,
|
|
259
256
|
value: str,
|
|
260
|
-
description:
|
|
257
|
+
description: str | None = None,
|
|
261
258
|
required: bool = True,
|
|
262
259
|
) -> None:
|
|
263
260
|
"""Add environment variable.
|
|
@@ -268,7 +265,7 @@ class ExportResult:
|
|
|
268
265
|
The name of the environment variable.
|
|
269
266
|
value : str
|
|
270
267
|
The value of the environment variable.
|
|
271
|
-
description :
|
|
268
|
+
description : str | None, optional
|
|
272
269
|
Description of the variable, by default None
|
|
273
270
|
required : bool, optional
|
|
274
271
|
Whether the variable is required, by default True
|
|
@@ -353,7 +350,7 @@ class ExportResult:
|
|
|
353
350
|
return sorted(content)
|
|
354
351
|
|
|
355
352
|
def get_agent_content(
|
|
356
|
-
self, agent_id: str, agent_position:
|
|
353
|
+
self, agent_id: str, agent_position: AgentPosition | None = None
|
|
357
354
|
) -> list[PositionedContent]:
|
|
358
355
|
"""Get content positioned relative to a specific agent.
|
|
359
356
|
|
|
@@ -561,8 +558,8 @@ class ExportResultBuilder:
|
|
|
561
558
|
content: str,
|
|
562
559
|
position: ExportPosition = DEFAULT_EXPORT_POSITION,
|
|
563
560
|
order: ContentOrder = ContentOrder.MAIN_CONTENT,
|
|
564
|
-
agent_id:
|
|
565
|
-
agent_position:
|
|
561
|
+
agent_id: str | None = None,
|
|
562
|
+
agent_position: AgentPosition | None = None,
|
|
566
563
|
) -> "ExportResultBuilder":
|
|
567
564
|
"""Add positioned content.
|
|
568
565
|
|
|
@@ -574,7 +571,7 @@ class ExportResultBuilder:
|
|
|
574
571
|
The content position, by default AGENTS
|
|
575
572
|
order : int, optional
|
|
576
573
|
The order within position, by default 0
|
|
577
|
-
agent_id :
|
|
574
|
+
agent_id : str | None, optional
|
|
578
575
|
Agent ID for agent-relative positioning, by default None
|
|
579
576
|
agent_position : Optional[AgentPosition], optional
|
|
580
577
|
Position relative to agent, by default None
|
|
@@ -594,7 +591,7 @@ class ExportResultBuilder:
|
|
|
594
591
|
return self
|
|
595
592
|
|
|
596
593
|
def with_env_var(
|
|
597
|
-
self, name: str, value: str, description:
|
|
594
|
+
self, name: str, value: str, description: str | None = None
|
|
598
595
|
) -> "ExportResultBuilder":
|
|
599
596
|
"""Add environment variable.
|
|
600
597
|
|
|
@@ -604,7 +601,7 @@ class ExportResultBuilder:
|
|
|
604
601
|
Variable name.
|
|
605
602
|
value : str
|
|
606
603
|
Variable value.
|
|
607
|
-
description :
|
|
604
|
+
description : str | None, optional
|
|
608
605
|
Variable description, by default None
|
|
609
606
|
|
|
610
607
|
Returns
|