cortexhub 2.0.1__tar.gz → 2.0.2__tar.gz
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.
- {cortexhub-2.0.1 → cortexhub-2.0.2}/PKG-INFO +1 -1
- {cortexhub-2.0.1 → cortexhub-2.0.2}/pyproject.toml +1 -1
- {cortexhub-2.0.1 → cortexhub-2.0.2}/src/cortexhub/__init__.py +1 -1
- {cortexhub-2.0.1 → cortexhub-2.0.2}/src/cortexhub/client.py +6 -1
- {cortexhub-2.0.1 → cortexhub-2.0.2}/src/cortexhub/mcp_oauth.py +19 -1
- {cortexhub-2.0.1 → cortexhub-2.0.2}/.gitignore +0 -0
- {cortexhub-2.0.1 → cortexhub-2.0.2}/LICENSE +0 -0
- {cortexhub-2.0.1 → cortexhub-2.0.2}/README.md +0 -0
- {cortexhub-2.0.1 → cortexhub-2.0.2}/src/cortexhub/_config.py +0 -0
- {cortexhub-2.0.1 → cortexhub-2.0.2}/src/cortexhub/errors.py +0 -0
- {cortexhub-2.0.1 → cortexhub-2.0.2}/src/cortexhub/session.py +0 -0
|
@@ -15,7 +15,7 @@ from .errors import APIError, AuthenticationError, ConfigurationError, Cortexhub
|
|
|
15
15
|
from .mcp_oauth import CortexhubMcpOAuthClient, McpOAuthSession, McpOAuthToken
|
|
16
16
|
from .session import SessionMcp
|
|
17
17
|
|
|
18
|
-
__version__ = "2.
|
|
18
|
+
__version__ = "2.2.0"
|
|
19
19
|
__all__ = [
|
|
20
20
|
"Cortexhub",
|
|
21
21
|
"CortexhubMcpOAuthClient",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
|
+
from typing import Literal
|
|
6
7
|
|
|
7
8
|
from .errors import ConfigurationError
|
|
8
9
|
from .mcp_oauth import CortexhubMcpOAuthClient, McpOAuthSession
|
|
@@ -47,11 +48,15 @@ class Cortexhub(CortexhubMcpOAuthClient):
|
|
|
47
48
|
*,
|
|
48
49
|
agent: str,
|
|
49
50
|
mcp_session_id: str | None = None,
|
|
51
|
+
invocation_mode: Literal["interactive", "scheduled", "programmatic"] | None = None,
|
|
50
52
|
refresh: bool = False,
|
|
51
53
|
) -> McpOAuthSession:
|
|
52
54
|
"""Return MCP headers for ``agent`` (required on every programmatic call)."""
|
|
53
55
|
return super().session(
|
|
54
|
-
agent=agent,
|
|
56
|
+
agent=agent,
|
|
57
|
+
mcp_session_id=mcp_session_id,
|
|
58
|
+
invocation_mode=invocation_mode,
|
|
59
|
+
refresh=refresh,
|
|
55
60
|
)
|
|
56
61
|
|
|
57
62
|
def __repr__(self) -> str:
|
|
@@ -7,12 +7,13 @@ import urllib.error
|
|
|
7
7
|
import urllib.parse
|
|
8
8
|
import urllib.request
|
|
9
9
|
from dataclasses import dataclass, field
|
|
10
|
-
from typing import Any
|
|
10
|
+
from typing import Any, Literal
|
|
11
11
|
|
|
12
12
|
from ._config import base_url
|
|
13
13
|
from .errors import APIError, AuthenticationError
|
|
14
14
|
from .session import SessionMcp
|
|
15
15
|
|
|
16
|
+
_INVOCATION_MODE_HEADER = "X-CortexHub-Invocation-Mode"
|
|
16
17
|
_AGENT_HEADER = "X-CortexHub-Agent"
|
|
17
18
|
_BEARER_HEADER = "Authorization"
|
|
18
19
|
|
|
@@ -26,6 +27,11 @@ class McpOAuthToken:
|
|
|
26
27
|
scope: str = ""
|
|
27
28
|
|
|
28
29
|
|
|
30
|
+
InvocationMode = Literal["interactive", "scheduled", "programmatic"]
|
|
31
|
+
|
|
32
|
+
_VALID_INVOCATION_MODES = frozenset({"interactive", "scheduled", "programmatic"})
|
|
33
|
+
|
|
34
|
+
|
|
29
35
|
@dataclass
|
|
30
36
|
class McpOAuthSession:
|
|
31
37
|
"""MCP connection using Bearer JWT + optional agent and session headers."""
|
|
@@ -33,6 +39,7 @@ class McpOAuthSession:
|
|
|
33
39
|
access_token: str
|
|
34
40
|
agent: str | None = None
|
|
35
41
|
mcp_session_id: str | None = None
|
|
42
|
+
invocation_mode: InvocationMode | None = None
|
|
36
43
|
mcp: SessionMcp = field(init=False)
|
|
37
44
|
|
|
38
45
|
def __post_init__(self) -> None:
|
|
@@ -43,6 +50,8 @@ class McpOAuthSession:
|
|
|
43
50
|
headers[_AGENT_HEADER] = self.agent
|
|
44
51
|
if self.mcp_session_id:
|
|
45
52
|
headers["Mcp-Session-Id"] = self.mcp_session_id
|
|
53
|
+
if self.invocation_mode:
|
|
54
|
+
headers[_INVOCATION_MODE_HEADER] = self.invocation_mode
|
|
46
55
|
self.mcp = SessionMcp(url=f"{base_url()}/v1/mcp", headers=headers)
|
|
47
56
|
|
|
48
57
|
|
|
@@ -97,21 +106,30 @@ class CortexhubMcpOAuthClient:
|
|
|
97
106
|
*,
|
|
98
107
|
agent: str,
|
|
99
108
|
mcp_session_id: str | None = None,
|
|
109
|
+
invocation_mode: InvocationMode | None = None,
|
|
100
110
|
refresh: bool = False,
|
|
101
111
|
) -> McpOAuthSession:
|
|
102
112
|
"""Return MCP headers for ``agent`` (required on every programmatic call).
|
|
103
113
|
|
|
104
114
|
Pass ``mcp_session_id`` (your chat or conversation id) to group tool
|
|
105
115
|
activity into separate rows in CortexHub Cloud.
|
|
116
|
+
|
|
117
|
+
Pass ``invocation_mode`` for cron or background workers when policy allows
|
|
118
|
+
unattended execution; omit for interactive sessions (gateway default).
|
|
106
119
|
"""
|
|
107
120
|
if not agent or not agent.strip():
|
|
108
121
|
raise ValueError("agent= is required for programmatic MCP OAuth.")
|
|
122
|
+
if invocation_mode is not None and invocation_mode not in _VALID_INVOCATION_MODES:
|
|
123
|
+
raise ValueError(
|
|
124
|
+
"invocation_mode must be interactive, scheduled, or programmatic."
|
|
125
|
+
)
|
|
109
126
|
token = self.fetch_token(refresh=refresh)
|
|
110
127
|
session_id = (mcp_session_id or "").strip() or None
|
|
111
128
|
return McpOAuthSession(
|
|
112
129
|
access_token=token.access_token,
|
|
113
130
|
agent=agent.strip(),
|
|
114
131
|
mcp_session_id=session_id,
|
|
132
|
+
invocation_mode=invocation_mode,
|
|
115
133
|
)
|
|
116
134
|
|
|
117
135
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|