zyonix-model 0.1.13__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.
- zyonix_model/__init__.py +34 -0
- zyonix_model/attributes.py +113 -0
- zyonix_model/boundary.py +118 -0
- zyonix_model/redaction.py +562 -0
- zyonix_model/sanitize.py +191 -0
- zyonix_model/spec.py +324 -0
- zyonix_model/taxonomy.py +46 -0
- zyonix_model/trace.py +87 -0
- zyonix_model-0.1.13.dist-info/METADATA +31 -0
- zyonix_model-0.1.13.dist-info/RECORD +12 -0
- zyonix_model-0.1.13.dist-info/WHEEL +4 -0
- zyonix_model-0.1.13.dist-info/licenses/LICENSE +202 -0
zyonix_model/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Shared Zyonix data models used by the SDK, checks library, CLI and backend."""
|
|
2
|
+
|
|
3
|
+
from zyonix_model.spec import (
|
|
4
|
+
ErrorClass,
|
|
5
|
+
FailureClass,
|
|
6
|
+
FieldSpec,
|
|
7
|
+
FixHints,
|
|
8
|
+
InvariantSpec,
|
|
9
|
+
PipelineSpec,
|
|
10
|
+
PipelineStep,
|
|
11
|
+
PrivacySpec,
|
|
12
|
+
ReliabilitySpec,
|
|
13
|
+
RepairAllowList,
|
|
14
|
+
SchemaSpec,
|
|
15
|
+
SuccessCriterion,
|
|
16
|
+
)
|
|
17
|
+
from zyonix_model.taxonomy import RootCause, RootCauseModifier
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"ErrorClass",
|
|
21
|
+
"FailureClass",
|
|
22
|
+
"FieldSpec",
|
|
23
|
+
"FixHints",
|
|
24
|
+
"InvariantSpec",
|
|
25
|
+
"PipelineSpec",
|
|
26
|
+
"PipelineStep",
|
|
27
|
+
"PrivacySpec",
|
|
28
|
+
"ReliabilitySpec",
|
|
29
|
+
"RepairAllowList",
|
|
30
|
+
"RootCause",
|
|
31
|
+
"RootCauseModifier",
|
|
32
|
+
"SchemaSpec",
|
|
33
|
+
"SuccessCriterion",
|
|
34
|
+
]
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""`zyonix.*` span attribute names (Plan v1 §5.3, Appendix B), shared by the SDK and the backend."""
|
|
2
|
+
|
|
3
|
+
# Span kinds (zyonix.span.kind)
|
|
4
|
+
RUN = "RUN"
|
|
5
|
+
INGEST = "INGEST"
|
|
6
|
+
PARSE = "PARSE"
|
|
7
|
+
RETRIEVE = "RETRIEVE"
|
|
8
|
+
LLM = "LLM"
|
|
9
|
+
TOOL = "TOOL"
|
|
10
|
+
TRANSFORM = "TRANSFORM"
|
|
11
|
+
GUARD = "GUARD"
|
|
12
|
+
REPAIR = "REPAIR"
|
|
13
|
+
DELIVER = "DELIVER"
|
|
14
|
+
# a check the application evaluated and reported (zyonix.check / zyonix.flag): not a step
|
|
15
|
+
CHECK = "CHECK"
|
|
16
|
+
SPAN_KINDS = (RUN, INGEST, PARSE, RETRIEVE, LLM, TOOL, TRANSFORM, GUARD, REPAIR, DELIVER, CHECK)
|
|
17
|
+
STEP_KINDS = (INGEST, PARSE, RETRIEVE, LLM, TOOL, TRANSFORM, DELIVER)
|
|
18
|
+
|
|
19
|
+
SPAN_KIND = "zyonix.span.kind"
|
|
20
|
+
|
|
21
|
+
RUN_DOC_ID = "zyonix.run.doc_id"
|
|
22
|
+
RUN_DOC_NAME = "zyonix.run.doc_name" # the real file name: full capture only, admins only
|
|
23
|
+
RUN_SOURCE = "zyonix.run.source"
|
|
24
|
+
RUN_ORIGIN = "zyonix.run.origin" # live | import | doctor
|
|
25
|
+
RUN_SERVICE = "zyonix.run.service"
|
|
26
|
+
RUN_RELEASE = "zyonix.run.release"
|
|
27
|
+
RUN_DOC_FINGERPRINT = "zyonix.run.doc_fingerprint" # P2+
|
|
28
|
+
|
|
29
|
+
# Per-run monotonic counter stamped on every step span: orders steps exactly even when the
|
|
30
|
+
# platform clock is coarse (Windows ticks ~1 ms, so consecutive steps can share a timestamp).
|
|
31
|
+
SEQ = "zyonix.seq"
|
|
32
|
+
|
|
33
|
+
STEP_NAME = "zyonix.step.name"
|
|
34
|
+
STEP_VERSION = "zyonix.step.version"
|
|
35
|
+
STEP_REPLAYABLE = "zyonix.step.replayable"
|
|
36
|
+
STEP_FUNCTION = "zyonix.step.function" # module:qualname of the decorated function
|
|
37
|
+
# a TOOL step whose calls change something outside the process (send, save, pay): never run
|
|
38
|
+
# again by `zyonix test` / `zyonix replay` (the SDK refuses the call during a replay)
|
|
39
|
+
STEP_SIDE_EFFECTS = "zyonix.step.side_effects"
|
|
40
|
+
|
|
41
|
+
# Application-reported checks (CHECK spans). name / passed / severity are metadata; the
|
|
42
|
+
# detail is free text (content: redacted by the SDK, hashed in hash_only, scrubbed by retention)
|
|
43
|
+
CHECK_NAME = "zyonix.check.name"
|
|
44
|
+
CHECK_PASSED = "zyonix.check.passed"
|
|
45
|
+
CHECK_SEVERITY = "zyonix.check.severity"
|
|
46
|
+
CHECK_DETAIL = "zyonix.check.detail"
|
|
47
|
+
|
|
48
|
+
# Payloads. *.value carries the (client-redacted) body inline; the backend moves it to the
|
|
49
|
+
# blob store and keeps only *.ref (``sha256:<hex>``) on the stored span.
|
|
50
|
+
INPUT_VALUE = "zyonix.input.value"
|
|
51
|
+
INPUT_REF = "zyonix.input.ref"
|
|
52
|
+
INPUT_MIME = "zyonix.input.mime_type"
|
|
53
|
+
INPUT_SIZE = "zyonix.input.size"
|
|
54
|
+
INPUT_TRUNCATED = "zyonix.input.truncated"
|
|
55
|
+
OUTPUT_VALUE = "zyonix.output.value"
|
|
56
|
+
OUTPUT_REF = "zyonix.output.ref"
|
|
57
|
+
OUTPUT_MIME = "zyonix.output.mime_type"
|
|
58
|
+
OUTPUT_SIZE = "zyonix.output.size"
|
|
59
|
+
OUTPUT_TRUNCATED = "zyonix.output.truncated"
|
|
60
|
+
|
|
61
|
+
# Final structured record registered with zyonix.output() (on the RUN span).
|
|
62
|
+
RECORD_VALUE = "zyonix.record.value"
|
|
63
|
+
RECORD_REF = "zyonix.record.ref"
|
|
64
|
+
RECORD_SIZE = "zyonix.record.size"
|
|
65
|
+
RECORD_TRUNCATED = "zyonix.record.truncated"
|
|
66
|
+
SCHEMA_NAME = "zyonix.schema.name"
|
|
67
|
+
SCHEMA_VERSION = "zyonix.schema.version"
|
|
68
|
+
|
|
69
|
+
PROMPT_HASH = "zyonix.prompt.hash"
|
|
70
|
+
CONFIG_HASH = "zyonix.config.hash"
|
|
71
|
+
|
|
72
|
+
SDK_VERSION = "zyonix.sdk.version"
|
|
73
|
+
SDK_DROPPED_SPANS = "zyonix.sdk.dropped_spans"
|
|
74
|
+
# Attributes set by an instrumentor (not zyonix.* payloads) that the SDK cut to the size limits
|
|
75
|
+
# before export: a list of their keys.
|
|
76
|
+
SDK_TRUNCATED_ATTRIBUTES = "zyonix.sdk.truncated_attributes"
|
|
77
|
+
|
|
78
|
+
# OpenInference raw request/response bodies (``input.value`` / ``output.value``). The backend
|
|
79
|
+
# moves them to the blob store and keeps the ref; in ``hash_only`` capture the SDK sends only the
|
|
80
|
+
# ref and the size.
|
|
81
|
+
OI_INPUT_REF = "zyonix.oi.input.ref"
|
|
82
|
+
OI_OUTPUT_REF = "zyonix.oi.output.ref"
|
|
83
|
+
OI_INPUT_SIZE = "zyonix.oi.input.size"
|
|
84
|
+
OI_OUTPUT_SIZE = "zyonix.oi.output.size"
|
|
85
|
+
|
|
86
|
+
# Guard / repair (P5)
|
|
87
|
+
GUARD_MODE = "zyonix.guard.mode" # weakest mode in the repair chain: shadow | dry_run | on
|
|
88
|
+
GUARD_CHECKS_FAILED = "zyonix.guard.checks_failed" # JSON list of the raw output's failed checks
|
|
89
|
+
GUARD_CLASS = "zyonix.guard.failure_class" # provider | truncation | json | schema | invariant |
|
|
90
|
+
# refusal | grounding | upstream | error
|
|
91
|
+
GUARD_OUTCOME = "zyonix.guard.outcome" # repaired | original | escalated | skipped
|
|
92
|
+
GUARD_DELIVERED = "zyonix.guard.delivered" # repaired | original | held
|
|
93
|
+
GUARD_STRATEGIES = "zyonix.guard.strategies" # JSON list, in the order tried (or "would try")
|
|
94
|
+
GUARD_VERDICT = "zyonix.guard.verdict" # V-gate verdict of the last repair attempt
|
|
95
|
+
GUARD_EXTRA_CALLS = "zyonix.guard.extra_calls"
|
|
96
|
+
GUARD_DURATION_MS = "zyonix.guard.duration_ms"
|
|
97
|
+
GUARD_REASON = "zyonix.guard.reason" # why no repair ran / was delivered
|
|
98
|
+
GUARD_POLICY_VERSION = "zyonix.guard.policy_version"
|
|
99
|
+
GUARD_BREAKER = "zyonix.guard.breaker_open" # JSON list of strategies whose breaker is open
|
|
100
|
+
REPAIR_STRATEGY = "zyonix.repair.strategy"
|
|
101
|
+
REPAIR_ATTEMPT = "zyonix.repair.attempt"
|
|
102
|
+
REPAIR_VERDICT = "zyonix.repair.verdict"
|
|
103
|
+
REPAIR_VGATES = "zyonix.repair.vgates" # JSON of the V-gate report
|
|
104
|
+
REPAIR_DELIVERED = "zyonix.repair.delivered" # this attempt's output is what the pipeline got
|
|
105
|
+
# A REPAIR span carries the output before the repair as zyonix.input.* and after as
|
|
106
|
+
# zyonix.output.* (same payload mechanism as steps), so `zyonix runs show` can print the diff.
|
|
107
|
+
|
|
108
|
+
# (value attribute, ref attribute, size attribute) triples moved to blobs at ingest.
|
|
109
|
+
PAYLOAD_ATTRIBUTES = (
|
|
110
|
+
(INPUT_VALUE, INPUT_REF, INPUT_SIZE),
|
|
111
|
+
(OUTPUT_VALUE, OUTPUT_REF, OUTPUT_SIZE),
|
|
112
|
+
(RECORD_VALUE, RECORD_REF, RECORD_SIZE),
|
|
113
|
+
)
|
zyonix_model/boundary.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""The data boundary: may a Zyonix component send data to this address?
|
|
2
|
+
|
|
3
|
+
Zyonix keeps what it collects (documents, traces, prompts, completions, extracted values,
|
|
4
|
+
findings) inside the customer's environment. Every component that opens a connection of its own
|
|
5
|
+
accord asks this module first: the SDK and CLI before talking to the configured Zyonix endpoint,
|
|
6
|
+
the server before posting an alert to a webhook. One rule, shared, so the SDK, the CLI and the
|
|
7
|
+
server can never disagree about what "local" means.
|
|
8
|
+
|
|
9
|
+
**Local** (allowed without being named) is an address that, by its shape, cannot be on the public
|
|
10
|
+
internet:
|
|
11
|
+
|
|
12
|
+
- loopback: ``localhost``, ``*.localhost``, ``127.0.0.0/8``, ``::1``;
|
|
13
|
+
- a private or link-local IP literal: ``10/8``, ``172.16/12``, ``192.168/16``, ``169.254/16``,
|
|
14
|
+
``fc00::/7``, ``fe80::/10``;
|
|
15
|
+
- a name that public DNS never answers for: a single label (``api``, ``zyonix``: Compose service
|
|
16
|
+
names, intranet hosts) or one under ``.local``, ``.internal`` (``host.docker.internal``),
|
|
17
|
+
``.lan``, ``.home.arpa``, ``.localhost``, or the reserved ``.test`` / ``.example`` /
|
|
18
|
+
``.invalid`` top-level names (RFC 2606, RFC 6761; not ``example.com``, which is public).
|
|
19
|
+
|
|
20
|
+
Everything else is **external** and is allowed only when the operator lists the host
|
|
21
|
+
(``ZYONIX_EGRESS_ALLOW`` / ``egress_allow:``), or when local-only mode is switched off.
|
|
22
|
+
|
|
23
|
+
This is a test of the address's *shape*, made without DNS lookups (a lookup would itself be
|
|
24
|
+
traffic, and its answer can change). It is not a proof of ownership: a private address reached over
|
|
25
|
+
a VPN can belong to someone else, and a listed public name is trusted because the operator said
|
|
26
|
+
so. Carrier-grade NAT space (``100.64/10``) is external.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
import ipaddress
|
|
32
|
+
from dataclasses import dataclass
|
|
33
|
+
from urllib.parse import urlsplit
|
|
34
|
+
|
|
35
|
+
LOCAL_SUFFIXES = (".local", ".internal", ".lan", ".home.arpa", ".localhost", ".test",
|
|
36
|
+
".example", ".invalid")
|
|
37
|
+
_PRIVATE_V4 = tuple(ipaddress.ip_network(n) for n in (
|
|
38
|
+
"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "169.254.0.0/16", "127.0.0.0/8"))
|
|
39
|
+
_PRIVATE_V6 = tuple(ipaddress.ip_network(n) for n in ("fc00::/7", "fe80::/10", "::1/128"))
|
|
40
|
+
|
|
41
|
+
LOOPBACK, PRIVATE, LOCAL_NAME, EXTERNAL = "loopback", "private", "local_name", "external"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def host_of(url: str) -> str:
|
|
45
|
+
"""The lower-case host of a URL ('' when there is none or the URL cannot be parsed)."""
|
|
46
|
+
try:
|
|
47
|
+
return (urlsplit(url).hostname or "").lower().rstrip(".")
|
|
48
|
+
except ValueError:
|
|
49
|
+
return ""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def classify(host: str) -> str:
|
|
53
|
+
"""``loopback`` | ``private`` | ``local_name`` | ``external`` for a bare host name or IP."""
|
|
54
|
+
host = (host or "").strip().lower().rstrip(".").strip("[]")
|
|
55
|
+
if not host:
|
|
56
|
+
return EXTERNAL
|
|
57
|
+
try:
|
|
58
|
+
ip = ipaddress.ip_address(host)
|
|
59
|
+
except ValueError:
|
|
60
|
+
ip = None
|
|
61
|
+
if ip is not None:
|
|
62
|
+
if getattr(ip, "ipv4_mapped", None) is not None:
|
|
63
|
+
ip = ip.ipv4_mapped
|
|
64
|
+
if ip.is_loopback:
|
|
65
|
+
return LOOPBACK
|
|
66
|
+
nets = _PRIVATE_V4 if ip.version == 4 else _PRIVATE_V6
|
|
67
|
+
return PRIVATE if any(ip in n for n in nets) else EXTERNAL
|
|
68
|
+
if host == "localhost" or host.endswith(".localhost"):
|
|
69
|
+
return LOOPBACK
|
|
70
|
+
if "." not in host or host.endswith(LOCAL_SUFFIXES):
|
|
71
|
+
return LOCAL_NAME
|
|
72
|
+
return EXTERNAL
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def is_local(host: str) -> bool:
|
|
76
|
+
return classify(host) != EXTERNAL
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def parse_allow(value: str | list[str] | tuple[str, ...] | None) -> tuple[str, ...]:
|
|
80
|
+
"""Hosts from ``a.example.com, b.example.com`` (or a list); lower-case, no duplicates. Only
|
|
81
|
+
exact host names: no wildcards, schemes, ports or paths (a ``https://`` prefix is removed)."""
|
|
82
|
+
if not value:
|
|
83
|
+
return ()
|
|
84
|
+
items = value.split(",") if isinstance(value, str) else list(value)
|
|
85
|
+
out: list[str] = []
|
|
86
|
+
for item in items:
|
|
87
|
+
item = str(item).strip().lower()
|
|
88
|
+
if "://" in item:
|
|
89
|
+
item = host_of(item)
|
|
90
|
+
item = item.rstrip(".")
|
|
91
|
+
if item and item not in out:
|
|
92
|
+
out.append(item)
|
|
93
|
+
return tuple(out)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass(frozen=True)
|
|
97
|
+
class Decision:
|
|
98
|
+
allowed: bool
|
|
99
|
+
host: str
|
|
100
|
+
kind: str # loopback | private | local_name | external
|
|
101
|
+
reason: str # one line for logs and the operator; never contains the URL (it can be a secret)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def check(url: str, *, local_only: bool = True, allow: tuple[str, ...] = ()) -> Decision:
|
|
105
|
+
"""May a Zyonix component send data to ``url``? The reason names the host, never the URL."""
|
|
106
|
+
host = host_of(url)
|
|
107
|
+
kind = classify(host)
|
|
108
|
+
if not host:
|
|
109
|
+
return Decision(False, "", EXTERNAL, "the address has no host")
|
|
110
|
+
if kind != EXTERNAL:
|
|
111
|
+
return Decision(True, host, kind, f"{host} is {kind.replace('_', ' ')}")
|
|
112
|
+
if host in allow:
|
|
113
|
+
return Decision(True, host, kind, f"{host} is external and explicitly allowed")
|
|
114
|
+
if not local_only:
|
|
115
|
+
return Decision(True, host, kind, f"{host} is external; local-only mode is off")
|
|
116
|
+
return Decision(False, host, kind,
|
|
117
|
+
f"{host} is outside the local environment and not in ZYONIX_EGRESS_ALLOW "
|
|
118
|
+
"(local-only mode)")
|