hud-python 0.4.0__py3-none-any.whl → 0.4.2__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 -17
- hud/agents/base.py +599 -599
- hud/agents/claude.py +373 -373
- hud/agents/langchain.py +250 -250
- hud/agents/misc/__init__.py +7 -7
- hud/agents/misc/response_agent.py +80 -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 +427 -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 +281 -281
- hud/cli/interactive.py +353 -353
- hud/cli/mcp_server.py +789 -756
- hud/cli/pull.py +336 -336
- hud/cli/push.py +370 -379
- 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 +379 -354
- hud/clients/fastmcp.py +202 -202
- hud/clients/mcp_use.py +278 -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 +322 -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 +168 -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.0.dist-info → hud_python-0.4.2.dist-info}/METADATA +23 -19
- hud_python-0.4.2.dist-info/RECORD +131 -0
- {hud_python-0.4.0.dist-info → hud_python-0.4.2.dist-info}/licenses/LICENSE +21 -21
- hud/agents/art.py +0 -101
- hud_python-0.4.0.dist-info/RECORD +0 -132
- {hud_python-0.4.0.dist-info → hud_python-0.4.2.dist-info}/WHEEL +0 -0
- {hud_python-0.4.0.dist-info → hud_python-0.4.2.dist-info}/entry_points.txt +0 -0
hud/utils/design.py
CHANGED
|
@@ -1,168 +1,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, console: Console | None = None, stderr: bool = False) -> None:
|
|
32
|
-
"""Initialize the design system.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
console: Rich console instance. Creates new one if not provided.
|
|
36
|
-
stderr: If True, output to stderr instead of stdout.
|
|
37
|
-
"""
|
|
38
|
-
self.console = console or Console(stderr=stderr)
|
|
39
|
-
|
|
40
|
-
def header(self, title: str, icon: str = "🚀") -> None:
|
|
41
|
-
"""Print a header panel with gold border.
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
title: The title text
|
|
45
|
-
icon: Optional emoji icon
|
|
46
|
-
"""
|
|
47
|
-
self.console.print(Panel.fit(f"{icon} [bold]{title}[/bold]", border_style=GOLD))
|
|
48
|
-
|
|
49
|
-
def section_title(self, title: str) -> None:
|
|
50
|
-
"""Print a section title in gold.
|
|
51
|
-
|
|
52
|
-
Args:
|
|
53
|
-
title: The section title
|
|
54
|
-
"""
|
|
55
|
-
self.console.print(f"\n[bold {GOLD}]{title}[/bold {GOLD}]")
|
|
56
|
-
|
|
57
|
-
def success(self, message: str) -> None:
|
|
58
|
-
"""Print a success message.
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
message: The success message
|
|
62
|
-
"""
|
|
63
|
-
self.console.print(f"[{GREEN} not bold]✅ {message}[/{GREEN} not bold]")
|
|
64
|
-
|
|
65
|
-
def error(self, message: str) -> None:
|
|
66
|
-
"""Print an error message.
|
|
67
|
-
|
|
68
|
-
Args:
|
|
69
|
-
message: The error message
|
|
70
|
-
"""
|
|
71
|
-
self.console.print(f"[{RED} not bold]❌ {message}[/{RED} not bold]")
|
|
72
|
-
|
|
73
|
-
def warning(self, message: str) -> None:
|
|
74
|
-
"""Print a warning message.
|
|
75
|
-
|
|
76
|
-
Args:
|
|
77
|
-
message: The warning message
|
|
78
|
-
"""
|
|
79
|
-
self.console.print(f"[yellow]⚠️ {message}[/yellow]")
|
|
80
|
-
|
|
81
|
-
def info(self, message: str) -> None:
|
|
82
|
-
"""Print an info message.
|
|
83
|
-
|
|
84
|
-
Args:
|
|
85
|
-
message: The info message
|
|
86
|
-
"""
|
|
87
|
-
self.console.print(f"[default not bold]{message}[/default not bold]")
|
|
88
|
-
|
|
89
|
-
def dim_info(self, label: str, value: str) -> None:
|
|
90
|
-
"""Print dimmed info with a label.
|
|
91
|
-
|
|
92
|
-
Args:
|
|
93
|
-
label: The label text
|
|
94
|
-
value: The value text
|
|
95
|
-
"""
|
|
96
|
-
self.console.print(f"[{DIM}]{label}[/{DIM}] [default]{value}[/default]")
|
|
97
|
-
|
|
98
|
-
def link(self, url: str) -> None:
|
|
99
|
-
"""Print an underlined link.
|
|
100
|
-
|
|
101
|
-
Args:
|
|
102
|
-
url: The URL to display
|
|
103
|
-
"""
|
|
104
|
-
self.console.print(f"[default not bold underline]{url}[/default not bold underline]")
|
|
105
|
-
|
|
106
|
-
def json_config(self, json_str: str) -> None:
|
|
107
|
-
"""Print JSON configuration with light theme.
|
|
108
|
-
|
|
109
|
-
Args:
|
|
110
|
-
json_str: JSON string to display
|
|
111
|
-
"""
|
|
112
|
-
# Just print the JSON as plain text to avoid any syntax coloring
|
|
113
|
-
self.console.print(f"[default not bold]{json_str}[/default not bold]")
|
|
114
|
-
|
|
115
|
-
def key_value_table(self, data: dict[str, str], show_header: bool = False) -> None:
|
|
116
|
-
"""Print a key-value table.
|
|
117
|
-
|
|
118
|
-
Args:
|
|
119
|
-
data: Dictionary of key-value pairs
|
|
120
|
-
show_header: Whether to show table header
|
|
121
|
-
"""
|
|
122
|
-
table = Table(show_header=show_header, box=None, padding=(0, 1))
|
|
123
|
-
table.add_column("Key", style=DIM, no_wrap=True)
|
|
124
|
-
table.add_column("Value")
|
|
125
|
-
|
|
126
|
-
for key, value in data.items():
|
|
127
|
-
table.add_row(key, value)
|
|
128
|
-
|
|
129
|
-
self.console.print(table)
|
|
130
|
-
|
|
131
|
-
def progress_message(self, message: str) -> None:
|
|
132
|
-
"""Print a progress message.
|
|
133
|
-
|
|
134
|
-
Args:
|
|
135
|
-
message: The progress message
|
|
136
|
-
"""
|
|
137
|
-
self.console.print(f"[{DIM} not bold]{message}[/{DIM} not bold]")
|
|
138
|
-
|
|
139
|
-
def phase(self, phase_num: int, title: str) -> None:
|
|
140
|
-
"""Print a phase header (for debug command).
|
|
141
|
-
|
|
142
|
-
Args:
|
|
143
|
-
phase_num: Phase number
|
|
144
|
-
title: Phase title
|
|
145
|
-
"""
|
|
146
|
-
self.console.print(f"\n{'=' * 80}", style=GOLD)
|
|
147
|
-
self.console.print(f"[bold {GOLD}]PHASE {phase_num}: {title}[/bold {GOLD}]")
|
|
148
|
-
self.console.print(f"{'=' * 80}", style=GOLD)
|
|
149
|
-
|
|
150
|
-
def command(self, cmd: list[str]) -> None:
|
|
151
|
-
"""Print a command being executed.
|
|
152
|
-
|
|
153
|
-
Args:
|
|
154
|
-
cmd: Command parts as list
|
|
155
|
-
"""
|
|
156
|
-
self.console.print(f"[bold]$ {' '.join(cmd)}[/bold]")
|
|
157
|
-
|
|
158
|
-
def hint(self, hint: str) -> None:
|
|
159
|
-
"""Print a hint message.
|
|
160
|
-
|
|
161
|
-
Args:
|
|
162
|
-
hint: The hint text
|
|
163
|
-
"""
|
|
164
|
-
self.console.print(f"\n[yellow]💡 Hint: {hint}[/yellow]")
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
# Global design instance for convenience
|
|
168
|
-
design = HUDDesign()
|
|
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, console: Console | None = None, stderr: bool = False) -> None:
|
|
32
|
+
"""Initialize the design system.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
console: Rich console instance. Creates new one if not provided.
|
|
36
|
+
stderr: If True, output to stderr instead of stdout.
|
|
37
|
+
"""
|
|
38
|
+
self.console = console or Console(stderr=stderr)
|
|
39
|
+
|
|
40
|
+
def header(self, title: str, icon: str = "🚀") -> None:
|
|
41
|
+
"""Print a header panel with gold border.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
title: The title text
|
|
45
|
+
icon: Optional emoji icon
|
|
46
|
+
"""
|
|
47
|
+
self.console.print(Panel.fit(f"{icon} [bold]{title}[/bold]", border_style=GOLD))
|
|
48
|
+
|
|
49
|
+
def section_title(self, title: str) -> None:
|
|
50
|
+
"""Print a section title in gold.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
title: The section title
|
|
54
|
+
"""
|
|
55
|
+
self.console.print(f"\n[bold {GOLD}]{title}[/bold {GOLD}]")
|
|
56
|
+
|
|
57
|
+
def success(self, message: str) -> None:
|
|
58
|
+
"""Print a success message.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
message: The success message
|
|
62
|
+
"""
|
|
63
|
+
self.console.print(f"[{GREEN} not bold]✅ {message}[/{GREEN} not bold]")
|
|
64
|
+
|
|
65
|
+
def error(self, message: str) -> None:
|
|
66
|
+
"""Print an error message.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
message: The error message
|
|
70
|
+
"""
|
|
71
|
+
self.console.print(f"[{RED} not bold]❌ {message}[/{RED} not bold]")
|
|
72
|
+
|
|
73
|
+
def warning(self, message: str) -> None:
|
|
74
|
+
"""Print a warning message.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
message: The warning message
|
|
78
|
+
"""
|
|
79
|
+
self.console.print(f"[yellow]⚠️ {message}[/yellow]")
|
|
80
|
+
|
|
81
|
+
def info(self, message: str) -> None:
|
|
82
|
+
"""Print an info message.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
message: The info message
|
|
86
|
+
"""
|
|
87
|
+
self.console.print(f"[default not bold]{message}[/default not bold]")
|
|
88
|
+
|
|
89
|
+
def dim_info(self, label: str, value: str) -> None:
|
|
90
|
+
"""Print dimmed info with a label.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
label: The label text
|
|
94
|
+
value: The value text
|
|
95
|
+
"""
|
|
96
|
+
self.console.print(f"[{DIM}]{label}[/{DIM}] [default]{value}[/default]")
|
|
97
|
+
|
|
98
|
+
def link(self, url: str) -> None:
|
|
99
|
+
"""Print an underlined link.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
url: The URL to display
|
|
103
|
+
"""
|
|
104
|
+
self.console.print(f"[default not bold underline]{url}[/default not bold underline]")
|
|
105
|
+
|
|
106
|
+
def json_config(self, json_str: str) -> None:
|
|
107
|
+
"""Print JSON configuration with light theme.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
json_str: JSON string to display
|
|
111
|
+
"""
|
|
112
|
+
# Just print the JSON as plain text to avoid any syntax coloring
|
|
113
|
+
self.console.print(f"[default not bold]{json_str}[/default not bold]")
|
|
114
|
+
|
|
115
|
+
def key_value_table(self, data: dict[str, str], show_header: bool = False) -> None:
|
|
116
|
+
"""Print a key-value table.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
data: Dictionary of key-value pairs
|
|
120
|
+
show_header: Whether to show table header
|
|
121
|
+
"""
|
|
122
|
+
table = Table(show_header=show_header, box=None, padding=(0, 1))
|
|
123
|
+
table.add_column("Key", style=DIM, no_wrap=True)
|
|
124
|
+
table.add_column("Value")
|
|
125
|
+
|
|
126
|
+
for key, value in data.items():
|
|
127
|
+
table.add_row(key, value)
|
|
128
|
+
|
|
129
|
+
self.console.print(table)
|
|
130
|
+
|
|
131
|
+
def progress_message(self, message: str) -> None:
|
|
132
|
+
"""Print a progress message.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
message: The progress message
|
|
136
|
+
"""
|
|
137
|
+
self.console.print(f"[{DIM} not bold]{message}[/{DIM} not bold]")
|
|
138
|
+
|
|
139
|
+
def phase(self, phase_num: int, title: str) -> None:
|
|
140
|
+
"""Print a phase header (for debug command).
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
phase_num: Phase number
|
|
144
|
+
title: Phase title
|
|
145
|
+
"""
|
|
146
|
+
self.console.print(f"\n{'=' * 80}", style=GOLD)
|
|
147
|
+
self.console.print(f"[bold {GOLD}]PHASE {phase_num}: {title}[/bold {GOLD}]")
|
|
148
|
+
self.console.print(f"{'=' * 80}", style=GOLD)
|
|
149
|
+
|
|
150
|
+
def command(self, cmd: list[str]) -> None:
|
|
151
|
+
"""Print a command being executed.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
cmd: Command parts as list
|
|
155
|
+
"""
|
|
156
|
+
self.console.print(f"[bold]$ {' '.join(cmd)}[/bold]")
|
|
157
|
+
|
|
158
|
+
def hint(self, hint: str) -> None:
|
|
159
|
+
"""Print a hint message.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
hint: The hint text
|
|
163
|
+
"""
|
|
164
|
+
self.console.print(f"\n[yellow]💡 Hint: {hint}[/yellow]")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# Global design instance for convenience
|
|
168
|
+
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
|
+
)
|