centive-sdk 2.2.0.dev5__py3-none-any.whl → 2.2.0.dev6__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.
- centive_sdk/models/requests.py +11 -0
- centive_sdk/resources/websocket_server.py +45 -2
- {centive_sdk-2.2.0.dev5.dist-info → centive_sdk-2.2.0.dev6.dist-info}/METADATA +1 -1
- {centive_sdk-2.2.0.dev5.dist-info → centive_sdk-2.2.0.dev6.dist-info}/RECORD +6 -6
- {centive_sdk-2.2.0.dev5.dist-info → centive_sdk-2.2.0.dev6.dist-info}/WHEEL +0 -0
- {centive_sdk-2.2.0.dev5.dist-info → centive_sdk-2.2.0.dev6.dist-info}/licenses/LICENSE +0 -0
centive_sdk/models/requests.py
CHANGED
|
@@ -20,6 +20,14 @@ class TriggerSessionRequest(BaseModel):
|
|
|
20
20
|
user_trigger: Optional[bool] = Field(
|
|
21
21
|
None, description="optional trigger to force session creation"
|
|
22
22
|
)
|
|
23
|
+
# The page the browser has open at the moment of the request. Centive builds
|
|
24
|
+
# the opening prompt from it instead of from stored page views, which travel
|
|
25
|
+
# through the telemetry batcher and were measured arriving 1.3 s after this
|
|
26
|
+
# call. Optional: an older browser SDK sends none, and the websocket server
|
|
27
|
+
# then falls back to the last page_view it saw on the connection.
|
|
28
|
+
current_page: Optional["TelemetryPage"] = Field(
|
|
29
|
+
None, description="page the browser reports having open when it asks for a session"
|
|
30
|
+
)
|
|
23
31
|
|
|
24
32
|
|
|
25
33
|
class SessionMessage(BaseModel):
|
|
@@ -107,6 +115,9 @@ class TelemetryPage(BaseModel):
|
|
|
107
115
|
referrer_path: Optional[str] = Field(default=None, max_length=TELEMETRY_MAX_PATH_CHARS)
|
|
108
116
|
|
|
109
117
|
|
|
118
|
+
TriggerSessionRequest.model_rebuild()
|
|
119
|
+
|
|
120
|
+
|
|
110
121
|
class TelemetryEvent(BaseModel):
|
|
111
122
|
"""one C1 event as produced by the browser SDK; forwarded to Centive unchanged."""
|
|
112
123
|
|
|
@@ -17,6 +17,7 @@ from ..models.requests import (
|
|
|
17
17
|
SessionMessage,
|
|
18
18
|
SessionMetadata,
|
|
19
19
|
TelemetryEvent,
|
|
20
|
+
TelemetryPage,
|
|
20
21
|
TriggerSessionRequest,
|
|
21
22
|
)
|
|
22
23
|
|
|
@@ -77,6 +78,10 @@ class WebSocketServer:
|
|
|
77
78
|
self._pending_users: Deque[str] = deque() # legacy "open" mode only
|
|
78
79
|
self._connection_tokens: Dict[str, Tuple[str, float]] = {} # token -> (user_id, expiry)
|
|
79
80
|
self._connection_users: Dict[WebSocketServerProtocol, str] = {}
|
|
81
|
+
# Last page_view seen on each connection, forwarded as trigger-session's
|
|
82
|
+
# current_page when the FE's user_trigger frame carries no page of its
|
|
83
|
+
# own (older browser SDKs). Bounded by the number of live connections.
|
|
84
|
+
self._connection_last_page: Dict[WebSocketServerProtocol, dict] = {}
|
|
80
85
|
# Every session key touched by a connection, so a disconnect saves all of
|
|
81
86
|
# them rather than only the most recent one.
|
|
82
87
|
self._connection_sessions: Dict[WebSocketServerProtocol, Set[str]] = {}
|
|
@@ -340,6 +345,7 @@ class WebSocketServer:
|
|
|
340
345
|
stale = [ws for ws in self._connection_users if not self._is_live(ws)]
|
|
341
346
|
for ws in stale:
|
|
342
347
|
self._connection_users.pop(ws, None)
|
|
348
|
+
self._connection_last_page.pop(ws, None)
|
|
343
349
|
self._clients.discard(ws)
|
|
344
350
|
|
|
345
351
|
return sum(1 for bound in self._connection_users.values() if bound == user_id)
|
|
@@ -592,6 +598,7 @@ class WebSocketServer:
|
|
|
592
598
|
# immediately after a drop).
|
|
593
599
|
self._clients.discard(websocket)
|
|
594
600
|
self._connection_users.pop(websocket, None)
|
|
601
|
+
self._connection_last_page.pop(websocket, None)
|
|
595
602
|
self._telemetry_rate.forget(websocket)
|
|
596
603
|
session_keys = self._connection_sessions.pop(websocket, set())
|
|
597
604
|
|
|
@@ -1033,6 +1040,8 @@ class WebSocketServer:
|
|
|
1033
1040
|
}))
|
|
1034
1041
|
return
|
|
1035
1042
|
|
|
1043
|
+
self._remember_page(websocket, data["events"])
|
|
1044
|
+
|
|
1036
1045
|
batcher_active = self._telemetry is not None and self._config.telemetry_enabled
|
|
1037
1046
|
enqueued = 0
|
|
1038
1047
|
queue_dropped = 0
|
|
@@ -1394,7 +1403,38 @@ class WebSocketServer:
|
|
|
1394
1403
|
return
|
|
1395
1404
|
|
|
1396
1405
|
user_trigger = data.get("user_trigger")
|
|
1397
|
-
|
|
1406
|
+
# The page the browser has open right now, so Centive's opening prompt
|
|
1407
|
+
# starts from it rather than from a page_view still waiting in the
|
|
1408
|
+
# batcher. The frame's own page wins; the last page_view seen on this
|
|
1409
|
+
# connection stands in for browser SDKs that predate the field.
|
|
1410
|
+
current_page = self._coerce_page(data.get("page")) or self._connection_last_page.get(websocket)
|
|
1411
|
+
await self._trigger_and_emit(
|
|
1412
|
+
websocket, user_id, user_trigger, client_info, current_page=current_page
|
|
1413
|
+
)
|
|
1414
|
+
|
|
1415
|
+
def _remember_page(self, websocket: WebSocketServerProtocol, events: Any) -> None:
|
|
1416
|
+
"""Keeps the newest page_view's page for this connection (see _handle_user_trigger)."""
|
|
1417
|
+
if not isinstance(events, list):
|
|
1418
|
+
return
|
|
1419
|
+
for event in reversed(events):
|
|
1420
|
+
if isinstance(event, dict) and event.get("event_type") == "page_view":
|
|
1421
|
+
page = self._coerce_page(event.get("page"))
|
|
1422
|
+
if page is not None:
|
|
1423
|
+
self._connection_last_page[websocket] = page
|
|
1424
|
+
return
|
|
1425
|
+
|
|
1426
|
+
@staticmethod
|
|
1427
|
+
def _coerce_page(value: Any) -> Optional[dict]:
|
|
1428
|
+
"""A C1 page object reduced to the fields Centive accepts, or None.
|
|
1429
|
+
|
|
1430
|
+
Never raises: a malformed hint must not cost the user their session.
|
|
1431
|
+
"""
|
|
1432
|
+
if not isinstance(value, dict):
|
|
1433
|
+
return None
|
|
1434
|
+
try:
|
|
1435
|
+
return TelemetryPage.model_validate(value).model_dump(exclude_none=True)
|
|
1436
|
+
except Exception:
|
|
1437
|
+
return None
|
|
1398
1438
|
|
|
1399
1439
|
async def _trigger_and_emit(
|
|
1400
1440
|
self,
|
|
@@ -1402,19 +1442,22 @@ class WebSocketServer:
|
|
|
1402
1442
|
user_id: str,
|
|
1403
1443
|
user_trigger: Optional[bool],
|
|
1404
1444
|
client_info: str,
|
|
1445
|
+
current_page: Optional[dict] = None,
|
|
1405
1446
|
) -> None:
|
|
1406
1447
|
"""calls trigger_session API and emits response to FE."""
|
|
1407
1448
|
safe_log(
|
|
1408
1449
|
self._logger,
|
|
1409
1450
|
"info",
|
|
1410
1451
|
"triggering session",
|
|
1411
|
-
{"client": client_info, "user_id": user_id, "user_trigger": user_trigger
|
|
1452
|
+
{"client": client_info, "user_id": user_id, "user_trigger": user_trigger,
|
|
1453
|
+
"has_page": current_page is not None},
|
|
1412
1454
|
)
|
|
1413
1455
|
|
|
1414
1456
|
try:
|
|
1415
1457
|
request = TriggerSessionRequest(
|
|
1416
1458
|
user_id=user_id,
|
|
1417
1459
|
user_trigger=user_trigger,
|
|
1460
|
+
current_page=current_page,
|
|
1418
1461
|
)
|
|
1419
1462
|
|
|
1420
1463
|
response = await self._sessions.trigger_session(request)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: centive-sdk
|
|
3
|
-
Version: 2.2.0.
|
|
3
|
+
Version: 2.2.0.dev6
|
|
4
4
|
Summary: Python SDK for Centive backend integration
|
|
5
5
|
Project-URL: Homepage, https://github.com/TheAgenticAI/centive-backend-sdk
|
|
6
6
|
Project-URL: Repository, https://github.com/TheAgenticAI/centive-backend-sdk
|
|
@@ -8,7 +8,7 @@ centive_sdk/config.py,sha256=HX0N7UCu9QLS5bICW_iME1LeBBG83Za2-cYoV-9VgLA,6187
|
|
|
8
8
|
centive_sdk/exceptions.py,sha256=wFy-hU0TJ0dHa6TEDI7FIQu9Lbg5aMeWxW9E-IMMUbI,1841
|
|
9
9
|
centive_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
centive_sdk/models/__init__.py,sha256=-ledNpbOi1Q14ELhvlDbGPF37N3yv5XJ-QsH2I6UMVQ,598
|
|
11
|
-
centive_sdk/models/requests.py,sha256=
|
|
11
|
+
centive_sdk/models/requests.py,sha256=_SqXf-8wejbAVQOMf6Lk3W0q3F3yu401mFvB8dMhwp4,7736
|
|
12
12
|
centive_sdk/models/responses.py,sha256=zCYPB0aL2DXn-z0Febkuxo3DdZ_5sdpdGy2Jtf8Ubs8,2519
|
|
13
13
|
centive_sdk/resources/__init__.py,sha256=GLutz38X4F4FwPfSZy35EkWTV7l7t9RgcBKwXmz2X_Y,179
|
|
14
14
|
centive_sdk/resources/async_sessions.py,sha256=m0_gj2wLabs3BTe6rZuo9WGgSwEMJLmdKW8_s4T7KRM,21500
|
|
@@ -16,8 +16,8 @@ centive_sdk/resources/async_telemetry.py,sha256=wT12g9rG2dp_ml5YpAYCxobLlhfcsyy-
|
|
|
16
16
|
centive_sdk/resources/message_accumulator.py,sha256=Or3sMGkXG9upeQ9sm8YWL_V5vvsxtnE9tu52VBUUGgY,19261
|
|
17
17
|
centive_sdk/resources/sessions.py,sha256=Ipg4bpmpejA5WoALbT49ah0c3I7x4OgPn9tSmfW8JAw,16741
|
|
18
18
|
centive_sdk/resources/telemetry_batcher.py,sha256=OkOv2Iir6E_9mdtAKvelol3RaveGSlH-ckIoE2cQYCc,14629
|
|
19
|
-
centive_sdk/resources/websocket_server.py,sha256=
|
|
20
|
-
centive_sdk-2.2.0.
|
|
21
|
-
centive_sdk-2.2.0.
|
|
22
|
-
centive_sdk-2.2.0.
|
|
23
|
-
centive_sdk-2.2.0.
|
|
19
|
+
centive_sdk/resources/websocket_server.py,sha256=fGOWxz4lvshGFnWFgf-euQYie6mZUohaniidnWA0KvI,61860
|
|
20
|
+
centive_sdk-2.2.0.dev6.dist-info/METADATA,sha256=YeBnZ3uGkNme6CG2LcZYKEgHprUp5O0b7XRjGwgYgF0,36427
|
|
21
|
+
centive_sdk-2.2.0.dev6.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
22
|
+
centive_sdk-2.2.0.dev6.dist-info/licenses/LICENSE,sha256=9dFibPr7z9srhWwd35lQL2MX1Kx2qivEZdVQb9L8Q-Q,1064
|
|
23
|
+
centive_sdk-2.2.0.dev6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|