glaip-sdk 0.6.24__py3-none-any.whl → 0.6.26__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/cli/commands/agents/__init__.py +119 -0
- glaip_sdk/cli/commands/agents/_common.py +561 -0
- glaip_sdk/cli/commands/agents/create.py +151 -0
- glaip_sdk/cli/commands/agents/delete.py +64 -0
- glaip_sdk/cli/commands/agents/get.py +89 -0
- glaip_sdk/cli/commands/agents/list.py +129 -0
- glaip_sdk/cli/commands/agents/run.py +264 -0
- glaip_sdk/cli/commands/agents/sync_langflow.py +72 -0
- glaip_sdk/cli/commands/agents/update.py +112 -0
- glaip_sdk/cli/commands/mcps/__init__.py +98 -0
- glaip_sdk/cli/commands/mcps/_common.py +490 -0
- glaip_sdk/cli/commands/mcps/connect.py +82 -0
- glaip_sdk/cli/commands/mcps/create.py +153 -0
- glaip_sdk/cli/commands/mcps/delete.py +73 -0
- glaip_sdk/cli/commands/mcps/get.py +212 -0
- glaip_sdk/cli/commands/mcps/list.py +69 -0
- glaip_sdk/cli/commands/mcps/tools.py +235 -0
- glaip_sdk/cli/commands/mcps/update.py +146 -0
- glaip_sdk/cli/commands/shared/__init__.py +21 -0
- glaip_sdk/cli/commands/shared/formatters.py +91 -0
- glaip_sdk/cli/commands/tools/__init__.py +69 -0
- glaip_sdk/cli/commands/tools/_common.py +80 -0
- glaip_sdk/cli/commands/tools/create.py +228 -0
- glaip_sdk/cli/commands/tools/delete.py +61 -0
- glaip_sdk/cli/commands/tools/get.py +103 -0
- glaip_sdk/cli/commands/tools/list.py +69 -0
- glaip_sdk/cli/commands/tools/script.py +49 -0
- glaip_sdk/cli/commands/tools/update.py +102 -0
- glaip_sdk/cli/commands/transcripts/__init__.py +90 -0
- glaip_sdk/cli/commands/transcripts/_common.py +9 -0
- glaip_sdk/cli/commands/transcripts/clear.py +5 -0
- glaip_sdk/cli/commands/transcripts/detail.py +5 -0
- glaip_sdk/client/_agent_payloads.py +32 -500
- glaip_sdk/client/agents.py +1 -1
- glaip_sdk/client/main.py +1 -1
- glaip_sdk/client/mcps.py +44 -13
- glaip_sdk/client/payloads/agent/__init__.py +23 -0
- glaip_sdk/client/payloads/agent/requests.py +495 -0
- glaip_sdk/client/payloads/agent/responses.py +43 -0
- glaip_sdk/client/tools.py +38 -3
- glaip_sdk/registry/tool.py +54 -5
- glaip_sdk/tools/base.py +41 -10
- glaip_sdk/utils/import_resolver.py +40 -2
- {glaip_sdk-0.6.24.dist-info → glaip_sdk-0.6.26.dist-info}/METADATA +1 -1
- {glaip_sdk-0.6.24.dist-info → glaip_sdk-0.6.26.dist-info}/RECORD +49 -17
- glaip_sdk/cli/commands/agents.py +0 -1502
- glaip_sdk/cli/commands/mcps.py +0 -1355
- glaip_sdk/cli/commands/tools.py +0 -575
- /glaip_sdk/cli/commands/{transcripts.py → transcripts_original.py} +0 -0
- {glaip_sdk-0.6.24.dist-info → glaip_sdk-0.6.26.dist-info}/WHEEL +0 -0
- {glaip_sdk-0.6.24.dist-info → glaip_sdk-0.6.26.dist-info}/entry_points.txt +0 -0
- {glaip_sdk-0.6.24.dist-info → glaip_sdk-0.6.26.dist-info}/top_level.txt +0 -0
|
@@ -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.display import (
|
|
17
|
+
display_api_error,
|
|
18
|
+
display_creation_success,
|
|
19
|
+
handle_json_output,
|
|
20
|
+
handle_rich_output,
|
|
21
|
+
)
|
|
22
|
+
from glaip_sdk.cli.core.context import get_client, handle_best_effort_check
|
|
23
|
+
from glaip_sdk.cli.core.rendering import spinner_context
|
|
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
|