Skip to content

Commit c3b8b58

Browse files
committed
Merge branch 'hotfix/initial_message_not_sent' of https://github.com/BESSER-PEARL/bot-framework into hotfix/initial_message_not_sent
2 parents 07a804c + ed499d1 commit c3b8b58

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

besser/agent/db/monitoring_db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ def select_chat(
453453
stmt = (select(table).where(
454454
table.c.session_id == int(session_entry['id'][0])
455455
))
456-
457456
if until_timestamp is not None:
458457
stmt = stmt.where(table.c.timestamp <= until_timestamp)
459458

besser/agent/platforms/websocket/streamlit_ui/message_input.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ def submit_text():
2323
st.write(user_input)
2424
message = Message(t=MessageType.STR, content=user_input, is_user=True, timestamp=datetime.now())
2525
st.session_state.history.append(message)
26-
if st.session_state.get("authenticated", False):
27-
payload = Payload(action=PayloadAction.USER_MESSAGE,
28-
message=user_input)
29-
else:
30-
payload = Payload(action=PayloadAction.USER_MESSAGE,
31-
message=user_input)
26+
payload = Payload(action=PayloadAction.USER_MESSAGE, message=user_input)
3227
try:
3328
ws = st.session_state[WEBSOCKET]
3429
ws.send(json.dumps(payload, cls=PayloadEncoder))

besser/agent/platforms/websocket/websocket_platform.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def _extract_user_id_from_request(request) -> str | None:
4545
if not value:
4646
continue
4747
if isinstance(value, bytes):
48-
value = value.decode("latin-1")
48+
# Prefer UTF-8 for URL paths; fall back to latin-1 to remain robust to non-UTF-8 bytes.
49+
try:
50+
value = value.decode("utf-8")
51+
except UnicodeDecodeError:
52+
value = value.decode("latin-1", errors="replace")
4953
query = urlsplit(value).query
5054
if not query:
5155
continue
@@ -125,8 +129,6 @@ def message_handler(conn: ServerConnection) -> None:
125129
headers = getattr(request, "headers", {}) if request else {}
126130
header_user = headers.get("X-User-ID") if hasattr(headers, "get") else None
127131
query_user = _extract_user_id_from_request(request)
128-
129-
130132
session_key = header_user or query_user or str(conn.id)
131133
self._connections[str(session_key)] = conn
132134
session = self._agent.get_or_create_session(session_key, self)

docs/source/wiki/platforms/websocket_platform.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ The WebSocket platform allows the following kinds of user messages:
130130

131131
Enabling persistent user sessions
132132
---------------------------------
133-
When building your own UI on top of the WebSocket API, implement user authentication so every connection can be tied to a stable identifier. BAF maps connections to sessions via the ``X-User-ID`` header or the ``user_id`` query parameter on the handshake URL; the header is used if both are supplied, otherwise the query parameter keeps the connection pinned to the authenticated user. If none of these identifiers is available, the platform falls back to treating the connection as a new anonymous user.
133+
When building your own UI on top of the WebSocket API, implement user authentication so every connection can be tied to a stable identifier. BAF maps connections to sessions using either the ``X-User-ID`` header or the ``user_id`` query parameter from the handshake URL. If both are provided, the header takes precedence. If neither identifier is available, the platform treats the connection as a new anonymous user.
134134

135135
Once your client authenticates users, include the identifier in the WebSocket handshake headers:
136136

0 commit comments

Comments
 (0)