hud-python 0.4.1__py3-none-any.whl → 0.4.3__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 hud-python might be problematic. Click here for more details.
- hud/__init__.py +22 -22
- hud/agents/__init__.py +13 -15
- hud/agents/base.py +599 -599
- hud/agents/claude.py +373 -373
- hud/agents/langchain.py +261 -250
- hud/agents/misc/__init__.py +7 -7
- hud/agents/misc/response_agent.py +82 -80
- hud/agents/openai.py +352 -352
- hud/agents/openai_chat_generic.py +154 -154
- hud/agents/tests/__init__.py +1 -1
- hud/agents/tests/test_base.py +742 -742
- hud/agents/tests/test_claude.py +324 -324
- hud/agents/tests/test_client.py +363 -363
- hud/agents/tests/test_openai.py +237 -237
- hud/cli/__init__.py +617 -617
- hud/cli/__main__.py +8 -8
- hud/cli/analyze.py +371 -371
- hud/cli/analyze_metadata.py +230 -230
- hud/cli/build.py +498 -427
- hud/cli/clone.py +185 -185
- hud/cli/cursor.py +92 -92
- hud/cli/debug.py +392 -392
- hud/cli/docker_utils.py +83 -83
- hud/cli/init.py +280 -281
- hud/cli/interactive.py +353 -353
- hud/cli/mcp_server.py +764 -756
- hud/cli/pull.py +330 -336
- hud/cli/push.py +404 -370
- hud/cli/remote_runner.py +311 -311
- hud/cli/runner.py +160 -160
- hud/cli/tests/__init__.py +3 -3
- hud/cli/tests/test_analyze.py +284 -284
- hud/cli/tests/test_cli_init.py +265 -265
- hud/cli/tests/test_cli_main.py +27 -27
- hud/cli/tests/test_clone.py +142 -142
- hud/cli/tests/test_cursor.py +253 -253
- hud/cli/tests/test_debug.py +453 -453
- hud/cli/tests/test_mcp_server.py +139 -139
- hud/cli/tests/test_utils.py +388 -388
- hud/cli/utils.py +263 -263
- hud/clients/README.md +143 -143
- hud/clients/__init__.py +16 -16
- hud/clients/base.py +378 -379
- hud/clients/fastmcp.py +222 -222
- hud/clients/mcp_use.py +298 -278
- hud/clients/tests/__init__.py +1 -1
- hud/clients/tests/test_client_integration.py +111 -111
- hud/clients/tests/test_fastmcp.py +342 -342
- hud/clients/tests/test_protocol.py +188 -188
- hud/clients/utils/__init__.py +1 -1
- hud/clients/utils/retry_transport.py +160 -160
- hud/datasets.py +327 -322
- hud/misc/__init__.py +1 -1
- hud/misc/claude_plays_pokemon.py +292 -292
- hud/otel/__init__.py +35 -35
- hud/otel/collector.py +142 -142
- hud/otel/config.py +164 -164
- hud/otel/context.py +536 -536
- hud/otel/exporters.py +366 -366
- hud/otel/instrumentation.py +97 -97
- hud/otel/processors.py +118 -118
- hud/otel/tests/__init__.py +1 -1
- hud/otel/tests/test_processors.py +197 -197
- hud/server/__init__.py +5 -5
- hud/server/context.py +114 -114
- hud/server/helper/__init__.py +5 -5
- hud/server/low_level.py +132 -132
- hud/server/server.py +170 -166
- hud/server/tests/__init__.py +3 -3
- hud/settings.py +73 -73
- hud/shared/__init__.py +5 -5
- hud/shared/exceptions.py +180 -180
- hud/shared/requests.py +264 -264
- hud/shared/tests/test_exceptions.py +157 -157
- hud/shared/tests/test_requests.py +275 -275
- hud/telemetry/__init__.py +25 -25
- hud/telemetry/instrument.py +379 -379
- hud/telemetry/job.py +309 -309
- hud/telemetry/replay.py +74 -74
- hud/telemetry/trace.py +83 -83
- hud/tools/__init__.py +33 -33
- hud/tools/base.py +365 -365
- hud/tools/bash.py +161 -161
- hud/tools/computer/__init__.py +15 -15
- hud/tools/computer/anthropic.py +437 -437
- hud/tools/computer/hud.py +376 -376
- hud/tools/computer/openai.py +295 -295
- hud/tools/computer/settings.py +82 -82
- hud/tools/edit.py +314 -314
- hud/tools/executors/__init__.py +30 -30
- hud/tools/executors/base.py +539 -539
- hud/tools/executors/pyautogui.py +621 -621
- hud/tools/executors/tests/__init__.py +1 -1
- hud/tools/executors/tests/test_base_executor.py +338 -338
- hud/tools/executors/tests/test_pyautogui_executor.py +165 -165
- hud/tools/executors/xdo.py +511 -511
- hud/tools/playwright.py +412 -412
- hud/tools/tests/__init__.py +3 -3
- hud/tools/tests/test_base.py +282 -282
- hud/tools/tests/test_bash.py +158 -158
- hud/tools/tests/test_bash_extended.py +197 -197
- hud/tools/tests/test_computer.py +425 -425
- hud/tools/tests/test_computer_actions.py +34 -34
- hud/tools/tests/test_edit.py +259 -259
- hud/tools/tests/test_init.py +27 -27
- hud/tools/tests/test_playwright_tool.py +183 -183
- hud/tools/tests/test_tools.py +145 -145
- hud/tools/tests/test_utils.py +156 -156
- hud/tools/types.py +72 -72
- hud/tools/utils.py +50 -50
- hud/types.py +136 -136
- hud/utils/__init__.py +10 -10
- hud/utils/async_utils.py +65 -65
- hud/utils/design.py +236 -168
- hud/utils/mcp.py +55 -55
- hud/utils/progress.py +149 -149
- hud/utils/telemetry.py +66 -66
- hud/utils/tests/test_async_utils.py +173 -173
- hud/utils/tests/test_init.py +17 -17
- hud/utils/tests/test_progress.py +261 -261
- hud/utils/tests/test_telemetry.py +82 -82
- hud/utils/tests/test_version.py +8 -8
- hud/version.py +7 -7
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/METADATA +10 -8
- hud_python-0.4.3.dist-info/RECORD +131 -0
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/licenses/LICENSE +21 -21
- hud/agents/art.py +0 -101
- hud_python-0.4.1.dist-info/RECORD +0 -132
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/WHEEL +0 -0
- {hud_python-0.4.1.dist-info → hud_python-0.4.3.dist-info}/entry_points.txt +0 -0
hud/utils/design.py
CHANGED
|
@@ -1,168 +1,236 @@
|
|
|
1
|
-
"""HUD Design System - Consistent styling utilities for CLI output.
|
|
2
|
-
|
|
3
|
-
This module provides a unified design system for HUD CLI commands,
|
|
4
|
-
ensuring consistent colors, formatting, and visual hierarchy across
|
|
5
|
-
all commands.
|
|
6
|
-
|
|
7
|
-
Color Palette:
|
|
8
|
-
- Gold (#c0960c): Primary brand color for headers and important elements
|
|
9
|
-
- Black: Standard text and underlined links
|
|
10
|
-
- Red: Errors and failures
|
|
11
|
-
- Green: Success messages
|
|
12
|
-
- Dim/Gray: Secondary information
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
from __future__ import annotations
|
|
16
|
-
|
|
17
|
-
from rich.console import Console
|
|
18
|
-
from rich.panel import Panel
|
|
19
|
-
from rich.table import Table
|
|
20
|
-
|
|
21
|
-
# HUD Brand Colors
|
|
22
|
-
GOLD = "rgb(192,150,12)" # #c0960c
|
|
23
|
-
RED = "red"
|
|
24
|
-
GREEN = "green"
|
|
25
|
-
DIM = "dim"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class HUDDesign:
|
|
29
|
-
"""Design system for HUD CLI output."""
|
|
30
|
-
|
|
31
|
-
def __init__(self
|
|
32
|
-
"""Initialize the design system.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def success(self, message: str) -> None:
|
|
58
|
-
"""Print a success message.
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
message: The success message
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"""
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
""
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
"""
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
""
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
1
|
+
"""HUD Design System - Consistent styling utilities for CLI output.
|
|
2
|
+
|
|
3
|
+
This module provides a unified design system for HUD CLI commands,
|
|
4
|
+
ensuring consistent colors, formatting, and visual hierarchy across
|
|
5
|
+
all commands.
|
|
6
|
+
|
|
7
|
+
Color Palette:
|
|
8
|
+
- Gold (#c0960c): Primary brand color for headers and important elements
|
|
9
|
+
- Black: Standard text and underlined links
|
|
10
|
+
- Red: Errors and failures
|
|
11
|
+
- Green: Success messages
|
|
12
|
+
- Dim/Gray: Secondary information
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from rich.console import Console
|
|
18
|
+
from rich.panel import Panel
|
|
19
|
+
from rich.table import Table
|
|
20
|
+
|
|
21
|
+
# HUD Brand Colors
|
|
22
|
+
GOLD = "rgb(192,150,12)" # #c0960c
|
|
23
|
+
RED = "red"
|
|
24
|
+
GREEN = "green"
|
|
25
|
+
DIM = "dim"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class HUDDesign:
|
|
29
|
+
"""Design system for HUD CLI output."""
|
|
30
|
+
|
|
31
|
+
def __init__(self) -> None:
|
|
32
|
+
"""Initialize the design system."""
|
|
33
|
+
self._stdout_console = Console(stderr=False)
|
|
34
|
+
self._stderr_console = Console(stderr=True)
|
|
35
|
+
|
|
36
|
+
def header(self, title: str, icon: str = "🚀", stderr: bool = True) -> None:
|
|
37
|
+
"""Print a header panel with gold border.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
title: The title text
|
|
41
|
+
icon: Optional emoji icon
|
|
42
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
43
|
+
"""
|
|
44
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
45
|
+
console.print(Panel.fit(f"{icon} [bold]{title}[/bold]", border_style=GOLD))
|
|
46
|
+
|
|
47
|
+
def section_title(self, title: str, stderr: bool = True) -> None:
|
|
48
|
+
"""Print a section title in gold.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
title: The section title
|
|
52
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
53
|
+
"""
|
|
54
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
55
|
+
console.print(f"\n[bold {GOLD}]{title}[/bold {GOLD}]")
|
|
56
|
+
|
|
57
|
+
def success(self, message: str, stderr: bool = True) -> None:
|
|
58
|
+
"""Print a success message.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
message: The success message
|
|
62
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
63
|
+
"""
|
|
64
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
65
|
+
console.print(f"[{GREEN} not bold]✅ {message}[/{GREEN} not bold]")
|
|
66
|
+
|
|
67
|
+
def error(self, message: str, stderr: bool = True) -> None:
|
|
68
|
+
"""Print an error message.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
message: The error message
|
|
72
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
73
|
+
"""
|
|
74
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
75
|
+
console.print(f"[{RED} not bold]❌ {message}[/{RED} not bold]")
|
|
76
|
+
|
|
77
|
+
def warning(self, message: str, stderr: bool = True) -> None:
|
|
78
|
+
"""Print a warning message.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
message: The warning message
|
|
82
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
83
|
+
"""
|
|
84
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
85
|
+
console.print(f"[yellow]⚠️ {message}[/yellow]")
|
|
86
|
+
|
|
87
|
+
def info(self, message: str, stderr: bool = True) -> None:
|
|
88
|
+
"""Print an info message.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
message: The info message
|
|
92
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
93
|
+
"""
|
|
94
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
95
|
+
console.print(f"[default not bold]{message}[/default not bold]")
|
|
96
|
+
|
|
97
|
+
def dim_info(self, label: str, value: str, stderr: bool = True) -> None:
|
|
98
|
+
"""Print dimmed info with a label.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
label: The label text
|
|
102
|
+
value: The value text
|
|
103
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
104
|
+
"""
|
|
105
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
106
|
+
console.print(f"[{DIM}]{label}[/{DIM}] [default]{value}[/default]")
|
|
107
|
+
|
|
108
|
+
def link(self, url: str, stderr: bool = True) -> None:
|
|
109
|
+
"""Print an underlined link.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
url: The URL to display
|
|
113
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
114
|
+
"""
|
|
115
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
116
|
+
console.print(f"[default not bold underline]{url}[/default not bold underline]")
|
|
117
|
+
|
|
118
|
+
def json_config(self, json_str: str, stderr: bool = True) -> None:
|
|
119
|
+
"""Print JSON configuration with light theme.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
json_str: JSON string to display
|
|
123
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
124
|
+
"""
|
|
125
|
+
# Just print the JSON as plain text to avoid any syntax coloring
|
|
126
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
127
|
+
console.print(f"[default not bold]{json_str}[/default not bold]")
|
|
128
|
+
|
|
129
|
+
def key_value_table(self, data: dict[str, str], show_header: bool = False, stderr: bool = True) -> None:
|
|
130
|
+
"""Print a key-value table.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
data: Dictionary of key-value pairs
|
|
134
|
+
show_header: Whether to show table header
|
|
135
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
136
|
+
"""
|
|
137
|
+
table = Table(show_header=show_header, box=None, padding=(0, 1))
|
|
138
|
+
table.add_column("Key", style=DIM, no_wrap=True)
|
|
139
|
+
table.add_column("Value")
|
|
140
|
+
|
|
141
|
+
for key, value in data.items():
|
|
142
|
+
table.add_row(key, value)
|
|
143
|
+
|
|
144
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
145
|
+
console.print(table)
|
|
146
|
+
|
|
147
|
+
def progress_message(self, message: str, stderr: bool = True) -> None:
|
|
148
|
+
"""Print a progress message.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
message: The progress message
|
|
152
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
153
|
+
"""
|
|
154
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
155
|
+
console.print(f"[{DIM} not bold]{message}[/{DIM} not bold]")
|
|
156
|
+
|
|
157
|
+
def phase(self, phase_num: int, title: str, stderr: bool = True) -> None:
|
|
158
|
+
"""Print a phase header (for debug command).
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
phase_num: Phase number
|
|
162
|
+
title: Phase title
|
|
163
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
164
|
+
"""
|
|
165
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
166
|
+
console.print(f"\n{'=' * 80}", style=GOLD)
|
|
167
|
+
console.print(f"[bold {GOLD}]PHASE {phase_num}: {title}[/bold {GOLD}]")
|
|
168
|
+
console.print(f"{'=' * 80}", style=GOLD)
|
|
169
|
+
|
|
170
|
+
def command(self, cmd: list[str], stderr: bool = True) -> None:
|
|
171
|
+
"""Print a command being executed.
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
cmd: Command parts as list
|
|
175
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
176
|
+
"""
|
|
177
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
178
|
+
console.print(f"[bold]$ {' '.join(cmd)}[/bold]")
|
|
179
|
+
|
|
180
|
+
def hint(self, hint: str, stderr: bool = True) -> None:
|
|
181
|
+
"""Print a hint message.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
hint: The hint text
|
|
185
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
186
|
+
"""
|
|
187
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
188
|
+
console.print(f"\n[yellow]💡 Hint: {hint}[/yellow]")
|
|
189
|
+
|
|
190
|
+
def status_item(self, label: str, value: str, status: str = "success", primary: bool = False, stderr: bool = True) -> None:
|
|
191
|
+
"""Print a status item with indicator.
|
|
192
|
+
|
|
193
|
+
Args:
|
|
194
|
+
label: The label text
|
|
195
|
+
value: The value text
|
|
196
|
+
status: Status type - "success" (✓), "error" (✗), "warning" (⚠), "info" (•)
|
|
197
|
+
primary: If True, highlight the value as primary
|
|
198
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
199
|
+
"""
|
|
200
|
+
indicators = {
|
|
201
|
+
"success": f"[{GREEN} not bold]✓[/{GREEN} not bold]",
|
|
202
|
+
"error": f"[{RED} not bold]✗[/{RED} not bold]",
|
|
203
|
+
"warning": "[yellow]⚠[/yellow]",
|
|
204
|
+
"info": f"[{DIM}]•[/{DIM}]"
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
indicator = indicators.get(status, indicators["info"])
|
|
208
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
209
|
+
|
|
210
|
+
if primary:
|
|
211
|
+
console.print(f"{indicator} {label}: [bold cyan]{value}[/bold cyan]")
|
|
212
|
+
else:
|
|
213
|
+
console.print(f"{indicator} {label}: {value}")
|
|
214
|
+
|
|
215
|
+
def command_example(self, command: str, description: str | None = None, stderr: bool = True) -> None:
|
|
216
|
+
"""Print a command example with cyan highlighting.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
command: The command to show
|
|
220
|
+
description: Optional description after the command
|
|
221
|
+
stderr: If True, output to stderr (default), otherwise stdout
|
|
222
|
+
"""
|
|
223
|
+
console = self._stderr_console if stderr else self._stdout_console
|
|
224
|
+
if description:
|
|
225
|
+
console.print(f" [cyan]{command}[/cyan] # {description}")
|
|
226
|
+
else:
|
|
227
|
+
console.print(f" [cyan]{command}[/cyan]")
|
|
228
|
+
|
|
229
|
+
@property
|
|
230
|
+
def console(self) -> Console:
|
|
231
|
+
"""Get the stderr console for direct access when needed."""
|
|
232
|
+
return self._stderr_console
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
# Global design instance for convenience
|
|
236
|
+
design = HUDDesign()
|
hud/utils/mcp.py
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
|
-
from pydantic import BaseModel, Field
|
|
6
|
-
|
|
7
|
-
from hud.settings import settings
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class MCPConfigPatch(BaseModel):
|
|
11
|
-
"""Patch for MCP config."""
|
|
12
|
-
|
|
13
|
-
headers: dict[str, Any] | None = Field(default_factory=dict, alias="headers")
|
|
14
|
-
meta: dict[str, Any] | None = Field(default_factory=dict, alias="meta")
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def patch_mcp_config(mcp_config: dict[str, dict[str, Any]], patch: MCPConfigPatch) -> None:
|
|
18
|
-
"""Patch MCP config with additional values."""
|
|
19
|
-
hud_mcp_url = settings.hud_mcp_url
|
|
20
|
-
|
|
21
|
-
for server_cfg in mcp_config.values():
|
|
22
|
-
url = server_cfg.get("url", "")
|
|
23
|
-
|
|
24
|
-
# 1) HTTP header lane (only for hud MCP servers)
|
|
25
|
-
if hud_mcp_url in url and patch.headers:
|
|
26
|
-
for key, value in patch.headers.items():
|
|
27
|
-
headers = server_cfg.setdefault("headers", {})
|
|
28
|
-
headers.setdefault(key, value)
|
|
29
|
-
|
|
30
|
-
# 2) Metadata lane (for all servers)
|
|
31
|
-
if patch.meta:
|
|
32
|
-
for key, value in patch.meta.items():
|
|
33
|
-
meta = server_cfg.setdefault("meta", {})
|
|
34
|
-
meta.setdefault(key, value)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def setup_hud_telemetry(mcp_config: dict[str, dict[str, Any]], auto_trace: bool = True) -> None:
|
|
38
|
-
"""Setup telemetry for hud servers."""
|
|
39
|
-
if not mcp_config:
|
|
40
|
-
raise ValueError("Please run initialize() before setting up client-side telemetry")
|
|
41
|
-
|
|
42
|
-
from hud.otel import get_current_task_run_id
|
|
43
|
-
from hud.telemetry import trace
|
|
44
|
-
|
|
45
|
-
run_id = get_current_task_run_id()
|
|
46
|
-
if not run_id and auto_trace:
|
|
47
|
-
auto_trace_cm = trace("My Trace")
|
|
48
|
-
run_id = auto_trace_cm.__enter__()
|
|
49
|
-
|
|
50
|
-
# Patch HUD servers with run-id (works whether auto or user trace)
|
|
51
|
-
if run_id:
|
|
52
|
-
patch_mcp_config(
|
|
53
|
-
mcp_config,
|
|
54
|
-
MCPConfigPatch(headers={"Run-Id": run_id}, meta={"run_id": run_id}),
|
|
55
|
-
)
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
|
+
|
|
7
|
+
from hud.settings import settings
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MCPConfigPatch(BaseModel):
|
|
11
|
+
"""Patch for MCP config."""
|
|
12
|
+
|
|
13
|
+
headers: dict[str, Any] | None = Field(default_factory=dict, alias="headers")
|
|
14
|
+
meta: dict[str, Any] | None = Field(default_factory=dict, alias="meta")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def patch_mcp_config(mcp_config: dict[str, dict[str, Any]], patch: MCPConfigPatch) -> None:
|
|
18
|
+
"""Patch MCP config with additional values."""
|
|
19
|
+
hud_mcp_url = settings.hud_mcp_url
|
|
20
|
+
|
|
21
|
+
for server_cfg in mcp_config.values():
|
|
22
|
+
url = server_cfg.get("url", "")
|
|
23
|
+
|
|
24
|
+
# 1) HTTP header lane (only for hud MCP servers)
|
|
25
|
+
if hud_mcp_url in url and patch.headers:
|
|
26
|
+
for key, value in patch.headers.items():
|
|
27
|
+
headers = server_cfg.setdefault("headers", {})
|
|
28
|
+
headers.setdefault(key, value)
|
|
29
|
+
|
|
30
|
+
# 2) Metadata lane (for all servers)
|
|
31
|
+
if patch.meta:
|
|
32
|
+
for key, value in patch.meta.items():
|
|
33
|
+
meta = server_cfg.setdefault("meta", {})
|
|
34
|
+
meta.setdefault(key, value)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def setup_hud_telemetry(mcp_config: dict[str, dict[str, Any]], auto_trace: bool = True) -> None:
|
|
38
|
+
"""Setup telemetry for hud servers."""
|
|
39
|
+
if not mcp_config:
|
|
40
|
+
raise ValueError("Please run initialize() before setting up client-side telemetry")
|
|
41
|
+
|
|
42
|
+
from hud.otel import get_current_task_run_id
|
|
43
|
+
from hud.telemetry import trace
|
|
44
|
+
|
|
45
|
+
run_id = get_current_task_run_id()
|
|
46
|
+
if not run_id and auto_trace:
|
|
47
|
+
auto_trace_cm = trace("My Trace")
|
|
48
|
+
run_id = auto_trace_cm.__enter__()
|
|
49
|
+
|
|
50
|
+
# Patch HUD servers with run-id (works whether auto or user trace)
|
|
51
|
+
if run_id:
|
|
52
|
+
patch_mcp_config(
|
|
53
|
+
mcp_config,
|
|
54
|
+
MCPConfigPatch(headers={"Run-Id": run_id}, meta={"run_id": run_id}),
|
|
55
|
+
)
|