hammad-python 0.0.15__py3-none-any.whl → 0.0.17__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.
Files changed (111) hide show
  1. hammad/__init__.py +178 -0
  2. hammad/_internal.py +237 -0
  3. hammad/cache/__init__.py +40 -0
  4. hammad/cache/base_cache.py +181 -0
  5. hammad/cache/cache.py +169 -0
  6. hammad/cache/decorators.py +261 -0
  7. hammad/cache/file_cache.py +80 -0
  8. hammad/cache/ttl_cache.py +74 -0
  9. hammad/cli/__init__.py +35 -0
  10. hammad/cli/_runner.py +265 -0
  11. hammad/cli/animations.py +573 -0
  12. hammad/cli/plugins.py +836 -0
  13. hammad/cli/styles/__init__.py +55 -0
  14. hammad/cli/styles/settings.py +139 -0
  15. hammad/cli/styles/types.py +358 -0
  16. hammad/cli/styles/utils.py +626 -0
  17. hammad/data/__init__.py +83 -0
  18. hammad/data/collections/__init__.py +44 -0
  19. hammad/data/collections/collection.py +274 -0
  20. hammad/data/collections/indexes/__init__.py +37 -0
  21. hammad/data/collections/indexes/qdrant/__init__.py +1 -0
  22. hammad/data/collections/indexes/qdrant/index.py +735 -0
  23. hammad/data/collections/indexes/qdrant/settings.py +94 -0
  24. hammad/data/collections/indexes/qdrant/utils.py +220 -0
  25. hammad/data/collections/indexes/tantivy/__init__.py +1 -0
  26. hammad/data/collections/indexes/tantivy/index.py +428 -0
  27. hammad/data/collections/indexes/tantivy/settings.py +51 -0
  28. hammad/data/collections/indexes/tantivy/utils.py +200 -0
  29. hammad/data/configurations/__init__.py +35 -0
  30. hammad/data/configurations/configuration.py +564 -0
  31. hammad/data/models/__init__.py +55 -0
  32. hammad/data/models/extensions/__init__.py +4 -0
  33. hammad/data/models/extensions/pydantic/__init__.py +42 -0
  34. hammad/data/models/extensions/pydantic/converters.py +759 -0
  35. hammad/data/models/fields.py +546 -0
  36. hammad/data/models/model.py +1078 -0
  37. hammad/data/models/utils.py +280 -0
  38. hammad/data/sql/__init__.py +23 -0
  39. hammad/data/sql/database.py +578 -0
  40. hammad/data/sql/types.py +141 -0
  41. hammad/data/types/__init__.py +39 -0
  42. hammad/data/types/file.py +358 -0
  43. hammad/data/types/multimodal/__init__.py +24 -0
  44. hammad/data/types/multimodal/audio.py +96 -0
  45. hammad/data/types/multimodal/image.py +80 -0
  46. hammad/data/types/text.py +1066 -0
  47. hammad/formatting/__init__.py +20 -0
  48. hammad/formatting/json/__init__.py +27 -0
  49. hammad/formatting/json/converters.py +158 -0
  50. hammad/formatting/text/__init__.py +63 -0
  51. hammad/formatting/text/converters.py +723 -0
  52. hammad/formatting/text/markdown.py +131 -0
  53. hammad/formatting/yaml/__init__.py +26 -0
  54. hammad/formatting/yaml/converters.py +5 -0
  55. hammad/genai/__init__.py +78 -0
  56. hammad/genai/agents/__init__.py +1 -0
  57. hammad/genai/agents/types/__init__.py +35 -0
  58. hammad/genai/agents/types/history.py +277 -0
  59. hammad/genai/agents/types/tool.py +490 -0
  60. hammad/genai/embedding_models/__init__.py +41 -0
  61. hammad/genai/embedding_models/embedding_model.py +193 -0
  62. hammad/genai/embedding_models/embedding_model_name.py +77 -0
  63. hammad/genai/embedding_models/embedding_model_request.py +65 -0
  64. hammad/genai/embedding_models/embedding_model_response.py +69 -0
  65. hammad/genai/embedding_models/run.py +161 -0
  66. hammad/genai/language_models/__init__.py +35 -0
  67. hammad/genai/language_models/_streaming.py +622 -0
  68. hammad/genai/language_models/_types.py +276 -0
  69. hammad/genai/language_models/_utils/__init__.py +31 -0
  70. hammad/genai/language_models/_utils/_completions.py +131 -0
  71. hammad/genai/language_models/_utils/_messages.py +89 -0
  72. hammad/genai/language_models/_utils/_requests.py +202 -0
  73. hammad/genai/language_models/_utils/_structured_outputs.py +124 -0
  74. hammad/genai/language_models/language_model.py +734 -0
  75. hammad/genai/language_models/language_model_request.py +135 -0
  76. hammad/genai/language_models/language_model_response.py +219 -0
  77. hammad/genai/language_models/language_model_response_chunk.py +53 -0
  78. hammad/genai/language_models/run.py +530 -0
  79. hammad/genai/multimodal_models.py +48 -0
  80. hammad/genai/rerank_models.py +26 -0
  81. hammad/logging/__init__.py +35 -0
  82. hammad/logging/decorators.py +834 -0
  83. hammad/logging/logger.py +954 -0
  84. hammad/mcp/__init__.py +50 -0
  85. hammad/mcp/client/__init__.py +36 -0
  86. hammad/mcp/client/client.py +624 -0
  87. hammad/mcp/client/client_service.py +400 -0
  88. hammad/mcp/client/settings.py +178 -0
  89. hammad/mcp/servers/__init__.py +25 -0
  90. hammad/mcp/servers/launcher.py +1161 -0
  91. hammad/runtime/__init__.py +32 -0
  92. hammad/runtime/decorators.py +142 -0
  93. hammad/runtime/run.py +299 -0
  94. hammad/service/__init__.py +49 -0
  95. hammad/service/create.py +527 -0
  96. hammad/service/decorators.py +285 -0
  97. hammad/typing/__init__.py +435 -0
  98. hammad/web/__init__.py +43 -0
  99. hammad/web/http/__init__.py +1 -0
  100. hammad/web/http/client.py +944 -0
  101. hammad/web/models.py +277 -0
  102. hammad/web/openapi/__init__.py +1 -0
  103. hammad/web/openapi/client.py +740 -0
  104. hammad/web/search/__init__.py +1 -0
  105. hammad/web/search/client.py +1035 -0
  106. hammad/web/utils.py +472 -0
  107. {hammad_python-0.0.15.dist-info → hammad_python-0.0.17.dist-info}/METADATA +8 -1
  108. hammad_python-0.0.17.dist-info/RECORD +110 -0
  109. hammad_python-0.0.15.dist-info/RECORD +0 -4
  110. {hammad_python-0.0.15.dist-info → hammad_python-0.0.17.dist-info}/WHEEL +0 -0
  111. {hammad_python-0.0.15.dist-info → hammad_python-0.0.17.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,626 @@
1
+ """hammad.cli.styles.utils"""
2
+
3
+ import time
4
+ from typing import Optional, TYPE_CHECKING
5
+
6
+ if TYPE_CHECKING:
7
+ from rich import get_console as get_rich_console
8
+ from rich.console import Console, RenderableType
9
+ from rich.live import Live
10
+ from rich.panel import Panel
11
+ from rich.style import Style
12
+ from rich.text import Text
13
+
14
+ from .types import (
15
+ CLIStyleError,
16
+ CLIStyleType,
17
+ CLIStyleBackgroundType,
18
+ )
19
+ from .settings import (
20
+ CLIStyleRenderableSettings,
21
+ CLIStyleBackgroundSettings,
22
+ CLIStyleLiveSettings,
23
+ )
24
+
25
+ # Lazy import cache for rich components
26
+ _RICH_CACHE = {}
27
+
28
+
29
+ def _get_rich_console():
30
+ """Lazy import for rich console"""
31
+ if "get_console" not in _RICH_CACHE:
32
+ from rich import get_console as get_rich_console
33
+
34
+ _RICH_CACHE["get_console"] = get_rich_console
35
+ return _RICH_CACHE["get_console"]
36
+
37
+
38
+ def _get_rich_classes():
39
+ """Lazy import for rich classes"""
40
+ if "classes" not in _RICH_CACHE:
41
+ from rich.console import Console, RenderableType
42
+ from rich.live import Live
43
+ from rich.panel import Panel
44
+ from rich.style import Style
45
+ from rich.text import Text
46
+
47
+ _RICH_CACHE["classes"] = {
48
+ "Console": Console,
49
+ "RenderableType": RenderableType,
50
+ "Live": Live,
51
+ "Panel": Panel,
52
+ "Style": Style,
53
+ "Text": Text,
54
+ }
55
+ return _RICH_CACHE["classes"]
56
+
57
+
58
+ def live_render(
59
+ r,
60
+ live_settings: CLIStyleLiveSettings,
61
+ console=None,
62
+ ) -> None:
63
+ """Runs a rich live renderable.
64
+
65
+ Args:
66
+ r : The renderable to run.
67
+ settings : The settings to use for the live renderable.
68
+ console : The console to use for the live renderable."""
69
+
70
+ rich_classes = _get_rich_classes()
71
+ RenderableType = rich_classes["RenderableType"]
72
+ Live = rich_classes["Live"]
73
+
74
+ if console is None:
75
+ get_rich_console = _get_rich_console()
76
+ console = get_rich_console()
77
+
78
+ if not isinstance(r, RenderableType):
79
+ raise CLIStyleError("The renderable must be a RenderableType.")
80
+
81
+ if not live_settings.get("duration"):
82
+ duration = 2.0
83
+ else:
84
+ duration = live_settings["duration"]
85
+ if "duration" in live_settings:
86
+ del live_settings["duration"]
87
+
88
+ if not live_settings.get("refresh_rate"):
89
+ refresh_rate = 20
90
+ else:
91
+ refresh_rate = live_settings["refresh_rate"]
92
+ if "refresh_rate" in live_settings:
93
+ del live_settings["refresh_rate"]
94
+
95
+ if not live_settings.get("auto_refresh"):
96
+ live_settings["auto_refresh"] = True
97
+ if not live_settings.get("transient"):
98
+ live_settings["transient"] = False
99
+ if not live_settings.get("redirect_stdout"):
100
+ live_settings["redirect_stdout"] = True
101
+ if not live_settings.get("redirect_stderr"):
102
+ live_settings["redirect_stderr"] = True
103
+ if not live_settings.get("vertical_overflow"):
104
+ live_settings["vertical_overflow"] = "ellipsis"
105
+
106
+ try:
107
+ with Live(r, console=console, **live_settings) as live:
108
+ start_time = time.time()
109
+ while time.time() - start_time < duration:
110
+ time.sleep(1 / refresh_rate)
111
+ live.refresh()
112
+ except Exception as e:
113
+ raise CLIStyleError(f"Error running rich live: {e}") from e
114
+
115
+
116
+ def style_renderable(
117
+ r,
118
+ style: CLIStyleType | None = None,
119
+ style_settings: CLIStyleRenderableSettings | None = None,
120
+ bg: CLIStyleBackgroundType | None = None,
121
+ bg_settings: CLIStyleBackgroundSettings | None = None,
122
+ border = None,
123
+ padding = None,
124
+ title: str | None = None,
125
+ expand: bool | None = None,
126
+ ):
127
+ """Styles a renderable with a rich string tag or settings.
128
+
129
+ Args:
130
+ r : The renderable to style.
131
+ style : The rich string tag to apply to the renderable.
132
+ style_settings : The settings to apply to the renderable.
133
+ bg : The rich string tag to apply to the background.
134
+ bg_settings : The settings to apply to the background.
135
+ border : Border style for panel rendering.
136
+ padding : Padding dimensions for panel rendering.
137
+ title : Title for panel rendering.
138
+ expand : Whether to expand panel to full width.
139
+ """
140
+
141
+ try:
142
+ rich_classes = _get_rich_classes()
143
+ Style = rich_classes["Style"]
144
+ Text = rich_classes["Text"]
145
+ Panel = rich_classes["Panel"]
146
+
147
+ # First handle style processing to get styled_renderable
148
+ styled_renderable = r
149
+
150
+ # Handle string-based styles (including color tags and complex styles)
151
+ if isinstance(style, str):
152
+ try:
153
+ # For strings, use Rich's style parsing directly to support things like 'black on red'
154
+ rich_style = Style.parse(style)
155
+ styled_renderable = (
156
+ Text(r, style=rich_style) if isinstance(r, str) else r
157
+ )
158
+ except Exception:
159
+ # Fallback to treating as simple color if parsing fails
160
+ rich_style = Style(color=style)
161
+ styled_renderable = (
162
+ Text(r, style=rich_style) if isinstance(r, str) else r
163
+ )
164
+
165
+ # Handle tuple-based styles (RGB color tuples)
166
+ elif isinstance(style, tuple):
167
+ try:
168
+ # Convert tuple to RGB format for Rich
169
+ rgb_color = f"rgb({style[0]},{style[1]},{style[2]})"
170
+ rich_style = Style(color=rgb_color)
171
+ styled_renderable = (
172
+ Text(r, style=rich_style) if isinstance(r, str) else r
173
+ )
174
+ except Exception:
175
+ # Fallback to original renderable if tuple processing fails
176
+ styled_renderable = r
177
+
178
+ # Handle dict-based styles passed as style parameter
179
+ elif isinstance(style, dict):
180
+ try:
181
+ # Process text/style properties from dict
182
+ text_style_kwargs = {}
183
+
184
+ # Handle color from style dict
185
+ if "color" in style:
186
+ try:
187
+ color_value = style["color"]
188
+ if isinstance(color_value, tuple):
189
+ text_style_kwargs["color"] = (
190
+ f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
191
+ )
192
+ else:
193
+ text_style_kwargs["color"] = color_value
194
+ except Exception:
195
+ # Skip color if processing fails
196
+ pass
197
+
198
+ # Handle text style properties
199
+ text_style_props = [
200
+ "bold",
201
+ "dim",
202
+ "italic",
203
+ "underline",
204
+ "blink",
205
+ "blink2",
206
+ "reverse",
207
+ "conceal",
208
+ "strike",
209
+ "underline2",
210
+ "frame",
211
+ "encircle",
212
+ "overline",
213
+ "link",
214
+ ]
215
+
216
+ for prop in text_style_props:
217
+ if prop in style:
218
+ try:
219
+ text_style_kwargs[prop] = style[prop]
220
+ except Exception:
221
+ # Skip property if processing fails
222
+ continue
223
+
224
+ # Create rich style from text properties
225
+ try:
226
+ rich_style = (
227
+ Style(**text_style_kwargs) if text_style_kwargs else None
228
+ )
229
+ except Exception:
230
+ rich_style = None
231
+
232
+ # Apply text style to renderable
233
+ try:
234
+ if isinstance(r, str):
235
+ styled_renderable = (
236
+ Text(r, style=rich_style) if rich_style else Text(r)
237
+ )
238
+ elif isinstance(r, Text) and rich_style:
239
+ styled_renderable = Text(r.plain, style=rich_style)
240
+ else:
241
+ styled_renderable = r
242
+ except Exception:
243
+ styled_renderable = r
244
+
245
+ except Exception:
246
+ # Fallback to original renderable if dict processing fails
247
+ styled_renderable = r
248
+
249
+ # Handle style_settings dict
250
+ elif style_settings:
251
+ try:
252
+ # Process text/style properties
253
+ text_style_kwargs = {}
254
+
255
+ # Handle color from style settings
256
+ if "color" in style_settings:
257
+ try:
258
+ color_value = style_settings["color"]
259
+ if isinstance(color_value, tuple):
260
+ text_style_kwargs["color"] = (
261
+ f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
262
+ )
263
+ else:
264
+ text_style_kwargs["color"] = color_value
265
+ except Exception:
266
+ # Skip color if processing fails
267
+ pass
268
+
269
+ # Handle text style properties
270
+ text_style_props = [
271
+ "bold",
272
+ "dim",
273
+ "italic",
274
+ "underline",
275
+ "blink",
276
+ "blink2",
277
+ "reverse",
278
+ "conceal",
279
+ "strike",
280
+ "underline2",
281
+ "frame",
282
+ "encircle",
283
+ "overline",
284
+ "link",
285
+ ]
286
+
287
+ for prop in text_style_props:
288
+ if prop in style_settings:
289
+ try:
290
+ text_style_kwargs[prop] = style_settings[prop]
291
+ except Exception:
292
+ # Skip property if processing fails
293
+ continue
294
+
295
+ # Create rich style from text properties
296
+ try:
297
+ rich_style = (
298
+ Style(**text_style_kwargs) if text_style_kwargs else None
299
+ )
300
+ except Exception:
301
+ rich_style = None
302
+
303
+ # Apply text style to renderable
304
+ try:
305
+ if isinstance(r, str):
306
+ styled_renderable = (
307
+ Text(r, style=rich_style) if rich_style else Text(r)
308
+ )
309
+ elif isinstance(r, Text) and rich_style:
310
+ styled_renderable = Text(r.plain, style=rich_style)
311
+ else:
312
+ styled_renderable = r
313
+ except Exception:
314
+ styled_renderable = r
315
+
316
+ except Exception:
317
+ # Fallback to original renderable if dict processing fails
318
+ styled_renderable = r
319
+
320
+ # Handle background settings (from bg or bg_settings parameter) or panel parameters
321
+ if bg or bg_settings or border or padding or title or expand:
322
+ try:
323
+ if bg_settings:
324
+ # Full background configuration
325
+ panel_kwargs = {}
326
+
327
+ # Handle box style
328
+ if "box" in bg_settings:
329
+ try:
330
+ box_name = bg_settings["box"]
331
+ from rich import box as rich_box_module
332
+
333
+ box_map = {
334
+ "ascii": rich_box_module.ASCII,
335
+ "ascii2": rich_box_module.ASCII2,
336
+ "ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
337
+ "square": rich_box_module.SQUARE,
338
+ "square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
339
+ "minimal": rich_box_module.MINIMAL,
340
+ "minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
341
+ "minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
342
+ "simple": rich_box_module.SIMPLE,
343
+ "simple_head": rich_box_module.SIMPLE_HEAD,
344
+ "simple_heavy": rich_box_module.SIMPLE_HEAVY,
345
+ "horizontals": rich_box_module.HORIZONTALS,
346
+ "rounded": rich_box_module.ROUNDED,
347
+ "heavy": rich_box_module.HEAVY,
348
+ "heavy_edge": rich_box_module.HEAVY_EDGE,
349
+ "heavy_head": rich_box_module.HEAVY_HEAD,
350
+ "double": rich_box_module.DOUBLE,
351
+ "double_edge": rich_box_module.DOUBLE_EDGE,
352
+ "markdown": getattr(
353
+ rich_box_module,
354
+ "MARKDOWN",
355
+ rich_box_module.ROUNDED,
356
+ ),
357
+ }
358
+ panel_kwargs["box"] = box_map.get(
359
+ box_name, rich_box_module.ROUNDED
360
+ )
361
+ except Exception:
362
+ # Use default box if box processing fails
363
+ pass
364
+
365
+ # Handle panel properties
366
+ panel_props = [
367
+ "title",
368
+ "subtitle",
369
+ "title_align",
370
+ "subtitle_align",
371
+ "safe_box",
372
+ "expand",
373
+ "width",
374
+ "height",
375
+ "padding",
376
+ "highlight",
377
+ ]
378
+
379
+ for prop in panel_props:
380
+ if prop in bg_settings:
381
+ try:
382
+ panel_kwargs[prop] = bg_settings[prop]
383
+ except Exception:
384
+ # Skip property if processing fails
385
+ continue
386
+
387
+ # Handle direct panel parameters
388
+ if title is not None:
389
+ panel_kwargs["title"] = title
390
+ if padding is not None:
391
+ panel_kwargs["padding"] = padding
392
+ if expand is not None:
393
+ panel_kwargs["expand"] = expand
394
+ if border is not None:
395
+ try:
396
+ from rich import box as rich_box_module
397
+ box_map = {
398
+ "ascii": rich_box_module.ASCII,
399
+ "ascii2": rich_box_module.ASCII2,
400
+ "ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
401
+ "square": rich_box_module.SQUARE,
402
+ "square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
403
+ "minimal": rich_box_module.MINIMAL,
404
+ "minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
405
+ "minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
406
+ "simple": rich_box_module.SIMPLE,
407
+ "simple_head": rich_box_module.SIMPLE_HEAD,
408
+ "simple_heavy": rich_box_module.SIMPLE_HEAVY,
409
+ "horizontals": rich_box_module.HORIZONTALS,
410
+ "rounded": rich_box_module.ROUNDED,
411
+ "heavy": rich_box_module.HEAVY,
412
+ "heavy_edge": rich_box_module.HEAVY_EDGE,
413
+ "heavy_head": rich_box_module.HEAVY_HEAD,
414
+ "double": rich_box_module.DOUBLE,
415
+ "double_edge": rich_box_module.DOUBLE_EDGE,
416
+ "markdown": getattr(
417
+ rich_box_module,
418
+ "MARKDOWN",
419
+ rich_box_module.ROUNDED,
420
+ ),
421
+ }
422
+ panel_kwargs["box"] = box_map.get(
423
+ border, rich_box_module.ROUNDED
424
+ )
425
+ except Exception:
426
+ # Use default box if box processing fails
427
+ pass
428
+
429
+ # Handle background style
430
+ if "style" in bg_settings:
431
+ try:
432
+ bg_style = bg_settings["style"]
433
+ if isinstance(bg_style, dict):
434
+ bg_style_kwargs = {}
435
+ if "color" in bg_style:
436
+ try:
437
+ color_value = bg_style["color"]
438
+ if isinstance(color_value, tuple):
439
+ bg_style_kwargs["bgcolor"] = (
440
+ f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
441
+ )
442
+ else:
443
+ bg_style_kwargs["bgcolor"] = color_value
444
+ except Exception:
445
+ pass
446
+ panel_kwargs["style"] = Style(**bg_style_kwargs)
447
+ else:
448
+ # Handle string or tuple background style
449
+ if isinstance(bg_style, tuple):
450
+ panel_kwargs["style"] = Style(
451
+ bgcolor=f"rgb({bg_style[0]},{bg_style[1]},{bg_style[2]})"
452
+ )
453
+ else:
454
+ panel_kwargs["style"] = Style(bgcolor=bg_style)
455
+ except Exception:
456
+ # Skip background style if processing fails
457
+ pass
458
+
459
+ # Handle border style
460
+ if "border_style" in bg_settings:
461
+ try:
462
+ border_style = bg_settings["border_style"]
463
+ if isinstance(border_style, dict):
464
+ border_style_kwargs = {}
465
+ if "color" in border_style:
466
+ try:
467
+ color_value = border_style["color"]
468
+ if isinstance(color_value, tuple):
469
+ border_style_kwargs["color"] = (
470
+ f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
471
+ )
472
+ else:
473
+ border_style_kwargs["color"] = color_value
474
+ except Exception:
475
+ pass
476
+
477
+ for prop in ["bold", "dim", "italic"]:
478
+ if prop in border_style:
479
+ try:
480
+ border_style_kwargs[prop] = border_style[
481
+ prop
482
+ ]
483
+ except Exception:
484
+ continue
485
+
486
+ panel_kwargs["border_style"] = Style(
487
+ **border_style_kwargs
488
+ )
489
+ except Exception:
490
+ # Skip border style if processing fails
491
+ pass
492
+
493
+ # Handle background color if specified at top level
494
+ if "color" in bg_settings and "style" not in bg_settings:
495
+ try:
496
+ color_value = bg_settings["color"]
497
+ if isinstance(color_value, tuple):
498
+ panel_kwargs["style"] = Style(
499
+ bgcolor=f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
500
+ )
501
+ else:
502
+ panel_kwargs["style"] = Style(bgcolor=color_value)
503
+ except Exception:
504
+ # Skip background color if processing fails
505
+ pass
506
+
507
+ try:
508
+ return Panel(styled_renderable, **panel_kwargs)
509
+ except Exception:
510
+ # Fallback to styled renderable if panel creation fails
511
+ return styled_renderable
512
+
513
+ elif bg:
514
+ # Simple background color (string from bg parameter)
515
+ try:
516
+ panel_kwargs = {}
517
+ bg_style = Style(bgcolor=bg)
518
+ panel_kwargs["style"] = bg_style
519
+
520
+ # Handle direct panel parameters even with simple bg
521
+ if title is not None:
522
+ panel_kwargs["title"] = title
523
+ if padding is not None:
524
+ panel_kwargs["padding"] = padding
525
+ if expand is not None:
526
+ panel_kwargs["expand"] = expand
527
+ if border is not None:
528
+ try:
529
+ from rich import box as rich_box_module
530
+ box_map = {
531
+ "ascii": rich_box_module.ASCII,
532
+ "ascii2": rich_box_module.ASCII2,
533
+ "ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
534
+ "square": rich_box_module.SQUARE,
535
+ "square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
536
+ "minimal": rich_box_module.MINIMAL,
537
+ "minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
538
+ "minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
539
+ "simple": rich_box_module.SIMPLE,
540
+ "simple_head": rich_box_module.SIMPLE_HEAD,
541
+ "simple_heavy": rich_box_module.SIMPLE_HEAVY,
542
+ "horizontals": rich_box_module.HORIZONTALS,
543
+ "rounded": rich_box_module.ROUNDED,
544
+ "heavy": rich_box_module.HEAVY,
545
+ "heavy_edge": rich_box_module.HEAVY_EDGE,
546
+ "heavy_head": rich_box_module.HEAVY_HEAD,
547
+ "double": rich_box_module.DOUBLE,
548
+ "double_edge": rich_box_module.DOUBLE_EDGE,
549
+ "markdown": getattr(
550
+ rich_box_module,
551
+ "MARKDOWN",
552
+ rich_box_module.ROUNDED,
553
+ ),
554
+ }
555
+ panel_kwargs["box"] = box_map.get(
556
+ border, rich_box_module.ROUNDED
557
+ )
558
+ except Exception:
559
+ # Use default box if box processing fails
560
+ pass
561
+
562
+ return Panel(styled_renderable, **panel_kwargs)
563
+ except Exception:
564
+ # Fallback to styled renderable if panel creation fails
565
+ return styled_renderable
566
+ else:
567
+ # Handle panel parameters without background
568
+ if title is not None or padding is not None or expand is not None or border is not None:
569
+ try:
570
+ panel_kwargs = {}
571
+
572
+ if title is not None:
573
+ panel_kwargs["title"] = title
574
+ if padding is not None:
575
+ panel_kwargs["padding"] = padding
576
+ if expand is not None:
577
+ panel_kwargs["expand"] = expand
578
+ if border is not None:
579
+ try:
580
+ from rich import box as rich_box_module
581
+ box_map = {
582
+ "ascii": rich_box_module.ASCII,
583
+ "ascii2": rich_box_module.ASCII2,
584
+ "ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
585
+ "square": rich_box_module.SQUARE,
586
+ "square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
587
+ "minimal": rich_box_module.MINIMAL,
588
+ "minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
589
+ "minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
590
+ "simple": rich_box_module.SIMPLE,
591
+ "simple_head": rich_box_module.SIMPLE_HEAD,
592
+ "simple_heavy": rich_box_module.SIMPLE_HEAVY,
593
+ "horizontals": rich_box_module.HORIZONTALS,
594
+ "rounded": rich_box_module.ROUNDED,
595
+ "heavy": rich_box_module.HEAVY,
596
+ "heavy_edge": rich_box_module.HEAVY_EDGE,
597
+ "heavy_head": rich_box_module.HEAVY_HEAD,
598
+ "double": rich_box_module.DOUBLE,
599
+ "double_edge": rich_box_module.DOUBLE_EDGE,
600
+ "markdown": getattr(
601
+ rich_box_module,
602
+ "MARKDOWN",
603
+ rich_box_module.ROUNDED,
604
+ ),
605
+ }
606
+ panel_kwargs["box"] = box_map.get(
607
+ border, rich_box_module.ROUNDED
608
+ )
609
+ except Exception:
610
+ # Use default box if box processing fails
611
+ pass
612
+
613
+ return Panel(styled_renderable, **panel_kwargs)
614
+ except Exception:
615
+ # Fallback to styled renderable if panel creation fails
616
+ return styled_renderable
617
+ except Exception:
618
+ # Skip background processing if it fails
619
+ pass
620
+
621
+ # Return styled renderable (with or without background processing)
622
+ return styled_renderable
623
+
624
+ except Exception:
625
+ # Ultimate fallback - return original renderable
626
+ return r