glaip-sdk 0.1.2__py3-none-any.whl → 0.7.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 (217) hide show
  1. glaip_sdk/__init__.py +44 -4
  2. glaip_sdk/_version.py +9 -0
  3. glaip_sdk/agents/__init__.py +27 -0
  4. glaip_sdk/agents/base.py +1413 -0
  5. glaip_sdk/branding.py +126 -2
  6. glaip_sdk/cli/account_store.py +555 -0
  7. glaip_sdk/cli/auth.py +260 -15
  8. glaip_sdk/cli/commands/__init__.py +2 -2
  9. glaip_sdk/cli/commands/accounts.py +746 -0
  10. glaip_sdk/cli/commands/agents/__init__.py +116 -0
  11. glaip_sdk/cli/commands/agents/_common.py +562 -0
  12. glaip_sdk/cli/commands/agents/create.py +155 -0
  13. glaip_sdk/cli/commands/agents/delete.py +64 -0
  14. glaip_sdk/cli/commands/agents/get.py +89 -0
  15. glaip_sdk/cli/commands/agents/list.py +129 -0
  16. glaip_sdk/cli/commands/agents/run.py +264 -0
  17. glaip_sdk/cli/commands/agents/sync_langflow.py +72 -0
  18. glaip_sdk/cli/commands/agents/update.py +112 -0
  19. glaip_sdk/cli/commands/common_config.py +104 -0
  20. glaip_sdk/cli/commands/configure.py +728 -113
  21. glaip_sdk/cli/commands/mcps/__init__.py +94 -0
  22. glaip_sdk/cli/commands/mcps/_common.py +459 -0
  23. glaip_sdk/cli/commands/mcps/connect.py +82 -0
  24. glaip_sdk/cli/commands/mcps/create.py +152 -0
  25. glaip_sdk/cli/commands/mcps/delete.py +73 -0
  26. glaip_sdk/cli/commands/mcps/get.py +212 -0
  27. glaip_sdk/cli/commands/mcps/list.py +69 -0
  28. glaip_sdk/cli/commands/mcps/tools.py +235 -0
  29. glaip_sdk/cli/commands/mcps/update.py +190 -0
  30. glaip_sdk/cli/commands/models.py +12 -8
  31. glaip_sdk/cli/commands/shared/__init__.py +21 -0
  32. glaip_sdk/cli/commands/shared/formatters.py +91 -0
  33. glaip_sdk/cli/commands/tools/__init__.py +69 -0
  34. glaip_sdk/cli/commands/tools/_common.py +80 -0
  35. glaip_sdk/cli/commands/tools/create.py +228 -0
  36. glaip_sdk/cli/commands/tools/delete.py +61 -0
  37. glaip_sdk/cli/commands/tools/get.py +103 -0
  38. glaip_sdk/cli/commands/tools/list.py +69 -0
  39. glaip_sdk/cli/commands/tools/script.py +49 -0
  40. glaip_sdk/cli/commands/tools/update.py +102 -0
  41. glaip_sdk/cli/commands/transcripts/__init__.py +90 -0
  42. glaip_sdk/cli/commands/transcripts/_common.py +9 -0
  43. glaip_sdk/cli/commands/transcripts/clear.py +5 -0
  44. glaip_sdk/cli/commands/transcripts/detail.py +5 -0
  45. glaip_sdk/cli/commands/transcripts_original.py +756 -0
  46. glaip_sdk/cli/commands/update.py +163 -17
  47. glaip_sdk/cli/config.py +49 -4
  48. glaip_sdk/cli/constants.py +38 -0
  49. glaip_sdk/cli/context.py +8 -0
  50. glaip_sdk/cli/core/__init__.py +79 -0
  51. glaip_sdk/cli/core/context.py +124 -0
  52. glaip_sdk/cli/core/output.py +851 -0
  53. glaip_sdk/cli/core/prompting.py +649 -0
  54. glaip_sdk/cli/core/rendering.py +187 -0
  55. glaip_sdk/cli/display.py +41 -20
  56. glaip_sdk/cli/entrypoint.py +20 -0
  57. glaip_sdk/cli/hints.py +57 -0
  58. glaip_sdk/cli/io.py +6 -3
  59. glaip_sdk/cli/main.py +340 -143
  60. glaip_sdk/cli/masking.py +21 -33
  61. glaip_sdk/cli/pager.py +12 -13
  62. glaip_sdk/cli/parsers/__init__.py +1 -3
  63. glaip_sdk/cli/resolution.py +2 -1
  64. glaip_sdk/cli/slash/__init__.py +0 -9
  65. glaip_sdk/cli/slash/accounts_controller.py +580 -0
  66. glaip_sdk/cli/slash/accounts_shared.py +75 -0
  67. glaip_sdk/cli/slash/agent_session.py +62 -21
  68. glaip_sdk/cli/slash/prompt.py +21 -0
  69. glaip_sdk/cli/slash/remote_runs_controller.py +568 -0
  70. glaip_sdk/cli/slash/session.py +1105 -153
  71. glaip_sdk/cli/slash/tui/__init__.py +36 -0
  72. glaip_sdk/cli/slash/tui/accounts.tcss +177 -0
  73. glaip_sdk/cli/slash/tui/accounts_app.py +1853 -0
  74. glaip_sdk/cli/slash/tui/background_tasks.py +72 -0
  75. glaip_sdk/cli/slash/tui/clipboard.py +195 -0
  76. glaip_sdk/cli/slash/tui/context.py +92 -0
  77. glaip_sdk/cli/slash/tui/indicators.py +341 -0
  78. glaip_sdk/cli/slash/tui/keybind_registry.py +235 -0
  79. glaip_sdk/cli/slash/tui/layouts/__init__.py +14 -0
  80. glaip_sdk/cli/slash/tui/layouts/harlequin.py +184 -0
  81. glaip_sdk/cli/slash/tui/loading.py +80 -0
  82. glaip_sdk/cli/slash/tui/remote_runs_app.py +760 -0
  83. glaip_sdk/cli/slash/tui/terminal.py +407 -0
  84. glaip_sdk/cli/slash/tui/theme/__init__.py +15 -0
  85. glaip_sdk/cli/slash/tui/theme/catalog.py +79 -0
  86. glaip_sdk/cli/slash/tui/theme/manager.py +112 -0
  87. glaip_sdk/cli/slash/tui/theme/tokens.py +55 -0
  88. glaip_sdk/cli/slash/tui/toast.py +388 -0
  89. glaip_sdk/cli/transcript/__init__.py +12 -52
  90. glaip_sdk/cli/transcript/cache.py +255 -44
  91. glaip_sdk/cli/transcript/capture.py +66 -1
  92. glaip_sdk/cli/transcript/history.py +815 -0
  93. glaip_sdk/cli/transcript/viewer.py +72 -463
  94. glaip_sdk/cli/tui_settings.py +125 -0
  95. glaip_sdk/cli/update_notifier.py +227 -10
  96. glaip_sdk/cli/validators.py +5 -6
  97. glaip_sdk/client/__init__.py +3 -1
  98. glaip_sdk/client/_schedule_payloads.py +89 -0
  99. glaip_sdk/client/agent_runs.py +147 -0
  100. glaip_sdk/client/agents.py +576 -44
  101. glaip_sdk/client/base.py +26 -0
  102. glaip_sdk/client/hitl.py +136 -0
  103. glaip_sdk/client/main.py +25 -14
  104. glaip_sdk/client/mcps.py +165 -24
  105. glaip_sdk/client/payloads/agent/__init__.py +23 -0
  106. glaip_sdk/client/{_agent_payloads.py → payloads/agent/requests.py} +63 -47
  107. glaip_sdk/client/payloads/agent/responses.py +43 -0
  108. glaip_sdk/client/run_rendering.py +546 -92
  109. glaip_sdk/client/schedules.py +439 -0
  110. glaip_sdk/client/shared.py +21 -0
  111. glaip_sdk/client/tools.py +206 -32
  112. glaip_sdk/config/constants.py +33 -2
  113. glaip_sdk/guardrails/__init__.py +80 -0
  114. glaip_sdk/guardrails/serializer.py +89 -0
  115. glaip_sdk/hitl/__init__.py +48 -0
  116. glaip_sdk/hitl/base.py +64 -0
  117. glaip_sdk/hitl/callback.py +43 -0
  118. glaip_sdk/hitl/local.py +121 -0
  119. glaip_sdk/hitl/remote.py +523 -0
  120. glaip_sdk/mcps/__init__.py +21 -0
  121. glaip_sdk/mcps/base.py +345 -0
  122. glaip_sdk/models/__init__.py +136 -0
  123. glaip_sdk/models/_provider_mappings.py +101 -0
  124. glaip_sdk/models/_validation.py +97 -0
  125. glaip_sdk/models/agent.py +48 -0
  126. glaip_sdk/models/agent_runs.py +117 -0
  127. glaip_sdk/models/common.py +42 -0
  128. glaip_sdk/models/constants.py +141 -0
  129. glaip_sdk/models/mcp.py +33 -0
  130. glaip_sdk/models/model.py +170 -0
  131. glaip_sdk/models/schedule.py +224 -0
  132. glaip_sdk/models/tool.py +33 -0
  133. glaip_sdk/payload_schemas/__init__.py +1 -13
  134. glaip_sdk/payload_schemas/agent.py +1 -0
  135. glaip_sdk/payload_schemas/guardrails.py +34 -0
  136. glaip_sdk/registry/__init__.py +55 -0
  137. glaip_sdk/registry/agent.py +164 -0
  138. glaip_sdk/registry/base.py +139 -0
  139. glaip_sdk/registry/mcp.py +253 -0
  140. glaip_sdk/registry/tool.py +445 -0
  141. glaip_sdk/rich_components.py +58 -2
  142. glaip_sdk/runner/__init__.py +76 -0
  143. glaip_sdk/runner/base.py +84 -0
  144. glaip_sdk/runner/deps.py +115 -0
  145. glaip_sdk/runner/langgraph.py +1055 -0
  146. glaip_sdk/runner/logging_config.py +77 -0
  147. glaip_sdk/runner/mcp_adapter/__init__.py +13 -0
  148. glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py +43 -0
  149. glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py +257 -0
  150. glaip_sdk/runner/mcp_adapter/mcp_config_builder.py +116 -0
  151. glaip_sdk/runner/tool_adapter/__init__.py +18 -0
  152. glaip_sdk/runner/tool_adapter/base_tool_adapter.py +44 -0
  153. glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py +242 -0
  154. glaip_sdk/schedules/__init__.py +22 -0
  155. glaip_sdk/schedules/base.py +291 -0
  156. glaip_sdk/tools/__init__.py +22 -0
  157. glaip_sdk/tools/base.py +488 -0
  158. glaip_sdk/utils/__init__.py +59 -12
  159. glaip_sdk/utils/a2a/__init__.py +34 -0
  160. glaip_sdk/utils/a2a/event_processor.py +188 -0
  161. glaip_sdk/utils/agent_config.py +8 -2
  162. glaip_sdk/utils/bundler.py +403 -0
  163. glaip_sdk/utils/client.py +111 -0
  164. glaip_sdk/utils/client_utils.py +39 -7
  165. glaip_sdk/utils/datetime_helpers.py +58 -0
  166. glaip_sdk/utils/discovery.py +78 -0
  167. glaip_sdk/utils/display.py +23 -15
  168. glaip_sdk/utils/export.py +143 -0
  169. glaip_sdk/utils/general.py +0 -33
  170. glaip_sdk/utils/import_export.py +12 -7
  171. glaip_sdk/utils/import_resolver.py +524 -0
  172. glaip_sdk/utils/instructions.py +101 -0
  173. glaip_sdk/utils/rendering/__init__.py +115 -1
  174. glaip_sdk/utils/rendering/formatting.py +5 -30
  175. glaip_sdk/utils/rendering/layout/__init__.py +64 -0
  176. glaip_sdk/utils/rendering/{renderer → layout}/panels.py +9 -0
  177. glaip_sdk/utils/rendering/{renderer → layout}/progress.py +70 -1
  178. glaip_sdk/utils/rendering/layout/summary.py +74 -0
  179. glaip_sdk/utils/rendering/layout/transcript.py +606 -0
  180. glaip_sdk/utils/rendering/models.py +1 -0
  181. glaip_sdk/utils/rendering/renderer/__init__.py +9 -47
  182. glaip_sdk/utils/rendering/renderer/base.py +299 -1434
  183. glaip_sdk/utils/rendering/renderer/config.py +1 -5
  184. glaip_sdk/utils/rendering/renderer/debug.py +26 -20
  185. glaip_sdk/utils/rendering/renderer/factory.py +138 -0
  186. glaip_sdk/utils/rendering/renderer/stream.py +4 -33
  187. glaip_sdk/utils/rendering/renderer/summary_window.py +79 -0
  188. glaip_sdk/utils/rendering/renderer/thinking.py +273 -0
  189. glaip_sdk/utils/rendering/renderer/tool_panels.py +442 -0
  190. glaip_sdk/utils/rendering/renderer/transcript_mode.py +162 -0
  191. glaip_sdk/utils/rendering/state.py +204 -0
  192. glaip_sdk/utils/rendering/steps/__init__.py +34 -0
  193. glaip_sdk/utils/rendering/{steps.py → steps/event_processor.py} +53 -440
  194. glaip_sdk/utils/rendering/steps/format.py +176 -0
  195. glaip_sdk/utils/rendering/steps/manager.py +387 -0
  196. glaip_sdk/utils/rendering/timing.py +36 -0
  197. glaip_sdk/utils/rendering/viewer/__init__.py +21 -0
  198. glaip_sdk/utils/rendering/viewer/presenter.py +184 -0
  199. glaip_sdk/utils/resource_refs.py +25 -13
  200. glaip_sdk/utils/runtime_config.py +426 -0
  201. glaip_sdk/utils/serialization.py +18 -0
  202. glaip_sdk/utils/sync.py +162 -0
  203. glaip_sdk/utils/tool_detection.py +301 -0
  204. glaip_sdk/utils/tool_storage_provider.py +140 -0
  205. glaip_sdk/utils/validation.py +16 -24
  206. {glaip_sdk-0.1.2.dist-info → glaip_sdk-0.7.17.dist-info}/METADATA +69 -23
  207. glaip_sdk-0.7.17.dist-info/RECORD +224 -0
  208. {glaip_sdk-0.1.2.dist-info → glaip_sdk-0.7.17.dist-info}/WHEEL +2 -1
  209. glaip_sdk-0.7.17.dist-info/entry_points.txt +2 -0
  210. glaip_sdk-0.7.17.dist-info/top_level.txt +1 -0
  211. glaip_sdk/cli/commands/agents.py +0 -1369
  212. glaip_sdk/cli/commands/mcps.py +0 -1187
  213. glaip_sdk/cli/commands/tools.py +0 -584
  214. glaip_sdk/cli/utils.py +0 -1278
  215. glaip_sdk/models.py +0 -240
  216. glaip_sdk-0.1.2.dist-info/RECORD +0 -82
  217. glaip_sdk-0.1.2.dist-info/entry_points.txt +0 -3
@@ -0,0 +1,80 @@
1
+ """Common helpers and group definition for tool commands.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ import click
12
+ from rich.console import Console
13
+
14
+ from glaip_sdk.cli.core.context import get_client
15
+ from glaip_sdk.cli.core.rendering import spinner_context
16
+ from glaip_sdk.cli.resolution import resolve_resource_reference
17
+
18
+ console = Console()
19
+
20
+
21
+ @click.group(name="tools", no_args_is_help=True)
22
+ def tools_group() -> None:
23
+ """Tool management operations."""
24
+ pass
25
+
26
+
27
+ def _resolve_tool(ctx: Any, client: Any, ref: str, select: int | None = None) -> Any | None:
28
+ """Resolve a tool by ID or name, handling ambiguous matches interactively.
29
+
30
+ This function provides tool-specific resolution logic. It uses
31
+ resolve_resource_reference to find tools by UUID or name, with interactive
32
+ selection when multiple matches are found.
33
+
34
+ Args:
35
+ ctx: Click context for CLI operations.
36
+ client: API client instance.
37
+ ref: Tool reference (UUID string or name).
38
+ select: Pre-selected index for non-interactive mode (1-based).
39
+
40
+ Returns:
41
+ Tool object if found, None otherwise.
42
+ """
43
+ # Configure tool-specific resolution with standard fuzzy matching
44
+ get_by_id = client.get_tool
45
+ find_by_name = client.find_tools
46
+ return resolve_resource_reference(
47
+ ctx,
48
+ client,
49
+ ref,
50
+ "tool",
51
+ get_by_id,
52
+ find_by_name,
53
+ "Tool",
54
+ select=select,
55
+ )
56
+
57
+
58
+ def _get_tool_by_id_with_spinner(ctx: Any, tool_id: str) -> Any:
59
+ """Get tool by ID with spinner context and error handling.
60
+
61
+ Args:
62
+ ctx: Click context.
63
+ tool_id: Tool ID to fetch.
64
+
65
+ Returns:
66
+ Tool object.
67
+
68
+ Raises:
69
+ click.ClickException: If tool not found.
70
+ """
71
+ client = get_client(ctx)
72
+ try:
73
+ with spinner_context(
74
+ ctx,
75
+ "[bold blue]Fetching tool…[/bold blue]",
76
+ console_override=console,
77
+ ):
78
+ return client.get_tool_by_id(tool_id)
79
+ except Exception as e:
80
+ raise click.ClickException(f"Tool with ID '{tool_id}' not found: {e}") from e
@@ -0,0 +1,228 @@
1
+ """Create tool command.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import re
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ import click
14
+
15
+ from glaip_sdk.cli.context import get_ctx_value, output_flags
16
+ from glaip_sdk.cli.core.context import get_client, handle_best_effort_check
17
+ from glaip_sdk.cli.core.rendering import spinner_context
18
+ from glaip_sdk.cli.display import (
19
+ display_api_error,
20
+ display_creation_success,
21
+ handle_json_output,
22
+ handle_rich_output,
23
+ )
24
+ from glaip_sdk.cli.io import load_resource_from_file_with_validation as load_resource_from_file
25
+ from glaip_sdk.utils.import_export import merge_import_with_cli_args
26
+
27
+ from ._common import console, tools_group
28
+
29
+
30
+ def _extract_internal_name(code: str) -> str:
31
+ """Extract plugin class name attribute from tool code."""
32
+ m = re.search(r'^\s*name\s*:\s*str\s*=\s*"([^"]+)"', code, re.M)
33
+ if not m:
34
+ m = re.search(r'^\s*name\s*=\s*"([^"]+)"', code, re.M)
35
+ if not m:
36
+ raise click.ClickException(
37
+ "Could not find plugin 'name' attribute in the tool file. "
38
+ 'Ensure your plugin class defines e.g. name: str = "my_tool".'
39
+ )
40
+ return m.group(1)
41
+
42
+
43
+ def _validate_name_match(provided: str | None, internal: str) -> str:
44
+ """Validate provided --name against internal name; return effective name."""
45
+ if provided and provided != internal:
46
+ raise click.ClickException(
47
+ f"--name '{provided}' does not match plugin internal name '{internal}'. "
48
+ "Either update the code or pass a matching --name."
49
+ )
50
+ return provided or internal
51
+
52
+
53
+ def _check_duplicate_name(client: Any, tool_name: str) -> None:
54
+ """Raise if a tool with the same name already exists."""
55
+
56
+ def _check_duplicate() -> None:
57
+ existing = client.find_tools(name=tool_name)
58
+ if existing:
59
+ raise click.ClickException(
60
+ f"A tool named '{tool_name}' already exists. "
61
+ "Please change your plugin's 'name' to a unique value, then re-run."
62
+ )
63
+
64
+ handle_best_effort_check(_check_duplicate)
65
+
66
+
67
+ def _parse_tags(tags: str | None) -> list[str]:
68
+ """Return a cleaned list of tag strings from a comma-separated input."""
69
+ return [t.strip() for t in (tags.split(",") if tags else []) if t.strip()]
70
+
71
+
72
+ def _handle_import_file(
73
+ import_file: str | None,
74
+ name: str | None,
75
+ description: str | None,
76
+ tags: str | None,
77
+ ) -> dict[str, Any]:
78
+ """Handle import file logic and merge with CLI arguments."""
79
+ if import_file:
80
+ import_data = load_resource_from_file(Path(import_file), "tool")
81
+
82
+ # Merge CLI args with imported data
83
+ cli_args = {
84
+ "name": name,
85
+ "description": description,
86
+ "tags": tags,
87
+ }
88
+
89
+ return merge_import_with_cli_args(import_data, cli_args)
90
+ else:
91
+ # No import file - use CLI args directly
92
+ return {
93
+ "name": name,
94
+ "description": description,
95
+ "tags": tags,
96
+ }
97
+
98
+
99
+ def _create_tool_from_file(
100
+ client: Any,
101
+ file_path: str,
102
+ name: str | None,
103
+ description: str | None,
104
+ tags: str | None,
105
+ ) -> Any:
106
+ """Create tool from file upload."""
107
+ with open(file_path, encoding="utf-8") as f:
108
+ code_content = f.read()
109
+
110
+ internal_name = _extract_internal_name(code_content)
111
+ tool_name = _validate_name_match(name, internal_name)
112
+ _check_duplicate_name(client, tool_name)
113
+
114
+ # Upload the plugin code as-is (no rewrite)
115
+ return client.create_tool_from_code(
116
+ name=tool_name,
117
+ code=code_content,
118
+ framework="langchain", # Always langchain
119
+ description=description,
120
+ tags=_parse_tags(tags) if tags else None,
121
+ )
122
+
123
+
124
+ def _validate_creation_parameters(
125
+ file: str | None,
126
+ import_file: str | None,
127
+ ) -> None:
128
+ """Validate required parameters for tool creation."""
129
+ if not file and not import_file:
130
+ raise click.ClickException("A tool file must be provided. Use --file to specify the tool file to upload.")
131
+
132
+
133
+ @tools_group.command()
134
+ @click.argument("file_arg", required=False, type=click.Path(exists=True))
135
+ @click.option(
136
+ "--file",
137
+ type=click.Path(exists=True),
138
+ help="Tool file to upload",
139
+ )
140
+ @click.option(
141
+ "--name",
142
+ help="Tool name (extracted from script if file provided)",
143
+ )
144
+ @click.option(
145
+ "--description",
146
+ help="Tool description (extracted from script if file provided)",
147
+ )
148
+ @click.option(
149
+ "--tags",
150
+ help="Comma-separated tags for the tool",
151
+ )
152
+ @click.option(
153
+ "--import",
154
+ "import_file",
155
+ type=click.Path(exists=True, dir_okay=False),
156
+ help="Import tool configuration from JSON file",
157
+ )
158
+ @output_flags()
159
+ @click.pass_context
160
+ def create(
161
+ ctx: Any,
162
+ file_arg: str | None,
163
+ file: str | None,
164
+ name: str | None,
165
+ description: str | None,
166
+ tags: str | None,
167
+ import_file: str | None,
168
+ ) -> None:
169
+ r"""Create a new tool.
170
+
171
+ \b
172
+ Examples:
173
+ aip tools create tool.py # Create from file
174
+ aip tools create --import tool.json # Create from exported configuration
175
+ """
176
+ try:
177
+ client = get_client(ctx)
178
+
179
+ # Allow positional file argument for better DX (matches examples)
180
+ if not file and file_arg:
181
+ file = file_arg
182
+
183
+ # Handle import file and merge with CLI arguments
184
+ merged_data = _handle_import_file(import_file, name, description, tags)
185
+
186
+ # Extract merged values
187
+ name = merged_data.get("name")
188
+ description = merged_data.get("description")
189
+ tags_raw = merged_data.get("tags")
190
+ # Convert tags to string format (for _create_tool_from_file which expects str | None)
191
+ # Import data may have tags as list, CLI provides string
192
+ if isinstance(tags_raw, list):
193
+ tags = ",".join(str(tag).strip() for tag in tags_raw) if tags_raw else None
194
+ else:
195
+ tags = tags_raw # Already string or None
196
+
197
+ # Validate required parameters
198
+ _validate_creation_parameters(file, import_file)
199
+
200
+ # Create tool from file (either direct file or import file)
201
+ with spinner_context(
202
+ ctx,
203
+ "[bold blue]Creating tool…[/bold blue]",
204
+ console_override=console,
205
+ ):
206
+ tool = _create_tool_from_file(client, file, name, description, tags)
207
+
208
+ # Handle JSON output
209
+ handle_json_output(ctx, tool.model_dump())
210
+
211
+ # Handle Rich output
212
+ creation_method = "file upload (custom)"
213
+ rich_panel = display_creation_success(
214
+ "Tool",
215
+ tool.name,
216
+ tool.id,
217
+ Framework=getattr(tool, "framework", "N/A"),
218
+ Type=getattr(tool, "tool_type", "N/A"),
219
+ Description=getattr(tool, "description", "No description"),
220
+ Method=creation_method,
221
+ )
222
+ handle_rich_output(ctx, rich_panel)
223
+
224
+ except Exception as e:
225
+ handle_json_output(ctx, error=e)
226
+ if get_ctx_value(ctx, "view") != "json":
227
+ display_api_error(e, "tool creation")
228
+ raise click.ClickException(str(e)) from e
@@ -0,0 +1,61 @@
1
+ """Delete tool command.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ import click
12
+
13
+ from glaip_sdk.cli.context import get_ctx_value, output_flags
14
+ from glaip_sdk.cli.display import (
15
+ display_api_error,
16
+ display_confirmation_prompt,
17
+ display_deletion_success,
18
+ handle_json_output,
19
+ handle_rich_output,
20
+ )
21
+ from glaip_sdk.cli.core.rendering import spinner_context
22
+
23
+ from ._common import _get_tool_by_id_with_spinner, console, tools_group
24
+
25
+
26
+ @tools_group.command()
27
+ @click.argument("tool_id")
28
+ @click.option("-y", "--yes", is_flag=True, help="Skip confirmation")
29
+ @output_flags()
30
+ @click.pass_context
31
+ def delete(ctx: Any, tool_id: str, yes: bool) -> None:
32
+ """Delete a tool."""
33
+ try:
34
+ # Get tool by ID (no ambiguity handling needed)
35
+ tool = _get_tool_by_id_with_spinner(ctx, tool_id)
36
+
37
+ # Confirm deletion via centralized display helper
38
+ if not yes and not display_confirmation_prompt("Tool", tool.name):
39
+ return
40
+
41
+ with spinner_context(
42
+ ctx,
43
+ "[bold blue]Deleting tool…[/bold blue]",
44
+ console_override=console,
45
+ ):
46
+ tool.delete()
47
+
48
+ handle_json_output(
49
+ ctx,
50
+ {
51
+ "success": True,
52
+ "message": f"Tool '{tool.name}' deleted",
53
+ },
54
+ )
55
+ handle_rich_output(ctx, display_deletion_success("Tool", tool.name))
56
+
57
+ except Exception as e:
58
+ handle_json_output(ctx, error=e)
59
+ if get_ctx_value(ctx, "view") != "json":
60
+ display_api_error(e, "tool deletion")
61
+ raise click.ClickException(str(e)) from e
@@ -0,0 +1,103 @@
1
+ """Get tool command.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ import click
13
+
14
+ from glaip_sdk.branding import WARNING_STYLE
15
+ from glaip_sdk.cli.context import output_flags
16
+ from glaip_sdk.cli.core.context import get_client
17
+ from glaip_sdk.cli.core.output import format_datetime_fields, handle_resource_export, output_result
18
+ from glaip_sdk.cli.core.rendering import spinner_context
19
+ from glaip_sdk.cli.io import fetch_raw_resource_details
20
+ from glaip_sdk.icons import ICON_TOOL
21
+
22
+ from ._common import _resolve_tool, console, tools_group
23
+
24
+
25
+ @tools_group.command()
26
+ @click.argument("tool_ref")
27
+ @click.option("--select", type=int, help="Choose among ambiguous matches (1-based)")
28
+ @click.option(
29
+ "--export",
30
+ type=click.Path(dir_okay=False, writable=True),
31
+ help="Export complete tool configuration to file (format auto-detected from .json/.yaml extension)",
32
+ )
33
+ @output_flags()
34
+ @click.pass_context
35
+ def get(ctx: Any, tool_ref: str, select: int | None, export: str | None) -> None:
36
+ r"""Get tool details.
37
+
38
+ \b
39
+ Examples:
40
+ aip tools get my-tool
41
+ aip tools get my-tool --export tool.json # Exports complete configuration as JSON
42
+ aip tools get my-tool --export tool.yaml # Exports complete configuration as YAML
43
+ """
44
+ try:
45
+ client = get_client(ctx)
46
+
47
+ # Resolve tool with ambiguity handling
48
+ tool = _resolve_tool(ctx, client, tool_ref, select)
49
+
50
+ # Handle export option
51
+ if export:
52
+ handle_resource_export(
53
+ ctx,
54
+ tool,
55
+ Path(export),
56
+ resource_type="tool",
57
+ get_by_id_func=client.get_tool_by_id,
58
+ console_override=console,
59
+ )
60
+
61
+ # Try to fetch raw API data first to preserve ALL fields
62
+ with spinner_context(
63
+ ctx,
64
+ "[bold blue]Fetching detailed tool data…[/bold blue]",
65
+ console_override=console,
66
+ ):
67
+ raw_tool_data = fetch_raw_resource_details(client, tool, "tools")
68
+
69
+ if raw_tool_data:
70
+ # Use raw API data - this preserves ALL fields
71
+ # Format dates for better display (minimal postprocessing)
72
+ formatted_data = format_datetime_fields(raw_tool_data)
73
+
74
+ # Display using output_result with raw data
75
+ output_result(
76
+ ctx,
77
+ formatted_data,
78
+ title="Tool Details",
79
+ panel_title=f"{ICON_TOOL} {raw_tool_data.get('name', 'Unknown')}",
80
+ )
81
+ else:
82
+ # Fall back to original method if raw fetch fails
83
+ console.print(f"[{WARNING_STYLE}]Falling back to Pydantic model data[/]")
84
+
85
+ # Create result data with all available fields from backend
86
+ result_data = {
87
+ "id": str(getattr(tool, "id", "N/A")),
88
+ "name": getattr(tool, "name", "N/A"),
89
+ "tool_type": getattr(tool, "tool_type", "N/A"),
90
+ "framework": getattr(tool, "framework", "N/A"),
91
+ "version": getattr(tool, "version", "N/A"),
92
+ "description": getattr(tool, "description", "N/A"),
93
+ }
94
+
95
+ output_result(
96
+ ctx,
97
+ result_data,
98
+ title="Tool Details",
99
+ panel_title=f"{ICON_TOOL} {tool.name}",
100
+ )
101
+
102
+ except Exception as e:
103
+ raise click.ClickException(str(e)) from e
@@ -0,0 +1,69 @@
1
+ """List tools command.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ import click
12
+
13
+ from glaip_sdk.branding import ACCENT_STYLE, INFO
14
+ from glaip_sdk.cli.context import output_flags
15
+ from glaip_sdk.cli.core.context import get_client
16
+ from glaip_sdk.cli.core.output import coerce_to_row, output_list
17
+ from glaip_sdk.cli.core.rendering import spinner_context
18
+ from glaip_sdk.icons import ICON_TOOL
19
+
20
+ from ._common import console, tools_group
21
+
22
+
23
+ @tools_group.command(name="list")
24
+ @output_flags()
25
+ @click.option(
26
+ "--type",
27
+ "tool_type",
28
+ help="Filter tools by type (e.g., custom, native)",
29
+ type=str,
30
+ required=False,
31
+ )
32
+ @click.pass_context
33
+ def list_tools(ctx: Any, tool_type: str | None) -> None:
34
+ """List all tools."""
35
+ try:
36
+ client = get_client(ctx)
37
+ with spinner_context(
38
+ ctx,
39
+ "[bold blue]Fetching tools…[/bold blue]",
40
+ console_override=console,
41
+ ):
42
+ tools = client.list_tools(tool_type=tool_type)
43
+
44
+ # Define table columns: (data_key, header, style, width)
45
+ columns = [
46
+ ("id", "ID", "dim", 36),
47
+ ("name", "Name", ACCENT_STYLE, None),
48
+ ("framework", "Framework", INFO, None),
49
+ ]
50
+
51
+ # Transform function for safe dictionary access
52
+ def transform_tool(tool: Any) -> dict[str, Any]:
53
+ """Transform a tool object to a display row dictionary.
54
+
55
+ Args:
56
+ tool: Tool object to transform.
57
+
58
+ Returns:
59
+ Dictionary with id, name, and framework fields.
60
+ """
61
+ row = coerce_to_row(tool, ["id", "name", "framework"])
62
+ # Ensure id is always a string
63
+ row["id"] = str(row["id"])
64
+ return row
65
+
66
+ output_list(ctx, tools, f"{ICON_TOOL} Available Tools", columns, transform_tool)
67
+
68
+ except Exception as e:
69
+ raise click.ClickException(str(e)) from e
@@ -0,0 +1,49 @@
1
+ """Get tool script command.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ from typing import Any
11
+
12
+ import click
13
+
14
+ from glaip_sdk.branding import ERROR_STYLE, SUCCESS_STYLE
15
+ from glaip_sdk.cli.context import get_ctx_value, output_flags
16
+ from glaip_sdk.cli.core.context import get_client
17
+ from glaip_sdk.cli.core.rendering import spinner_context
18
+ from glaip_sdk.cli.display import handle_json_output
19
+ from glaip_sdk.cli.rich_helpers import print_markup
20
+
21
+ from ._common import console, tools_group
22
+
23
+
24
+ @tools_group.command("script")
25
+ @click.argument("tool_id")
26
+ @output_flags()
27
+ @click.pass_context
28
+ def script(ctx: Any, tool_id: str) -> None:
29
+ """Get tool script content."""
30
+ try:
31
+ client = get_client(ctx)
32
+ with spinner_context(
33
+ ctx,
34
+ "[bold blue]Fetching tool script…[/bold blue]",
35
+ console_override=console,
36
+ ):
37
+ script_content = client.get_tool_script(tool_id)
38
+
39
+ if get_ctx_value(ctx, "view") == "json":
40
+ click.echo(json.dumps({"script": script_content}, indent=2))
41
+ else:
42
+ console.print(f"[{SUCCESS_STYLE}]📜 Tool Script for '{tool_id}':[/]")
43
+ console.print(script_content)
44
+
45
+ except Exception as e:
46
+ handle_json_output(ctx, error=e)
47
+ if get_ctx_value(ctx, "view") != "json":
48
+ print_markup(f"[{ERROR_STYLE}]Error getting tool script: {e}[/]", console=console)
49
+ raise click.ClickException(str(e)) from e
@@ -0,0 +1,102 @@
1
+ """Update tool command.
2
+
3
+ Authors:
4
+ Raymond Christopher (raymond.christopher@gdplabs.id)
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+
11
+ import click
12
+
13
+ from glaip_sdk.branding import SUCCESS_STYLE, WARNING_STYLE
14
+ from glaip_sdk.cli.context import get_ctx_value, output_flags
15
+ from glaip_sdk.cli.display import display_api_error, display_update_success, handle_json_output, handle_rich_output
16
+ from glaip_sdk.cli.core.context import get_client
17
+ from glaip_sdk.cli.core.rendering import spinner_context
18
+ from glaip_sdk.cli.rich_helpers import markup_text
19
+
20
+ from ._common import _get_tool_by_id_with_spinner, console, tools_group
21
+ from .create import _parse_tags
22
+
23
+
24
+ @tools_group.command()
25
+ @click.argument("tool_id")
26
+ @click.option(
27
+ "--file",
28
+ type=click.Path(exists=True),
29
+ help="New tool file for code update (custom tools only)",
30
+ )
31
+ @click.option("--description", help="New description")
32
+ @click.option("--tags", help="Comma-separated tags")
33
+ @output_flags()
34
+ @click.pass_context
35
+ def update(
36
+ ctx: Any,
37
+ tool_id: str,
38
+ file: str | None,
39
+ description: str | None,
40
+ tags: str | None,
41
+ ) -> None:
42
+ """Update a tool (code or metadata)."""
43
+ try:
44
+ client = get_client(ctx)
45
+
46
+ # Get tool by ID (no ambiguity handling needed)
47
+ tool = _get_tool_by_id_with_spinner(ctx, tool_id)
48
+
49
+ update_kwargs: dict[str, Any] = {}
50
+ if description is not None:
51
+ update_kwargs["description"] = description
52
+ if tags:
53
+ update_kwargs["tags"] = _parse_tags(tags)
54
+
55
+ if file:
56
+ # Update code via file upload (custom tools only)
57
+ if tool.tool_type != "custom":
58
+ raise click.ClickException(
59
+ "File updates are only supported for custom tools. "
60
+ f"Tool '{tool.name}' is of type '{tool.tool_type}'."
61
+ )
62
+ with spinner_context(
63
+ ctx,
64
+ "[bold blue]Uploading new tool code…[/bold blue]",
65
+ console_override=console,
66
+ ):
67
+ updated_tool = client.tools.update_tool_via_file(
68
+ tool.id,
69
+ file,
70
+ framework=tool.framework,
71
+ **update_kwargs,
72
+ )
73
+ handle_rich_output(
74
+ ctx,
75
+ markup_text(f"[{SUCCESS_STYLE}]✓[/] Tool code updated from {file}"),
76
+ )
77
+ elif update_kwargs:
78
+ # Update metadata only (native tools only)
79
+ if tool.tool_type != "native":
80
+ raise click.ClickException(
81
+ "Metadata updates are only supported for native tools. "
82
+ f"Tool '{tool.name}' is of type '{tool.tool_type}'."
83
+ )
84
+ with spinner_context(
85
+ ctx,
86
+ "[bold blue]Updating tool metadata…[/bold blue]",
87
+ console_override=console,
88
+ ):
89
+ updated_tool = client.tools.update_tool(tool, **update_kwargs)
90
+ handle_rich_output(ctx, markup_text(f"[{SUCCESS_STYLE}]✓[/] Tool metadata updated"))
91
+ else:
92
+ handle_rich_output(ctx, markup_text(f"[{WARNING_STYLE}]No updates specified[/]"))
93
+ return
94
+
95
+ handle_json_output(ctx, updated_tool.model_dump())
96
+ handle_rich_output(ctx, display_update_success("Tool", updated_tool.name))
97
+
98
+ except Exception as e:
99
+ handle_json_output(ctx, error=e)
100
+ if get_ctx_value(ctx, "view") != "json":
101
+ display_api_error(e, "tool update")
102
+ raise click.ClickException(str(e)) from e