last_activity

View as MarkdownOpen in Claude

Epoch seconds of the newest message, or None when nothing is dated. A static method.

This bootstraps a browser’s idle clock across a reload. Without it a widget restarts the clock at zero on load, so a tab closed for 55 minutes of a 60-minute timeout would wait another full hour before warning, while the conversation actually dies in five.

Every role counts, not just the visible ones. The service’s idle clock runs off the conversation’s own last write, so filtering to user and assistant would report an older time than the service is measuring and warn early for no reason. Call this before visible_messages(), which strips timestamps.

Parameters

messages
list[dict[str, Any]] | NoneRequired

The raw messages, as returned by AIChatClient.log().

Returns

float | None — epoch seconds of the newest message, converted from the microseconds the service stores. None when no message carries a timestamp.

Example

1import time
2
3from signalwire.ai_chat import AIChatClient, ChatGateway
4
5gateway = ChatGateway(config_url="https://bayview-taxi.example.com/swml")
6
7
8async def idle_seconds_left(client: AIChatClient, conversation_id: str) -> float | None:
9 conversation = await client.log(conversation_id)
10 last = ChatGateway.last_activity(conversation.messages)
11 if last is None:
12 return None
13 return gateway.effective_timeout - (time.time() - last)