Message queueing
Send-while-streaming without ever throwing
Prompting a busy session never throws — the turn is queued and starts when its predecessors settle:
const first = session.prompt("run the tests");
const followUp = session.prompt("now fix whatever failed"); // queued, runs nextEverything a send-while-streaming input box needs:
turn.queuedevents — emitted with a 1-basedpositionwhen a prompt lands in the queue.session.queuedTurns— the current queue as{ turnId, input }[].session.cancelQueued(turnId)— remove a queued turn; returnsfalseif it already started.turn.interrupt()on a queued turn — cancels just that turn (its promise rejects with codeQUEUE_CANCELED).session.interrupt()— stops the running turn; the queue then advances.
session.on("turn.queued", ({ turnId, position }) => {
ui.showQueuedChip(turnId, position);
});
// user hits ✕ on a queued message:
session.cancelQueued(turnId);Closing the session settles everything: the active turn resolves as interrupted and queued turns reject with "session closed before turn started".