kweaver-dolphin 0.1.0__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.
- DolphinLanguageSDK/__init__.py +58 -0
- dolphin/__init__.py +62 -0
- dolphin/cli/__init__.py +20 -0
- dolphin/cli/args/__init__.py +9 -0
- dolphin/cli/args/parser.py +567 -0
- dolphin/cli/builtin_agents/__init__.py +22 -0
- dolphin/cli/commands/__init__.py +4 -0
- dolphin/cli/interrupt/__init__.py +8 -0
- dolphin/cli/interrupt/handler.py +205 -0
- dolphin/cli/interrupt/keyboard.py +82 -0
- dolphin/cli/main.py +49 -0
- dolphin/cli/multimodal/__init__.py +34 -0
- dolphin/cli/multimodal/clipboard.py +327 -0
- dolphin/cli/multimodal/handler.py +249 -0
- dolphin/cli/multimodal/image_processor.py +214 -0
- dolphin/cli/multimodal/input_parser.py +149 -0
- dolphin/cli/runner/__init__.py +8 -0
- dolphin/cli/runner/runner.py +989 -0
- dolphin/cli/ui/__init__.py +10 -0
- dolphin/cli/ui/console.py +2795 -0
- dolphin/cli/ui/input.py +340 -0
- dolphin/cli/ui/layout.py +425 -0
- dolphin/cli/ui/stream_renderer.py +302 -0
- dolphin/cli/utils/__init__.py +8 -0
- dolphin/cli/utils/helpers.py +135 -0
- dolphin/cli/utils/version.py +49 -0
- dolphin/core/__init__.py +107 -0
- dolphin/core/agent/__init__.py +10 -0
- dolphin/core/agent/agent_state.py +69 -0
- dolphin/core/agent/base_agent.py +970 -0
- dolphin/core/code_block/__init__.py +0 -0
- dolphin/core/code_block/agent_init_block.py +0 -0
- dolphin/core/code_block/assign_block.py +98 -0
- dolphin/core/code_block/basic_code_block.py +1865 -0
- dolphin/core/code_block/explore_block.py +1327 -0
- dolphin/core/code_block/explore_block_v2.py +712 -0
- dolphin/core/code_block/explore_strategy.py +672 -0
- dolphin/core/code_block/judge_block.py +220 -0
- dolphin/core/code_block/prompt_block.py +32 -0
- dolphin/core/code_block/skill_call_deduplicator.py +291 -0
- dolphin/core/code_block/tool_block.py +129 -0
- dolphin/core/common/__init__.py +17 -0
- dolphin/core/common/constants.py +176 -0
- dolphin/core/common/enums.py +1173 -0
- dolphin/core/common/exceptions.py +133 -0
- dolphin/core/common/multimodal.py +539 -0
- dolphin/core/common/object_type.py +165 -0
- dolphin/core/common/output_format.py +432 -0
- dolphin/core/common/types.py +36 -0
- dolphin/core/config/__init__.py +16 -0
- dolphin/core/config/global_config.py +1289 -0
- dolphin/core/config/ontology_config.py +133 -0
- dolphin/core/context/__init__.py +12 -0
- dolphin/core/context/context.py +1580 -0
- dolphin/core/context/context_manager.py +161 -0
- dolphin/core/context/var_output.py +82 -0
- dolphin/core/context/variable_pool.py +356 -0
- dolphin/core/context_engineer/__init__.py +41 -0
- dolphin/core/context_engineer/config/__init__.py +5 -0
- dolphin/core/context_engineer/config/settings.py +402 -0
- dolphin/core/context_engineer/core/__init__.py +7 -0
- dolphin/core/context_engineer/core/budget_manager.py +327 -0
- dolphin/core/context_engineer/core/context_assembler.py +583 -0
- dolphin/core/context_engineer/core/context_manager.py +637 -0
- dolphin/core/context_engineer/core/tokenizer_service.py +260 -0
- dolphin/core/context_engineer/example/incremental_example.py +267 -0
- dolphin/core/context_engineer/example/traditional_example.py +334 -0
- dolphin/core/context_engineer/services/__init__.py +5 -0
- dolphin/core/context_engineer/services/compressor.py +399 -0
- dolphin/core/context_engineer/utils/__init__.py +6 -0
- dolphin/core/context_engineer/utils/context_utils.py +441 -0
- dolphin/core/context_engineer/utils/message_formatter.py +270 -0
- dolphin/core/context_engineer/utils/token_utils.py +139 -0
- dolphin/core/coroutine/__init__.py +15 -0
- dolphin/core/coroutine/context_snapshot.py +154 -0
- dolphin/core/coroutine/context_snapshot_profile.py +922 -0
- dolphin/core/coroutine/context_snapshot_store.py +268 -0
- dolphin/core/coroutine/execution_frame.py +145 -0
- dolphin/core/coroutine/execution_state_registry.py +161 -0
- dolphin/core/coroutine/resume_handle.py +101 -0
- dolphin/core/coroutine/step_result.py +101 -0
- dolphin/core/executor/__init__.py +18 -0
- dolphin/core/executor/debug_controller.py +630 -0
- dolphin/core/executor/dolphin_executor.py +1063 -0
- dolphin/core/executor/executor.py +624 -0
- dolphin/core/flags/__init__.py +27 -0
- dolphin/core/flags/definitions.py +49 -0
- dolphin/core/flags/manager.py +113 -0
- dolphin/core/hook/__init__.py +95 -0
- dolphin/core/hook/expression_evaluator.py +499 -0
- dolphin/core/hook/hook_dispatcher.py +380 -0
- dolphin/core/hook/hook_types.py +248 -0
- dolphin/core/hook/isolated_variable_pool.py +284 -0
- dolphin/core/interfaces.py +53 -0
- dolphin/core/llm/__init__.py +0 -0
- dolphin/core/llm/llm.py +495 -0
- dolphin/core/llm/llm_call.py +100 -0
- dolphin/core/llm/llm_client.py +1285 -0
- dolphin/core/llm/message_sanitizer.py +120 -0
- dolphin/core/logging/__init__.py +20 -0
- dolphin/core/logging/logger.py +526 -0
- dolphin/core/message/__init__.py +8 -0
- dolphin/core/message/compressor.py +749 -0
- dolphin/core/parser/__init__.py +8 -0
- dolphin/core/parser/parser.py +405 -0
- dolphin/core/runtime/__init__.py +10 -0
- dolphin/core/runtime/runtime_graph.py +926 -0
- dolphin/core/runtime/runtime_instance.py +446 -0
- dolphin/core/skill/__init__.py +14 -0
- dolphin/core/skill/context_retention.py +157 -0
- dolphin/core/skill/skill_function.py +686 -0
- dolphin/core/skill/skill_matcher.py +282 -0
- dolphin/core/skill/skillkit.py +700 -0
- dolphin/core/skill/skillset.py +72 -0
- dolphin/core/trajectory/__init__.py +10 -0
- dolphin/core/trajectory/recorder.py +189 -0
- dolphin/core/trajectory/trajectory.py +522 -0
- dolphin/core/utils/__init__.py +9 -0
- dolphin/core/utils/cache_kv.py +212 -0
- dolphin/core/utils/tools.py +340 -0
- dolphin/lib/__init__.py +93 -0
- dolphin/lib/debug/__init__.py +8 -0
- dolphin/lib/debug/visualizer.py +409 -0
- dolphin/lib/memory/__init__.py +28 -0
- dolphin/lib/memory/async_processor.py +220 -0
- dolphin/lib/memory/llm_calls.py +195 -0
- dolphin/lib/memory/manager.py +78 -0
- dolphin/lib/memory/sandbox.py +46 -0
- dolphin/lib/memory/storage.py +245 -0
- dolphin/lib/memory/utils.py +51 -0
- dolphin/lib/ontology/__init__.py +12 -0
- dolphin/lib/ontology/basic/__init__.py +0 -0
- dolphin/lib/ontology/basic/base.py +102 -0
- dolphin/lib/ontology/basic/concept.py +130 -0
- dolphin/lib/ontology/basic/object.py +11 -0
- dolphin/lib/ontology/basic/relation.py +63 -0
- dolphin/lib/ontology/datasource/__init__.py +27 -0
- dolphin/lib/ontology/datasource/datasource.py +66 -0
- dolphin/lib/ontology/datasource/oracle_datasource.py +338 -0
- dolphin/lib/ontology/datasource/sql.py +845 -0
- dolphin/lib/ontology/mapping.py +177 -0
- dolphin/lib/ontology/ontology.py +733 -0
- dolphin/lib/ontology/ontology_context.py +16 -0
- dolphin/lib/ontology/ontology_manager.py +107 -0
- dolphin/lib/skill_results/__init__.py +31 -0
- dolphin/lib/skill_results/cache_backend.py +559 -0
- dolphin/lib/skill_results/result_processor.py +181 -0
- dolphin/lib/skill_results/result_reference.py +179 -0
- dolphin/lib/skill_results/skillkit_hook.py +324 -0
- dolphin/lib/skill_results/strategies.py +328 -0
- dolphin/lib/skill_results/strategy_registry.py +150 -0
- dolphin/lib/skillkits/__init__.py +44 -0
- dolphin/lib/skillkits/agent_skillkit.py +155 -0
- dolphin/lib/skillkits/cognitive_skillkit.py +82 -0
- dolphin/lib/skillkits/env_skillkit.py +250 -0
- dolphin/lib/skillkits/mcp_adapter.py +616 -0
- dolphin/lib/skillkits/mcp_skillkit.py +771 -0
- dolphin/lib/skillkits/memory_skillkit.py +650 -0
- dolphin/lib/skillkits/noop_skillkit.py +31 -0
- dolphin/lib/skillkits/ontology_skillkit.py +89 -0
- dolphin/lib/skillkits/plan_act_skillkit.py +452 -0
- dolphin/lib/skillkits/resource/__init__.py +52 -0
- dolphin/lib/skillkits/resource/models/__init__.py +6 -0
- dolphin/lib/skillkits/resource/models/skill_config.py +109 -0
- dolphin/lib/skillkits/resource/models/skill_meta.py +127 -0
- dolphin/lib/skillkits/resource/resource_skillkit.py +393 -0
- dolphin/lib/skillkits/resource/skill_cache.py +215 -0
- dolphin/lib/skillkits/resource/skill_loader.py +395 -0
- dolphin/lib/skillkits/resource/skill_validator.py +406 -0
- dolphin/lib/skillkits/resource_skillkit.py +11 -0
- dolphin/lib/skillkits/search_skillkit.py +163 -0
- dolphin/lib/skillkits/sql_skillkit.py +274 -0
- dolphin/lib/skillkits/system_skillkit.py +509 -0
- dolphin/lib/skillkits/vm_skillkit.py +65 -0
- dolphin/lib/utils/__init__.py +9 -0
- dolphin/lib/utils/data_process.py +207 -0
- dolphin/lib/utils/handle_progress.py +178 -0
- dolphin/lib/utils/security.py +139 -0
- dolphin/lib/utils/text_retrieval.py +462 -0
- dolphin/lib/vm/__init__.py +11 -0
- dolphin/lib/vm/env_executor.py +895 -0
- dolphin/lib/vm/python_session_manager.py +453 -0
- dolphin/lib/vm/vm.py +610 -0
- dolphin/sdk/__init__.py +60 -0
- dolphin/sdk/agent/__init__.py +12 -0
- dolphin/sdk/agent/agent_factory.py +236 -0
- dolphin/sdk/agent/dolphin_agent.py +1106 -0
- dolphin/sdk/api/__init__.py +4 -0
- dolphin/sdk/runtime/__init__.py +8 -0
- dolphin/sdk/runtime/env.py +363 -0
- dolphin/sdk/skill/__init__.py +10 -0
- dolphin/sdk/skill/global_skills.py +706 -0
- dolphin/sdk/skill/traditional_toolkit.py +260 -0
- kweaver_dolphin-0.1.0.dist-info/METADATA +521 -0
- kweaver_dolphin-0.1.0.dist-info/RECORD +199 -0
- kweaver_dolphin-0.1.0.dist-info/WHEEL +5 -0
- kweaver_dolphin-0.1.0.dist-info/entry_points.txt +27 -0
- kweaver_dolphin-0.1.0.dist-info/licenses/LICENSE.txt +201 -0
- kweaver_dolphin-0.1.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Token utility functions."""
|
|
2
|
+
|
|
3
|
+
from typing import Union, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from dolphin.core.common.enums import Messages
|
|
6
|
+
from ..core.tokenizer_service import TokenizerService
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def estimate_tokens(
|
|
10
|
+
text: Union[str, List[str], Dict[str, str]], avg_chars_per_token: float = 4.0
|
|
11
|
+
) -> int:
|
|
12
|
+
"""
|
|
13
|
+
Estimate token count based on character length.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
text: Input text (string, list, or dict)
|
|
17
|
+
avg_chars_per_token: Average characters per token
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Estimated token count
|
|
21
|
+
"""
|
|
22
|
+
if isinstance(text, str):
|
|
23
|
+
return int(len(text) / avg_chars_per_token)
|
|
24
|
+
elif isinstance(text, list):
|
|
25
|
+
return sum(int(len(item) / avg_chars_per_token) for item in text)
|
|
26
|
+
elif isinstance(text, dict):
|
|
27
|
+
total = 0
|
|
28
|
+
for key, value in text.items():
|
|
29
|
+
total += int(len(str(key)) / avg_chars_per_token)
|
|
30
|
+
total += int(len(str(value)) / avg_chars_per_token)
|
|
31
|
+
return total
|
|
32
|
+
else:
|
|
33
|
+
return int(len(str(text)) / avg_chars_per_token)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def count_tokens(
|
|
37
|
+
text: Union[str, List[str], Dict[str, str]],
|
|
38
|
+
tokenizer_service: Optional[TokenizerService] = None,
|
|
39
|
+
) -> int:
|
|
40
|
+
"""
|
|
41
|
+
Count tokens using tokenizer service.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
text: Input text (string, list, or dict)
|
|
45
|
+
tokenizer_service: TokenizerService instance (creates default if None)
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Token count
|
|
49
|
+
"""
|
|
50
|
+
if tokenizer_service is None:
|
|
51
|
+
tokenizer_service = TokenizerService()
|
|
52
|
+
|
|
53
|
+
return tokenizer_service.count_tokens(text)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_text_chunks(
|
|
57
|
+
text: str, max_tokens: int, tokenizer_service: Optional[TokenizerService] = None
|
|
58
|
+
) -> List[str]:
|
|
59
|
+
"""
|
|
60
|
+
Split text into chunks based on token limit.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
text: Input text
|
|
64
|
+
max_tokens: Maximum tokens per chunk
|
|
65
|
+
tokenizer_service: TokenizerService instance
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
List of text chunks
|
|
69
|
+
"""
|
|
70
|
+
if tokenizer_service is None:
|
|
71
|
+
tokenizer_service = TokenizerService()
|
|
72
|
+
|
|
73
|
+
words = text.split()
|
|
74
|
+
chunks = []
|
|
75
|
+
current_chunk = []
|
|
76
|
+
current_tokens = 0
|
|
77
|
+
|
|
78
|
+
for word in words:
|
|
79
|
+
word_tokens = tokenizer_service.count_tokens(word)
|
|
80
|
+
|
|
81
|
+
if current_tokens + word_tokens > max_tokens and current_chunk:
|
|
82
|
+
chunks.append(" ".join(current_chunk))
|
|
83
|
+
current_chunk = [word]
|
|
84
|
+
current_tokens = word_tokens
|
|
85
|
+
else:
|
|
86
|
+
current_chunk.append(word)
|
|
87
|
+
current_tokens += word_tokens
|
|
88
|
+
|
|
89
|
+
if current_chunk:
|
|
90
|
+
chunks.append(" ".join(current_chunk))
|
|
91
|
+
|
|
92
|
+
return chunks
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def truncate_to_tokens(
|
|
96
|
+
text: Union[str, Messages],
|
|
97
|
+
max_tokens: int,
|
|
98
|
+
tokenizer_service: Optional[TokenizerService] = None,
|
|
99
|
+
) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Truncate text to fit within token limit.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
text: Input text (string or Messages)
|
|
105
|
+
max_tokens: Maximum tokens allowed
|
|
106
|
+
tokenizer_service: TokenizerService instance
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
Truncated text
|
|
110
|
+
"""
|
|
111
|
+
if tokenizer_service is None:
|
|
112
|
+
tokenizer_service = TokenizerService()
|
|
113
|
+
|
|
114
|
+
# If it is a Messages type, extract the content of all messages and concatenate them.
|
|
115
|
+
if isinstance(text, Messages):
|
|
116
|
+
contents = []
|
|
117
|
+
for msg in text.messages:
|
|
118
|
+
if hasattr(msg, "content") and msg.content:
|
|
119
|
+
contents.append(str(msg.content))
|
|
120
|
+
text_content = "\n".join(contents)
|
|
121
|
+
else:
|
|
122
|
+
text_content = str(text)
|
|
123
|
+
|
|
124
|
+
if tokenizer_service.count_tokens(text_content) <= max_tokens:
|
|
125
|
+
return text_content
|
|
126
|
+
|
|
127
|
+
words = text_content.split()
|
|
128
|
+
result = []
|
|
129
|
+
current_tokens = 0
|
|
130
|
+
|
|
131
|
+
for word in words:
|
|
132
|
+
word_tokens = tokenizer_service.count_tokens(word)
|
|
133
|
+
|
|
134
|
+
if current_tokens + word_tokens > max_tokens:
|
|
135
|
+
break
|
|
136
|
+
result.append(word)
|
|
137
|
+
current_tokens += word_tokens
|
|
138
|
+
|
|
139
|
+
return " ".join(result)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Coroutine Execution System
|
|
2
|
+
from .execution_frame import ExecutionFrame, FrameStatus
|
|
3
|
+
from .context_snapshot import ContextSnapshot
|
|
4
|
+
from .resume_handle import ResumeHandle
|
|
5
|
+
from .execution_state_registry import ExecutionStateRegistry
|
|
6
|
+
from .context_snapshot_store import ContextSnapshotStore
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"ExecutionFrame",
|
|
10
|
+
"FrameStatus",
|
|
11
|
+
"ContextSnapshot",
|
|
12
|
+
"ResumeHandle",
|
|
13
|
+
"ExecutionStateRegistry",
|
|
14
|
+
"ContextSnapshotStore",
|
|
15
|
+
]
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import uuid
|
|
3
|
+
from dataclasses import dataclass, asdict
|
|
4
|
+
from typing import Dict, List, Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class ContextSnapshot:
|
|
9
|
+
"""Context Snapshot - Saves runtime data at execution time"""
|
|
10
|
+
|
|
11
|
+
snapshot_id: str
|
|
12
|
+
frame_id: str
|
|
13
|
+
timestamp: float
|
|
14
|
+
schema_version: str = "2.0" # Upgrade version number to support context_manager_state
|
|
15
|
+
variables: Dict[str, Any] = None
|
|
16
|
+
messages: List[Dict] = None
|
|
17
|
+
runtime_state: Dict = None
|
|
18
|
+
skillkit_state: Dict = None
|
|
19
|
+
context_manager_state: Dict = None # Added: Save the complete bucket structure
|
|
20
|
+
|
|
21
|
+
def __post_init__(self):
|
|
22
|
+
if self.variables is None:
|
|
23
|
+
self.variables = {}
|
|
24
|
+
if self.messages is None:
|
|
25
|
+
self.messages = []
|
|
26
|
+
if self.runtime_state is None:
|
|
27
|
+
self.runtime_state = {}
|
|
28
|
+
if self.skillkit_state is None:
|
|
29
|
+
self.skillkit_state = {}
|
|
30
|
+
if self.context_manager_state is None:
|
|
31
|
+
self.context_manager_state = {}
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def create_snapshot(
|
|
35
|
+
cls,
|
|
36
|
+
frame_id: str,
|
|
37
|
+
variables: Dict = None,
|
|
38
|
+
messages: List = None,
|
|
39
|
+
runtime_state: Dict = None,
|
|
40
|
+
skillkit_state: Dict = None,
|
|
41
|
+
context_manager_state: Dict = None,
|
|
42
|
+
) -> "ContextSnapshot":
|
|
43
|
+
"""Create Snapshot"""
|
|
44
|
+
return cls(
|
|
45
|
+
snapshot_id=str(uuid.uuid4()),
|
|
46
|
+
frame_id=frame_id,
|
|
47
|
+
timestamp=time.time(),
|
|
48
|
+
variables=variables or {},
|
|
49
|
+
messages=messages or [],
|
|
50
|
+
runtime_state=runtime_state or {},
|
|
51
|
+
skillkit_state=skillkit_state or {},
|
|
52
|
+
context_manager_state=context_manager_state or {},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def encode(self) -> Dict:
|
|
56
|
+
"""Encode as dictionary format for serialization"""
|
|
57
|
+
return asdict(self)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def decode(cls, data: Dict) -> "ContextSnapshot":
|
|
61
|
+
"""Create a snapshot from dictionary decoding"""
|
|
62
|
+
return cls(**data)
|
|
63
|
+
|
|
64
|
+
def get_variable(self, name: str, default_value=None):
|
|
65
|
+
"""Get variable value"""
|
|
66
|
+
return self.variables.get(name, default_value)
|
|
67
|
+
|
|
68
|
+
def set_variable(self, name: str, value: Any):
|
|
69
|
+
"""Set variable value"""
|
|
70
|
+
self.variables[name] = value
|
|
71
|
+
|
|
72
|
+
def update_variables(self, new_variables: Dict[str, Any]):
|
|
73
|
+
"""Batch update variables"""
|
|
74
|
+
self.variables.update(new_variables)
|
|
75
|
+
|
|
76
|
+
def get_message_count(self) -> int:
|
|
77
|
+
"""Get message count"""
|
|
78
|
+
return len(self.messages)
|
|
79
|
+
|
|
80
|
+
def add_message(self, message: Dict):
|
|
81
|
+
"""Add message"""
|
|
82
|
+
self.messages.append(message)
|
|
83
|
+
|
|
84
|
+
def get_size_info(self) -> Dict[str, int]:
|
|
85
|
+
"""Get snapshot size information"""
|
|
86
|
+
import json
|
|
87
|
+
|
|
88
|
+
encoded = self.encode()
|
|
89
|
+
return {
|
|
90
|
+
"variables_count": len(self.variables),
|
|
91
|
+
"messages_count": len(self.messages),
|
|
92
|
+
"total_size_bytes": len(json.dumps(encoded, ensure_ascii=False)),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
def profile(
|
|
96
|
+
self,
|
|
97
|
+
format: str = 'markdown',
|
|
98
|
+
title: str = None,
|
|
99
|
+
options: Dict = None
|
|
100
|
+
):
|
|
101
|
+
"""Visual analysis report for generating snapshots
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
format: Output format, 'markdown' or 'json'
|
|
105
|
+
title: Custom title (used only for markdown)
|
|
106
|
+
options: Configuration options dictionary
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
str (markdown) or Dict (json)
|
|
110
|
+
|
|
111
|
+
Examples:
|
|
112
|
+
# Basic usage
|
|
113
|
+
profile_md = snapshot.profile()
|
|
114
|
+
print(profile_md)
|
|
115
|
+
|
|
116
|
+
# JSON output
|
|
117
|
+
profile_json = snapshot.profile(format='json')
|
|
118
|
+
|
|
119
|
+
# Custom configuration
|
|
120
|
+
profile = snapshot.profile(
|
|
121
|
+
format='markdown',
|
|
122
|
+
title='Step 5: After Processing',
|
|
123
|
+
options={
|
|
124
|
+
'size_thresholds': {
|
|
125
|
+
'message_bytes': [1000, 10000],
|
|
126
|
+
'variable_bytes': [1000, 10000]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
"""
|
|
131
|
+
from .context_snapshot_profile import (
|
|
132
|
+
SnapshotProfileAnalyzer,
|
|
133
|
+
ProfileOptions,
|
|
134
|
+
MarkdownFormatter,
|
|
135
|
+
JSONFormatter
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Parse options
|
|
139
|
+
if options is None:
|
|
140
|
+
profile_options = ProfileOptions()
|
|
141
|
+
else:
|
|
142
|
+
profile_options = ProfileOptions(**options)
|
|
143
|
+
|
|
144
|
+
# Analyze Snapshot
|
|
145
|
+
analyzer = SnapshotProfileAnalyzer(self, profile_options)
|
|
146
|
+
snapshot_profile = analyzer.analyze()
|
|
147
|
+
|
|
148
|
+
# Formatted output
|
|
149
|
+
if format == 'json':
|
|
150
|
+
formatter = JSONFormatter(snapshot_profile)
|
|
151
|
+
return formatter.format()
|
|
152
|
+
else: # markdown
|
|
153
|
+
formatter = MarkdownFormatter(snapshot_profile, title=title, options=profile_options)
|
|
154
|
+
return formatter.format()
|