chatops-sdk 1.0.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.
- chatops_sdk-1.0.0/LICENSE +21 -0
- chatops_sdk-1.0.0/PKG-INFO +79 -0
- chatops_sdk-1.0.0/README.md +53 -0
- chatops_sdk-1.0.0/chatops_sdk/__init__.py +91 -0
- chatops_sdk-1.0.0/chatops_sdk/agent.py +461 -0
- chatops_sdk-1.0.0/chatops_sdk/decorators.py +590 -0
- chatops_sdk-1.0.0/chatops_sdk/models.py +360 -0
- chatops_sdk-1.0.0/chatops_sdk/py.typed +0 -0
- chatops_sdk-1.0.0/chatops_sdk/ui.py +191 -0
- chatops_sdk-1.0.0/chatops_sdk.egg-info/PKG-INFO +79 -0
- chatops_sdk-1.0.0/chatops_sdk.egg-info/SOURCES.txt +16 -0
- chatops_sdk-1.0.0/chatops_sdk.egg-info/dependency_links.txt +1 -0
- chatops_sdk-1.0.0/chatops_sdk.egg-info/requires.txt +6 -0
- chatops_sdk-1.0.0/chatops_sdk.egg-info/top_level.txt +1 -0
- chatops_sdk-1.0.0/pyproject.toml +50 -0
- chatops_sdk-1.0.0/setup.cfg +4 -0
- chatops_sdk-1.0.0/tests/test_agent_ws.py +286 -0
- chatops_sdk-1.0.0/tests/test_sdk_introspection.py +619 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Francisco Manzano
|
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chatops-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: SDK para conectar aplicaciones Python al Relay Hub de ChatOps como bots con comandos slash
|
|
5
|
+
Author-email: Francisco Manzano <keoh77@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: chatops,bot,websocket,slash-commands,pydantic
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Framework :: AsyncIO
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pydantic<3,>=2.6
|
|
21
|
+
Requires-Dist: websockets>=13
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# chatops-sdk
|
|
28
|
+
|
|
29
|
+
SDK de Python para convertir cualquier aplicación en un bot del **ChatOps Bot Control Center**.
|
|
30
|
+
Declaras funciones con `@bot.command()` y el SDK genera el manifiesto de comandos a partir de sus
|
|
31
|
+
type hints. El bot abre un WebSocket **saliente** hacia el Relay Hub, así que no necesita puertos
|
|
32
|
+
abiertos ni IP pública.
|
|
33
|
+
|
|
34
|
+
## Instalación
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install chatops-sdk
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Requiere Python 3.11 o superior.
|
|
41
|
+
|
|
42
|
+
## Uso
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import os
|
|
46
|
+
from typing import Literal
|
|
47
|
+
|
|
48
|
+
from fastapi import FastAPI
|
|
49
|
+
from chatops_sdk import BotAgent, CommandContext, UIBlock
|
|
50
|
+
|
|
51
|
+
os.environ.setdefault("CHATOPS_HUB_URL", "ws://localhost:8000/ws/bot")
|
|
52
|
+
os.environ.setdefault("CHATOPS_BOT_TOKEN", "bot_xxxxxxxxxxxx:secreto")
|
|
53
|
+
|
|
54
|
+
bot = BotAgent(name="Mi-Bot", version="1.0.0", environment="production", project="Pagos")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@bot.command(name="deploy", description="Despliega un servicio")
|
|
58
|
+
async def deploy(ctx: CommandContext, service: str, env: Literal["staging", "prod"] = "staging", dry_run: bool = False):
|
|
59
|
+
await ctx.report_progress(40, f"Construyendo {service}...")
|
|
60
|
+
return [
|
|
61
|
+
UIBlock.header(f"✅ {service} desplegado en {env}"),
|
|
62
|
+
UIBlock.metrics([("Duración", "42s"), ("Réplicas", "3", "up")]),
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
app = FastAPI(lifespan=bot.lifespan) # conecta al arrancar y reconecta con backoff
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- `CHATOPS_HUB_URL`: URL del Hub (`ws://…/ws/bot` o `wss://…/ws/bot`).
|
|
70
|
+
- `CHATOPS_BOT_TOKEN`: token del bot (`bot_<id>:<secreto>`), que se obtiene en el Control Center con **+ Nuevo Bot**.
|
|
71
|
+
|
|
72
|
+
## Versiones
|
|
73
|
+
|
|
74
|
+
Sigue [semver](https://semver.org). El protocolo con el Relay Hub es un contrato cerrado: un cambio
|
|
75
|
+
incompatible en los sobres o en los `UIBlock` implica subir la versión mayor.
|
|
76
|
+
|
|
77
|
+
## Licencia
|
|
78
|
+
|
|
79
|
+
MIT.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# chatops-sdk
|
|
2
|
+
|
|
3
|
+
SDK de Python para convertir cualquier aplicación en un bot del **ChatOps Bot Control Center**.
|
|
4
|
+
Declaras funciones con `@bot.command()` y el SDK genera el manifiesto de comandos a partir de sus
|
|
5
|
+
type hints. El bot abre un WebSocket **saliente** hacia el Relay Hub, así que no necesita puertos
|
|
6
|
+
abiertos ni IP pública.
|
|
7
|
+
|
|
8
|
+
## Instalación
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install chatops-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requiere Python 3.11 o superior.
|
|
15
|
+
|
|
16
|
+
## Uso
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import os
|
|
20
|
+
from typing import Literal
|
|
21
|
+
|
|
22
|
+
from fastapi import FastAPI
|
|
23
|
+
from chatops_sdk import BotAgent, CommandContext, UIBlock
|
|
24
|
+
|
|
25
|
+
os.environ.setdefault("CHATOPS_HUB_URL", "ws://localhost:8000/ws/bot")
|
|
26
|
+
os.environ.setdefault("CHATOPS_BOT_TOKEN", "bot_xxxxxxxxxxxx:secreto")
|
|
27
|
+
|
|
28
|
+
bot = BotAgent(name="Mi-Bot", version="1.0.0", environment="production", project="Pagos")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@bot.command(name="deploy", description="Despliega un servicio")
|
|
32
|
+
async def deploy(ctx: CommandContext, service: str, env: Literal["staging", "prod"] = "staging", dry_run: bool = False):
|
|
33
|
+
await ctx.report_progress(40, f"Construyendo {service}...")
|
|
34
|
+
return [
|
|
35
|
+
UIBlock.header(f"✅ {service} desplegado en {env}"),
|
|
36
|
+
UIBlock.metrics([("Duración", "42s"), ("Réplicas", "3", "up")]),
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
app = FastAPI(lifespan=bot.lifespan) # conecta al arrancar y reconecta con backoff
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- `CHATOPS_HUB_URL`: URL del Hub (`ws://…/ws/bot` o `wss://…/ws/bot`).
|
|
44
|
+
- `CHATOPS_BOT_TOKEN`: token del bot (`bot_<id>:<secreto>`), que se obtiene en el Control Center con **+ Nuevo Bot**.
|
|
45
|
+
|
|
46
|
+
## Versiones
|
|
47
|
+
|
|
48
|
+
Sigue [semver](https://semver.org). El protocolo con el Relay Hub es un contrato cerrado: un cambio
|
|
49
|
+
incompatible en los sobres o en los `UIBlock` implica subir la versión mayor.
|
|
50
|
+
|
|
51
|
+
## Licencia
|
|
52
|
+
|
|
53
|
+
MIT.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""chatops-sdk: convierte cualquier app Python en un bot controlable desde el Control Center."""
|
|
2
|
+
|
|
3
|
+
from .agent import BOT_TOKEN_ENV, HUB_URL_ENV, BotAgent, BotConfigurationError, backoff_delay
|
|
4
|
+
from .decorators import (
|
|
5
|
+
CommandArgumentsError,
|
|
6
|
+
CommandContext,
|
|
7
|
+
CommandDefinitionError,
|
|
8
|
+
CommandRegistry,
|
|
9
|
+
CommandResult,
|
|
10
|
+
RegisteredCommand,
|
|
11
|
+
build_command,
|
|
12
|
+
execute_command,
|
|
13
|
+
normalize_blocks,
|
|
14
|
+
)
|
|
15
|
+
from .models import (
|
|
16
|
+
ActionButton,
|
|
17
|
+
ActionsBlock,
|
|
18
|
+
AnyEnvelope,
|
|
19
|
+
AnyUIBlock,
|
|
20
|
+
BotDeletedEnvelope,
|
|
21
|
+
BotMessageEnvelope,
|
|
22
|
+
BotPresenceChangedEnvelope,
|
|
23
|
+
BotPresencePayload,
|
|
24
|
+
BotRegisterEnvelope,
|
|
25
|
+
BotRegisterPayload,
|
|
26
|
+
CodeLogBlock,
|
|
27
|
+
CommandArgSchema,
|
|
28
|
+
CommandInvokeEnvelope,
|
|
29
|
+
CommandInvokePayload,
|
|
30
|
+
CommandManifest,
|
|
31
|
+
CommandSchema,
|
|
32
|
+
HeaderBlock,
|
|
33
|
+
MarkdownBlock,
|
|
34
|
+
MessageAckEnvelope,
|
|
35
|
+
MetricItem,
|
|
36
|
+
MetricsBlock,
|
|
37
|
+
ProgressBlock,
|
|
38
|
+
TableBlock,
|
|
39
|
+
UIBlockBase,
|
|
40
|
+
parse_block,
|
|
41
|
+
parse_envelope,
|
|
42
|
+
)
|
|
43
|
+
from .ui import BlockList, UIBlock
|
|
44
|
+
|
|
45
|
+
__version__ = "1.0.0"
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"BOT_TOKEN_ENV",
|
|
49
|
+
"HUB_URL_ENV",
|
|
50
|
+
"ActionButton",
|
|
51
|
+
"ActionsBlock",
|
|
52
|
+
"AnyEnvelope",
|
|
53
|
+
"AnyUIBlock",
|
|
54
|
+
"BlockList",
|
|
55
|
+
"BotAgent",
|
|
56
|
+
"BotConfigurationError",
|
|
57
|
+
"BotDeletedEnvelope",
|
|
58
|
+
"BotMessageEnvelope",
|
|
59
|
+
"BotPresenceChangedEnvelope",
|
|
60
|
+
"BotPresencePayload",
|
|
61
|
+
"BotRegisterEnvelope",
|
|
62
|
+
"BotRegisterPayload",
|
|
63
|
+
"CodeLogBlock",
|
|
64
|
+
"CommandArgSchema",
|
|
65
|
+
"CommandArgumentsError",
|
|
66
|
+
"CommandContext",
|
|
67
|
+
"CommandDefinitionError",
|
|
68
|
+
"CommandInvokeEnvelope",
|
|
69
|
+
"CommandInvokePayload",
|
|
70
|
+
"CommandManifest",
|
|
71
|
+
"CommandRegistry",
|
|
72
|
+
"CommandResult",
|
|
73
|
+
"CommandSchema",
|
|
74
|
+
"HeaderBlock",
|
|
75
|
+
"MarkdownBlock",
|
|
76
|
+
"MessageAckEnvelope",
|
|
77
|
+
"MetricItem",
|
|
78
|
+
"MetricsBlock",
|
|
79
|
+
"ProgressBlock",
|
|
80
|
+
"RegisteredCommand",
|
|
81
|
+
"TableBlock",
|
|
82
|
+
"UIBlock",
|
|
83
|
+
"UIBlockBase",
|
|
84
|
+
"__version__",
|
|
85
|
+
"backoff_delay",
|
|
86
|
+
"build_command",
|
|
87
|
+
"execute_command",
|
|
88
|
+
"normalize_blocks",
|
|
89
|
+
"parse_block",
|
|
90
|
+
"parse_envelope",
|
|
91
|
+
]
|