glaip-sdk 0.0.20__py3-none-any.whl → 0.7.7__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 (216) hide show
  1. glaip_sdk/__init__.py +44 -4
  2. glaip_sdk/_version.py +10 -3
  3. glaip_sdk/agents/__init__.py +27 -0
  4. glaip_sdk/agents/base.py +1250 -0
  5. glaip_sdk/branding.py +15 -6
  6. glaip_sdk/cli/account_store.py +540 -0
  7. glaip_sdk/cli/agent_config.py +2 -6
  8. glaip_sdk/cli/auth.py +271 -45
  9. glaip_sdk/cli/commands/__init__.py +2 -2
  10. glaip_sdk/cli/commands/accounts.py +746 -0
  11. glaip_sdk/cli/commands/agents/__init__.py +119 -0
  12. glaip_sdk/cli/commands/agents/_common.py +561 -0
  13. glaip_sdk/cli/commands/agents/create.py +151 -0
  14. glaip_sdk/cli/commands/agents/delete.py +64 -0
  15. glaip_sdk/cli/commands/agents/get.py +89 -0
  16. glaip_sdk/cli/commands/agents/list.py +129 -0
  17. glaip_sdk/cli/commands/agents/run.py +264 -0
  18. glaip_sdk/cli/commands/agents/sync_langflow.py +72 -0
  19. glaip_sdk/cli/commands/agents/update.py +112 -0
  20. glaip_sdk/cli/commands/common_config.py +104 -0
  21. glaip_sdk/cli/commands/configure.py +734 -143
  22. glaip_sdk/cli/commands/mcps/__init__.py +94 -0
  23. glaip_sdk/cli/commands/mcps/_common.py +459 -0
  24. glaip_sdk/cli/commands/mcps/connect.py +82 -0
  25. glaip_sdk/cli/commands/mcps/create.py +152 -0
  26. glaip_sdk/cli/commands/mcps/delete.py +73 -0
  27. glaip_sdk/cli/commands/mcps/get.py +212 -0
  28. glaip_sdk/cli/commands/mcps/list.py +69 -0
  29. glaip_sdk/cli/commands/mcps/tools.py +235 -0
  30. glaip_sdk/cli/commands/mcps/update.py +190 -0
  31. glaip_sdk/cli/commands/models.py +14 -12
  32. glaip_sdk/cli/commands/shared/__init__.py +21 -0
  33. glaip_sdk/cli/commands/shared/formatters.py +91 -0
  34. glaip_sdk/cli/commands/tools/__init__.py +69 -0
  35. glaip_sdk/cli/commands/tools/_common.py +80 -0
  36. glaip_sdk/cli/commands/tools/create.py +228 -0
  37. glaip_sdk/cli/commands/tools/delete.py +61 -0
  38. glaip_sdk/cli/commands/tools/get.py +103 -0
  39. glaip_sdk/cli/commands/tools/list.py +69 -0
  40. glaip_sdk/cli/commands/tools/script.py +49 -0
  41. glaip_sdk/cli/commands/tools/update.py +102 -0
  42. glaip_sdk/cli/commands/transcripts/__init__.py +90 -0
  43. glaip_sdk/cli/commands/transcripts/_common.py +9 -0
  44. glaip_sdk/cli/commands/transcripts/clear.py +5 -0
  45. glaip_sdk/cli/commands/transcripts/detail.py +5 -0
  46. glaip_sdk/cli/commands/transcripts_original.py +756 -0
  47. glaip_sdk/cli/commands/update.py +164 -23
  48. glaip_sdk/cli/config.py +49 -7
  49. glaip_sdk/cli/constants.py +38 -0
  50. glaip_sdk/cli/context.py +8 -0
  51. glaip_sdk/cli/core/__init__.py +79 -0
  52. glaip_sdk/cli/core/context.py +124 -0
  53. glaip_sdk/cli/core/output.py +851 -0
  54. glaip_sdk/cli/core/prompting.py +649 -0
  55. glaip_sdk/cli/core/rendering.py +187 -0
  56. glaip_sdk/cli/display.py +45 -32
  57. glaip_sdk/cli/entrypoint.py +20 -0
  58. glaip_sdk/cli/hints.py +57 -0
  59. glaip_sdk/cli/io.py +14 -17
  60. glaip_sdk/cli/main.py +344 -167
  61. glaip_sdk/cli/masking.py +21 -33
  62. glaip_sdk/cli/mcp_validators.py +5 -15
  63. glaip_sdk/cli/pager.py +15 -22
  64. glaip_sdk/cli/parsers/__init__.py +1 -3
  65. glaip_sdk/cli/parsers/json_input.py +11 -22
  66. glaip_sdk/cli/resolution.py +5 -10
  67. glaip_sdk/cli/rich_helpers.py +1 -3
  68. glaip_sdk/cli/slash/__init__.py +0 -9
  69. glaip_sdk/cli/slash/accounts_controller.py +580 -0
  70. glaip_sdk/cli/slash/accounts_shared.py +75 -0
  71. glaip_sdk/cli/slash/agent_session.py +65 -29
  72. glaip_sdk/cli/slash/prompt.py +24 -10
  73. glaip_sdk/cli/slash/remote_runs_controller.py +566 -0
  74. glaip_sdk/cli/slash/session.py +827 -232
  75. glaip_sdk/cli/slash/tui/__init__.py +34 -0
  76. glaip_sdk/cli/slash/tui/accounts.tcss +88 -0
  77. glaip_sdk/cli/slash/tui/accounts_app.py +933 -0
  78. glaip_sdk/cli/slash/tui/background_tasks.py +72 -0
  79. glaip_sdk/cli/slash/tui/clipboard.py +147 -0
  80. glaip_sdk/cli/slash/tui/context.py +59 -0
  81. glaip_sdk/cli/slash/tui/keybind_registry.py +235 -0
  82. glaip_sdk/cli/slash/tui/loading.py +58 -0
  83. glaip_sdk/cli/slash/tui/remote_runs_app.py +628 -0
  84. glaip_sdk/cli/slash/tui/terminal.py +402 -0
  85. glaip_sdk/cli/slash/tui/theme/__init__.py +15 -0
  86. glaip_sdk/cli/slash/tui/theme/catalog.py +79 -0
  87. glaip_sdk/cli/slash/tui/theme/manager.py +86 -0
  88. glaip_sdk/cli/slash/tui/theme/tokens.py +55 -0
  89. glaip_sdk/cli/slash/tui/toast.py +123 -0
  90. glaip_sdk/cli/transcript/__init__.py +12 -52
  91. glaip_sdk/cli/transcript/cache.py +258 -60
  92. glaip_sdk/cli/transcript/capture.py +72 -21
  93. glaip_sdk/cli/transcript/history.py +815 -0
  94. glaip_sdk/cli/transcript/launcher.py +1 -3
  95. glaip_sdk/cli/transcript/viewer.py +79 -329
  96. glaip_sdk/cli/update_notifier.py +385 -24
  97. glaip_sdk/cli/validators.py +16 -18
  98. glaip_sdk/client/__init__.py +3 -1
  99. glaip_sdk/client/_schedule_payloads.py +89 -0
  100. glaip_sdk/client/agent_runs.py +147 -0
  101. glaip_sdk/client/agents.py +370 -100
  102. glaip_sdk/client/base.py +78 -35
  103. glaip_sdk/client/hitl.py +136 -0
  104. glaip_sdk/client/main.py +25 -10
  105. glaip_sdk/client/mcps.py +166 -27
  106. glaip_sdk/client/payloads/agent/__init__.py +23 -0
  107. glaip_sdk/client/{_agent_payloads.py → payloads/agent/requests.py} +65 -74
  108. glaip_sdk/client/payloads/agent/responses.py +43 -0
  109. glaip_sdk/client/run_rendering.py +583 -79
  110. glaip_sdk/client/schedules.py +439 -0
  111. glaip_sdk/client/shared.py +21 -0
  112. glaip_sdk/client/tools.py +214 -56
  113. glaip_sdk/client/validators.py +20 -48
  114. glaip_sdk/config/constants.py +11 -0
  115. glaip_sdk/exceptions.py +1 -3
  116. glaip_sdk/hitl/__init__.py +48 -0
  117. glaip_sdk/hitl/base.py +64 -0
  118. glaip_sdk/hitl/callback.py +43 -0
  119. glaip_sdk/hitl/local.py +121 -0
  120. glaip_sdk/hitl/remote.py +523 -0
  121. glaip_sdk/icons.py +9 -3
  122. glaip_sdk/mcps/__init__.py +21 -0
  123. glaip_sdk/mcps/base.py +345 -0
  124. glaip_sdk/models/__init__.py +107 -0
  125. glaip_sdk/models/agent.py +47 -0
  126. glaip_sdk/models/agent_runs.py +117 -0
  127. glaip_sdk/models/common.py +42 -0
  128. glaip_sdk/models/mcp.py +33 -0
  129. glaip_sdk/models/schedule.py +224 -0
  130. glaip_sdk/models/tool.py +33 -0
  131. glaip_sdk/payload_schemas/__init__.py +1 -13
  132. glaip_sdk/payload_schemas/agent.py +1 -3
  133. glaip_sdk/registry/__init__.py +55 -0
  134. glaip_sdk/registry/agent.py +164 -0
  135. glaip_sdk/registry/base.py +139 -0
  136. glaip_sdk/registry/mcp.py +253 -0
  137. glaip_sdk/registry/tool.py +445 -0
  138. glaip_sdk/rich_components.py +58 -2
  139. glaip_sdk/runner/__init__.py +76 -0
  140. glaip_sdk/runner/base.py +84 -0
  141. glaip_sdk/runner/deps.py +112 -0
  142. glaip_sdk/runner/langgraph.py +872 -0
  143. glaip_sdk/runner/logging_config.py +77 -0
  144. glaip_sdk/runner/mcp_adapter/__init__.py +13 -0
  145. glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py +43 -0
  146. glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py +257 -0
  147. glaip_sdk/runner/mcp_adapter/mcp_config_builder.py +95 -0
  148. glaip_sdk/runner/tool_adapter/__init__.py +18 -0
  149. glaip_sdk/runner/tool_adapter/base_tool_adapter.py +44 -0
  150. glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py +242 -0
  151. glaip_sdk/schedules/__init__.py +22 -0
  152. glaip_sdk/schedules/base.py +291 -0
  153. glaip_sdk/tools/__init__.py +22 -0
  154. glaip_sdk/tools/base.py +468 -0
  155. glaip_sdk/utils/__init__.py +59 -12
  156. glaip_sdk/utils/a2a/__init__.py +34 -0
  157. glaip_sdk/utils/a2a/event_processor.py +188 -0
  158. glaip_sdk/utils/agent_config.py +4 -14
  159. glaip_sdk/utils/bundler.py +403 -0
  160. glaip_sdk/utils/client.py +111 -0
  161. glaip_sdk/utils/client_utils.py +46 -28
  162. glaip_sdk/utils/datetime_helpers.py +58 -0
  163. glaip_sdk/utils/discovery.py +78 -0
  164. glaip_sdk/utils/display.py +25 -21
  165. glaip_sdk/utils/export.py +143 -0
  166. glaip_sdk/utils/general.py +1 -36
  167. glaip_sdk/utils/import_export.py +15 -16
  168. glaip_sdk/utils/import_resolver.py +524 -0
  169. glaip_sdk/utils/instructions.py +101 -0
  170. glaip_sdk/utils/rendering/__init__.py +115 -1
  171. glaip_sdk/utils/rendering/formatting.py +38 -23
  172. glaip_sdk/utils/rendering/layout/__init__.py +64 -0
  173. glaip_sdk/utils/rendering/{renderer → layout}/panels.py +10 -3
  174. glaip_sdk/utils/rendering/{renderer → layout}/progress.py +73 -12
  175. glaip_sdk/utils/rendering/layout/summary.py +74 -0
  176. glaip_sdk/utils/rendering/layout/transcript.py +606 -0
  177. glaip_sdk/utils/rendering/models.py +18 -8
  178. glaip_sdk/utils/rendering/renderer/__init__.py +9 -51
  179. glaip_sdk/utils/rendering/renderer/base.py +534 -882
  180. glaip_sdk/utils/rendering/renderer/config.py +4 -10
  181. glaip_sdk/utils/rendering/renderer/debug.py +30 -34
  182. glaip_sdk/utils/rendering/renderer/factory.py +138 -0
  183. glaip_sdk/utils/rendering/renderer/stream.py +13 -54
  184. glaip_sdk/utils/rendering/renderer/summary_window.py +79 -0
  185. glaip_sdk/utils/rendering/renderer/thinking.py +273 -0
  186. glaip_sdk/utils/rendering/renderer/toggle.py +182 -0
  187. glaip_sdk/utils/rendering/renderer/tool_panels.py +442 -0
  188. glaip_sdk/utils/rendering/renderer/transcript_mode.py +162 -0
  189. glaip_sdk/utils/rendering/state.py +204 -0
  190. glaip_sdk/utils/rendering/step_tree_state.py +100 -0
  191. glaip_sdk/utils/rendering/steps/__init__.py +34 -0
  192. glaip_sdk/utils/rendering/steps/event_processor.py +778 -0
  193. glaip_sdk/utils/rendering/steps/format.py +176 -0
  194. glaip_sdk/utils/rendering/{steps.py → steps/manager.py} +122 -26
  195. glaip_sdk/utils/rendering/timing.py +36 -0
  196. glaip_sdk/utils/rendering/viewer/__init__.py +21 -0
  197. glaip_sdk/utils/rendering/viewer/presenter.py +184 -0
  198. glaip_sdk/utils/resource_refs.py +29 -26
  199. glaip_sdk/utils/runtime_config.py +425 -0
  200. glaip_sdk/utils/serialization.py +32 -46
  201. glaip_sdk/utils/sync.py +162 -0
  202. glaip_sdk/utils/tool_detection.py +301 -0
  203. glaip_sdk/utils/tool_storage_provider.py +140 -0
  204. glaip_sdk/utils/validation.py +20 -28
  205. {glaip_sdk-0.0.20.dist-info → glaip_sdk-0.7.7.dist-info}/METADATA +78 -23
  206. glaip_sdk-0.7.7.dist-info/RECORD +213 -0
  207. {glaip_sdk-0.0.20.dist-info → glaip_sdk-0.7.7.dist-info}/WHEEL +2 -1
  208. glaip_sdk-0.7.7.dist-info/entry_points.txt +2 -0
  209. glaip_sdk-0.7.7.dist-info/top_level.txt +1 -0
  210. glaip_sdk/cli/commands/agents.py +0 -1412
  211. glaip_sdk/cli/commands/mcps.py +0 -1225
  212. glaip_sdk/cli/commands/tools.py +0 -597
  213. glaip_sdk/cli/utils.py +0 -1330
  214. glaip_sdk/models.py +0 -259
  215. glaip_sdk-0.0.20.dist-info/RECORD +0 -80
  216. glaip_sdk-0.0.20.dist-info/entry_points.txt +0 -3
@@ -0,0 +1,187 @@
1
+ """CLI rendering utilities: Rich console helpers, viewer launchers, renderer builders.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ Putu Ravindra Wiguna (putu.r.wiguna@gdplabs.id)
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ import sys
12
+ from contextlib import AbstractContextManager, contextmanager, nullcontext
13
+ from typing import Any
14
+
15
+ from rich.console import Console
16
+
17
+ from glaip_sdk.branding import ACCENT_STYLE
18
+ from glaip_sdk.cli.context import _get_view, get_ctx_value
19
+ from glaip_sdk.utils.rendering.renderer import (
20
+ CapturingConsole,
21
+ RendererFactoryOptions,
22
+ RichStreamRenderer,
23
+ make_default_renderer,
24
+ make_verbose_renderer,
25
+ )
26
+
27
+ # Export console for backward compatibility
28
+ console = Console()
29
+
30
+
31
+ def _can_use_spinner(ctx: Any | None, active_console: Console) -> bool:
32
+ """Check if spinner output is allowed in the current environment."""
33
+ if ctx is not None:
34
+ tty_enabled = bool(get_ctx_value(ctx, "tty", True))
35
+ view = (_get_view(ctx) or "rich").lower()
36
+ if not tty_enabled or view not in {"", "rich"}:
37
+ return False
38
+
39
+ if not active_console.is_terminal:
40
+ return False
41
+
42
+ return _stream_supports_tty(getattr(active_console, "file", None))
43
+
44
+
45
+ def _stream_supports_tty(stream: Any) -> bool:
46
+ """Return True if the provided stream can safely render a spinner."""
47
+ target = stream if hasattr(stream, "isatty") else sys.stdout
48
+ try:
49
+ return bool(target.isatty())
50
+ except Exception:
51
+ return False
52
+
53
+
54
+ def update_spinner(status_indicator: Any | None, message: str) -> None:
55
+ """Update spinner text when a status indicator is active."""
56
+ if status_indicator is None:
57
+ return
58
+
59
+ try:
60
+ status_indicator.update(message)
61
+ except Exception: # pragma: no cover - defensive update
62
+ pass
63
+
64
+
65
+ def stop_spinner(status_indicator: Any | None) -> None:
66
+ """Stop an active spinner safely."""
67
+ if status_indicator is None:
68
+ return
69
+
70
+ try:
71
+ status_indicator.stop()
72
+ except Exception: # pragma: no cover - defensive stop
73
+ pass
74
+
75
+
76
+ # Backwards compatibility aliases for legacy callers
77
+ _spinner_update = update_spinner
78
+ _spinner_stop = stop_spinner
79
+
80
+
81
+ def spinner_context(
82
+ ctx: Any | None,
83
+ message: str,
84
+ *,
85
+ console_override: Console | None = None,
86
+ spinner: str = "dots",
87
+ spinner_style: str = ACCENT_STYLE,
88
+ ) -> AbstractContextManager[Any]:
89
+ """Return a context manager that renders a spinner when appropriate."""
90
+ active_console = console_override or console
91
+ if not _can_use_spinner(ctx, active_console):
92
+ return nullcontext()
93
+
94
+ status = active_console.status(
95
+ message,
96
+ spinner=spinner,
97
+ spinner_style=spinner_style,
98
+ )
99
+
100
+ if not hasattr(status, "__enter__") or not hasattr(status, "__exit__"):
101
+ return nullcontext()
102
+
103
+ return status
104
+
105
+
106
+ def _register_renderer_with_session(ctx: Any, renderer: RichStreamRenderer) -> None:
107
+ """Attach renderer to an active slash session when present."""
108
+ try:
109
+ ctx_obj = getattr(ctx, "obj", None)
110
+ session = ctx_obj.get("_slash_session") if isinstance(ctx_obj, dict) else None
111
+ if session and hasattr(session, "register_active_renderer"):
112
+ session.register_active_renderer(renderer)
113
+ except Exception:
114
+ # Never let session bookkeeping break renderer creation
115
+ pass
116
+
117
+
118
+ def build_renderer(
119
+ _ctx: Any,
120
+ *,
121
+ save_path: str | os.PathLike[str] | None,
122
+ verbose: bool = False,
123
+ _tty_enabled: bool = True,
124
+ live: bool | None = None,
125
+ snapshots: bool | None = None,
126
+ ) -> tuple[RichStreamRenderer, Console | CapturingConsole]:
127
+ """Build renderer and capturing console for CLI commands.
128
+
129
+ Args:
130
+ _ctx: Click context object for CLI operations.
131
+ save_path: Path to save output to (enables capturing console).
132
+ verbose: Whether to enable verbose mode.
133
+ _tty_enabled: Whether TTY is available for interactive features.
134
+ live: Whether to enable live rendering mode (overrides verbose default).
135
+ snapshots: Whether to capture and store snapshots.
136
+
137
+ Returns:
138
+ Tuple of (renderer, capturing_console) for streaming output.
139
+ """
140
+ # Use capturing console if saving output
141
+ working_console = CapturingConsole(console, capture=True) if save_path else console
142
+
143
+ # Configure renderer based on verbose mode and explicit overrides
144
+ live_enabled = bool(live) if live is not None else not verbose
145
+ cfg_overrides = {
146
+ "live": live_enabled,
147
+ "append_finished_snapshots": bool(snapshots) if snapshots is not None else False,
148
+ }
149
+ renderer_console = (
150
+ working_console.original_console if isinstance(working_console, CapturingConsole) else working_console
151
+ )
152
+ factory = make_verbose_renderer if verbose else make_default_renderer
153
+ factory_options = RendererFactoryOptions(
154
+ console=renderer_console,
155
+ cfg_overrides=cfg_overrides,
156
+ verbose=verbose if factory is make_default_renderer else None,
157
+ )
158
+ renderer = factory_options.build(factory)
159
+
160
+ # Link the renderer back to the slash session when running from the palette.
161
+ _register_renderer_with_session(_ctx, renderer)
162
+
163
+ return renderer, working_console
164
+
165
+
166
+ @contextmanager
167
+ def with_client_and_spinner(
168
+ ctx: Any,
169
+ spinner_message: str,
170
+ *,
171
+ console_override: Console | None = None,
172
+ ) -> Any:
173
+ """Context manager for commands that need client and spinner.
174
+
175
+ Args:
176
+ ctx: Click context.
177
+ spinner_message: Message to display in spinner.
178
+ console_override: Optional console override.
179
+
180
+ Yields:
181
+ Client instance.
182
+ """
183
+ from glaip_sdk.cli.core.context import get_client # noqa: PLC0415
184
+
185
+ client = get_client(ctx)
186
+ with spinner_context(ctx, spinner_message, console_override=console_override):
187
+ yield client
glaip_sdk/cli/display.py CHANGED
@@ -16,8 +16,8 @@ from rich.panel import Panel
16
16
  from rich.text import Text
17
17
 
18
18
  from glaip_sdk.branding import ERROR_STYLE, SUCCESS, SUCCESS_STYLE, WARNING_STYLE
19
+ from glaip_sdk.cli.hints import command_hint, format_command_hint, in_slash_mode
19
20
  from glaip_sdk.cli.rich_helpers import markup_text
20
- from glaip_sdk.cli.utils import command_hint, format_command_hint
21
21
  from glaip_sdk.icons import ICON_AGENT, ICON_TOOL
22
22
  from glaip_sdk.rich_components import AIPPanel
23
23
 
@@ -41,9 +41,7 @@ def display_creation_success(
41
41
  # Build additional fields display
42
42
  fields_display = ""
43
43
  if additional_fields:
44
- fields_display = "\n" + "\n".join(
45
- f"{key}: {value}" for key, value in additional_fields.items()
46
- )
44
+ fields_display = "\n" + "\n".join(f"{key}: {value}" for key, value in additional_fields.items())
47
45
 
48
46
  return AIPPanel(
49
47
  f"[{SUCCESS_STYLE}]✅ {resource_type} '{resource_name}' created successfully![/]\n\n"
@@ -64,9 +62,7 @@ def display_update_success(resource_type: str, resource_name: str) -> Text:
64
62
  Returns:
65
63
  Rich Text object for display
66
64
  """
67
- return markup_text(
68
- f"[{SUCCESS_STYLE}]✅ {resource_type} '{resource_name}' updated successfully[/]"
69
- )
65
+ return markup_text(f"[{SUCCESS_STYLE}]✅ {resource_type} '{resource_name}' updated successfully[/]")
70
66
 
71
67
 
72
68
  def display_deletion_success(resource_type: str, resource_name: str) -> Text:
@@ -79,9 +75,7 @@ def display_deletion_success(resource_type: str, resource_name: str) -> Text:
79
75
  Returns:
80
76
  Rich Text object for display
81
77
  """
82
- return markup_text(
83
- f"[{SUCCESS_STYLE}]✅ {resource_type} '{resource_name}' deleted successfully[/]"
84
- )
78
+ return markup_text(f"[{SUCCESS_STYLE}]✅ {resource_type} '{resource_name}' deleted successfully[/]")
85
79
 
86
80
 
87
81
  def display_api_error(error: Exception, operation: str = "operation") -> None:
@@ -123,7 +117,12 @@ def print_api_error(e: Exception) -> None:
123
117
  console.print(f"[{ERROR_STYLE}]Error: {e}[/]")
124
118
  return
125
119
 
126
- console.print(f"[{ERROR_STYLE}]API Error: {e}[/]")
120
+ error_text = str(e).strip()
121
+ if not error_text:
122
+ error_text = "Unknown error"
123
+ if "\n" in error_text:
124
+ error_text = error_text.splitlines()[0]
125
+ console.print(f"[{ERROR_STYLE}]API Error: {error_text}[/]")
127
126
  status_code = getattr(e, "status_code", None)
128
127
  if status_code is not None:
129
128
  console.print(f"[{WARNING_STYLE}]Status: {status_code}[/]")
@@ -209,6 +208,7 @@ def build_resource_result_data(resource: Any, fields: list[str]) -> dict[str, An
209
208
 
210
209
 
211
210
  def _normalise_field_value(field: str, value: Any) -> Any:
211
+ """Convert special sentinel values into display-friendly text."""
212
212
  if value is _MISSING:
213
213
  return "N/A"
214
214
  if hasattr(value, "_mock_name"):
@@ -293,9 +293,7 @@ def display_confirmation_prompt(resource_type: str, resource_name: str) -> bool:
293
293
  Returns:
294
294
  True if user confirms, False otherwise
295
295
  """
296
- if not click.confirm(
297
- f"Are you sure you want to delete {resource_type.lower()} '{resource_name}'?"
298
- ):
296
+ if not click.confirm(f"Are you sure you want to delete {resource_type.lower()} '{resource_name}'?"):
299
297
  if console.is_terminal:
300
298
  console.print(Text("Deletion cancelled."))
301
299
  return False
@@ -306,6 +304,7 @@ def display_agent_run_suggestions(agent: Any) -> Panel:
306
304
  """Return a panel with post-creation suggestions for an agent."""
307
305
  agent_id = getattr(agent, "id", "")
308
306
  agent_name = getattr(agent, "name", "")
307
+ slash_mode = in_slash_mode()
309
308
  run_hint_id = command_hint(
310
309
  f'agents run {agent_id} "Your message here"',
311
310
  slash_command=None,
@@ -315,27 +314,41 @@ def display_agent_run_suggestions(agent: Any) -> Panel:
315
314
  slash_command=None,
316
315
  )
317
316
 
318
- cli_section = ""
319
- if run_hint_id and run_hint_name:
320
- cli_section = (
321
- "📋 Prefer the CLI instead?\n"
322
- f" {format_command_hint(run_hint_id) or run_hint_id}\n"
323
- f" {format_command_hint(run_hint_name) or run_hint_name}\n\n"
317
+ content_parts: list[str] = ["[bold blue]💡 Next Steps:[/bold blue]\n\n"]
318
+
319
+ if slash_mode:
320
+ slash_shortcuts = "\n".join(
321
+ f" {format_command_hint(command, description) or command}"
322
+ for command, description in (
323
+ ("/details", "Show configuration (toggle preview)"),
324
+ ("/help", "Show command palette menu"),
325
+ ("/exit", "Return to the palette"),
326
+ )
327
+ )
328
+ content_parts.append(
329
+ f"🚀 Start chatting with [bold]{agent_name}[/bold] right here:\n"
330
+ f" Type your message below and press Enter to run it immediately.\n\n"
331
+ f"{ICON_TOOL} Slash shortcuts:\n"
332
+ f"{slash_shortcuts}"
333
+ )
334
+ else:
335
+ cli_hint_lines = [format_command_hint(hint) or hint for hint in (run_hint_id, run_hint_name) if hint]
336
+ if cli_hint_lines:
337
+ joined_hints = "\n".join(f" {hint}" for hint in cli_hint_lines)
338
+ content_parts.append(f"🚀 Run this agent from the CLI:\n{joined_hints}\n\n")
339
+ content_parts.append(
340
+ f"{ICON_TOOL} Available options:\n"
341
+ f" [dim]--chat-history[/dim] Include previous conversation\n"
342
+ f" [dim]--file[/dim] Attach files\n"
343
+ f" [dim]--input[/dim] Alternative input method\n"
344
+ f" [dim]--timeout[/dim] Set execution timeout\n"
345
+ f" [dim]--save[/dim] Save transcript to file\n"
346
+ f" [dim]--verbose[/dim] Show detailed execution\n\n"
347
+ f"💡 [dim]Input text can be positional OR use --input flag (both work!)[/dim]"
324
348
  )
325
349
 
326
350
  return AIPPanel(
327
- f"[bold blue]💡 Next Steps:[/bold blue]\n\n"
328
- f"🚀 Start chatting with [bold]{agent_name}[/bold] right here:\n"
329
- f" Type your message below and press Enter to run it immediately.\n\n"
330
- f"{cli_section}"
331
- f"{ICON_TOOL} Available options:\n"
332
- f" [dim]--chat-history[/dim] Include previous conversation\n"
333
- f" [dim]--file[/dim] Attach files\n"
334
- f" [dim]--input[/dim] Alternative input method\n"
335
- f" [dim]--timeout[/dim] Set execution timeout\n"
336
- f" [dim]--save[/dim] Save transcript to file\n"
337
- f" [dim]--verbose[/dim] Show detailed execution\n\n"
338
- f"💡 [dim]Input text can be positional OR use --input flag (both work!)[/dim]",
351
+ "".join(content_parts),
339
352
  title=f"{ICON_AGENT} Ready to Run Agent",
340
353
  border_style="blue",
341
354
  padding=(0, 1),
@@ -0,0 +1,20 @@
1
+ """Entry point wrapper for early logging configuration.
2
+
3
+ This must be imported BEFORE glaip_sdk.cli.main to catch import-time warnings.
4
+
5
+ Authors:
6
+ Raymond Christopher (raymond.christopher@gdplabs.id)
7
+ """
8
+
9
+ import sys
10
+
11
+ # Configure logging BEFORE importing anything else
12
+ from glaip_sdk.runner.logging_config import setup_cli_logging
13
+
14
+ setup_cli_logging()
15
+
16
+ # Now import and run CLI
17
+ from glaip_sdk.cli import main # noqa: E402
18
+
19
+ if __name__ == "__main__":
20
+ sys.exit(main()) # pylint: disable=no-value-for-parameter
glaip_sdk/cli/hints.py ADDED
@@ -0,0 +1,57 @@
1
+ """Helpers for formatting CLI/slash command hints.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import click
10
+
11
+ from glaip_sdk.branding import HINT_COMMAND_STYLE, HINT_DESCRIPTION_COLOR
12
+
13
+
14
+ def in_slash_mode(ctx: click.Context | None = None) -> bool:
15
+ """Return True when running inside the slash command palette."""
16
+ if ctx is None:
17
+ try:
18
+ ctx = click.get_current_context(silent=True)
19
+ except RuntimeError:
20
+ ctx = None
21
+
22
+ if ctx is None:
23
+ return False
24
+
25
+ obj = getattr(ctx, "obj", None)
26
+ if isinstance(obj, dict):
27
+ return bool(obj.get("_slash_session"))
28
+
29
+ return bool(getattr(obj, "_slash_session", False))
30
+
31
+
32
+ def command_hint(
33
+ cli_command: str | None,
34
+ slash_command: str | None = None,
35
+ *,
36
+ ctx: click.Context | None = None,
37
+ ) -> str | None:
38
+ """Return the appropriate command string for the current mode."""
39
+ if in_slash_mode(ctx):
40
+ if not slash_command:
41
+ return None
42
+ return slash_command if slash_command.startswith("/") else f"/{slash_command}"
43
+
44
+ if not cli_command:
45
+ return None
46
+ return f"aip {cli_command}"
47
+
48
+
49
+ def format_command_hint(command: str | None, description: str | None = None) -> str | None:
50
+ """Return a Rich markup string that highlights a command hint."""
51
+ if not command:
52
+ return None
53
+
54
+ highlighted = f"[{HINT_COMMAND_STYLE}]{command}[/]"
55
+ if description:
56
+ highlighted += f" [{HINT_DESCRIPTION_COLOR}]{description}[/{HINT_DESCRIPTION_COLOR}]"
57
+ return highlighted
glaip_sdk/cli/io.py CHANGED
@@ -7,6 +7,7 @@ Authors:
7
7
  Raymond Christopher (raymond.christopher@gdplabs.id)
8
8
  """
9
9
 
10
+ from importlib import import_module
10
11
  from pathlib import Path
11
12
  from typing import TYPE_CHECKING, Any
12
13
 
@@ -25,14 +26,14 @@ if TYPE_CHECKING: # pragma: no cover - typing-only imports
25
26
 
26
27
  def _create_console() -> "Console":
27
28
  """Return a Console instance (lazy import for easier testing)."""
28
- from rich.console import Console # Local import for test patching
29
-
30
- return Console()
29
+ try:
30
+ console_module = import_module("rich.console")
31
+ except ImportError as exc: # pragma: no cover - optional dependency missing
32
+ raise RuntimeError("Rich Console is not available") from exc
33
+ return console_module.Console()
31
34
 
32
35
 
33
- def load_resource_from_file_with_validation(
34
- file_path: Path, resource_type: str
35
- ) -> dict[str, Any]:
36
+ def load_resource_from_file_with_validation(file_path: Path, resource_type: str) -> dict[str, Any]:
36
37
  """Load resource data from JSON or YAML file with CLI-friendly error handling.
37
38
 
38
39
  Args:
@@ -47,17 +48,15 @@ def load_resource_from_file_with_validation(
47
48
  """
48
49
  try:
49
50
  return load_resource_from_file(file_path)
50
- except FileNotFoundError:
51
- raise click.ClickException(f"File not found: {file_path}")
51
+ except FileNotFoundError as err:
52
+ raise click.ClickException(f"File not found: {file_path}") from err
52
53
  except ValueError as e:
53
- raise click.ClickException(f"Invalid {resource_type.lower()} file format: {e}")
54
+ raise click.ClickException(f"Invalid {resource_type.lower()} file format: {e}") from e
54
55
  except Exception as e:
55
- raise click.ClickException(f"Failed to load {resource_type.lower()} file: {e}")
56
+ raise click.ClickException(f"Failed to load {resource_type.lower()} file: {e}") from e
56
57
 
57
58
 
58
- def export_resource_to_file_with_validation(
59
- resource: Any, file_path: Path, format: str = "json"
60
- ) -> None:
59
+ def export_resource_to_file_with_validation(resource: Any, file_path: Path, format: str = "json") -> None:
61
60
  """Export resource to file with CLI-friendly error handling.
62
61
 
63
62
  Args:
@@ -73,7 +72,7 @@ def export_resource_to_file_with_validation(
73
72
  export_data = collect_attributes_for_export(resource)
74
73
  write_resource_export(file_path, export_data, format)
75
74
  except Exception as e:
76
- raise click.ClickException(f"Failed to export resource: {e}")
75
+ raise click.ClickException(f"Failed to export resource: {e}") from e
77
76
 
78
77
 
79
78
  def fetch_raw_resource_details(client: Any, resource: Any, resource_type: str) -> Any:
@@ -107,9 +106,7 @@ def fetch_raw_resource_details(client: Any, resource: Any, resource_type: str) -
107
106
  # Direct response
108
107
  return raw_response
109
108
  except Exception as e:
110
- console.print(
111
- f"[{WARNING_STYLE}]Failed to fetch raw {resource_type} details: {e}[/]"
112
- )
109
+ console.print(f"[{WARNING_STYLE}]Failed to fetch raw {resource_type} details: {e}[/]")
113
110
  # Fall back to regular method
114
111
  return None
115
112
  return None