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
glaip_sdk/icons.py
CHANGED
|
@@ -5,10 +5,13 @@ Authors:
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
ICON_AGENT = "🤖"
|
|
8
|
-
ICON_AGENT_STEP = "
|
|
8
|
+
ICON_AGENT_STEP = "🤖"
|
|
9
9
|
ICON_TOOL = "🔧"
|
|
10
|
-
ICON_TOOL_STEP = "
|
|
11
|
-
ICON_DELEGATE =
|
|
10
|
+
ICON_TOOL_STEP = "🔧"
|
|
11
|
+
ICON_DELEGATE = ICON_AGENT_STEP
|
|
12
|
+
ICON_STATUS_SUCCESS = "✓"
|
|
13
|
+
ICON_STATUS_FAILED = "✗"
|
|
14
|
+
ICON_STATUS_WARNING = "⚠"
|
|
12
15
|
|
|
13
16
|
__all__ = [
|
|
14
17
|
"ICON_AGENT",
|
|
@@ -16,4 +19,7 @@ __all__ = [
|
|
|
16
19
|
"ICON_TOOL",
|
|
17
20
|
"ICON_TOOL_STEP",
|
|
18
21
|
"ICON_DELEGATE",
|
|
22
|
+
"ICON_STATUS_SUCCESS",
|
|
23
|
+
"ICON_STATUS_FAILED",
|
|
24
|
+
"ICON_STATUS_WARNING",
|
|
19
25
|
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""MCP (Model Context Protocol) package for GL AIP platform.
|
|
2
|
+
|
|
3
|
+
This package provides the MCP class and MCPRegistry for managing
|
|
4
|
+
Model Context Protocol configurations on the GL AIP platform.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
>>> from glaip_sdk.mcps import MCP, get_mcp_registry
|
|
8
|
+
>>> mcp = MCP.from_native("arxiv-search")
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from glaip_sdk.mcps.base import MCP, MCPConfigValue
|
|
14
|
+
from glaip_sdk.registry.mcp import MCPRegistry, get_mcp_registry
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"MCP",
|
|
18
|
+
"MCPConfigValue",
|
|
19
|
+
"MCPRegistry",
|
|
20
|
+
"get_mcp_registry",
|
|
21
|
+
]
|
glaip_sdk/mcps/base.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"""MCP (Model Context Protocol) helper for glaip_sdk.
|
|
2
|
+
|
|
3
|
+
Provides a simple, migration-ready way to declare and resolve MCPs with
|
|
4
|
+
in-memory caching and create-on-missing functionality.
|
|
5
|
+
|
|
6
|
+
The MCP class also supports runtime operations (update, delete, get_tools)
|
|
7
|
+
when retrieved from the API via client.mcps.get().
|
|
8
|
+
|
|
9
|
+
Authors:
|
|
10
|
+
Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
|
|
11
|
+
|
|
12
|
+
Example - Lazy Reference:
|
|
13
|
+
>>> from glaip_sdk.mcps import MCP
|
|
14
|
+
>>>
|
|
15
|
+
>>> # Create from known ID
|
|
16
|
+
>>> mcp = MCP.from_id("mcp_abc123")
|
|
17
|
+
>>>
|
|
18
|
+
>>> # Create lookup-only by name (error if not found)
|
|
19
|
+
>>> mcp = MCP.from_native("arxiv-search")
|
|
20
|
+
>>>
|
|
21
|
+
>>> # Create for lookup/creation by name (create if missing)
|
|
22
|
+
>>> mcp = MCP(name="my-filesystem-mcp", transport="sse", config={"url": "..."})
|
|
23
|
+
|
|
24
|
+
Example - Runtime Operations:
|
|
25
|
+
>>> from glaip_sdk import Glaip
|
|
26
|
+
>>>
|
|
27
|
+
>>> client = Glaip()
|
|
28
|
+
>>> mcp = client.mcps.get("mcp-123")
|
|
29
|
+
>>> tools = mcp.get_tools() # Get tools from MCP
|
|
30
|
+
>>> mcp.update(description="Updated description")
|
|
31
|
+
>>> mcp.delete()
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
from typing import TYPE_CHECKING, Any
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from glaip_sdk.models import MCPResponse
|
|
40
|
+
|
|
41
|
+
# Type alias for MCP configuration values
|
|
42
|
+
MCPConfigValue = str | int | bool | list[str] | dict[str, str]
|
|
43
|
+
|
|
44
|
+
_MCP_NOT_DEPLOYED_MSG = "MCP not available on platform. No ID set."
|
|
45
|
+
_CLIENT_NOT_AVAILABLE_MSG = "Client not available. Use client.mcps.get() to get a client-connected MCP."
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class MCP:
|
|
49
|
+
"""MCP reference helper for declaring MCPs in Agent definitions.
|
|
50
|
+
|
|
51
|
+
Supports both lazy references and runtime operations:
|
|
52
|
+
- Lazy reference: Created via from_native() or from_id()
|
|
53
|
+
- Runtime: Created via from_response() or client.mcps.get()
|
|
54
|
+
|
|
55
|
+
Attributes:
|
|
56
|
+
name: Human-readable MCP name (used for lookup/creation).
|
|
57
|
+
id: Backend MCP ID (used for direct fetch if known).
|
|
58
|
+
transport: Transport type (e.g., "sse", "stdio", "websocket").
|
|
59
|
+
config: Transport configuration dict (URLs, args, env vars).
|
|
60
|
+
description: Optional description for the MCP.
|
|
61
|
+
metadata: Optional additional metadata dict.
|
|
62
|
+
authentication: Authentication configuration.
|
|
63
|
+
|
|
64
|
+
Example - Lazy Reference:
|
|
65
|
+
>>> # Create from known ID
|
|
66
|
+
>>> mcp = MCP.from_id("mcp_abc123")
|
|
67
|
+
>>>
|
|
68
|
+
>>> # Create lookup-only by name (error if not found)
|
|
69
|
+
>>> mcp = MCP.from_native("arxiv-search")
|
|
70
|
+
>>>
|
|
71
|
+
>>> # Create for lookup/creation by name (create if missing)
|
|
72
|
+
>>> mcp = MCP(name="my-filesystem-mcp", transport="sse", config={"url": "..."})
|
|
73
|
+
|
|
74
|
+
Example - Runtime Operations:
|
|
75
|
+
>>> mcp = client.mcps.get("mcp-123")
|
|
76
|
+
>>> mcp.update(description="New description")
|
|
77
|
+
>>> mcp.delete()
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def __init__(
|
|
81
|
+
self,
|
|
82
|
+
name: str | None = None,
|
|
83
|
+
*,
|
|
84
|
+
id: str | None = None, # noqa: A002 - Allow shadowing builtin for API compat
|
|
85
|
+
transport: str | None = None,
|
|
86
|
+
config: dict[str, MCPConfigValue] | None = None,
|
|
87
|
+
description: str | None = None,
|
|
88
|
+
metadata: dict[str, Any] | None = None,
|
|
89
|
+
authentication: dict[str, Any] | None = None,
|
|
90
|
+
_lookup_only: bool = False,
|
|
91
|
+
_client: Any = None,
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Initialize an MCP.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
name: Human-readable MCP name.
|
|
97
|
+
id: Backend MCP ID.
|
|
98
|
+
transport: Transport type (e.g., "sse", "stdio").
|
|
99
|
+
config: Transport configuration dict.
|
|
100
|
+
description: Optional description.
|
|
101
|
+
metadata: Optional metadata dict.
|
|
102
|
+
authentication: Authentication configuration.
|
|
103
|
+
_lookup_only: If True, don't create if not found.
|
|
104
|
+
_client: Internal client reference.
|
|
105
|
+
|
|
106
|
+
Raises:
|
|
107
|
+
ValueError: If neither name nor id is provided.
|
|
108
|
+
"""
|
|
109
|
+
if not name and not id:
|
|
110
|
+
raise ValueError("At least one of 'name' or 'id' must be provided")
|
|
111
|
+
|
|
112
|
+
self.name = name
|
|
113
|
+
self._id = id
|
|
114
|
+
self.transport = transport
|
|
115
|
+
self.config = config
|
|
116
|
+
self.description = description
|
|
117
|
+
self.metadata = metadata
|
|
118
|
+
self.authentication = authentication
|
|
119
|
+
self._lookup_only = _lookup_only
|
|
120
|
+
self._client = _client
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def id(self) -> str | None: # noqa: A003 - Allow shadowing builtin for API compat
|
|
124
|
+
"""MCP ID on the platform."""
|
|
125
|
+
return self._id
|
|
126
|
+
|
|
127
|
+
@id.setter
|
|
128
|
+
def id(self, value: str | None) -> None: # noqa: A003
|
|
129
|
+
"""Set the MCP ID."""
|
|
130
|
+
self._id = value
|
|
131
|
+
|
|
132
|
+
def __repr__(self) -> str:
|
|
133
|
+
"""Return string representation."""
|
|
134
|
+
if self._id:
|
|
135
|
+
return f"MCP(id={self._id!r}, name={self.name!r})"
|
|
136
|
+
if self._lookup_only:
|
|
137
|
+
return f"MCP.from_native({self.name!r})"
|
|
138
|
+
return f"MCP(name={self.name!r})"
|
|
139
|
+
|
|
140
|
+
def __eq__(self, other: object) -> bool:
|
|
141
|
+
"""Check equality based on id if available, else name."""
|
|
142
|
+
if not isinstance(other, MCP):
|
|
143
|
+
return NotImplemented
|
|
144
|
+
if self._id and other._id:
|
|
145
|
+
return self._id == other._id
|
|
146
|
+
return self.name == other.name
|
|
147
|
+
|
|
148
|
+
def __hash__(self) -> int:
|
|
149
|
+
"""Hash based on id if available, else name."""
|
|
150
|
+
if self._id:
|
|
151
|
+
return hash(self._id)
|
|
152
|
+
return hash(self.name)
|
|
153
|
+
|
|
154
|
+
def model_dump(self, *, exclude_none: bool = False) -> dict[str, Any]:
|
|
155
|
+
"""Return a dict representation of the MCP.
|
|
156
|
+
|
|
157
|
+
Provides Pydantic-style serialization for backward compatibility.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
exclude_none: If True, exclude None values from the output.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
Dictionary containing MCP attributes.
|
|
164
|
+
"""
|
|
165
|
+
data = {
|
|
166
|
+
"id": self._id,
|
|
167
|
+
"name": self.name,
|
|
168
|
+
"transport": self.transport,
|
|
169
|
+
"config": self.config,
|
|
170
|
+
"description": self.description,
|
|
171
|
+
"metadata": self.metadata,
|
|
172
|
+
"authentication": self.authentication,
|
|
173
|
+
}
|
|
174
|
+
if exclude_none:
|
|
175
|
+
return {k: v for k, v in data.items() if v is not None}
|
|
176
|
+
return data
|
|
177
|
+
|
|
178
|
+
@classmethod
|
|
179
|
+
def from_native(cls, name: str) -> MCP:
|
|
180
|
+
"""Create a lookup-only MCP reference by name.
|
|
181
|
+
|
|
182
|
+
Use this when referencing an MCP that already exists on the platform.
|
|
183
|
+
Resolution will NOT create the MCP if not found - it will raise an error.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
name: The name of the existing MCP.
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
MCP instance configured for lookup-only resolution.
|
|
190
|
+
|
|
191
|
+
Raises:
|
|
192
|
+
ValueError: If name is empty.
|
|
193
|
+
|
|
194
|
+
Example:
|
|
195
|
+
>>> mcp = MCP.from_native("arxiv-search")
|
|
196
|
+
>>> # Registry will find by name, error if not found or ambiguous
|
|
197
|
+
"""
|
|
198
|
+
if not name:
|
|
199
|
+
raise ValueError("Name cannot be empty")
|
|
200
|
+
return cls(name=name, _lookup_only=True)
|
|
201
|
+
|
|
202
|
+
@classmethod
|
|
203
|
+
def from_id(cls, mcp_id: str) -> MCP:
|
|
204
|
+
"""Create an MCP helper for lookup-only by ID.
|
|
205
|
+
|
|
206
|
+
This creates a minimal MCP reference that will be resolved
|
|
207
|
+
from the backend using the ID. Use this when you know the
|
|
208
|
+
backend MCP ID but don't have the full configuration.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
mcp_id: The backend MCP ID.
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
An MCP instance with only the ID set, marked for lookup-only.
|
|
215
|
+
|
|
216
|
+
Raises:
|
|
217
|
+
ValueError: If mcp_id is empty.
|
|
218
|
+
|
|
219
|
+
Example:
|
|
220
|
+
>>> mcp = MCP.from_id("550e8400-e29b-41d4-a716-446655440000")
|
|
221
|
+
>>> # Registry will fetch directly by ID
|
|
222
|
+
"""
|
|
223
|
+
if not mcp_id:
|
|
224
|
+
raise ValueError("ID cannot be empty")
|
|
225
|
+
return cls(id=mcp_id, _lookup_only=True)
|
|
226
|
+
|
|
227
|
+
# ─────────────────────────────────────────────────────────────────
|
|
228
|
+
# Runtime Methods (require client connection)
|
|
229
|
+
# ─────────────────────────────────────────────────────────────────
|
|
230
|
+
|
|
231
|
+
def _set_client(self, client: Any) -> MCP:
|
|
232
|
+
"""Set the client reference for this MCP.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
client: The Glaip client instance.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
Self for method chaining.
|
|
239
|
+
"""
|
|
240
|
+
self._client = client
|
|
241
|
+
return self
|
|
242
|
+
|
|
243
|
+
def get_tools(self) -> list[dict[str, Any]]:
|
|
244
|
+
"""Get tools available from this MCP.
|
|
245
|
+
|
|
246
|
+
Returns:
|
|
247
|
+
List of tool definitions from the MCP.
|
|
248
|
+
|
|
249
|
+
Raises:
|
|
250
|
+
ValueError: If the MCP has no ID.
|
|
251
|
+
RuntimeError: If client is not available.
|
|
252
|
+
"""
|
|
253
|
+
if not self._id:
|
|
254
|
+
raise ValueError(_MCP_NOT_DEPLOYED_MSG)
|
|
255
|
+
if not self._client:
|
|
256
|
+
raise RuntimeError(_CLIENT_NOT_AVAILABLE_MSG)
|
|
257
|
+
|
|
258
|
+
# Delegate to the client's MCP tools endpoint
|
|
259
|
+
return self._client.mcps.get_tools(mcp_id=self._id)
|
|
260
|
+
|
|
261
|
+
def update(self, **kwargs: Any) -> MCP:
|
|
262
|
+
"""Update the MCP with new configuration.
|
|
263
|
+
|
|
264
|
+
Args:
|
|
265
|
+
**kwargs: MCP properties to update (name, description, config, etc.).
|
|
266
|
+
|
|
267
|
+
Returns:
|
|
268
|
+
Self with updated properties.
|
|
269
|
+
|
|
270
|
+
Raises:
|
|
271
|
+
ValueError: If the MCP has no ID.
|
|
272
|
+
RuntimeError: If client is not available.
|
|
273
|
+
"""
|
|
274
|
+
if not self._id:
|
|
275
|
+
raise ValueError(_MCP_NOT_DEPLOYED_MSG)
|
|
276
|
+
if not self._client:
|
|
277
|
+
raise RuntimeError(_CLIENT_NOT_AVAILABLE_MSG)
|
|
278
|
+
|
|
279
|
+
response = self._client.mcps.update(mcp_id=self._id, **kwargs)
|
|
280
|
+
|
|
281
|
+
# Update local properties from response
|
|
282
|
+
if hasattr(response, "name") and response.name:
|
|
283
|
+
self.name = response.name
|
|
284
|
+
if hasattr(response, "description"):
|
|
285
|
+
self.description = response.description
|
|
286
|
+
if hasattr(response, "config"):
|
|
287
|
+
self.config = response.config
|
|
288
|
+
if hasattr(response, "transport"):
|
|
289
|
+
self.transport = response.transport
|
|
290
|
+
|
|
291
|
+
return self
|
|
292
|
+
|
|
293
|
+
def delete(self) -> None:
|
|
294
|
+
"""Delete the MCP from the platform.
|
|
295
|
+
|
|
296
|
+
Raises:
|
|
297
|
+
ValueError: If the MCP has no ID.
|
|
298
|
+
RuntimeError: If client is not available.
|
|
299
|
+
"""
|
|
300
|
+
if not self._id:
|
|
301
|
+
raise ValueError(_MCP_NOT_DEPLOYED_MSG)
|
|
302
|
+
if not self._client:
|
|
303
|
+
raise RuntimeError(_CLIENT_NOT_AVAILABLE_MSG)
|
|
304
|
+
|
|
305
|
+
self._client.mcps.delete(mcp_id=self._id)
|
|
306
|
+
self._id = None
|
|
307
|
+
self._client = None
|
|
308
|
+
|
|
309
|
+
@classmethod
|
|
310
|
+
def from_response(
|
|
311
|
+
cls,
|
|
312
|
+
response: MCPResponse,
|
|
313
|
+
client: Any = None,
|
|
314
|
+
) -> MCP:
|
|
315
|
+
"""Create an MCP instance from an API response.
|
|
316
|
+
|
|
317
|
+
This allows you to work with MCPs retrieved from the API
|
|
318
|
+
as full MCP instances with all methods available.
|
|
319
|
+
|
|
320
|
+
Args:
|
|
321
|
+
response: The MCPResponse from an API call.
|
|
322
|
+
client: The Glaip client instance for API operations.
|
|
323
|
+
|
|
324
|
+
Returns:
|
|
325
|
+
An MCP instance initialized from the response.
|
|
326
|
+
|
|
327
|
+
Example:
|
|
328
|
+
>>> response = client.mcps.get("mcp-123")
|
|
329
|
+
>>> mcp = MCP.from_response(response, client)
|
|
330
|
+
>>> tools = mcp.get_tools()
|
|
331
|
+
"""
|
|
332
|
+
mcp = cls(
|
|
333
|
+
name=response.name,
|
|
334
|
+
id=response.id,
|
|
335
|
+
description=getattr(response, "description", None),
|
|
336
|
+
transport=getattr(response, "transport", None),
|
|
337
|
+
config=getattr(response, "config", None),
|
|
338
|
+
metadata=getattr(response, "metadata", None),
|
|
339
|
+
authentication=getattr(response, "authentication", None),
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
if client:
|
|
343
|
+
mcp._set_client(client)
|
|
344
|
+
|
|
345
|
+
return mcp
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Models package for AIP SDK.
|
|
2
|
+
|
|
3
|
+
This package provides Pydantic models for API responses.
|
|
4
|
+
|
|
5
|
+
For the public runtime API with methods like run(), deploy(), update(), delete():
|
|
6
|
+
- glaip_sdk.agents.Agent
|
|
7
|
+
- glaip_sdk.tools.Tool
|
|
8
|
+
- glaip_sdk.mcps.MCP
|
|
9
|
+
|
|
10
|
+
The Agent, Tool, and MCP exports from this module are DEPRECATED.
|
|
11
|
+
They redirect to glaip_sdk.agents.Agent, glaip_sdk.tools.Tool, glaip_sdk.mcps.MCP
|
|
12
|
+
respectively with deprecation warnings.
|
|
13
|
+
|
|
14
|
+
Authors:
|
|
15
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import warnings
|
|
19
|
+
|
|
20
|
+
# Pure Pydantic models for API responses (no runtime methods)
|
|
21
|
+
from glaip_sdk.models.agent import AgentResponse
|
|
22
|
+
from glaip_sdk.models.agent_runs import (
|
|
23
|
+
RunOutputChunk,
|
|
24
|
+
RunsPage,
|
|
25
|
+
RunSummary,
|
|
26
|
+
RunWithOutput,
|
|
27
|
+
)
|
|
28
|
+
from glaip_sdk.models.common import LanguageModelResponse, TTYRenderer
|
|
29
|
+
from glaip_sdk.models.mcp import MCPResponse
|
|
30
|
+
|
|
31
|
+
# Export schedule models
|
|
32
|
+
from glaip_sdk.models.schedule import ( # noqa: F401
|
|
33
|
+
ScheduleConfig,
|
|
34
|
+
ScheduleMetadata,
|
|
35
|
+
ScheduleResponse,
|
|
36
|
+
ScheduleRunOutputChunk,
|
|
37
|
+
ScheduleRunResponse,
|
|
38
|
+
ScheduleRunResult,
|
|
39
|
+
)
|
|
40
|
+
from glaip_sdk.models.tool import ToolResponse
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def __getattr__(name: str) -> type:
|
|
44
|
+
"""Deprecation warnings for backward compatibility."""
|
|
45
|
+
if name == "Agent":
|
|
46
|
+
warnings.warn(
|
|
47
|
+
"Importing Agent from glaip_sdk.models is deprecated. "
|
|
48
|
+
"Use 'from glaip_sdk.agents import Agent' instead. "
|
|
49
|
+
"This will be removed in v1.0.0",
|
|
50
|
+
DeprecationWarning,
|
|
51
|
+
stacklevel=2,
|
|
52
|
+
)
|
|
53
|
+
from glaip_sdk.agents import Agent # noqa: PLC0415
|
|
54
|
+
|
|
55
|
+
return Agent
|
|
56
|
+
|
|
57
|
+
if name == "Tool":
|
|
58
|
+
warnings.warn(
|
|
59
|
+
"Importing Tool from glaip_sdk.models is deprecated. "
|
|
60
|
+
"Use 'from glaip_sdk.tools import Tool' instead. "
|
|
61
|
+
"This will be removed in v1.0.0",
|
|
62
|
+
DeprecationWarning,
|
|
63
|
+
stacklevel=2,
|
|
64
|
+
)
|
|
65
|
+
from glaip_sdk.tools import Tool # noqa: PLC0415
|
|
66
|
+
|
|
67
|
+
return Tool
|
|
68
|
+
|
|
69
|
+
if name == "MCP":
|
|
70
|
+
warnings.warn(
|
|
71
|
+
"Importing MCP from glaip_sdk.models is deprecated. "
|
|
72
|
+
"Use 'from glaip_sdk.mcps import MCP' instead. "
|
|
73
|
+
"This will be removed in v1.0.0",
|
|
74
|
+
DeprecationWarning,
|
|
75
|
+
stacklevel=2,
|
|
76
|
+
)
|
|
77
|
+
from glaip_sdk.mcps import MCP # noqa: PLC0415
|
|
78
|
+
|
|
79
|
+
return MCP
|
|
80
|
+
|
|
81
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
__all__ = [
|
|
85
|
+
# Pure Pydantic response models (recommended for type hints)
|
|
86
|
+
"AgentResponse",
|
|
87
|
+
"ToolResponse",
|
|
88
|
+
"MCPResponse",
|
|
89
|
+
# Deprecated aliases (redirect to runtime classes with warning)
|
|
90
|
+
"Agent",
|
|
91
|
+
"Tool",
|
|
92
|
+
"MCP",
|
|
93
|
+
# Other models
|
|
94
|
+
"LanguageModelResponse",
|
|
95
|
+
"TTYRenderer",
|
|
96
|
+
"RunSummary",
|
|
97
|
+
"RunsPage",
|
|
98
|
+
"RunWithOutput",
|
|
99
|
+
"RunOutputChunk",
|
|
100
|
+
# Schedule models
|
|
101
|
+
"ScheduleConfig",
|
|
102
|
+
"ScheduleMetadata",
|
|
103
|
+
"ScheduleResponse",
|
|
104
|
+
"ScheduleRunResponse",
|
|
105
|
+
"ScheduleRunOutputChunk",
|
|
106
|
+
"ScheduleRunResult",
|
|
107
|
+
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Agent response model for AIP SDK.
|
|
2
|
+
|
|
3
|
+
This module contains the Pydantic model for Agent API responses.
|
|
4
|
+
This is a pure data model with no runtime behavior.
|
|
5
|
+
|
|
6
|
+
For the runtime Agent class with deploy/run methods, use glaip_sdk.agents.Agent.
|
|
7
|
+
|
|
8
|
+
Authors:
|
|
9
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
10
|
+
Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from datetime import datetime
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from glaip_sdk.config.constants import DEFAULT_AGENT_RUN_TIMEOUT
|
|
17
|
+
from pydantic import BaseModel
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AgentResponse(BaseModel):
|
|
21
|
+
"""Pydantic model for Agent API responses.
|
|
22
|
+
|
|
23
|
+
This is a pure data model for deserializing API responses.
|
|
24
|
+
It does NOT have runtime methods (run, update, delete).
|
|
25
|
+
|
|
26
|
+
For the runtime Agent class, use glaip_sdk.agents.Agent.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
id: str
|
|
30
|
+
name: str
|
|
31
|
+
instruction: str | None = None
|
|
32
|
+
description: str | None = None
|
|
33
|
+
type: str | None = None
|
|
34
|
+
framework: str | None = None
|
|
35
|
+
version: str | None = None
|
|
36
|
+
tools: list[dict[str, Any]] | None = None
|
|
37
|
+
agents: list[dict[str, Any]] | None = None
|
|
38
|
+
mcps: list[dict[str, Any]] | None = None
|
|
39
|
+
tool_configs: dict[str, Any] | None = None
|
|
40
|
+
mcp_configs: dict[str, Any] | None = None
|
|
41
|
+
agent_config: dict[str, Any] | None = None
|
|
42
|
+
timeout: int = DEFAULT_AGENT_RUN_TIMEOUT
|
|
43
|
+
metadata: dict[str, Any] | None = None
|
|
44
|
+
language_model_id: str | None = None
|
|
45
|
+
a2a_profile: dict[str, Any] | None = None
|
|
46
|
+
created_at: datetime | None = None
|
|
47
|
+
updated_at: datetime | None = None
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Agent run models for AIP SDK.
|
|
3
|
+
|
|
4
|
+
Authors:
|
|
5
|
+
Raymond Christopher (raymond.christopher@gdplabs.id)
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from datetime import datetime, timedelta
|
|
9
|
+
from typing import Any, Literal
|
|
10
|
+
from uuid import UUID
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, Field, field_validator, model_validator
|
|
13
|
+
|
|
14
|
+
# Type alias for SSE event dictionaries
|
|
15
|
+
RunOutputChunk = dict[str, Any]
|
|
16
|
+
RunStatus = Literal["started", "success", "failed", "cancelled", "aborted", "unavailable"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RunSummary(BaseModel):
|
|
20
|
+
"""Represents a single agent run in list/table views with metadata only."""
|
|
21
|
+
|
|
22
|
+
id: UUID
|
|
23
|
+
agent_id: UUID
|
|
24
|
+
run_type: Literal["manual", "schedule"]
|
|
25
|
+
schedule_id: UUID | None = None
|
|
26
|
+
status: RunStatus
|
|
27
|
+
started_at: datetime
|
|
28
|
+
completed_at: datetime | None = None
|
|
29
|
+
input: str | None = None
|
|
30
|
+
config: dict[str, Any] | None = None
|
|
31
|
+
created_at: datetime
|
|
32
|
+
updated_at: datetime
|
|
33
|
+
|
|
34
|
+
@field_validator("completed_at")
|
|
35
|
+
@classmethod
|
|
36
|
+
def validate_completed_after_started(cls, v: datetime | None, info) -> datetime | None:
|
|
37
|
+
"""Validate that completed_at is after started_at if present."""
|
|
38
|
+
if v is not None and "started_at" in info.data:
|
|
39
|
+
started_at = info.data["started_at"]
|
|
40
|
+
if v < started_at:
|
|
41
|
+
raise ValueError("completed_at must be after started_at")
|
|
42
|
+
return v
|
|
43
|
+
|
|
44
|
+
def duration(self) -> timedelta | None:
|
|
45
|
+
"""Calculate duration from started_at to completed_at.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Duration as timedelta if completed_at exists, None otherwise
|
|
49
|
+
"""
|
|
50
|
+
if self.completed_at is not None:
|
|
51
|
+
return self.completed_at - self.started_at
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
def duration_formatted(self) -> str:
|
|
55
|
+
"""Format duration as HH:MM:SS string.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Formatted duration string or "—" if not completed
|
|
59
|
+
"""
|
|
60
|
+
duration = self.duration()
|
|
61
|
+
if duration is None:
|
|
62
|
+
return "—"
|
|
63
|
+
total_seconds = int(duration.total_seconds())
|
|
64
|
+
hours = total_seconds // 3600
|
|
65
|
+
minutes = (total_seconds % 3600) // 60
|
|
66
|
+
seconds = total_seconds % 60
|
|
67
|
+
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
|
|
68
|
+
|
|
69
|
+
def input_preview(self, max_length: int = 120) -> str:
|
|
70
|
+
"""Generate truncated input preview for table display.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
max_length: Maximum length of preview string
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Truncated input string or "—" if input is None or empty
|
|
77
|
+
"""
|
|
78
|
+
if not self.input:
|
|
79
|
+
return "—"
|
|
80
|
+
# Strip newlines and collapse whitespace
|
|
81
|
+
preview = " ".join(self.input.split())
|
|
82
|
+
if len(preview) > max_length:
|
|
83
|
+
return preview[:max_length] + "…"
|
|
84
|
+
return preview
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class RunsPage(BaseModel):
|
|
88
|
+
"""Represents a paginated collection of run summaries from the list endpoint."""
|
|
89
|
+
|
|
90
|
+
data: list[RunSummary]
|
|
91
|
+
total: int = Field(ge=0)
|
|
92
|
+
page: int = Field(ge=1)
|
|
93
|
+
limit: int = Field(ge=1, le=100)
|
|
94
|
+
has_next: bool
|
|
95
|
+
has_prev: bool
|
|
96
|
+
|
|
97
|
+
@model_validator(mode="after")
|
|
98
|
+
def validate_pagination_consistency(self) -> "RunsPage":
|
|
99
|
+
"""Validate pagination consistency."""
|
|
100
|
+
# If has_next is True, then page * limit < total
|
|
101
|
+
if self.has_next and self.page * self.limit >= self.total:
|
|
102
|
+
raise ValueError("has_next inconsistency: page * limit must be < total when has_next is True")
|
|
103
|
+
return self
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class RunWithOutput(RunSummary):
|
|
107
|
+
"""Extends RunSummary with the complete SSE event stream for detailed viewing."""
|
|
108
|
+
|
|
109
|
+
output: list[RunOutputChunk] = Field(default_factory=list)
|
|
110
|
+
|
|
111
|
+
@field_validator("output", mode="before")
|
|
112
|
+
@classmethod
|
|
113
|
+
def normalize_output(cls, v: Any) -> list[RunOutputChunk]:
|
|
114
|
+
"""Normalize output field to empty list when null."""
|
|
115
|
+
if v is None:
|
|
116
|
+
return []
|
|
117
|
+
return v
|