unique_toolkit 2026.48.0.dev8__py3-none-any.whl → 2026.48.0.dev10__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,17 @@
1
+ """Event model for Activity Records, mirroring ``@unique/activity-events-client``."""
2
+
3
+ from .schemas import (
4
+ ACTIVITY_METADATA_MAX_LENGTH,
5
+ ActivityActor,
6
+ ActivityAgent,
7
+ ActivityCloudEvent,
8
+ ActivityEventData,
9
+ )
10
+
11
+ __all__ = [
12
+ "ACTIVITY_METADATA_MAX_LENGTH",
13
+ "ActivityActor",
14
+ "ActivityAgent",
15
+ "ActivityCloudEvent",
16
+ "ActivityEventData",
17
+ ]
@@ -0,0 +1,132 @@
1
+ """Activity Records event model, mirroring the zod schema the service validates with: it
2
+ rejects a whole batch if one event fails. Extra keys are forbidden on every path. The
3
+ constructor and plain ``model_validate`` accept both the camelCase wire keys and the
4
+ Python field names (the toolkit convention); ``ActivityCloudEvent.from_wire`` accepts only
5
+ the wire keys, like zod. Experimental: the shape may still change."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from collections.abc import Mapping
10
+ from datetime import UTC, datetime
11
+ from typing import Annotated, Any, Final, Literal, Self
12
+ from uuid import UUID, uuid4
13
+
14
+ from pydantic import (
15
+ AfterValidator,
16
+ AwareDatetime,
17
+ BaseModel,
18
+ Field,
19
+ JsonValue,
20
+ StringConstraints,
21
+ field_serializer,
22
+ model_validator,
23
+ )
24
+
25
+ from unique_toolkit._common.pydantic_helpers import get_configuration_dict
26
+
27
+ ACTIVITY_METADATA_MAX_LENGTH: Final = {"identifier": 128, "ip": 64, "text": 256}
28
+
29
+ _model_config = get_configuration_dict(extra="forbid")
30
+ _NIL_UUID: Final = UUID(int=0)
31
+ _MAX_UUID: Final = UUID(int=2**128 - 1)
32
+
33
+
34
+ def _is_zod_uuid(value: UUID) -> UUID:
35
+ # zod's z.uuid(): versions 1 to 8 with the RFC variant, plus the nil and max UUIDs.
36
+ if value in (_NIL_UUID, _MAX_UUID) or (value.version or 0) in range(1, 9):
37
+ return value
38
+ raise ValueError("must be a UUID of version 1 to 8")
39
+
40
+
41
+ def _max_length(limit: int) -> AfterValidator:
42
+ # zod counts UTF-16 code units, Python counts code points.
43
+ def check(value: str) -> str:
44
+ if len(value.encode("utf-16-le", "surrogatepass")) > 2 * limit:
45
+ raise ValueError(f"must be at most {limit} characters")
46
+ return value
47
+
48
+ return AfterValidator(check)
49
+
50
+
51
+ _NonEmpty = Annotated[str, StringConstraints(strict=True, min_length=1)]
52
+ _Identifier = Annotated[
53
+ _NonEmpty, _max_length(ACTIVITY_METADATA_MAX_LENGTH["identifier"])
54
+ ]
55
+ _Ip = Annotated[_NonEmpty, _max_length(ACTIVITY_METADATA_MAX_LENGTH["ip"])]
56
+ _Text = Annotated[_NonEmpty, _max_length(ACTIVITY_METADATA_MAX_LENGTH["text"])]
57
+
58
+
59
+ class ActivityActor(BaseModel):
60
+ """Mirrors ``CloudEventActorSchema``."""
61
+
62
+ model_config = _model_config
63
+
64
+ id: _Identifier
65
+ type: Literal["user", "service"]
66
+ ip: _Ip | None = None
67
+
68
+
69
+ class ActivityAgent(BaseModel):
70
+ """Mirrors ``CloudEventAgentSchema``: the assistant or space the action ran in."""
71
+
72
+ model_config = _model_config
73
+
74
+ id: _Identifier
75
+
76
+
77
+ class ActivityEventData(BaseModel):
78
+ """Mirrors ``CloudEventDataSchema``."""
79
+
80
+ model_config = _model_config
81
+
82
+ actor: ActivityActor
83
+ agent: ActivityAgent | None = None
84
+ company_id: _NonEmpty
85
+ target_type: _Identifier | None = None
86
+ target_id: _Identifier | None = None
87
+ target_name: _Text | None = None
88
+ subtype: _Text | None = None
89
+ correlation_id: _Identifier | None = None
90
+ critical_data: dict[str, JsonValue] | None = None
91
+
92
+ @model_validator(mode="after")
93
+ def _target_set_together(self) -> ActivityEventData:
94
+ if (self.target_type is None) != (self.target_id is None):
95
+ raise ValueError("target_type and target_id must be set together")
96
+ return self
97
+
98
+
99
+ class ActivityCloudEvent(BaseModel):
100
+ """Mirrors ``CloudEventSchema``: the CloudEvents 1.0 envelope the ingest accepts.
101
+
102
+ Extra keys are always forbidden. The constructor and ``model_validate`` accept wire keys
103
+ and Python field names; ``from_wire`` is the strict wire check, used for stored payloads."""
104
+
105
+ model_config = _model_config
106
+
107
+ specversion: Literal["1.0"] = "1.0"
108
+ id: Annotated[UUID, AfterValidator(_is_zod_uuid)] = Field(default_factory=uuid4)
109
+ # "_" separates source and event id in the service's ``{source}_{id}`` record id.
110
+ source: Annotated[str, StringConstraints(strict=True, pattern=r"^[^:_]+$")]
111
+ type: _NonEmpty
112
+ time: AwareDatetime = Field(default_factory=lambda: datetime.now(UTC))
113
+ datacontenttype: Literal["application/json"] | None = "application/json"
114
+ data: ActivityEventData
115
+
116
+ @field_serializer("time")
117
+ def _serialize_time(self, value: datetime) -> str:
118
+ # Same shape as JS ``toISOString()``; the service schema rejects ``+00:00``.
119
+ return (
120
+ value.astimezone(UTC)
121
+ .isoformat(timespec="milliseconds")
122
+ .replace("+00:00", "Z")
123
+ )
124
+
125
+ @classmethod
126
+ def from_wire(cls, payload: Mapping[str, Any]) -> Self:
127
+ """Validate a wire dict like zod does: camelCase keys only, no Python field names."""
128
+ return cls.model_validate(payload, by_alias=True, by_name=False)
129
+
130
+ def to_wire(self) -> dict[str, Any]:
131
+ """JSON-ready dict in the camelCase wire format, without ``None`` fields."""
132
+ return self.model_dump(mode="json", by_alias=True, exclude_none=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: unique-toolkit
3
- Version: 2026.48.0.dev8
3
+ Version: 2026.48.0.dev10
4
4
  Summary:
5
5
  Author: Cedric Klinkert, Martin Fadler, Sadique Sheik, Fabian Schläpfer, Pascal Hauri, Ejiroghene Oki-Peter, Rami Azouz, Ricardo Visini, Sanzio Monti
6
6
  Author-email: Cedric Klinkert <cedric.klinkert@unique.ch>, Martin Fadler <martin.fadler@unique.ch>, Sadique Sheik <sadique@unique.ch>, Fabian Schläpfer <fabian@unique.ch>, Pascal Hauri <pascal@unique.ch>, Ejiroghene Oki-Peter <oki-peter.ejiroghene@unique.ai>, Rami Azouz <rami.ext@unique.ch>, Ricardo Visini <ricardo.visini@unique.ch>, Sanzio Monti <sanzio.monti@unique.ai>
@@ -16,7 +16,7 @@ Requires-Dist: sseclient>=0.0.27,<0.0.28
16
16
  Requires-Dist: openai>=1.105.0,<3
17
17
  Requires-Dist: platformdirs>=4.0.0,<5
18
18
  Requires-Dist: pillow>=13.0.0
19
- Requires-Dist: unique-sdk>=2026.48.0.dev5,<2026.48.0rc0
19
+ Requires-Dist: unique-sdk>=2026.48.0.dev8,<2026.48.0rc0
20
20
  Requires-Dist: jambo>=0.1.2,<0.2
21
21
  Requires-Dist: jinja2>=3.1.6,<4
22
22
  Requires-Dist: docxtpl>=0.20.1,<0.21
@@ -361,6 +361,8 @@ unique_toolkit/experimental/integrations/openai/streaming/event_routing/subscrib
361
361
  unique_toolkit/experimental/integrations/openai/streaming/event_routing/subscribers/message_persister.py,sha256=JVA0lcF3_WCYEUgWqX53gO5Lj7zR1iFCCuNXuWDPGbo,8930
362
362
  unique_toolkit/experimental/integrations/openai/streaming/event_routing/subscribers/progress_log_persister.py,sha256=VCYGZY3WSpI7mvVs2gO89-M0JenakW01BGfBfFkPDrw,3499
363
363
  unique_toolkit/experimental/resources/__init__.py,sha256=KdMPaaneY0twZ-JBfwImRjXZaWT68NVuOIeqdNXFh_Y,3377
364
+ unique_toolkit/experimental/resources/activity_records/__init__.py,sha256=QEvl-xjtN-5oQT6v1uPlKbnfJs5EHb4f7EDhOg6UyRU,375
365
+ unique_toolkit/experimental/resources/activity_records/schemas.py,sha256=l0AJLOR1Tj2ukRH3Kw06mVVFKEouHn6w05XToK47Go8,4728
364
366
  unique_toolkit/experimental/resources/content_folder/__init__.py,sha256=c5MUj1xIP10L7tcM4-hG2m1_yUMVfKr_jHAncUXVNvo,2492
365
367
  unique_toolkit/experimental/resources/content_folder/functions.py,sha256=nJle9Qnh-x1SLNetBBhTbQPu-zEBfQaHFnMq8N9RGEQ,16692
366
368
  unique_toolkit/experimental/resources/content_folder/schemas.py,sha256=LYWRpMLFVg_iKT9dw2AyCNfTPVmKeB8erMSsgbIkZ48,5345
@@ -435,6 +437,6 @@ unique_toolkit/short_term_memory/service.py,sha256=2JMBEBn6GoyK-a0xvdcWpPft-3C74
435
437
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
436
438
  unique_toolkit/smart_rules/compile.py,sha256=vRe0aMJWuVIK-VsqomgxQImzke7MDmwgSxxJfYCa7zw,1386
437
439
  unique_toolkit/test_utilities/events.py,sha256=FLrhMh0A_mQutAUjoD0FdMcVQ4Gq31r35OVGzRjvLro,6760
438
- unique_toolkit-2026.48.0.dev8.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
439
- unique_toolkit-2026.48.0.dev8.dist-info/METADATA,sha256=gxsLXECNy4VWoRvPkdPkWRZ_WG6rMPKdC2tYskBO2Ic,7821
440
- unique_toolkit-2026.48.0.dev8.dist-info/RECORD,,
440
+ unique_toolkit-2026.48.0.dev10.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
441
+ unique_toolkit-2026.48.0.dev10.dist-info/METADATA,sha256=KEfKeV7yvL6YZmLfI0Gd83eiPdnGfyUj_MIsLh5TgHQ,7822
442
+ unique_toolkit-2026.48.0.dev10.dist-info/RECORD,,