trigix-node-sdk 0.1.0__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.
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Copyright © 2026 北京祺智科技有限公司. All rights reserved.
|
|
2
|
+
# https://www.qzso.com/ · managecode@gmail.com
|
|
3
|
+
|
|
4
|
+
"""Trigix custom node SDK.
|
|
5
|
+
|
|
6
|
+
Write a workflow node as a plain Python function and serve it over HTTP — no
|
|
7
|
+
changes to the Trigix executor required. Register the node's endpoint in Trigix
|
|
8
|
+
(Custom Nodes settings) and it appears in the workflow editor.
|
|
9
|
+
|
|
10
|
+
from trigix_node_sdk import node, create_app
|
|
11
|
+
|
|
12
|
+
@node(slug="greet", label="Greeter",
|
|
13
|
+
config_schema={"type": "object",
|
|
14
|
+
"properties": {"name": {"type": "string"}}})
|
|
15
|
+
def greet(config, input, node_outputs):
|
|
16
|
+
name = config.get("name") or input.get("name", "world")
|
|
17
|
+
return {"greeting": f"Hello, {name}!"}
|
|
18
|
+
|
|
19
|
+
app = create_app() # uvicorn module:app --port 9000
|
|
20
|
+
|
|
21
|
+
The node contract (matches the executor): the runtime POSTs
|
|
22
|
+
``{node_id, config, input_json, node_outputs}`` to ``/nodes/<slug>`` and expects
|
|
23
|
+
``{output_json}``. Your handler receives the parsed ``input`` dict and returns a
|
|
24
|
+
JSON-serializable dict.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
from dataclasses import dataclass
|
|
31
|
+
from typing import Any, Callable
|
|
32
|
+
|
|
33
|
+
from pydantic import BaseModel
|
|
34
|
+
|
|
35
|
+
Handler = Callable[[dict, dict, dict], Any]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class NodeRequest(BaseModel):
|
|
39
|
+
node_id: str = ""
|
|
40
|
+
config: dict = {}
|
|
41
|
+
input_json: str = "{}"
|
|
42
|
+
node_outputs: dict = {}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class NodeDef:
|
|
47
|
+
slug: str
|
|
48
|
+
label: str
|
|
49
|
+
description: str
|
|
50
|
+
config_schema: dict
|
|
51
|
+
handler: Handler
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
_REGISTRY: dict[str, NodeDef] = {}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def node(
|
|
58
|
+
slug: str,
|
|
59
|
+
label: str | None = None,
|
|
60
|
+
description: str = "",
|
|
61
|
+
config_schema: dict | None = None,
|
|
62
|
+
) -> Callable[[Handler], Handler]:
|
|
63
|
+
"""Register a function as a Trigix custom node."""
|
|
64
|
+
|
|
65
|
+
def decorator(fn: Handler) -> Handler:
|
|
66
|
+
_REGISTRY[slug] = NodeDef(
|
|
67
|
+
slug=slug,
|
|
68
|
+
label=label or slug,
|
|
69
|
+
description=description,
|
|
70
|
+
config_schema=config_schema or {"type": "object"},
|
|
71
|
+
handler=fn,
|
|
72
|
+
)
|
|
73
|
+
return fn
|
|
74
|
+
|
|
75
|
+
return decorator
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def registry() -> dict[str, NodeDef]:
|
|
79
|
+
return dict(_REGISTRY)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def run_node(slug: str, config: dict, input_json: str, node_outputs: dict) -> str:
|
|
83
|
+
"""Execute a registered node and return its ``output_json``. Raises
|
|
84
|
+
KeyError for an unknown slug."""
|
|
85
|
+
nd = _REGISTRY[slug]
|
|
86
|
+
try:
|
|
87
|
+
input_data = json.loads(input_json or "{}")
|
|
88
|
+
except (json.JSONDecodeError, TypeError):
|
|
89
|
+
input_data = {}
|
|
90
|
+
result = nd.handler(config or {}, input_data, node_outputs or {})
|
|
91
|
+
return json.dumps(result)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def create_app(base_url: str = ""):
|
|
95
|
+
"""Build a FastAPI app serving every registered node plus a discovery
|
|
96
|
+
manifest. `base_url` is prefixed to the endpoint URLs in the manifest."""
|
|
97
|
+
from fastapi import FastAPI, HTTPException
|
|
98
|
+
|
|
99
|
+
app = FastAPI(title="Trigix Custom Nodes")
|
|
100
|
+
|
|
101
|
+
@app.get("/healthz")
|
|
102
|
+
def healthz() -> dict[str, str]:
|
|
103
|
+
return {"status": "ok"}
|
|
104
|
+
|
|
105
|
+
@app.get("/manifest")
|
|
106
|
+
def manifest() -> dict[str, list[dict]]:
|
|
107
|
+
return {
|
|
108
|
+
"nodes": [
|
|
109
|
+
{
|
|
110
|
+
"slug": d.slug,
|
|
111
|
+
"label": d.label,
|
|
112
|
+
"description": d.description,
|
|
113
|
+
"config_schema": d.config_schema,
|
|
114
|
+
"endpoint": f"{base_url}/nodes/{d.slug}",
|
|
115
|
+
}
|
|
116
|
+
for d in _REGISTRY.values()
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@app.post("/nodes/{slug}")
|
|
121
|
+
def run(slug: str, req: NodeRequest) -> dict[str, str]:
|
|
122
|
+
if slug not in _REGISTRY:
|
|
123
|
+
raise HTTPException(status_code=404, detail=f"unknown node '{slug}'")
|
|
124
|
+
try:
|
|
125
|
+
return {"output_json": run_node(slug, req.config, req.input_json, req.node_outputs)}
|
|
126
|
+
except Exception as exc: # surface handler errors as 500
|
|
127
|
+
raise HTTPException(status_code=500, detail=f"node '{slug}' failed: {exc}") from exc
|
|
128
|
+
|
|
129
|
+
return app
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trigix-node-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Write and serve custom Trigix workflow nodes over HTTP.
|
|
5
|
+
Author-email: 北京祺智科技有限公司 <managecode@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/bj-qizhi/trigix
|
|
8
|
+
Project-URL: Repository, https://github.com/bj-qizhi/trigix
|
|
9
|
+
Project-URL: Documentation, https://github.com/bj-qizhi/trigix/tree/master/sdk/python
|
|
10
|
+
Keywords: trigix,workflow,automation,nodes,sdk,ai
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: fastapi>=0.115.0
|
|
22
|
+
Requires-Dist: pydantic>=2.0.0
|
|
23
|
+
Requires-Dist: uvicorn[standard]>=0.30.0
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest>=8.0.0; extra == "test"
|
|
26
|
+
Requires-Dist: httpx>=0.27.0; extra == "test"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# Trigix Node SDK (Python)
|
|
30
|
+
|
|
31
|
+
Write a custom Trigix workflow node as a Python function and serve it over HTTP.
|
|
32
|
+
No changes to the Trigix executor are required — the executor calls your node
|
|
33
|
+
like any other.
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install trigix-node-sdk
|
|
39
|
+
# or from this repo: pip install -e sdk/python
|
|
40
|
+
uvicorn examples.greeter:app --port 9000
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from trigix_node_sdk import node, create_app
|
|
45
|
+
|
|
46
|
+
@node(slug="greet", label="Greeter",
|
|
47
|
+
config_schema={"type": "object",
|
|
48
|
+
"properties": {"name": {"type": "string"}}})
|
|
49
|
+
def greet(config, input, node_outputs):
|
|
50
|
+
name = config.get("name") or input.get("name", "world")
|
|
51
|
+
return {"greeting": f"Hello, {name}!"}
|
|
52
|
+
|
|
53
|
+
app = create_app()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then in Trigix → **Custom Nodes**, register:
|
|
57
|
+
- **slug**: `greet`
|
|
58
|
+
- **endpoint**: `http://your-host:9000/nodes/greet`
|
|
59
|
+
- **config schema**: copy from `GET /manifest`
|
|
60
|
+
|
|
61
|
+
Add a **Custom** node to a workflow, pick `greet`, and it runs your code.
|
|
62
|
+
|
|
63
|
+
## The contract
|
|
64
|
+
|
|
65
|
+
The executor POSTs to `/nodes/<slug>`:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{ "node_id": "n1", "config": { "name": "Ada" },
|
|
69
|
+
"input_json": "{\"...\":\"...\"}", "node_outputs": { "prev": "{...}" } }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Your handler `def handler(config, input, node_outputs) -> dict` receives the
|
|
73
|
+
parsed `input` and returns a JSON-serializable dict. The server wraps it as:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{ "output_json": "{\"greeting\":\"Hello, Ada!\"}" }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Downstream nodes reference your output via `{{node_id.field}}`.
|
|
80
|
+
|
|
81
|
+
## Discovery
|
|
82
|
+
|
|
83
|
+
`GET /manifest` lists every registered node (slug, label, description,
|
|
84
|
+
config schema, endpoint) so it can be registered in Trigix in one step.
|
|
85
|
+
|
|
86
|
+
## Security
|
|
87
|
+
|
|
88
|
+
Custom nodes run in your own process, isolated from the Trigix core. Run the
|
|
89
|
+
node service on a trusted network; the executor reaches it by URL. (WASM-based
|
|
90
|
+
in-process isolation for untrusted nodes is a planned future option.)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
trigix_node_sdk/__init__.py,sha256=Bq-ohhkQl7hIa1Ff4L2TXe1gARmrM3qHYrcZKFGg32c,3903
|
|
2
|
+
trigix_node_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=axQOQXSu9vvvrE7ebNHet1xI7wHzWMF2UmTJ8LxtryQ,1087
|
|
3
|
+
trigix_node_sdk-0.1.0.dist-info/METADATA,sha256=MBXVU_nlwwQuL-Mnzi1i7rIpkAyGcuuGMrU-0Tng1Ng,2988
|
|
4
|
+
trigix_node_sdk-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
trigix_node_sdk-0.1.0.dist-info/top_level.txt,sha256=XFcKWFSoeh2MFa5a-Xa1f2cf6NOpHcN_XDp7WW-6Xss,16
|
|
6
|
+
trigix_node_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 北京祺智科技有限公司
|
|
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 @@
|
|
|
1
|
+
trigix_node_sdk
|