glaip-sdk 0.0.1b5__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.
glaip_sdk/utils.py ADDED
@@ -0,0 +1,167 @@
1
+ """Utility functions for AIP SDK.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from typing import Any
8
+ from uuid import UUID
9
+
10
+ try:
11
+ from rich import box
12
+ from rich.console import Console
13
+ from rich.panel import Panel
14
+ from rich.text import Text
15
+
16
+ RICH_AVAILABLE = True
17
+ except ImportError:
18
+ RICH_AVAILABLE = False
19
+
20
+
21
+ def is_uuid(value: str) -> bool:
22
+ """Check if a string is a valid UUID.
23
+
24
+ Args:
25
+ value: String to check
26
+
27
+ Returns:
28
+ True if value is a valid UUID, False otherwise
29
+ """
30
+ try:
31
+ UUID(value)
32
+ return True
33
+ except (ValueError, TypeError):
34
+ return False
35
+
36
+
37
+ def sanitize_name(name: str) -> str:
38
+ """Sanitize a name for resource creation.
39
+
40
+ Args:
41
+ name: Raw name input
42
+
43
+ Returns:
44
+ Sanitized name suitable for resource creation
45
+ """
46
+ # Remove special characters and normalize
47
+ import re
48
+
49
+ sanitized = re.sub(r"[^a-zA-Z0-9\-_]", "-", name.strip())
50
+ sanitized = re.sub(r"-+", "-", sanitized) # Collapse multiple dashes
51
+ return sanitized.lower().strip("-")
52
+
53
+
54
+ def format_file_size(size_bytes: int) -> str:
55
+ """Format file size in human readable format.
56
+
57
+ Args:
58
+ size_bytes: Size in bytes
59
+
60
+ Returns:
61
+ Human readable size string (e.g., "1.5 MB")
62
+ """
63
+ for unit in ["B", "KB", "MB", "GB"]:
64
+ if size_bytes < 1024.0:
65
+ return f"{size_bytes:.1f} {unit}"
66
+ size_bytes /= 1024.0
67
+ return f"{size_bytes:.1f} TB"
68
+
69
+
70
+ def progress_bar(iterable, description: str = "Processing"):
71
+ """Simple progress bar using click.
72
+
73
+ Args:
74
+ iterable: Iterable to process
75
+ description: Progress description
76
+
77
+ Yields:
78
+ Items from iterable with progress display
79
+ """
80
+ try:
81
+ import click
82
+
83
+ with click.progressbar(iterable, label=description) as bar:
84
+ for item in bar:
85
+ yield item
86
+ except ImportError:
87
+ # Fallback if click not available
88
+ for item in iterable:
89
+ yield item
90
+
91
+
92
+ # Rich display utilities for enhanced output
93
+ def print_agent_output(output: str, title: str = "Agent Output") -> None:
94
+ """Print agent output with rich formatting.
95
+
96
+ Args:
97
+ output: The agent's response text
98
+ title: Title for the output panel
99
+ """
100
+ if RICH_AVAILABLE:
101
+ console = Console()
102
+ panel = Panel(
103
+ Text(output, style="green"),
104
+ title=title,
105
+ border_style="green",
106
+ box=box.ROUNDED,
107
+ )
108
+ console.print(panel)
109
+ else:
110
+ print(f"\n=== {title} ===")
111
+ print(output)
112
+ print("=" * (len(title) + 8))
113
+
114
+
115
+ def print_agent_created(agent: Any) -> None:
116
+ """Print agent creation success with rich formatting.
117
+
118
+ Args:
119
+ agent: The created agent object
120
+ """
121
+ if RICH_AVAILABLE:
122
+ console = Console()
123
+ panel = Panel(
124
+ f"[green]✅ Agent '{agent.name}' created successfully![/green]\n\n"
125
+ f"ID: {agent.id}\n"
126
+ f"Model: {getattr(agent, 'model', 'N/A')}\n"
127
+ f"Type: {getattr(agent, 'type', 'config')}\n"
128
+ f"Framework: {getattr(agent, 'framework', 'langchain')}\n"
129
+ f"Version: {getattr(agent, 'version', '1.0')}",
130
+ title="🤖 Agent Created",
131
+ border_style="green",
132
+ box=box.ROUNDED,
133
+ )
134
+ console.print(panel)
135
+ else:
136
+ print(f"✅ Agent '{agent.name}' created successfully!")
137
+ print(f"ID: {agent.id}")
138
+ print(f"Model: {getattr(agent, 'model', 'N/A')}")
139
+ print(f"Type: {getattr(agent, 'type', 'config')}")
140
+ print(f"Framework: {getattr(agent, 'framework', 'langchain')}")
141
+ print(f"Version: {getattr(agent, 'version', '1.0')}")
142
+
143
+
144
+ def print_agent_updated(agent: Any) -> None:
145
+ """Print agent update success with rich formatting.
146
+
147
+ Args:
148
+ agent: The updated agent object
149
+ """
150
+ if RICH_AVAILABLE:
151
+ console = Console()
152
+ console.print(f"[green]✅ Agent '{agent.name}' updated successfully[/green]")
153
+ else:
154
+ print(f"✅ Agent '{agent.name}' updated successfully")
155
+
156
+
157
+ def print_agent_deleted(agent_id: str) -> None:
158
+ """Print agent deletion success with rich formatting.
159
+
160
+ Args:
161
+ agent_id: The deleted agent's ID
162
+ """
163
+ if RICH_AVAILABLE:
164
+ console = Console()
165
+ console.print(f"[green]✅ Agent deleted successfully (ID: {agent_id})[/green]")
166
+ else:
167
+ print(f"✅ Agent deleted successfully (ID: {agent_id})")