Skip to navigation

lastActivity

View as MarkdownOpen in Claude

A static method that returns when a conversation last moved, so a browser can restore its idle clock after a reload. Without it a widget restarts the clock at zero: a tab closed for 55 minutes of a 60-minute timeout would wait another hour before warning, while the conversation ends in five.

The service stamps messages in microseconds; this converts to seconds. Every role counts, not only the ones visibleMessages() keeps, because the service’s idle clock moves on any write. Messages without a positive integer timestamp are skipped.

Parameters

messages
readonly unknown[] | null | undefinedRequired

Messages as log() returns them in messages.

Returns

number | null — epoch seconds of the newest dated message, or null when none is dated.

Examples

import { AIChatClient, ChatGateway } from '@signalwire/sdk';
const client = new AIChatClient({ space: 'your-space' });
const log = await client.log('chat-8f21');
const last = ChatGateway.lastActivity(log.messages);
if (last !== null) {
const idleSeconds = Date.now() / 1000 - last;
console.log(`Idle for ${Math.round(idleSeconds)} seconds`);
}