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.
- glaip_sdk/__init__.py +44 -4
- glaip_sdk/_version.py +10 -3
- glaip_sdk/agents/__init__.py +27 -0
- glaip_sdk/agents/base.py +1250 -0
- glaip_sdk/branding.py +15 -6
- glaip_sdk/cli/account_store.py +540 -0
- glaip_sdk/cli/agent_config.py +2 -6
- glaip_sdk/cli/auth.py +271 -45
- glaip_sdk/cli/commands/__init__.py +2 -2
- glaip_sdk/cli/commands/accounts.py +746 -0
- 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/common_config.py +104 -0
- glaip_sdk/cli/commands/configure.py +734 -143
- glaip_sdk/cli/commands/mcps/__init__.py +94 -0
- glaip_sdk/cli/commands/mcps/_common.py +459 -0
- glaip_sdk/cli/commands/mcps/connect.py +82 -0
- glaip_sdk/cli/commands/mcps/create.py +152 -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 +190 -0
- glaip_sdk/cli/commands/models.py +14 -12
- 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/cli/commands/transcripts_original.py +756 -0
- glaip_sdk/cli/commands/update.py +164 -23
- glaip_sdk/cli/config.py +49 -7
- glaip_sdk/cli/constants.py +38 -0
- glaip_sdk/cli/context.py +8 -0
- glaip_sdk/cli/core/__init__.py +79 -0
- glaip_sdk/cli/core/context.py +124 -0
- glaip_sdk/cli/core/output.py +851 -0
- glaip_sdk/cli/core/prompting.py +649 -0
- glaip_sdk/cli/core/rendering.py +187 -0
- glaip_sdk/cli/display.py +45 -32
- glaip_sdk/cli/entrypoint.py +20 -0
- glaip_sdk/cli/hints.py +57 -0
- glaip_sdk/cli/io.py +14 -17
- glaip_sdk/cli/main.py +344 -167
- glaip_sdk/cli/masking.py +21 -33
- glaip_sdk/cli/mcp_validators.py +5 -15
- glaip_sdk/cli/pager.py +15 -22
- glaip_sdk/cli/parsers/__init__.py +1 -3
- glaip_sdk/cli/parsers/json_input.py +11 -22
- glaip_sdk/cli/resolution.py +5 -10
- glaip_sdk/cli/rich_helpers.py +1 -3
- glaip_sdk/cli/slash/__init__.py +0 -9
- glaip_sdk/cli/slash/accounts_controller.py +580 -0
- glaip_sdk/cli/slash/accounts_shared.py +75 -0
- glaip_sdk/cli/slash/agent_session.py +65 -29
- glaip_sdk/cli/slash/prompt.py +24 -10
- glaip_sdk/cli/slash/remote_runs_controller.py +566 -0
- glaip_sdk/cli/slash/session.py +827 -232
- glaip_sdk/cli/slash/tui/__init__.py +34 -0
- glaip_sdk/cli/slash/tui/accounts.tcss +88 -0
- glaip_sdk/cli/slash/tui/accounts_app.py +933 -0
- glaip_sdk/cli/slash/tui/background_tasks.py +72 -0
- glaip_sdk/cli/slash/tui/clipboard.py +147 -0
- glaip_sdk/cli/slash/tui/context.py +59 -0
- glaip_sdk/cli/slash/tui/keybind_registry.py +235 -0
- glaip_sdk/cli/slash/tui/loading.py +58 -0
- glaip_sdk/cli/slash/tui/remote_runs_app.py +628 -0
- glaip_sdk/cli/slash/tui/terminal.py +402 -0
- glaip_sdk/cli/slash/tui/theme/__init__.py +15 -0
- glaip_sdk/cli/slash/tui/theme/catalog.py +79 -0
- glaip_sdk/cli/slash/tui/theme/manager.py +86 -0
- glaip_sdk/cli/slash/tui/theme/tokens.py +55 -0
- glaip_sdk/cli/slash/tui/toast.py +123 -0
- glaip_sdk/cli/transcript/__init__.py +12 -52
- glaip_sdk/cli/transcript/cache.py +258 -60
- glaip_sdk/cli/transcript/capture.py +72 -21
- glaip_sdk/cli/transcript/history.py +815 -0
- glaip_sdk/cli/transcript/launcher.py +1 -3
- glaip_sdk/cli/transcript/viewer.py +79 -329
- glaip_sdk/cli/update_notifier.py +385 -24
- glaip_sdk/cli/validators.py +16 -18
- glaip_sdk/client/__init__.py +3 -1
- glaip_sdk/client/_schedule_payloads.py +89 -0
- glaip_sdk/client/agent_runs.py +147 -0
- glaip_sdk/client/agents.py +370 -100
- glaip_sdk/client/base.py +78 -35
- glaip_sdk/client/hitl.py +136 -0
- glaip_sdk/client/main.py +25 -10
- glaip_sdk/client/mcps.py +166 -27
- glaip_sdk/client/payloads/agent/__init__.py +23 -0
- glaip_sdk/client/{_agent_payloads.py ā payloads/agent/requests.py} +65 -74
- glaip_sdk/client/payloads/agent/responses.py +43 -0
- glaip_sdk/client/run_rendering.py +583 -79
- glaip_sdk/client/schedules.py +439 -0
- glaip_sdk/client/shared.py +21 -0
- glaip_sdk/client/tools.py +214 -56
- glaip_sdk/client/validators.py +20 -48
- glaip_sdk/config/constants.py +11 -0
- glaip_sdk/exceptions.py +1 -3
- glaip_sdk/hitl/__init__.py +48 -0
- glaip_sdk/hitl/base.py +64 -0
- glaip_sdk/hitl/callback.py +43 -0
- glaip_sdk/hitl/local.py +121 -0
- glaip_sdk/hitl/remote.py +523 -0
- glaip_sdk/icons.py +9 -3
- glaip_sdk/mcps/__init__.py +21 -0
- glaip_sdk/mcps/base.py +345 -0
- glaip_sdk/models/__init__.py +107 -0
- glaip_sdk/models/agent.py +47 -0
- glaip_sdk/models/agent_runs.py +117 -0
- glaip_sdk/models/common.py +42 -0
- glaip_sdk/models/mcp.py +33 -0
- glaip_sdk/models/schedule.py +224 -0
- glaip_sdk/models/tool.py +33 -0
- glaip_sdk/payload_schemas/__init__.py +1 -13
- glaip_sdk/payload_schemas/agent.py +1 -3
- glaip_sdk/registry/__init__.py +55 -0
- glaip_sdk/registry/agent.py +164 -0
- glaip_sdk/registry/base.py +139 -0
- glaip_sdk/registry/mcp.py +253 -0
- glaip_sdk/registry/tool.py +445 -0
- glaip_sdk/rich_components.py +58 -2
- glaip_sdk/runner/__init__.py +76 -0
- glaip_sdk/runner/base.py +84 -0
- glaip_sdk/runner/deps.py +112 -0
- glaip_sdk/runner/langgraph.py +872 -0
- glaip_sdk/runner/logging_config.py +77 -0
- glaip_sdk/runner/mcp_adapter/__init__.py +13 -0
- glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py +43 -0
- glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py +257 -0
- glaip_sdk/runner/mcp_adapter/mcp_config_builder.py +95 -0
- glaip_sdk/runner/tool_adapter/__init__.py +18 -0
- glaip_sdk/runner/tool_adapter/base_tool_adapter.py +44 -0
- glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py +242 -0
- glaip_sdk/schedules/__init__.py +22 -0
- glaip_sdk/schedules/base.py +291 -0
- glaip_sdk/tools/__init__.py +22 -0
- glaip_sdk/tools/base.py +468 -0
- glaip_sdk/utils/__init__.py +59 -12
- glaip_sdk/utils/a2a/__init__.py +34 -0
- glaip_sdk/utils/a2a/event_processor.py +188 -0
- glaip_sdk/utils/agent_config.py +4 -14
- glaip_sdk/utils/bundler.py +403 -0
- glaip_sdk/utils/client.py +111 -0
- glaip_sdk/utils/client_utils.py +46 -28
- glaip_sdk/utils/datetime_helpers.py +58 -0
- glaip_sdk/utils/discovery.py +78 -0
- glaip_sdk/utils/display.py +25 -21
- glaip_sdk/utils/export.py +143 -0
- glaip_sdk/utils/general.py +1 -36
- glaip_sdk/utils/import_export.py +15 -16
- glaip_sdk/utils/import_resolver.py +524 -0
- glaip_sdk/utils/instructions.py +101 -0
- glaip_sdk/utils/rendering/__init__.py +115 -1
- glaip_sdk/utils/rendering/formatting.py +38 -23
- glaip_sdk/utils/rendering/layout/__init__.py +64 -0
- glaip_sdk/utils/rendering/{renderer ā layout}/panels.py +10 -3
- glaip_sdk/utils/rendering/{renderer ā layout}/progress.py +73 -12
- glaip_sdk/utils/rendering/layout/summary.py +74 -0
- glaip_sdk/utils/rendering/layout/transcript.py +606 -0
- glaip_sdk/utils/rendering/models.py +18 -8
- glaip_sdk/utils/rendering/renderer/__init__.py +9 -51
- glaip_sdk/utils/rendering/renderer/base.py +534 -882
- glaip_sdk/utils/rendering/renderer/config.py +4 -10
- glaip_sdk/utils/rendering/renderer/debug.py +30 -34
- glaip_sdk/utils/rendering/renderer/factory.py +138 -0
- glaip_sdk/utils/rendering/renderer/stream.py +13 -54
- glaip_sdk/utils/rendering/renderer/summary_window.py +79 -0
- glaip_sdk/utils/rendering/renderer/thinking.py +273 -0
- glaip_sdk/utils/rendering/renderer/toggle.py +182 -0
- glaip_sdk/utils/rendering/renderer/tool_panels.py +442 -0
- glaip_sdk/utils/rendering/renderer/transcript_mode.py +162 -0
- glaip_sdk/utils/rendering/state.py +204 -0
- glaip_sdk/utils/rendering/step_tree_state.py +100 -0
- glaip_sdk/utils/rendering/steps/__init__.py +34 -0
- glaip_sdk/utils/rendering/steps/event_processor.py +778 -0
- glaip_sdk/utils/rendering/steps/format.py +176 -0
- glaip_sdk/utils/rendering/{steps.py ā steps/manager.py} +122 -26
- glaip_sdk/utils/rendering/timing.py +36 -0
- glaip_sdk/utils/rendering/viewer/__init__.py +21 -0
- glaip_sdk/utils/rendering/viewer/presenter.py +184 -0
- glaip_sdk/utils/resource_refs.py +29 -26
- glaip_sdk/utils/runtime_config.py +425 -0
- glaip_sdk/utils/serialization.py +32 -46
- glaip_sdk/utils/sync.py +162 -0
- glaip_sdk/utils/tool_detection.py +301 -0
- glaip_sdk/utils/tool_storage_provider.py +140 -0
- glaip_sdk/utils/validation.py +20 -28
- {glaip_sdk-0.0.20.dist-info ā glaip_sdk-0.7.7.dist-info}/METADATA +78 -23
- glaip_sdk-0.7.7.dist-info/RECORD +213 -0
- {glaip_sdk-0.0.20.dist-info ā glaip_sdk-0.7.7.dist-info}/WHEEL +2 -1
- glaip_sdk-0.7.7.dist-info/entry_points.txt +2 -0
- glaip_sdk-0.7.7.dist-info/top_level.txt +1 -0
- glaip_sdk/cli/commands/agents.py +0 -1412
- glaip_sdk/cli/commands/mcps.py +0 -1225
- glaip_sdk/cli/commands/tools.py +0 -597
- glaip_sdk/cli/utils.py +0 -1330
- glaip_sdk/models.py +0 -259
- glaip_sdk-0.0.20.dist-info/RECORD +0 -80
- glaip_sdk-0.0.20.dist-info/entry_points.txt +0 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Sync LangFlow agents 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 handle_json_output, handle_rich_output
|
|
15
|
+
from glaip_sdk.cli.core.context import get_client
|
|
16
|
+
from glaip_sdk.cli.rich_helpers import markup_text
|
|
17
|
+
|
|
18
|
+
from ._common import _handle_command_exception, agents_group
|
|
19
|
+
|
|
20
|
+
from glaip_sdk.branding import SUCCESS_STYLE
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@agents_group.command()
|
|
24
|
+
@click.option(
|
|
25
|
+
"--base-url",
|
|
26
|
+
help="Custom LangFlow server base URL (overrides LANGFLOW_BASE_URL env var)",
|
|
27
|
+
)
|
|
28
|
+
@click.option("--api-key", help="Custom LangFlow API key (overrides LANGFLOW_API_KEY env var)")
|
|
29
|
+
@output_flags()
|
|
30
|
+
@click.pass_context
|
|
31
|
+
def sync_langflow(ctx: Any, base_url: str | None, api_key: str | None) -> None:
|
|
32
|
+
r"""Sync agents with LangFlow server flows.
|
|
33
|
+
|
|
34
|
+
This command fetches all flows from the configured LangFlow server and
|
|
35
|
+
creates/updates corresponding agents in the platform.
|
|
36
|
+
|
|
37
|
+
The LangFlow server configuration can be provided via:
|
|
38
|
+
- Command options (--base-url, --api-key)
|
|
39
|
+
- Environment variables (LANGFLOW_BASE_URL, LANGFLOW_API_KEY)
|
|
40
|
+
|
|
41
|
+
\b
|
|
42
|
+
Examples:
|
|
43
|
+
aip agents sync-langflow
|
|
44
|
+
aip agents sync-langflow --base-url https://my-langflow.com --api-key my-key
|
|
45
|
+
"""
|
|
46
|
+
try:
|
|
47
|
+
client = get_client(ctx)
|
|
48
|
+
|
|
49
|
+
# Perform the sync
|
|
50
|
+
result = client.sync_langflow_agents(base_url=base_url, api_key=api_key)
|
|
51
|
+
|
|
52
|
+
# Handle output format
|
|
53
|
+
handle_json_output(ctx, result)
|
|
54
|
+
|
|
55
|
+
# Show success message for non-JSON output
|
|
56
|
+
if get_ctx_value(ctx, "view") != "json":
|
|
57
|
+
# Extract some useful info from the result
|
|
58
|
+
success_count = result.get("data", {}).get("created_count", 0) + result.get("data", {}).get(
|
|
59
|
+
"updated_count", 0
|
|
60
|
+
)
|
|
61
|
+
total_count = result.get("data", {}).get("total_processed", 0)
|
|
62
|
+
|
|
63
|
+
handle_rich_output(
|
|
64
|
+
ctx,
|
|
65
|
+
markup_text(
|
|
66
|
+
f"[{SUCCESS_STYLE}]ā
Successfully synced {success_count} LangFlow agents "
|
|
67
|
+
f"({total_count} total processed)[/]"
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
except Exception as e:
|
|
72
|
+
_handle_command_exception(ctx, e)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Update agent 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 (
|
|
15
|
+
display_agent_run_suggestions,
|
|
16
|
+
display_update_success,
|
|
17
|
+
handle_json_output,
|
|
18
|
+
handle_rich_output,
|
|
19
|
+
)
|
|
20
|
+
from glaip_sdk.cli.core.context import get_client
|
|
21
|
+
|
|
22
|
+
from ._common import (
|
|
23
|
+
_get_agent_for_update,
|
|
24
|
+
_handle_click_exception_for_json,
|
|
25
|
+
_handle_command_exception,
|
|
26
|
+
_prepare_agent_output,
|
|
27
|
+
_resolve_resources_by_name,
|
|
28
|
+
_split_comma_separated_refs,
|
|
29
|
+
agents_group,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@agents_group.command()
|
|
34
|
+
@click.argument("agent_id")
|
|
35
|
+
@click.option("--name", help="New agent name")
|
|
36
|
+
@click.option("--instruction", help="New instruction")
|
|
37
|
+
@click.option("--tools", multiple=True, help="New tool names or IDs")
|
|
38
|
+
@click.option("--agents", multiple=True, help="New sub-agent names")
|
|
39
|
+
@click.option("--mcps", multiple=True, help="New MCP names or IDs")
|
|
40
|
+
@click.option("--timeout", type=int, help="New timeout value")
|
|
41
|
+
@click.option(
|
|
42
|
+
"--import",
|
|
43
|
+
"import_file",
|
|
44
|
+
type=click.Path(exists=True, dir_okay=False),
|
|
45
|
+
help="Import agent configuration from JSON file",
|
|
46
|
+
)
|
|
47
|
+
@output_flags()
|
|
48
|
+
@click.pass_context
|
|
49
|
+
def update(
|
|
50
|
+
ctx: Any,
|
|
51
|
+
agent_id: str,
|
|
52
|
+
name: str | None,
|
|
53
|
+
instruction: str | None,
|
|
54
|
+
tools: tuple[str, ...] | None,
|
|
55
|
+
agents: tuple[str, ...] | None,
|
|
56
|
+
mcps: tuple[str, ...] | None,
|
|
57
|
+
timeout: float | None,
|
|
58
|
+
import_file: str | None,
|
|
59
|
+
) -> None:
|
|
60
|
+
r"""Update an existing agent.
|
|
61
|
+
|
|
62
|
+
\b
|
|
63
|
+
Examples:
|
|
64
|
+
aip agents update my-agent --instruction "New instruction"
|
|
65
|
+
aip agents update my-agent --import agent.json
|
|
66
|
+
"""
|
|
67
|
+
try:
|
|
68
|
+
client = get_client(ctx)
|
|
69
|
+
tools = _split_comma_separated_refs(tools)
|
|
70
|
+
agents = _split_comma_separated_refs(agents)
|
|
71
|
+
mcps = _split_comma_separated_refs(mcps)
|
|
72
|
+
|
|
73
|
+
has_updates = bool(import_file) or any(
|
|
74
|
+
[
|
|
75
|
+
name is not None,
|
|
76
|
+
instruction is not None,
|
|
77
|
+
bool(tools),
|
|
78
|
+
bool(agents),
|
|
79
|
+
bool(mcps),
|
|
80
|
+
timeout is not None,
|
|
81
|
+
]
|
|
82
|
+
)
|
|
83
|
+
if not has_updates:
|
|
84
|
+
raise click.ClickException("No update fields specified")
|
|
85
|
+
|
|
86
|
+
agent = _get_agent_for_update(client, agent_id)
|
|
87
|
+
|
|
88
|
+
resolved_tools = _resolve_resources_by_name(client, tools, "tool", client.find_tools, "Tool") if tools else None
|
|
89
|
+
resolved_agents = (
|
|
90
|
+
_resolve_resources_by_name(client, agents, "agent", client.find_agents, "Agent") if agents else None
|
|
91
|
+
)
|
|
92
|
+
resolved_mcps = _resolve_resources_by_name(client, mcps, "mcp", client.find_mcps, "MCP") if mcps else None
|
|
93
|
+
|
|
94
|
+
updated_agent = client.agents.update_agent(
|
|
95
|
+
agent.id,
|
|
96
|
+
file=import_file,
|
|
97
|
+
name=name,
|
|
98
|
+
instruction=instruction,
|
|
99
|
+
tools=resolved_tools,
|
|
100
|
+
agents=resolved_agents,
|
|
101
|
+
mcps=resolved_mcps,
|
|
102
|
+
timeout=timeout,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
handle_json_output(ctx, _prepare_agent_output(updated_agent))
|
|
106
|
+
handle_rich_output(ctx, display_update_success("Agent", updated_agent.name))
|
|
107
|
+
handle_rich_output(ctx, display_agent_run_suggestions(updated_agent))
|
|
108
|
+
|
|
109
|
+
except click.ClickException as e:
|
|
110
|
+
_handle_click_exception_for_json(ctx, e)
|
|
111
|
+
except Exception as e:
|
|
112
|
+
_handle_command_exception(ctx, e)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Shared helpers for configuration/account flows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
from rich.console import Console
|
|
10
|
+
from rich.text import Text
|
|
11
|
+
from glaip_sdk.branding import PRIMARY, SUCCESS_STYLE, WARNING_STYLE, AIPBranding
|
|
12
|
+
from glaip_sdk.cli.core.output import sdk_version
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING: # pragma: no cover - type checking only
|
|
15
|
+
from glaip_sdk import Client
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def render_branding_header(console: Console, rule_text: str) -> None:
|
|
19
|
+
"""Render the standard CLI branding header with a custom rule text."""
|
|
20
|
+
branding = AIPBranding.create_from_sdk(sdk_version=sdk_version(), package_name="glaip-sdk")
|
|
21
|
+
heading = "[bold]>_ GDP Labs AI Agents Package (AIP CLI)[/bold]"
|
|
22
|
+
console.print(heading)
|
|
23
|
+
console.print()
|
|
24
|
+
console.print(branding.get_welcome_banner())
|
|
25
|
+
console.rule(rule_text, style=PRIMARY)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def check_connection(
|
|
29
|
+
api_url: str,
|
|
30
|
+
api_key: str,
|
|
31
|
+
console: Console,
|
|
32
|
+
*,
|
|
33
|
+
abort_on_error: bool = False,
|
|
34
|
+
extra_hint: str | None = None,
|
|
35
|
+
) -> bool:
|
|
36
|
+
"""Test connectivity and report results.
|
|
37
|
+
|
|
38
|
+
Returns True on success, False on handled failures. Raises click.Abort when
|
|
39
|
+
abort_on_error is True and a fatal error occurs.
|
|
40
|
+
"""
|
|
41
|
+
console.print("\nš Testing connection...")
|
|
42
|
+
client: Client | None = None
|
|
43
|
+
try:
|
|
44
|
+
# Import lazily to avoid pulling in SDK dependencies during CLI startup.
|
|
45
|
+
from glaip_sdk import Client # noqa: PLC0415
|
|
46
|
+
|
|
47
|
+
client = Client(api_url=api_url, api_key=api_key)
|
|
48
|
+
try:
|
|
49
|
+
agents = client.list_agents()
|
|
50
|
+
console.print(Text(f"ā
Connection successful! Found {len(agents)} agents", style=SUCCESS_STYLE))
|
|
51
|
+
return True
|
|
52
|
+
except Exception as exc: # pragma: no cover - API failures depend on network
|
|
53
|
+
console.print(Text(f"ā ļø Connection established but API call failed: {exc}", style=WARNING_STYLE))
|
|
54
|
+
console.print(" You may need to check your API permissions or network access")
|
|
55
|
+
if extra_hint:
|
|
56
|
+
console.print(extra_hint)
|
|
57
|
+
if abort_on_error:
|
|
58
|
+
raise click.Abort() from exc
|
|
59
|
+
return False
|
|
60
|
+
except Exception as exc:
|
|
61
|
+
console.print(Text(f"ā Connection failed: {exc}"))
|
|
62
|
+
console.print(" Please check your API URL and key")
|
|
63
|
+
if extra_hint:
|
|
64
|
+
console.print(extra_hint)
|
|
65
|
+
if abort_on_error:
|
|
66
|
+
raise click.Abort() from exc
|
|
67
|
+
return False
|
|
68
|
+
finally:
|
|
69
|
+
if client is not None:
|
|
70
|
+
client.close()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def check_connection_with_reason(
|
|
74
|
+
api_url: str,
|
|
75
|
+
api_key: str,
|
|
76
|
+
*,
|
|
77
|
+
abort_on_error: bool = False,
|
|
78
|
+
) -> tuple[bool, str]:
|
|
79
|
+
"""Test connectivity and return structured reason."""
|
|
80
|
+
client: Client | None = None
|
|
81
|
+
try:
|
|
82
|
+
# Import lazily to avoid pulling in SDK dependencies during CLI startup.
|
|
83
|
+
from glaip_sdk import Client # noqa: PLC0415
|
|
84
|
+
|
|
85
|
+
client = Client(api_url=api_url, api_key=api_key)
|
|
86
|
+
try:
|
|
87
|
+
client.list_agents()
|
|
88
|
+
return True, ""
|
|
89
|
+
except Exception as exc: # pragma: no cover - API failures depend on network
|
|
90
|
+
if abort_on_error:
|
|
91
|
+
raise click.Abort() from exc
|
|
92
|
+
return False, f"api_failed: {exc}"
|
|
93
|
+
except Exception as exc:
|
|
94
|
+
# Log unexpected exceptions in debug while keeping CLI-friendly messaging
|
|
95
|
+
logging.getLogger(__name__).debug("Unexpected connection error", exc_info=exc)
|
|
96
|
+
if abort_on_error:
|
|
97
|
+
raise click.Abort() from exc
|
|
98
|
+
return False, f"connection_failed: {exc}"
|
|
99
|
+
finally:
|
|
100
|
+
if client is not None:
|
|
101
|
+
try:
|
|
102
|
+
client.close()
|
|
103
|
+
except Exception:
|
|
104
|
+
pass
|