glaip-sdk 0.6.25__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/tools/base.py +41 -10
- glaip_sdk/utils/import_resolver.py +40 -2
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/METADATA +1 -1
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/RECORD +48 -16
- 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.25.dist-info → glaip_sdk-0.6.26.dist-info}/WHEEL +0 -0
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/entry_points.txt +0 -0
- {glaip_sdk-0.6.25.dist-info → glaip_sdk-0.6.26.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""List MCP tools 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 ACCENT_STYLE, INFO
|
|
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.output import output_list
|
|
18
|
+
from glaip_sdk.cli.core.rendering import spinner_context
|
|
19
|
+
from glaip_sdk.cli.display import handle_json_output
|
|
20
|
+
from glaip_sdk.cli.io import load_resource_from_file_with_validation
|
|
21
|
+
from glaip_sdk.cli.mcp_validators import validate_mcp_config_structure
|
|
22
|
+
from glaip_sdk.icons import ICON_TOOL
|
|
23
|
+
|
|
24
|
+
from ._common import _resolve_mcp, console, mcps_group
|
|
25
|
+
|
|
26
|
+
MAX_DESCRIPTION_LEN = 50
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _get_tools_from_config(ctx: Any, client: Any, config_file: str) -> tuple[list[dict[str, Any]], str]:
|
|
30
|
+
"""Get tools from MCP config file.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
ctx: Click context
|
|
34
|
+
client: GlaIP client instance
|
|
35
|
+
config_file: Path to config file
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Tuple of (tools list, title string)
|
|
39
|
+
"""
|
|
40
|
+
config_data = load_resource_from_file_with_validation(Path(config_file), "MCP config")
|
|
41
|
+
|
|
42
|
+
# Validate config structure
|
|
43
|
+
transport = config_data.get("transport")
|
|
44
|
+
if "config" not in config_data:
|
|
45
|
+
raise click.ClickException("Invalid MCP config: missing 'config' section in the file.")
|
|
46
|
+
config_data["config"] = validate_mcp_config_structure(
|
|
47
|
+
config_data["config"],
|
|
48
|
+
transport=transport,
|
|
49
|
+
source=config_file,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Get tools from config without saving
|
|
53
|
+
with spinner_context(
|
|
54
|
+
ctx,
|
|
55
|
+
"[bold blue]Fetching tools from config…[/bold blue]",
|
|
56
|
+
console_override=console,
|
|
57
|
+
):
|
|
58
|
+
tools = client.mcps.get_mcp_tools_from_config(config_data)
|
|
59
|
+
|
|
60
|
+
title = f"{ICON_TOOL} Tools from config: {Path(config_file).name}"
|
|
61
|
+
return tools, title
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _get_tools_from_mcp(ctx: Any, client: Any, mcp_ref: str | None) -> tuple[list[dict[str, Any]], str]:
|
|
65
|
+
"""Get tools from saved MCP.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
ctx: Click context
|
|
69
|
+
client: GlaIP client instance
|
|
70
|
+
mcp_ref: MCP reference (ID or name)
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
Tuple of (tools list, title string)
|
|
74
|
+
"""
|
|
75
|
+
mcp = _resolve_mcp(ctx, client, mcp_ref)
|
|
76
|
+
|
|
77
|
+
with spinner_context(
|
|
78
|
+
ctx,
|
|
79
|
+
"[bold blue]Fetching MCP tools…[/bold blue]",
|
|
80
|
+
console_override=console,
|
|
81
|
+
):
|
|
82
|
+
tools = client.mcps.get_mcp_tools(mcp.id)
|
|
83
|
+
|
|
84
|
+
title = f"{ICON_TOOL} Tools from MCP: {mcp.name}"
|
|
85
|
+
return tools, title
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _output_tool_names(ctx: Any, tools: list[dict[str, Any]]) -> None:
|
|
89
|
+
"""Output only tool names.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
ctx: Click context
|
|
93
|
+
tools: List of tool dictionaries
|
|
94
|
+
"""
|
|
95
|
+
view = get_ctx_value(ctx, "view", "rich")
|
|
96
|
+
tool_names = [tool.get("name", "N/A") for tool in tools]
|
|
97
|
+
|
|
98
|
+
if view == "json":
|
|
99
|
+
handle_json_output(ctx, tool_names)
|
|
100
|
+
elif view == "plain":
|
|
101
|
+
if tool_names:
|
|
102
|
+
for name in tool_names:
|
|
103
|
+
console.print(name, markup=False)
|
|
104
|
+
console.print(f"Total: {len(tool_names)} tools", markup=False)
|
|
105
|
+
else:
|
|
106
|
+
console.print("No tools found", markup=False)
|
|
107
|
+
else:
|
|
108
|
+
if tool_names:
|
|
109
|
+
for name in tool_names:
|
|
110
|
+
console.print(name)
|
|
111
|
+
console.print(f"[dim]Total: {len(tool_names)} tools[/dim]")
|
|
112
|
+
else:
|
|
113
|
+
console.print("[yellow]No tools found[/yellow]")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _transform_tool(tool: dict[str, Any]) -> dict[str, Any]:
|
|
117
|
+
"""Transform a tool dictionary to a display row dictionary.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
tool: Tool dictionary to transform.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Dictionary with name and description fields.
|
|
124
|
+
"""
|
|
125
|
+
description = tool.get("description", "N/A")
|
|
126
|
+
if len(description) > MAX_DESCRIPTION_LEN:
|
|
127
|
+
description = description[: MAX_DESCRIPTION_LEN - 3] + "..."
|
|
128
|
+
return {
|
|
129
|
+
"name": tool.get("name", "N/A"),
|
|
130
|
+
"description": description,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _output_tools_table(ctx: Any, tools: list[dict[str, Any]], title: str) -> None:
|
|
135
|
+
"""Output tools in table format.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
ctx: Click context
|
|
139
|
+
tools: List of tool dictionaries
|
|
140
|
+
title: Table title
|
|
141
|
+
"""
|
|
142
|
+
columns = [
|
|
143
|
+
("name", "Name", ACCENT_STYLE, None),
|
|
144
|
+
("description", "Description", INFO, 50),
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
output_list(
|
|
148
|
+
ctx,
|
|
149
|
+
tools,
|
|
150
|
+
title,
|
|
151
|
+
columns,
|
|
152
|
+
_transform_tool,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _validate_tool_command_args(mcp_ref: str | None, config_file: str | None) -> None:
|
|
157
|
+
"""Validate that exactly one of mcp_ref or config_file is provided.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
mcp_ref: MCP reference (ID or name)
|
|
161
|
+
config_file: Path to config file
|
|
162
|
+
|
|
163
|
+
Raises:
|
|
164
|
+
ClickException: If validation fails
|
|
165
|
+
"""
|
|
166
|
+
if not mcp_ref and not config_file:
|
|
167
|
+
raise click.ClickException(
|
|
168
|
+
"Either MCP_REF or --from-config must be provided.\n"
|
|
169
|
+
"Examples:\n"
|
|
170
|
+
" aip mcps tools <MCP_ID>\n"
|
|
171
|
+
" aip mcps tools --from-config mcp-config.json"
|
|
172
|
+
)
|
|
173
|
+
if mcp_ref and config_file:
|
|
174
|
+
raise click.ClickException(
|
|
175
|
+
"Cannot use both MCP_REF and --from-config at the same time.\n"
|
|
176
|
+
"Use either:\n"
|
|
177
|
+
" aip mcps tools <MCP_ID>\n"
|
|
178
|
+
" aip mcps tools --from-config mcp-config.json"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@mcps_group.command("tools")
|
|
183
|
+
@click.argument("mcp_ref", required=False)
|
|
184
|
+
@click.option(
|
|
185
|
+
"--from-config",
|
|
186
|
+
"--config",
|
|
187
|
+
"config_file",
|
|
188
|
+
type=click.Path(exists=True, dir_okay=False),
|
|
189
|
+
help="Get tools from MCP config file without saving to DB (JSON or YAML)",
|
|
190
|
+
)
|
|
191
|
+
@click.option(
|
|
192
|
+
"--names-only",
|
|
193
|
+
is_flag=True,
|
|
194
|
+
help="Show only tool names (useful for allowed_tools config)",
|
|
195
|
+
)
|
|
196
|
+
@output_flags()
|
|
197
|
+
@click.pass_context
|
|
198
|
+
def list_tools(ctx: Any, mcp_ref: str | None, config_file: str | None, names_only: bool) -> None:
|
|
199
|
+
"""List tools available from a specific MCP or config file.
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
ctx: Click context containing output format preferences
|
|
203
|
+
mcp_ref: MCP reference (ID or name) - required if --from-config not used
|
|
204
|
+
config_file: Path to MCP config file - alternative to mcp_ref
|
|
205
|
+
names_only: Show only tool names instead of full table
|
|
206
|
+
|
|
207
|
+
Raises:
|
|
208
|
+
ClickException: If MCP not found or tools fetch fails
|
|
209
|
+
|
|
210
|
+
Examples:
|
|
211
|
+
Get tools from saved MCP:
|
|
212
|
+
aip mcps tools <MCP_ID>
|
|
213
|
+
|
|
214
|
+
Get tools from config file (without saving to DB):
|
|
215
|
+
aip mcps tools --from-config mcp-config.json
|
|
216
|
+
|
|
217
|
+
Get just tool names for allowed_tools config:
|
|
218
|
+
aip mcps tools <MCP_ID> --names-only
|
|
219
|
+
"""
|
|
220
|
+
try:
|
|
221
|
+
_validate_tool_command_args(mcp_ref, config_file)
|
|
222
|
+
client = get_client(ctx)
|
|
223
|
+
|
|
224
|
+
if config_file:
|
|
225
|
+
tools, title = _get_tools_from_config(ctx, client, config_file)
|
|
226
|
+
else:
|
|
227
|
+
tools, title = _get_tools_from_mcp(ctx, client, mcp_ref)
|
|
228
|
+
|
|
229
|
+
if names_only:
|
|
230
|
+
_output_tool_names(ctx, tools)
|
|
231
|
+
else:
|
|
232
|
+
_output_tools_table(ctx, tools, title)
|
|
233
|
+
|
|
234
|
+
except Exception as e:
|
|
235
|
+
raise click.ClickException(str(e)) from e
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Update MCP 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 output_flags
|
|
14
|
+
from glaip_sdk.cli.display import display_update_success, handle_json_output, handle_rich_output
|
|
15
|
+
from glaip_sdk.cli.core.context import get_client
|
|
16
|
+
from glaip_sdk.cli.core.rendering import spinner_context
|
|
17
|
+
|
|
18
|
+
from ._common import (
|
|
19
|
+
_assemble_update_data_from_cli_options,
|
|
20
|
+
_assemble_update_data_from_import_payload,
|
|
21
|
+
_handle_cli_error,
|
|
22
|
+
_handle_update_preview_and_confirmation,
|
|
23
|
+
_load_import_ready_payload,
|
|
24
|
+
_resolve_mcp,
|
|
25
|
+
_validate_import_payload_fields,
|
|
26
|
+
_validate_update_inputs,
|
|
27
|
+
console,
|
|
28
|
+
mcps_group,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@mcps_group.command()
|
|
33
|
+
@click.argument("mcp_ref")
|
|
34
|
+
@click.option("--name", help="New MCP name")
|
|
35
|
+
@click.option("--transport", type=click.Choice(["http", "sse"]), help="New transport protocol")
|
|
36
|
+
@click.option("--description", help="New description")
|
|
37
|
+
@click.option(
|
|
38
|
+
"--config",
|
|
39
|
+
help="JSON configuration string or @file reference (e.g., @config.json)",
|
|
40
|
+
)
|
|
41
|
+
@click.option(
|
|
42
|
+
"--auth",
|
|
43
|
+
"--authentication",
|
|
44
|
+
"auth",
|
|
45
|
+
help="JSON authentication object or @file reference (e.g., @auth.json)",
|
|
46
|
+
)
|
|
47
|
+
@click.option(
|
|
48
|
+
"--import",
|
|
49
|
+
"import_file",
|
|
50
|
+
type=click.Path(exists=True, dir_okay=False, readable=True),
|
|
51
|
+
help="Import MCP configuration from JSON or YAML export",
|
|
52
|
+
)
|
|
53
|
+
@click.option("-y", is_flag=True, help="Skip confirmation prompt when using --import")
|
|
54
|
+
@output_flags()
|
|
55
|
+
@click.pass_context
|
|
56
|
+
def update(
|
|
57
|
+
ctx: Any,
|
|
58
|
+
mcp_ref: str,
|
|
59
|
+
name: str | None,
|
|
60
|
+
transport: str | None,
|
|
61
|
+
description: str | None,
|
|
62
|
+
config: str | None,
|
|
63
|
+
auth: str | None,
|
|
64
|
+
import_file: str | None,
|
|
65
|
+
y: bool,
|
|
66
|
+
) -> None:
|
|
67
|
+
r"""Update an existing MCP with new configuration values.
|
|
68
|
+
|
|
69
|
+
You can update an MCP by providing individual fields via CLI options, or by
|
|
70
|
+
importing from a file and optionally overriding specific fields.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
ctx: Click context containing output format preferences
|
|
74
|
+
mcp_ref: MCP reference (ID or name)
|
|
75
|
+
name: New MCP name (optional)
|
|
76
|
+
transport: New transport protocol (optional)
|
|
77
|
+
description: New description (optional)
|
|
78
|
+
config: New JSON configuration string or @file reference (optional)
|
|
79
|
+
auth: New JSON authentication object or @file reference (optional)
|
|
80
|
+
import_file: Optional path to import configuration from export file.
|
|
81
|
+
CLI options override imported values.
|
|
82
|
+
y: Skip confirmation prompt when using --import
|
|
83
|
+
|
|
84
|
+
Raises:
|
|
85
|
+
ClickException: If MCP not found, JSON invalid, or no fields specified
|
|
86
|
+
|
|
87
|
+
Note:
|
|
88
|
+
Must specify either --import OR at least one CLI field.
|
|
89
|
+
CLI options override imported values when both are specified.
|
|
90
|
+
Uses PATCH for import-based updates, PUT/PATCH for CLI-only updates.
|
|
91
|
+
|
|
92
|
+
\b
|
|
93
|
+
Examples:
|
|
94
|
+
Update with CLI options:
|
|
95
|
+
aip mcps update my-mcp --name new-name --transport sse
|
|
96
|
+
|
|
97
|
+
Import from file:
|
|
98
|
+
aip mcps update my-mcp --import mcp-export.json
|
|
99
|
+
|
|
100
|
+
Import with overrides:
|
|
101
|
+
aip mcps update my-mcp --import mcp-export.json --name new-name -y
|
|
102
|
+
"""
|
|
103
|
+
try:
|
|
104
|
+
client = get_client(ctx)
|
|
105
|
+
|
|
106
|
+
# Validate that at least one update method is provided
|
|
107
|
+
_validate_update_inputs(name, transport, description, config, auth, import_file)
|
|
108
|
+
|
|
109
|
+
# Resolve MCP using helper function
|
|
110
|
+
mcp = _resolve_mcp(ctx, client, mcp_ref)
|
|
111
|
+
|
|
112
|
+
# Load and validate import data if provided
|
|
113
|
+
import_payload = None
|
|
114
|
+
if import_file:
|
|
115
|
+
import_payload = _load_import_ready_payload(import_file)
|
|
116
|
+
if not _validate_import_payload_fields(import_payload):
|
|
117
|
+
return
|
|
118
|
+
|
|
119
|
+
# Build update_data from import payload and CLI options
|
|
120
|
+
update_data = _assemble_update_data_from_import_payload(import_payload)
|
|
121
|
+
update_data = _assemble_update_data_from_cli_options(
|
|
122
|
+
update_data, name, transport, description, config, auth, import_payload, mcp
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
if not update_data:
|
|
126
|
+
raise click.ClickException("No update fields specified")
|
|
127
|
+
|
|
128
|
+
# Show confirmation preview for import-based updates (unless -y flag)
|
|
129
|
+
if not _handle_update_preview_and_confirmation(
|
|
130
|
+
import_payload, y, mcp, update_data, name, transport, description, config, auth
|
|
131
|
+
):
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
# Update MCP
|
|
135
|
+
with spinner_context(
|
|
136
|
+
ctx,
|
|
137
|
+
"[bold blue]Updating MCP…[/bold blue]",
|
|
138
|
+
console_override=console,
|
|
139
|
+
):
|
|
140
|
+
updated_mcp = client.mcps.update_mcp(mcp, **update_data)
|
|
141
|
+
|
|
142
|
+
handle_json_output(ctx, updated_mcp.model_dump())
|
|
143
|
+
handle_rich_output(ctx, display_update_success("MCP", updated_mcp.name))
|
|
144
|
+
|
|
145
|
+
except Exception as e:
|
|
146
|
+
_handle_cli_error(ctx, e, "MCP update")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Shared CLI command helpers.
|
|
2
|
+
|
|
3
|
+
Authors:
|
|
4
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from glaip_sdk.cli.commands.shared.formatters import (
|
|
8
|
+
_format_empty_override_warnings,
|
|
9
|
+
_format_dict_value,
|
|
10
|
+
_format_preview_value,
|
|
11
|
+
_is_sensitive_data,
|
|
12
|
+
_redact_sensitive_dict,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"_format_empty_override_warnings",
|
|
17
|
+
"_format_dict_value",
|
|
18
|
+
"_format_preview_value",
|
|
19
|
+
"_is_sensitive_data",
|
|
20
|
+
"_redact_sensitive_dict",
|
|
21
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Shared formatting helpers for CLI commands.
|
|
2
|
+
|
|
3
|
+
Authors:
|
|
4
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _is_sensitive_data(val: Any) -> bool:
|
|
12
|
+
"""Check if value contains sensitive authentication data.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
val: Value to check for sensitive information
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
True if the value appears to contain sensitive data
|
|
19
|
+
"""
|
|
20
|
+
if not isinstance(val, dict):
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
sensitive_patterns = {"token", "password", "secret", "key", "credential"}
|
|
24
|
+
return any(pattern in str(k).lower() for k in val.keys() for pattern in sensitive_patterns)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _redact_sensitive_dict(val: dict[str, Any]) -> dict[str, Any]:
|
|
28
|
+
"""Redact sensitive fields from a dictionary.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
val: Dictionary to redact
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Redacted dictionary
|
|
35
|
+
"""
|
|
36
|
+
redacted = val.copy()
|
|
37
|
+
sensitive_patterns = {"token", "password", "secret", "key", "credential"}
|
|
38
|
+
for k in redacted.keys():
|
|
39
|
+
if any(pattern in k.lower() for pattern in sensitive_patterns):
|
|
40
|
+
redacted[k] = "<REDACTED>"
|
|
41
|
+
return redacted
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _format_dict_value(val: dict[str, Any]) -> str:
|
|
45
|
+
"""Format a dictionary value for display.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
val: Dictionary to format
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Formatted string representation
|
|
52
|
+
"""
|
|
53
|
+
if _is_sensitive_data(val):
|
|
54
|
+
redacted = _redact_sensitive_dict(val)
|
|
55
|
+
return json.dumps(redacted, indent=2)
|
|
56
|
+
return json.dumps(val, indent=2)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _format_preview_value(val: Any) -> str:
|
|
60
|
+
"""Format a value for display in update preview with sensitive data redaction.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
val: Value to format
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Formatted string representation of the value
|
|
67
|
+
"""
|
|
68
|
+
if val is None:
|
|
69
|
+
return "[dim]None[/dim]"
|
|
70
|
+
if isinstance(val, dict):
|
|
71
|
+
return _format_dict_value(val)
|
|
72
|
+
if isinstance(val, str):
|
|
73
|
+
return f'"{val}"' if val else '""'
|
|
74
|
+
return str(val)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _format_empty_override_warnings(empty_fields: list[str]) -> list[str]:
|
|
78
|
+
"""Format warning lines for empty CLI overrides.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
empty_fields: List of field names with empty string overrides
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
List of formatted warning lines
|
|
85
|
+
"""
|
|
86
|
+
if not empty_fields:
|
|
87
|
+
return []
|
|
88
|
+
|
|
89
|
+
warnings = ["\n[yellow]⚠️ Warning: Empty values provided via CLI will override import values[/yellow]"]
|
|
90
|
+
warnings.extend(f"- [yellow]{field}: will be set to empty string[/yellow]" for field in empty_fields)
|
|
91
|
+
return warnings
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Tool CLI commands package.
|
|
2
|
+
|
|
3
|
+
This package contains tool management commands split by operation.
|
|
4
|
+
The package is the canonical import surface.
|
|
5
|
+
|
|
6
|
+
Authors:
|
|
7
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# pylint: disable=duplicate-code
|
|
11
|
+
from glaip_sdk.cli.commands.tools._common import tools_group, _resolve_tool, console
|
|
12
|
+
from glaip_sdk.cli.commands.tools.create import create # noqa: E402
|
|
13
|
+
from glaip_sdk.cli.commands.tools.delete import delete # noqa: E402
|
|
14
|
+
from glaip_sdk.cli.commands.tools.get import get # noqa: E402
|
|
15
|
+
from glaip_sdk.cli.commands.tools.list import list_tools # noqa: E402
|
|
16
|
+
from glaip_sdk.cli.commands.tools.script import script # noqa: E402
|
|
17
|
+
from glaip_sdk.cli.commands.tools.update import update # noqa: E402
|
|
18
|
+
|
|
19
|
+
# Import helper functions from create module for backward compatibility
|
|
20
|
+
from glaip_sdk.cli.commands.tools.create import ( # noqa: E402
|
|
21
|
+
_check_duplicate_name,
|
|
22
|
+
_create_tool_from_file,
|
|
23
|
+
_extract_internal_name,
|
|
24
|
+
_handle_import_file,
|
|
25
|
+
_parse_tags,
|
|
26
|
+
_validate_name_match,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Import core functions for test compatibility
|
|
30
|
+
from glaip_sdk.cli.core.context import get_client # noqa: E402
|
|
31
|
+
from glaip_sdk.cli.core.output import ( # noqa: E402
|
|
32
|
+
output_list,
|
|
33
|
+
output_result,
|
|
34
|
+
)
|
|
35
|
+
from glaip_sdk.cli.core.rendering import spinner_context # noqa: E402
|
|
36
|
+
|
|
37
|
+
# Import IO functions for test compatibility
|
|
38
|
+
from glaip_sdk.cli.io import ( # noqa: E402
|
|
39
|
+
fetch_raw_resource_details,
|
|
40
|
+
load_resource_from_file_with_validation,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Alias for backward compatibility (used in create.py)
|
|
44
|
+
load_resource_from_file = load_resource_from_file_with_validation
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"tools_group",
|
|
48
|
+
"create",
|
|
49
|
+
"delete",
|
|
50
|
+
"get",
|
|
51
|
+
"list_tools",
|
|
52
|
+
"script",
|
|
53
|
+
"update",
|
|
54
|
+
"_check_duplicate_name",
|
|
55
|
+
"_create_tool_from_file",
|
|
56
|
+
"_extract_internal_name",
|
|
57
|
+
"_handle_import_file",
|
|
58
|
+
"_parse_tags",
|
|
59
|
+
"_resolve_tool",
|
|
60
|
+
"_validate_name_match",
|
|
61
|
+
"console",
|
|
62
|
+
"get_client",
|
|
63
|
+
"output_list",
|
|
64
|
+
"output_result",
|
|
65
|
+
"spinner_context",
|
|
66
|
+
"fetch_raw_resource_details",
|
|
67
|
+
"load_resource_from_file_with_validation",
|
|
68
|
+
"load_resource_from_file",
|
|
69
|
+
]
|
|
@@ -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
|