// What AparteClient does for you during a turn, by hand: open a message, append its
// tokens as they arrive, then complete it.
const viewport = document.querySelector('aparte-chat-viewport');
viewport.appendMessage({ id: 'u1', role: 'user', content: 'Explain the transports in one paragraph.', timestamp: Date.now() });
viewport.appendMessage({ id: 'a1', role: 'assistant', content: '', isStreaming: true, timestamp: Date.now() });
const words = 'A transport is the object that talks to the model. The direct one sends the request from the browser, the backend one sends it to your server, which holds the key. Both stream the same events, so the chat cannot tell them apart.'.split(' ');
let i = 0;
const tick = setInterval(() => {
viewport.appendToken('a1', (i ? ' ' : '') + words[i++]);
if (i === words.length) { clearInterval(tick); viewport.completeMessage('a1'); }
}, 90);