getstack 0.1.0__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.
- getstack-0.1.0/.gitignore +38 -0
- getstack-0.1.0/LICENSE +21 -0
- getstack-0.1.0/PKG-INFO +143 -0
- getstack-0.1.0/README.md +119 -0
- getstack-0.1.0/pyproject.toml +35 -0
- getstack-0.1.0/src/getstack/__init__.py +233 -0
- getstack-0.1.0/src/getstack/agents.py +70 -0
- getstack-0.1.0/src/getstack/audit.py +26 -0
- getstack-0.1.0/src/getstack/auth.py +78 -0
- getstack-0.1.0/src/getstack/client.py +102 -0
- getstack-0.1.0/src/getstack/credentials.py +33 -0
- getstack-0.1.0/src/getstack/dropoffs.py +43 -0
- getstack-0.1.0/src/getstack/errors.py +56 -0
- getstack-0.1.0/src/getstack/notifications.py +57 -0
- getstack-0.1.0/src/getstack/passports.py +359 -0
- getstack-0.1.0/src/getstack/py.typed +0 -0
- getstack-0.1.0/src/getstack/reviews.py +54 -0
- getstack-0.1.0/src/getstack/services.py +41 -0
- getstack-0.1.0/src/getstack/types.py +156 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
.turbo/
|
|
4
|
+
*.tsbuildinfo
|
|
5
|
+
|
|
6
|
+
# Environment / secrets
|
|
7
|
+
.env
|
|
8
|
+
.env.*
|
|
9
|
+
*.env
|
|
10
|
+
|
|
11
|
+
# Strategy docs (not sensitive, but private)
|
|
12
|
+
stack-claude-code-spec-v3.md
|
|
13
|
+
stack-gtm-distribution.md
|
|
14
|
+
stack-platform-spec-v2.md
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.vscode/settings.json
|
|
18
|
+
.idea/
|
|
19
|
+
|
|
20
|
+
# OS
|
|
21
|
+
.DS_Store
|
|
22
|
+
Thumbs.db
|
|
23
|
+
|
|
24
|
+
# Next.js
|
|
25
|
+
.next/
|
|
26
|
+
out/
|
|
27
|
+
|
|
28
|
+
# MCP publisher
|
|
29
|
+
mcp-publisher.exe
|
|
30
|
+
.mcpregistry_*
|
|
31
|
+
|
|
32
|
+
# Fly.io deployment config (contains app names, regions)
|
|
33
|
+
**/fly.toml
|
|
34
|
+
!**/fly.toml.example
|
|
35
|
+
|
|
36
|
+
# Logs
|
|
37
|
+
*.log
|
|
38
|
+
npm-debug.log*
|
getstack-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 STACK
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
getstack-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: getstack
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for STACK — trust infrastructure for AI agents
|
|
5
|
+
Project-URL: Homepage, https://getstack.run
|
|
6
|
+
Project-URL: Documentation, https://getstack.run/docs/sdk
|
|
7
|
+
Project-URL: Repository, https://github.com/getstack-run/sdk-python
|
|
8
|
+
Author-email: STACK <hello@getstack.run>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,ai,mcp,passport,stack,trust
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: httpx>=0.25.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# getstack
|
|
26
|
+
|
|
27
|
+
Python SDK for [STACK](https://getstack.run) — trust infrastructure for AI agents.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install getstack
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from getstack import Stack
|
|
39
|
+
|
|
40
|
+
stack = Stack(api_key="sk_live_...")
|
|
41
|
+
|
|
42
|
+
# Register an agent
|
|
43
|
+
agent = stack.agents.register("my-agent", accountability_mode="enforced")
|
|
44
|
+
|
|
45
|
+
# Run a mission with automatic checkpoints and checkout
|
|
46
|
+
with stack.passports.mission(
|
|
47
|
+
agent_id=agent.id,
|
|
48
|
+
intent="Process invoices from Slack",
|
|
49
|
+
services=["slack", "stripe"],
|
|
50
|
+
checkpoint_interval="5m",
|
|
51
|
+
) as mission:
|
|
52
|
+
mission.log("slack", "read_channel", "#invoices")
|
|
53
|
+
mission.log("stripe", "create_invoice")
|
|
54
|
+
# Checkpoints are submitted automatically on schedule
|
|
55
|
+
# Checkout is submitted automatically when the block exits
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Authentication
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
# API key (most common)
|
|
62
|
+
stack = Stack(api_key="sk_live_...")
|
|
63
|
+
|
|
64
|
+
# OAuth with auto-refresh
|
|
65
|
+
stack = Stack.from_oauth(
|
|
66
|
+
client_id="...",
|
|
67
|
+
client_secret="...",
|
|
68
|
+
access_token="...",
|
|
69
|
+
refresh_token="...",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Session JWT (dashboard integrations)
|
|
73
|
+
stack = Stack.from_session(session_token="...")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Continuous missions (24/7 agents)
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
for mission in stack.passports.continuous_mission(
|
|
80
|
+
agent_id=agent.id,
|
|
81
|
+
intent="Monitor Slack channels",
|
|
82
|
+
services=["slack"],
|
|
83
|
+
rotation_interval="4h",
|
|
84
|
+
checkpoint_interval="5m",
|
|
85
|
+
):
|
|
86
|
+
while not mission.should_rotate:
|
|
87
|
+
event = wait_for_event()
|
|
88
|
+
mission.log("slack", "read_message")
|
|
89
|
+
process(event)
|
|
90
|
+
# Passport rotates automatically at the boundary
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Services
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# Agents
|
|
97
|
+
stack.agents.register(name, description=None, accountability_mode="enforced")
|
|
98
|
+
stack.agents.get(agent_id)
|
|
99
|
+
stack.agents.list()
|
|
100
|
+
stack.agents.update(agent_id, **fields)
|
|
101
|
+
stack.agents.unblock(agent_id)
|
|
102
|
+
|
|
103
|
+
# Passports
|
|
104
|
+
stack.passports.issue(agent_id, intent=None, services=None, ...)
|
|
105
|
+
stack.passports.verify(token)
|
|
106
|
+
stack.passports.revoke(jti, reason=None)
|
|
107
|
+
stack.passports.checkpoint(jti, services_used, actions_count, ...)
|
|
108
|
+
stack.passports.checkout(jti, services_used, actions_count, ...)
|
|
109
|
+
stack.passports.report(jti)
|
|
110
|
+
|
|
111
|
+
# Credentials
|
|
112
|
+
stack.credentials.get(provider)
|
|
113
|
+
stack.credentials.get_by_connection(connection_id)
|
|
114
|
+
|
|
115
|
+
# Services
|
|
116
|
+
stack.services.list()
|
|
117
|
+
stack.services.connect_custom(name, credential, ...)
|
|
118
|
+
stack.services.verify(connection_id)
|
|
119
|
+
stack.services.disconnect(connection_id)
|
|
120
|
+
|
|
121
|
+
# Reviews
|
|
122
|
+
stack.reviews.list(status="flagged")
|
|
123
|
+
stack.reviews.decide(checkout_id, decision, notes=None, block_future=False)
|
|
124
|
+
|
|
125
|
+
# Drop-offs
|
|
126
|
+
stack.dropoffs.create(from_agent_id, to_agent_id, schema, ...)
|
|
127
|
+
stack.dropoffs.deposit(dropoff_id, data, agent_id)
|
|
128
|
+
stack.dropoffs.collect(dropoff_id, agent_id)
|
|
129
|
+
|
|
130
|
+
# Notifications
|
|
131
|
+
stack.notifications.list()
|
|
132
|
+
stack.notifications.create(channel_type, destination, ...)
|
|
133
|
+
stack.notifications.delete(channel_id)
|
|
134
|
+
|
|
135
|
+
# Audit
|
|
136
|
+
stack.audit.list(page=1, limit=50, action=None, agent_id=None)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Links
|
|
140
|
+
|
|
141
|
+
- [Documentation](https://getstack.run/docs/sdk)
|
|
142
|
+
- [Dashboard](https://getstack.run)
|
|
143
|
+
- [GitHub](https://github.com/getstack-run/sdk-python)
|
getstack-0.1.0/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# getstack
|
|
2
|
+
|
|
3
|
+
Python SDK for [STACK](https://getstack.run) — trust infrastructure for AI agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install getstack
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from getstack import Stack
|
|
15
|
+
|
|
16
|
+
stack = Stack(api_key="sk_live_...")
|
|
17
|
+
|
|
18
|
+
# Register an agent
|
|
19
|
+
agent = stack.agents.register("my-agent", accountability_mode="enforced")
|
|
20
|
+
|
|
21
|
+
# Run a mission with automatic checkpoints and checkout
|
|
22
|
+
with stack.passports.mission(
|
|
23
|
+
agent_id=agent.id,
|
|
24
|
+
intent="Process invoices from Slack",
|
|
25
|
+
services=["slack", "stripe"],
|
|
26
|
+
checkpoint_interval="5m",
|
|
27
|
+
) as mission:
|
|
28
|
+
mission.log("slack", "read_channel", "#invoices")
|
|
29
|
+
mission.log("stripe", "create_invoice")
|
|
30
|
+
# Checkpoints are submitted automatically on schedule
|
|
31
|
+
# Checkout is submitted automatically when the block exits
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Authentication
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
# API key (most common)
|
|
38
|
+
stack = Stack(api_key="sk_live_...")
|
|
39
|
+
|
|
40
|
+
# OAuth with auto-refresh
|
|
41
|
+
stack = Stack.from_oauth(
|
|
42
|
+
client_id="...",
|
|
43
|
+
client_secret="...",
|
|
44
|
+
access_token="...",
|
|
45
|
+
refresh_token="...",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Session JWT (dashboard integrations)
|
|
49
|
+
stack = Stack.from_session(session_token="...")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Continuous missions (24/7 agents)
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
for mission in stack.passports.continuous_mission(
|
|
56
|
+
agent_id=agent.id,
|
|
57
|
+
intent="Monitor Slack channels",
|
|
58
|
+
services=["slack"],
|
|
59
|
+
rotation_interval="4h",
|
|
60
|
+
checkpoint_interval="5m",
|
|
61
|
+
):
|
|
62
|
+
while not mission.should_rotate:
|
|
63
|
+
event = wait_for_event()
|
|
64
|
+
mission.log("slack", "read_message")
|
|
65
|
+
process(event)
|
|
66
|
+
# Passport rotates automatically at the boundary
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Services
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
# Agents
|
|
73
|
+
stack.agents.register(name, description=None, accountability_mode="enforced")
|
|
74
|
+
stack.agents.get(agent_id)
|
|
75
|
+
stack.agents.list()
|
|
76
|
+
stack.agents.update(agent_id, **fields)
|
|
77
|
+
stack.agents.unblock(agent_id)
|
|
78
|
+
|
|
79
|
+
# Passports
|
|
80
|
+
stack.passports.issue(agent_id, intent=None, services=None, ...)
|
|
81
|
+
stack.passports.verify(token)
|
|
82
|
+
stack.passports.revoke(jti, reason=None)
|
|
83
|
+
stack.passports.checkpoint(jti, services_used, actions_count, ...)
|
|
84
|
+
stack.passports.checkout(jti, services_used, actions_count, ...)
|
|
85
|
+
stack.passports.report(jti)
|
|
86
|
+
|
|
87
|
+
# Credentials
|
|
88
|
+
stack.credentials.get(provider)
|
|
89
|
+
stack.credentials.get_by_connection(connection_id)
|
|
90
|
+
|
|
91
|
+
# Services
|
|
92
|
+
stack.services.list()
|
|
93
|
+
stack.services.connect_custom(name, credential, ...)
|
|
94
|
+
stack.services.verify(connection_id)
|
|
95
|
+
stack.services.disconnect(connection_id)
|
|
96
|
+
|
|
97
|
+
# Reviews
|
|
98
|
+
stack.reviews.list(status="flagged")
|
|
99
|
+
stack.reviews.decide(checkout_id, decision, notes=None, block_future=False)
|
|
100
|
+
|
|
101
|
+
# Drop-offs
|
|
102
|
+
stack.dropoffs.create(from_agent_id, to_agent_id, schema, ...)
|
|
103
|
+
stack.dropoffs.deposit(dropoff_id, data, agent_id)
|
|
104
|
+
stack.dropoffs.collect(dropoff_id, agent_id)
|
|
105
|
+
|
|
106
|
+
# Notifications
|
|
107
|
+
stack.notifications.list()
|
|
108
|
+
stack.notifications.create(channel_type, destination, ...)
|
|
109
|
+
stack.notifications.delete(channel_id)
|
|
110
|
+
|
|
111
|
+
# Audit
|
|
112
|
+
stack.audit.list(page=1, limit=50, action=None, agent_id=None)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Links
|
|
116
|
+
|
|
117
|
+
- [Documentation](https://getstack.run/docs/sdk)
|
|
118
|
+
- [Dashboard](https://getstack.run)
|
|
119
|
+
- [GitHub](https://github.com/getstack-run/sdk-python)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "getstack"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for STACK — trust infrastructure for AI agents"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "STACK", email = "hello@getstack.run" }]
|
|
13
|
+
keywords = ["ai", "agents", "trust", "passport", "mcp", "stack"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.25.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://getstack.run"
|
|
31
|
+
Documentation = "https://getstack.run/docs/sdk"
|
|
32
|
+
Repository = "https://github.com/getstack-run/sdk-python"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/getstack"]
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"""STACK Python SDK — trust infrastructure for AI agents.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
from getstack import Stack
|
|
6
|
+
|
|
7
|
+
stack = Stack(api_key="sk_live_...")
|
|
8
|
+
agent = stack.agents.register("my-agent")
|
|
9
|
+
|
|
10
|
+
with stack.passports.mission(
|
|
11
|
+
agent_id=agent.id,
|
|
12
|
+
intent="Process invoices",
|
|
13
|
+
services=["slack", "stripe"],
|
|
14
|
+
) as mission:
|
|
15
|
+
mission.log("slack", "read_channel", "#invoices")
|
|
16
|
+
mission.log("stripe", "create_invoice")
|
|
17
|
+
|
|
18
|
+
For OAuth auth::
|
|
19
|
+
|
|
20
|
+
stack = Stack.from_oauth(
|
|
21
|
+
client_id="...",
|
|
22
|
+
client_secret="...",
|
|
23
|
+
access_token="...",
|
|
24
|
+
refresh_token="...",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
For async usage::
|
|
28
|
+
|
|
29
|
+
from getstack import AsyncStack
|
|
30
|
+
|
|
31
|
+
stack = AsyncStack(api_key="sk_live_...")
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
from .auth import ApiKeyAuth, SessionAuth, OAuthAuth
|
|
37
|
+
from .client import HttpClient, AsyncHttpClient, DEFAULT_BASE_URL
|
|
38
|
+
from .agents import AgentService
|
|
39
|
+
from .passports import PassportService, Mission
|
|
40
|
+
from .credentials import CredentialService
|
|
41
|
+
from .services import ServiceService
|
|
42
|
+
from .dropoffs import DropoffService
|
|
43
|
+
from .reviews import ReviewService
|
|
44
|
+
from .notifications import NotificationService
|
|
45
|
+
from .audit import AuditService
|
|
46
|
+
from .types import (
|
|
47
|
+
Agent,
|
|
48
|
+
Passport,
|
|
49
|
+
CheckpointResult,
|
|
50
|
+
CheckoutResult,
|
|
51
|
+
ReviewFlag,
|
|
52
|
+
PassportReport,
|
|
53
|
+
ReviewQueue,
|
|
54
|
+
ReviewQueueItem,
|
|
55
|
+
ReviewDecisionResult,
|
|
56
|
+
Credential,
|
|
57
|
+
NotificationChannel,
|
|
58
|
+
ToolCall,
|
|
59
|
+
)
|
|
60
|
+
from .errors import (
|
|
61
|
+
StackError,
|
|
62
|
+
NotFoundError,
|
|
63
|
+
UnauthorizedError,
|
|
64
|
+
ForbiddenError,
|
|
65
|
+
ValidationError,
|
|
66
|
+
PassportBlockedError,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
__version__ = "0.1.0"
|
|
70
|
+
|
|
71
|
+
__all__ = [
|
|
72
|
+
"Stack",
|
|
73
|
+
"AsyncStack",
|
|
74
|
+
"__version__",
|
|
75
|
+
# Types
|
|
76
|
+
"Agent",
|
|
77
|
+
"Passport",
|
|
78
|
+
"CheckpointResult",
|
|
79
|
+
"CheckoutResult",
|
|
80
|
+
"ReviewFlag",
|
|
81
|
+
"PassportReport",
|
|
82
|
+
"ReviewQueue",
|
|
83
|
+
"ReviewQueueItem",
|
|
84
|
+
"ReviewDecisionResult",
|
|
85
|
+
"Credential",
|
|
86
|
+
"NotificationChannel",
|
|
87
|
+
"Mission",
|
|
88
|
+
"ToolCall",
|
|
89
|
+
# Errors
|
|
90
|
+
"StackError",
|
|
91
|
+
"NotFoundError",
|
|
92
|
+
"UnauthorizedError",
|
|
93
|
+
"ForbiddenError",
|
|
94
|
+
"ValidationError",
|
|
95
|
+
"PassportBlockedError",
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class Stack:
|
|
100
|
+
"""Synchronous STACK client.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
api_key: A STACK API key (``sk_live_...``).
|
|
104
|
+
base_url: Override the API base URL.
|
|
105
|
+
timeout: HTTP timeout in seconds.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
def __init__(
|
|
109
|
+
self,
|
|
110
|
+
api_key: str | None = None,
|
|
111
|
+
*,
|
|
112
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
113
|
+
timeout: float = 30.0,
|
|
114
|
+
_auth: ApiKeyAuth | SessionAuth | OAuthAuth | None = None,
|
|
115
|
+
):
|
|
116
|
+
if _auth:
|
|
117
|
+
auth = _auth
|
|
118
|
+
elif api_key:
|
|
119
|
+
auth = ApiKeyAuth(api_key)
|
|
120
|
+
else:
|
|
121
|
+
raise ValueError("Either api_key or _auth must be provided")
|
|
122
|
+
|
|
123
|
+
self._client = HttpClient(auth, base_url=base_url, timeout=timeout)
|
|
124
|
+
self.agents = AgentService(self._client)
|
|
125
|
+
self.passports = PassportService(self._client)
|
|
126
|
+
self.credentials = CredentialService(self._client)
|
|
127
|
+
self.services = ServiceService(self._client)
|
|
128
|
+
self.dropoffs = DropoffService(self._client)
|
|
129
|
+
self.reviews = ReviewService(self._client)
|
|
130
|
+
self.notifications = NotificationService(self._client)
|
|
131
|
+
self.audit = AuditService(self._client)
|
|
132
|
+
|
|
133
|
+
@classmethod
|
|
134
|
+
def from_session(cls, session_token: str, **kwargs) -> Stack:
|
|
135
|
+
"""Create a client authenticated with a session JWT."""
|
|
136
|
+
return cls(_auth=SessionAuth(session_token), **kwargs)
|
|
137
|
+
|
|
138
|
+
@classmethod
|
|
139
|
+
def from_oauth(
|
|
140
|
+
cls,
|
|
141
|
+
client_id: str,
|
|
142
|
+
client_secret: str,
|
|
143
|
+
access_token: str,
|
|
144
|
+
refresh_token: str,
|
|
145
|
+
token_endpoint: str = "https://api.getstack.run/v1/oauth/token",
|
|
146
|
+
**kwargs,
|
|
147
|
+
) -> Stack:
|
|
148
|
+
"""Create a client with OAuth tokens. Auto-refreshes when expired."""
|
|
149
|
+
auth = OAuthAuth(
|
|
150
|
+
client_id=client_id,
|
|
151
|
+
client_secret=client_secret,
|
|
152
|
+
access_token=access_token,
|
|
153
|
+
refresh_token=refresh_token,
|
|
154
|
+
token_endpoint=token_endpoint,
|
|
155
|
+
)
|
|
156
|
+
return cls(_auth=auth, **kwargs)
|
|
157
|
+
|
|
158
|
+
def close(self) -> None:
|
|
159
|
+
"""Close the underlying HTTP client."""
|
|
160
|
+
self._client.close()
|
|
161
|
+
|
|
162
|
+
def __enter__(self) -> Stack:
|
|
163
|
+
return self
|
|
164
|
+
|
|
165
|
+
def __exit__(self, *args) -> None:
|
|
166
|
+
self.close()
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class AsyncStack:
|
|
170
|
+
"""Asynchronous STACK client.
|
|
171
|
+
|
|
172
|
+
Uses httpx.AsyncClient under the hood. All service methods are sync
|
|
173
|
+
(they use the sync HttpClient wrapper) — for true async, the async
|
|
174
|
+
client needs async service modules. This provides the async HTTP
|
|
175
|
+
transport layer for future async service implementations.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
api_key: A STACK API key (``sk_live_...``).
|
|
179
|
+
base_url: Override the API base URL.
|
|
180
|
+
timeout: HTTP timeout in seconds.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
def __init__(
|
|
184
|
+
self,
|
|
185
|
+
api_key: str | None = None,
|
|
186
|
+
*,
|
|
187
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
188
|
+
timeout: float = 30.0,
|
|
189
|
+
_auth: ApiKeyAuth | SessionAuth | OAuthAuth | None = None,
|
|
190
|
+
):
|
|
191
|
+
if _auth:
|
|
192
|
+
auth = _auth
|
|
193
|
+
elif api_key:
|
|
194
|
+
auth = ApiKeyAuth(api_key)
|
|
195
|
+
else:
|
|
196
|
+
raise ValueError("Either api_key or _auth must be provided")
|
|
197
|
+
|
|
198
|
+
self._client = AsyncHttpClient(auth, base_url=base_url, timeout=timeout)
|
|
199
|
+
|
|
200
|
+
@classmethod
|
|
201
|
+
def from_session(cls, session_token: str, **kwargs) -> AsyncStack:
|
|
202
|
+
"""Create an async client authenticated with a session JWT."""
|
|
203
|
+
return cls(_auth=SessionAuth(session_token), **kwargs)
|
|
204
|
+
|
|
205
|
+
@classmethod
|
|
206
|
+
def from_oauth(
|
|
207
|
+
cls,
|
|
208
|
+
client_id: str,
|
|
209
|
+
client_secret: str,
|
|
210
|
+
access_token: str,
|
|
211
|
+
refresh_token: str,
|
|
212
|
+
token_endpoint: str = "https://api.getstack.run/v1/oauth/token",
|
|
213
|
+
**kwargs,
|
|
214
|
+
) -> AsyncStack:
|
|
215
|
+
"""Create an async client with OAuth tokens. Auto-refreshes when expired."""
|
|
216
|
+
auth = OAuthAuth(
|
|
217
|
+
client_id=client_id,
|
|
218
|
+
client_secret=client_secret,
|
|
219
|
+
access_token=access_token,
|
|
220
|
+
refresh_token=refresh_token,
|
|
221
|
+
token_endpoint=token_endpoint,
|
|
222
|
+
)
|
|
223
|
+
return cls(_auth=auth, **kwargs)
|
|
224
|
+
|
|
225
|
+
async def close(self) -> None:
|
|
226
|
+
"""Close the underlying HTTP client."""
|
|
227
|
+
await self._client.close()
|
|
228
|
+
|
|
229
|
+
async def __aenter__(self) -> AsyncStack:
|
|
230
|
+
return self
|
|
231
|
+
|
|
232
|
+
async def __aexit__(self, *args) -> None:
|
|
233
|
+
await self.close()
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Agent management."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .client import HttpClient
|
|
8
|
+
from .types import Agent
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _to_agent(data: dict[str, Any]) -> Agent:
|
|
12
|
+
return Agent(
|
|
13
|
+
id=data["id"],
|
|
14
|
+
operator_id=data["operator_id"],
|
|
15
|
+
name=data["name"],
|
|
16
|
+
description=data.get("description"),
|
|
17
|
+
status=data["status"],
|
|
18
|
+
accountability_mode=data.get("accountability_mode", "standard"),
|
|
19
|
+
on_warning=data.get("on_warning", "notify"),
|
|
20
|
+
on_critical=data.get("on_critical", "notify"),
|
|
21
|
+
passport_blocked=data.get("passport_blocked", False),
|
|
22
|
+
passport_blocked_reason=data.get("passport_blocked_reason"),
|
|
23
|
+
passport_blocked_at=data.get("passport_blocked_at"),
|
|
24
|
+
created_at=data["created_at"],
|
|
25
|
+
updated_at=data["updated_at"],
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AgentService:
|
|
30
|
+
def __init__(self, client: HttpClient):
|
|
31
|
+
self._client = client
|
|
32
|
+
|
|
33
|
+
def register(
|
|
34
|
+
self,
|
|
35
|
+
name: str,
|
|
36
|
+
description: str | None = None,
|
|
37
|
+
accountability_mode: str = "enforced",
|
|
38
|
+
on_warning: str = "notify",
|
|
39
|
+
on_critical: str = "notify",
|
|
40
|
+
) -> Agent:
|
|
41
|
+
body: dict[str, Any] = {"name": name, "accountability_mode": accountability_mode}
|
|
42
|
+
if description:
|
|
43
|
+
body["description"] = description
|
|
44
|
+
if on_warning != "notify":
|
|
45
|
+
body["on_warning"] = on_warning
|
|
46
|
+
if on_critical != "notify":
|
|
47
|
+
body["on_critical"] = on_critical
|
|
48
|
+
return _to_agent(self._client.post("/v1/agents/register", json=body))
|
|
49
|
+
|
|
50
|
+
def get(self, agent_id: str) -> Agent:
|
|
51
|
+
return _to_agent(self._client.get(f"/v1/agents/{agent_id}"))
|
|
52
|
+
|
|
53
|
+
def list(self) -> list[Agent]:
|
|
54
|
+
data = self._client.get("/v1/agents")
|
|
55
|
+
return [_to_agent(a) for a in data]
|
|
56
|
+
|
|
57
|
+
def update(self, agent_id: str, **kwargs: Any) -> Agent:
|
|
58
|
+
return _to_agent(self._client.patch(f"/v1/agents/{agent_id}", json=kwargs))
|
|
59
|
+
|
|
60
|
+
def suspend(self, agent_id: str) -> Agent:
|
|
61
|
+
return self.update(agent_id, status="suspended")
|
|
62
|
+
|
|
63
|
+
def activate(self, agent_id: str) -> Agent:
|
|
64
|
+
return self.update(agent_id, status="active")
|
|
65
|
+
|
|
66
|
+
def delete(self, agent_id: str) -> dict[str, Any]:
|
|
67
|
+
return self._client.delete(f"/v1/agents/{agent_id}")
|
|
68
|
+
|
|
69
|
+
def unblock(self, agent_id: str) -> dict[str, Any]:
|
|
70
|
+
return self._client.post(f"/v1/agents/{agent_id}/unblock")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Audit log access."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .client import HttpClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AuditService:
|
|
11
|
+
def __init__(self, client: HttpClient):
|
|
12
|
+
self._client = client
|
|
13
|
+
|
|
14
|
+
def list(
|
|
15
|
+
self,
|
|
16
|
+
page: int = 1,
|
|
17
|
+
limit: int = 50,
|
|
18
|
+
action: str | None = None,
|
|
19
|
+
agent_id: str | None = None,
|
|
20
|
+
) -> list[dict[str, Any]]:
|
|
21
|
+
params: dict[str, str] = {"page": str(page), "limit": str(limit)}
|
|
22
|
+
if action:
|
|
23
|
+
params["action"] = action
|
|
24
|
+
if agent_id:
|
|
25
|
+
params["agent_id"] = agent_id
|
|
26
|
+
return self._client.get("/v1/audit", params=params)
|